class Metasm::MZ::Header

Public Instance Methods

decode(mz) click to toggle source
Calls superclass method Metasm::SerialStruct#decode
# File metasm/exe_format/mz.rb, line 40
def decode(mz)
        super(mz)
        raise InvalidExeFormat, "Invalid MZ signature #{h.magic.inspect}" if @magic != MAGIC
end
encode(mz, relocs) click to toggle source
Calls superclass method Metasm::SerialStruct#encode
# File metasm/exe_format/mz.rb, line 20
def encode(mz, relocs)
        h = EncodedData.new
        set_default_values mz, h, relocs
        h << super(mz)
end
set_default_values(mz, h=nil, relocs=nil) click to toggle source
Calls superclass method Metasm::SerialStruct#set_default_values
# File metasm/exe_format/mz.rb, line 26
def set_default_values(mz, h=nil, relocs=nil)
        return if not h
        @cblp     ||= Expression[[mz.label_at(mz.body, mz.body.virtsize), :-, mz.label_at(h, 0)], :%, 512]   # number of bytes used in last page
        @cp       ||= Expression[[mz.label_at(mz.body, mz.body.virtsize), :-, mz.label_at(h, 0)], :/, 512]   # number of pages used
        @crlc     ||= relocs.virtsize/4
        @cparhdr  ||= Expression[[mz.label_at(relocs, 0), :-, mz.label_at(h, 0)], :/, 16]    # header size in paragraphs (16o)
        @minalloc ||= ((mz.body.virtsize - mz.body.rawsize) + 15) / 16
        @maxalloc ||= @minalloc
        @sp       ||= 0              # ss:sp points at 1st byte of body => works if body does not reach end of segment (or maybe the overflow make the stack go to header space)
        @lfarlc   ||= Expression[mz.label_at(relocs, 0), :-, mz.label_at(h, 0)]

        super(mz)
end