class Metasm::XCoff

Constants

FLAGS
SECTION_FLAGS

Attributes

endianness[RW]
header[RW]
intsize[RW]
relocs[RW]
segments[RW]

Public Class Methods

new(cpu=nil) click to toggle source
Calls superclass method Metasm::ExeFormat::new
# File metasm/exe_format/xcoff.rb, line 112
def initialize(cpu=nil)
        @header = Header.new
        @sections = []
        if @cpu
                @intsize = @cpu.size
                @endianness = @cpu.endianness
        else
                @intsize = 32
                @endianness = :little
        end
        super(cpu)
end

Public Instance Methods

decode() click to toggle source
# File metasm/exe_format/xcoff.rb, line 134
def decode
        decode_header
        @sections.each { |s| s.encoded = @encoded[s.scnptr, s.size] }
end
decode_half( edata = @encoded) click to toggle source

basic immediates decoding functions

# File metasm/exe_format/xcoff.rb, line 96
def decode_half( edata = @encoded) edata.decode_imm(:u16, @endianness) end
decode_header(off = 0) click to toggle source
# File metasm/exe_format/xcoff.rb, line 125
def decode_header(off = 0)
        @encoded.ptr = off
        @header.decode(self)
        if @header.opthdr != 0
                @optheader = OptHeader.decode(self)
        end
        @header.nsec.times { @sections << Section.decode(self) }
end
decode_word( edata = @encoded) click to toggle source
# File metasm/exe_format/xcoff.rb, line 97
def decode_word( edata = @encoded) edata.decode_imm(:u32, @endianness) end
decode_xhalf(edata = @encoded) click to toggle source
# File metasm/exe_format/xcoff.rb, line 98
def decode_xhalf(edata = @encoded) edata.decode_imm((@intsize == 32 ? :u16 : :u32), @endianness) end
decode_xword(edata = @encoded) click to toggle source
# File metasm/exe_format/xcoff.rb, line 99
def decode_xword(edata = @encoded) edata.decode_imm((@intsize == 32 ? :u32 : :u64), @endianness) end
encode() click to toggle source
# File metasm/exe_format/xcoff.rb, line 139
def encode
        @encoded = EncodedData.new
        @encoded << @header.encode(self)
        @encoded << @optheader.encode(self) if @optheader
        @sections.each { |s| @encoded << s.encode(self) }
        va = @encoded.size
        binding = {}
        @sections.each { |s|
                if s.scnptr.kind_of? ::String
                        binding[s.scnptr] = @encoded.size
                else
                        raise 'scnptr too low' if @encoded.virtsize > s.scnptr
                        @encoded.virtsize = s.scnptr
                end
                va = (va + 4096 - 1)/4096*4096
                if s.vaddr.kind_of? ::String
                        binding[s.vaddr] = va
                else
                        va = s.vaddr
                end
                binding.update s.encoded.binding(va)
                va += s.encoded.size
                @encoded << s.encoded
        }
        @encoded.fixup!(binding)
        @encoded.data
end
encode_half(w) click to toggle source
# File metasm/exe_format/xcoff.rb, line 100
def encode_half(w)  Expression[w].encode(:u16, @endianness) end
encode_word(w) click to toggle source
# File metasm/exe_format/xcoff.rb, line 101
def encode_word(w)  Expression[w].encode(:u32, @endianness) end
encode_xhalf(w) click to toggle source
# File metasm/exe_format/xcoff.rb, line 102
def encode_xhalf(w) Expression[w].encode((@intsize == 32 ? :u16 : :u32), @endianness) end
encode_xword(w) click to toggle source
# File metasm/exe_format/xcoff.rb, line 103
def encode_xword(w) Expression[w].encode((@intsize == 32 ? :u32 : :u64), @endianness) end
sizeof_half() click to toggle source
# File metasm/exe_format/xcoff.rb, line 104
def sizeof_half ; 2 ; end
sizeof_word() click to toggle source
# File metasm/exe_format/xcoff.rb, line 105
def sizeof_word ; 4 ; end
sizeof_xhalf() click to toggle source
# File metasm/exe_format/xcoff.rb, line 106
def sizeof_xhalf ; @intsize == 32 ? 2 : 4 ; end
sizeof_xword() click to toggle source
# File metasm/exe_format/xcoff.rb, line 107
def sizeof_xword ; @intsize == 32 ? 4 : 8 ; end