node/lib/metasm/metasm/exe_format/coff_encode.rb
def encode(coff, edata)
			edata['iat'] << EncodedData.new
			# edata['ilt'] = edata['iat']
			label = lambda { |n| coff.label_at(edata[n], 0, n) }
			rva_end = lambda { |n| Expression[[label[n], :-, coff.label_at(coff.encoded, 0)], :+, edata[n].virtsize] }

			@libname_p = rva_end['nametable']
			@ilt_p = rva_end['ilt']
			@iat_p ||= Expression[coff.label_at(edata['iat'].last, 0, 'iat'), :-, coff.label_at(coff.encoded, 0)]
			edata['idata'] << super(coff)

			edata['nametable'] << @libname << 0

			ord_mask = 1 << (coff.bitsize - 1)
			@imports.each { |i|
				edata['iat'].last.add_export i.target, edata['iat'].last.virtsize if i.target
				if i.ordinal
					ptr = coff.encode_xword(Expression[i.ordinal, :|, ord_mask])
				else
					edata['nametable'].align 2
					ptr = coff.encode_xword(rva_end['nametable'])
					edata['nametable'] << coff.encode_half(i.hint || 0) << i.name << 0
				end
				edata['ilt'] << ptr
				edata['iat'].last << ptr
			}
			edata['ilt'] << coff.encode_xword(0)
			edata['iat'].last << coff.encode_xword(0)
		end
# encode one import directory + iat + names in the edata hash received as arg
encode one import directory + iat + names in the edata hash received as arg
encode one import directory + iat + names in the edata hash received as arg
def encode(coff, edata)
			edata['iat'] << EncodedData.new
			label = lambda { |n| coff.label_at(edata[n], 0, n) }
			rva_end = lambda { |n| Expression[[label[n], :-, coff.label_at(coff.encoded, 0)], :+, edata[n].virtsize] }
			@libname_p = rva_end['nametable']
			@ilt_p = rva_end['ilt']
			@iat_p ||= Expression[coff.label_at(edata['iat'].last, 0, 'iat'), :-, coff.label_at(coff.encoded, 0)]
			edata['idata'] << super(coff)
			edata['nametable'] << @libname << 0
			ord_mask = 1 << (coff.bitsize - 1)
			@imports.each { |i|
				edata['iat'].last.add_export i.target, edata['iat'].last.virtsize if i.target
				if i.ordinal
					ptr = coff.encode_xword(Expression[i.ordinal, :|, ord_mask])
				else
					edata['nametable'].align 2
					ptr = coff.encode_xword(rva_end['nametable'])
					edata['nametable'] << coff.encode_half(i.hint || 0) << i.name << 0
				end
				edata['ilt'] << ptr
				edata['iat'].last << ptr
			}
			edata['ilt'] << coff.encode_xword(0)
			edata['iat'].last << coff.encode_xword(0)
		end
def encode ( coff , edata ) edata [ 'iat' ] << EncodedData . new label = lambda { | n | coff . label_at ( edata [ n ] , 0 , n ) } rva_end = lambda { | n | Expression [ [ label [ n ] , :- , coff . label_at ( coff . encoded , 0 ) ] , :+ , edata [ n ] . virtsize ] } @libname_p = rva_end [ 'nametable' ] @ilt_p = rva_end [ 'ilt' ] @iat_p ||= Expression [ coff . label_at ( edata [ 'iat' ] . last , 0 , 'iat' ) , :- , coff . label_at ( coff . encoded , 0 ) ] edata [ 'idata' ] << super ( coff ) edata [ 'nametable' ] << @libname << 0 ord_mask = 1 << ( coff . bitsize - 1 ) @imports . each { | i | edata [ 'iat' ] . last . add_export i . target , edata [ 'iat' ] . last . virtsize if i . target if i . ordinal ptr = coff . encode_xword ( Expression [ i . ordinal , :| , ord_mask ] ) else edata [ 'nametable' ] . align 2 ptr = coff . encode_xword ( rva_end [ 'nametable' ] ) edata [ 'nametable' ] << coff . encode_half ( i . hint || 0 ) << i . name << 0 end edata [ 'ilt' ] << ptr edata [ 'iat' ] . last << ptr } edata [ 'ilt' ] << coff . encode_xword ( 0 ) edata [ 'iat' ] . last << coff . encode_xword ( 0 ) end
encode one import directory + iat + names in the edata hash received as arg
encode one import directory + iat + names in the edata hash received as arg
# edata['ilt'] = edata['iat']
coff
edata