Exemplo n.º 1
0
# DEX Structures -----------------

Header = Entry.create('Header',[
        ['magic',           8, BinData],
        ['checksum',        4, BinHex],
        ['signature',      20, BinData],
        ['file_size',       4, BinInt],
        ['header_size',     4, BinInt],
        ['endian_tag',      4, BinHex],
        ['link_size',       4, BinInt],
        ['link_off',        4, BinHex],
        ['map_off',         4, BinHex],
        ['string_ids_size', 4, BinInt],
        ['string_ids_off',  4, BinHex],
        ['type_ids_size',   4, BinInt],
        ['type_ids_off',    4, BinHex],
        ['proto_ids_size',  4, BinInt],
        ['proto_ids_off',   4, BinHex],
        ['field_ids_size',  4, BinInt],
        ['field_ids_off',   4, BinHex],
        ['method_ids_size', 4, BinInt],
        ['method_ids_off',  4, BinHex],
        ['class_defs_size', 4, BinInt],
        ['class_defs_off',  4, BinHex],
        ['data_size',       4, BinInt],
        ['data_off',        4, BinHex],
        ])

MapItem = Entry.create('MapItem',[
        ['type',   2, BinMapType],
Exemplo n.º 2
0
        elif self.value_type == 0x1d:
            self.value = EncodedAnnotation(bstream)
        elif self.value_type == 0x1f:
            self.value = (self.value_arg == 0)
        elif self.value_type in [
                0x00, 0x02, 0x03, 0x04, 0x06, 0x10, 0x11, 0x17, 0x18, 0x19,
                0x1a, 0x1b
        ]:
            self.value = BinData(self.value_arg + 1)
            self.value.init_data(bstream.read(self.value_arg + 1))

    def blob(self):
        raise ("Implement me!")


AnnotationElement = Entry.create('AnnotationElement', [
    ['name_idx', 1, ULEB128],
    ['value', 1, EncodedValue],
])

EncodedAnnotation = Entry.create('EncodedAnnotation', [
    ['type_idx', 1, ULEB128],
    ['size', 1, ULEB128],
    ['elements', 'size', EntryList, AnnotationElement],
])

EncodedArray = Entry.create('EncodedArray', [
    ['size', 1, ULEB128],
    ['values', 'size', EntryList, EncodedValue],
])
Exemplo n.º 3
0
def uleb128_to_int(self):
    value = 0
    for b in reversed(self.value.data):
        value = value * 128 + (b & 0x7F)
    return value

def uleb128p1_to_int(self):
    value = 0
    for b in reversed(self.value.data):
        value = value * 128 + (b & 0x7F)
    return value-1

def sleb128_to_int(self):
    value = 0
    for b in reversed(self.value.data):
        value = value * 128 + (b & 0x7F)
    if self.value.data[-1] & 0x40 != 0:
        value = value | ~((1 << (len(self.value.data)*7))-1)
    return value

# LEB128 Structures

ULEB128 = Entry.create('ULEB128',[['value', len_leb128, BinData],])
ULEB128.__int__ = uleb128_to_int

ULEB128P1 = Entry.create('ULEB128P1',[['value', len_leb128, BinData],])
ULEB128P1.__int__ = uleb128p1_to_int

SLEB128 = Entry.create('SLEB128',[['value', len_leb128, BinData],])
SLEB128.__int__ = sleb128_to_int
Exemplo n.º 4
0
    for b in reversed(self.value.data):
        value = value * 128 + (b & 0x7F)
    return value - 1


def sleb128_to_int(self):
    value = 0
    for b in reversed(self.value.data):
        value = value * 128 + (b & 0x7F)
    if self.value.data[-1] & 0x40 != 0:
        value = value | ~((1 << (len(self.value.data) * 7)) - 1)
    return value


# LEB128 Structures

ULEB128 = Entry.create('ULEB128', [
    ['value', len_leb128, BinData],
])
ULEB128.__int__ = uleb128_to_int

ULEB128P1 = Entry.create('ULEB128P1', [
    ['value', len_leb128, BinData],
])
ULEB128P1.__int__ = uleb128p1_to_int

SLEB128 = Entry.create('SLEB128', [
    ['value', len_leb128, BinData],
])
SLEB128.__int__ = sleb128_to_int
Exemplo n.º 5
0
        if self.value_type == 0x1c:
            self.value = EncodedArray(bstream)
        elif self.value_type == 0x1d:
            self.value = EncodedAnnotation(bstream)
        elif self.value_type == 0x1f:
            self.value = (self.value_arg == 0)
        elif self.value_type in [0x00,0x02,0x03,0x04,0x06,0x10,
                                 0x11,0x17,0x18,0x19,0x1a,0x1b]:
            self.value = BinData(self.value_arg+1)
            self.value.init_data(bstream.read(self.value_arg+1))

    def blob(self):
        raise("Implement me!")

AnnotationElement = Entry.create('AnnotationElement',[
        ['name_idx', 1, ULEB128],
        ['value',    1, EncodedValue],
])

EncodedAnnotation = Entry.create('EncodedAnnotation',[
        ['type_idx',      1, ULEB128],
        ['size',          1, ULEB128],
        ['elements', 'size', EntryList, AnnotationElement],
])

EncodedArray = Entry.create('EncodedArray',[
        ['size',          1, ULEB128],
        ['values', 'size', EntryList, EncodedValue],
])