node/lib/metasm/metasm/exe_format/coff_encode.rb
def arch_encode_thunk(edata, import)
		case @cpu.shortname
		when 'ia32', 'x64'
			shellcode = lambda { |c| Shellcode.new(@cpu).share_namespace(self).assemble(c).encoded }
			if @cpu.generate_PIC
				if @cpu.shortname == 'x64'
					edata << shellcode["#{import.thunk}: jmp [rip-$_+#{import.target}]"]
					return
				end
				# sections starts with a helper function that returns the address of metasm_intern_geteip in eax (PIC)
				if not @sections.find { |s| s.encoded and s.encoded.export['metasm_intern_geteip'] } and edata.empty?
					edata << shellcode["metasm_intern_geteip: call 42f\n42:\npop eax\nsub eax, 42b-metasm_intern_geteip\nret"]
				end
				edata << shellcode["#{import.thunk}: call metasm_intern_geteip\njmp [eax+#{import.target}-metasm_intern_geteip]"]
			else
				edata << shellcode["#{import.thunk}: jmp [#{import.target}]"]
			end
		else raise EncodeError, 'E: COFF: encode import thunk: unsupported architecture'
		end
	end
# encodes a thunk to imported function
encodes a thunk to imported function
encodes a thunk to imported function
def arch_encode_thunk(edata, import)
		case @cpu.shortname
		when 'ia32', 'x64'
			shellcode = lambda { |c| Shellcode.new(@cpu).share_namespace(self).assemble(c).encoded }
			if @cpu.generate_PIC
				if @cpu.shortname == 'x64'
					edata << shellcode["#{import.thunk}: jmp [rip-$_+#{import.target}]"]
					return
				end
				if not @sections.find { |s| s.encoded and s.encoded.export['metasm_intern_geteip'] } and edata.empty?
					edata << shellcode["metasm_intern_geteip: call 42f\n42:\npop eax\nsub eax, 42b-metasm_intern_geteip\nret"]
				end
				edata << shellcode["#{import.thunk}: call metasm_intern_geteip\njmp [eax+#{import.target}-metasm_intern_geteip]"]
			else
				edata << shellcode["#{import.thunk}: jmp [#{import.target}]"]
			end
		else raise EncodeError, 'E: COFF: encode import thunk: unsupported architecture'
		end
	end
def arch_encode_thunk ( edata , import ) case @cpu . shortname when 'ia32' , 'x64' shellcode = lambda { | c | Shellcode . new ( @cpu ) . share_namespace ( self ) . assemble ( c ) . encoded } if @cpu . generate_PIC if @cpu . shortname == 'x64' edata << shellcode [ "#{import.thunk}: jmp [rip-$_+#{import.target}]" ] return end if not @sections . find { | s | s . encoded and s . encoded . export [ 'metasm_intern_geteip' ] } and edata . empty? edata << shellcode [ "metasm_intern_geteip: call 42f\n42:\npop eax\nsub eax, 42b-metasm_intern_geteip\nret" ] end edata << shellcode [ "#{import.thunk}: call metasm_intern_geteip\njmp [eax+#{import.target}-metasm_intern_geteip]" ] else edata << shellcode [ "#{import.thunk}: jmp [#{import.target}]" ] end else raise EncodeError , 'E: COFF: encode import thunk: unsupported architecture' end end
encodes a thunk to imported function
encodes a thunk to imported function
# sections starts with a helper function that returns the address of metasm_intern_geteip in eax (PIC)
edata
import