class Metasm::SWF::Rectangle

Public Instance Methods

decode(swf) click to toggle source
# File metasm/exe_format/swf.rb, line 47
def decode(swf)
        byte = swf.decode_u8
        bleft = 3
        @nbits = byte >> bleft
        @xmin, @xmax, @ymin, @ymax = (0..3).map {
                nb = @nbits
                v = 0
                while nb > bleft
                        nb -= bleft
                        v |= (byte & ((1<<bleft)-1)) << nb

                        bleft = 8
                        byte = swf.decode_u8
                end
                v |= (byte >> (bleft-nb)) & ((1<<nb)-1)
                bleft -= nb

                Expression.make_signed(v, @nbits)
        }
end
encode(swf) click to toggle source
Calls superclass method Metasm::SerialStruct#encode
# File metasm/exe_format/swf.rb, line 86
def encode(swf)
        ed = super(swf)

        byte = @nbits << 3
        bleft = 3
        [@xmin, @xmax, @ymin, @ymax].each { |v|
                nb = @nbits
                while nb > bleft
                        byte |= (v >> (nb-bleft)) & ((1<<bleft)-1)
                        nb -= bleft

                        ed << byte
                        byte = 0
                        bleft = 8
                end
                byte |= (v & ((1<<nb)-1)) << (bleft-nb)
                bleft -= nb
        }
        ed << byte if bleft < 8

        ed
end
set_default_values(swf) click to toggle source
# File metasm/exe_format/swf.rb, line 68
def set_default_values(swf)
        @xmin ||= 0
        @xmax ||= 31
        @ymin ||= 0
        @ymax ||= 31
        @nbits = (0..30).find { |nb|
                [@xmin, @xmax, @ymin, @ymax].all? { |v|
                        if nb == 0
                                v == 0
                        elsif v >= 0
                                # reserve sign bit
                                (v >> (nb-1)) == 0
                        else
                                (v >> nb) == -1
                        end
                } } || 31
end