assemble(*a)
click to toggle source
def assemble(*a)
parse(*a) if not a.empty?
@text << assemble_sequence(@textsrc, @cpu)
@textsrc.clear
@data << assemble_sequence(@datasrc, @cpu)
@datasrc.clear
self
end
decode()
click to toggle source
def decode
decode_header
tlen = @header.text
case @header.magic
when 'ZMAGIC'; @encoded.ptr = 1024
when 'QMAGIC'; tlen -= 32
end
@text = EncodedData.new << @encoded.read(tlen)
@data = EncodedData.new << @encoded.read(@header.data)
end
decode_byte(edata = @encoded)
click to toggle source
def decode_byte(edata = @encoded) edata.decode_imm(:u8 , @endianness) end
decode_half(edata = @encoded)
click to toggle source
def decode_half(edata = @encoded) edata.decode_imm(:u16, @endianness) end
decode_word(edata = @encoded)
click to toggle source
def decode_word(edata = @encoded) edata.decode_imm(:u32, @endianness) end
each_section() { |text, tva| ... }
click to toggle source
def each_section
tva = 0
tva = 4096+32 if @header.magic == 'QMAGIC'
yield @text, tva
yield @data, tva + @text.virtsize
end
encode()
click to toggle source
def encode
raise EncodeError, 'cannot encode non-QMAGIC a.out' if @header.magic and @header.magic != 'QMAGIC'
@text.virtsize = (@text.virtsize + 32 + 4096 - 1) / 4096 * 4096 - 32
if @data.rawsize % 4096 != 0
@data[(@data.rawsize + 4096 - 1) / 4096 * 4096 - 1] = 0
end
@header.text = @text.length+32
@header.data = @data.rawsize
@header.bss = @data.virtsize - @data.rawsize
@encoded = EncodedData.new
@encoded << @header.encode(self)
binding = @text.binding(4096+32).merge @data.binding(4096 + @header.text)
@encoded << @text << @data
@encoded.fixup! binding
@encoded.data
end
encode_byte(w)
click to toggle source
def encode_byte(w) Expression[w].encode(:u8 , @endianness) end
encode_half(w)
click to toggle source
def encode_half(w) Expression[w].encode(:u16, @endianness) end
encode_word(w)
click to toggle source
def encode_word(w) Expression[w].encode(:u32, @endianness) end
parse_init()
click to toggle source
def parse_init
@textsrc ||= []
@datasrc ||= []
@cursource ||= @textsrc
super()
end
parse_parser_instruction(instr)
click to toggle source
def parse_parser_instruction(instr)
case instr.raw.downcase
when '.text'; @cursource = @textsrc
when '.data'; @cursource = @datasrc
when '.entrypoint'
@lexer.skip_space
if tok = @lexer.nexttok and tok.type == :string
raise instr if not entrypoint = Expression.parse(@lexer)
else
entrypoint = new_label('entrypoint')
@cursource << Label.new(entrypoint, instr.backtrace.dup)
end
@header.entry = entrypoint
else super(instr)
end
end
sizeof_byte()
click to toggle source
def sizeof_byte ; 1 ; end
sizeof_half()
click to toggle source
def sizeof_half ; 2 ; end
sizeof_word()
click to toggle source
def sizeof_word ; 4 ; end