node/lib/metasm/metasm/exe_format/pe.rb
def encode_default_mz_header
		# XXX use single-quoted source, to avoid ruby interpretation of \r\n
		@mz.cpu = Ia32.new(386, 16)
		@mz.assemble <<'EOMZSTUB'
	db "Needs Win32!\r\n$"
.entrypoint
	push cs
	pop  ds
	xor  dx, dx	  ; ds:dx = addr of $-terminated string
	mov  ah, 9        ; output string
	int  21h
	mov  ax, 4c01h    ; exit with code in al
	int  21h
EOMZSTUB

		mzparts = @mz.pre_encode

		# put stuff before 0x3c
		@mz.encoded << mzparts.shift
		raise 'OH NOES !!1!!!1!' if @mz.encoded.virtsize > 0x3c	# MZ header is too long, cannot happen
		until mzparts.empty?
			break if mzparts.first.virtsize + @mz.encoded.virtsize > 0x3c
			@mz.encoded << mzparts.shift
		end

		# set PE signature pointer
		@mz.encoded.align 0x3c
		@mz.encoded << encode_word('pesigptr')

		# put last parts of the MZ program
		until mzparts.empty?
			@mz.encoded << mzparts.shift
		end

		# ensure the sig will be 8bytes-aligned
		@mz.encoded.align 8

		@mz.encoded.fixup 'pesigptr' => @mz.encoded.virtsize
		@mz.encoded.fixup @mz.encoded.binding
		@mz.encoded.fill
		@mz.encode_fix_checksum
	end
# creates a default MZ file to be used in the PE header
# this one is specially crafted to fit in the 0x3c bytes before the signature
creates a default MZ file to be used in the PE header
this one is specially crafted to fit in the 0x3c bytes before the signature
creates a default MZ file to be used in the PE header this one is specially crafted to fit in the 0x3c bytes before the signature
def encode_default_mz_header
		@mz.cpu = Ia32.new(386, 16)
		@mz.assemble <<'EOMZSTUB'
	db "Needs Win32!\r\n$"
.entrypoint
	push cs
	pop  ds
	xor  dx, dx	  ; ds:dx = addr of $-terminated string
	mov  ah, 9        ; output string
	int  21h
	mov  ax, 4c01h    ; exit with code in al
	int  21h
EOMZSTUB
		mzparts = @mz.pre_encode
		@mz.encoded << mzparts.shift
		raise 'OH NOES !!1!!!1!' if @mz.encoded.virtsize > 0x3c	
		until mzparts.empty?
			break if mzparts.first.virtsize + @mz.encoded.virtsize > 0x3c
			@mz.encoded << mzparts.shift
		end
		@mz.encoded.align 0x3c
		@mz.encoded << encode_word('pesigptr')
		until mzparts.empty?
			@mz.encoded << mzparts.shift
		end
		@mz.encoded.align 8
		@mz.encoded.fixup 'pesigptr' => @mz.encoded.virtsize
		@mz.encoded.fixup @mz.encoded.binding
		@mz.encoded.fill
		@mz.encode_fix_checksum
	end
def encode_default_mz_header @mz . cpu = Ia32 . new ( 386 , 16 ) @mz . assemble <<'EOMZSTUB' 
	db "Needs Win32!\r\n$"
.entrypoint
	push cs
	pop  ds
	xor  dx, dx	  ; ds:dx = addr of $-terminated string
	mov  ah, 9        ; output string
	int  21h
	mov  ax, 4c01h    ; exit with code in al
	int  21h
 EOMZSTUB mzparts = @mz . pre_encode @mz . encoded << mzparts . shift raise 'OH NOES !!1!!!1!' if @mz . encoded . virtsize > 0x3c until mzparts . empty? break if mzparts . first . virtsize + @mz . encoded . virtsize > 0x3c @mz . encoded << mzparts . shift end @mz . encoded . align 0x3c @mz . encoded << encode_word ( 'pesigptr' ) until mzparts . empty? @mz . encoded << mzparts . shift end @mz . encoded . align 8 @mz . encoded . fixup 'pesigptr' => @mz . encoded . virtsize @mz . encoded . fixup @mz . encoded . binding @mz . encoded . fill @mz . encode_fix_checksum end
creates a default MZ file to be used in the PE header
this one is specially crafted to fit in the 0x3c bytes before the signature
creates a default MZ file to be used in the PE header this one is specially crafted to fit in the 0x3c bytes before the signature
# XXX use single-quoted source, to avoid ruby interpretation of \r\n # put stuff before 0x3c # MZ header is too long, cannot happen # set PE signature pointer # put last parts of the MZ program # ensure the sig will be 8bytes-aligned