示例#1
0
    def get_source(self):
        source = []
        if not self.inner and self.package:
            source.append('package %s;\n' % self.package)

        superclass, prototype = self.superclass, self.prototype
        if superclass is not None and superclass != 'Ljava/lang/Object;':
            superclass = superclass[1:-1].replace('/', '.')
            prototype += ' extends %s' % superclass

        if len(self.interfaces) > 0:
            prototype += ' implements %s' % ', '.join(
                [n[1:-1].replace('/', '.') for n in self.interfaces])

        source.append('%s {\n' % prototype)
        for field in self.fields:
            name = field.get_name()
            access = util.get_access_field(field.get_access_flags())
            f_type = util.get_type(field.get_descriptor())
            source.append('    ')
            if access:
                source.append(' '.join(access))
                source.append(' ')
            if field.init_value:
                value = field.init_value.value
                if f_type == 'String':
                    value = '"%s"' % value
                elif field.proto == 'B':
                    value = '0x%x' % struct.unpack('b', value)[0]
                source.append('%s %s = %s;\n' % (f_type, name, value))
            else:
                source.append('%s %s;\n' % (f_type, name))

        for klass in self.subclasses.values():
            source.append(klass.get_source())

        for method in self.methods:
            if isinstance(method, DvMethod):
                source.append(method.get_source())
            else:
                source.append(
                    DvMethod(self.vma.get_method(method)).get_source())
        source.append('}\n')
        return ''.join(source)
示例#2
0
def get_field_ast(field):
    triple = field.get_class_name()[1:-1], field.get_name(), field.get_descriptor()

    expr = None
    if field.init_value:
        val = field.init_value.value
        expr = dummy(str(val))

        if val is not None:
            if field.get_descriptor() == 'Ljava/lang/String;':
                expr = literal_string(val)
            elif field.proto == 'B':
                expr = literal_hex_int(struct.unpack('<b', val)[0])

    return {
        'triple': triple,
        'type': parse_descriptor(field.get_descriptor()),
        'flags': util.get_access_field(field.get_access_flags()),
        'expr': expr,
    }
示例#3
0
    def get_source(self):
        source = []
        if not self.inner and self.package:
            source.append('package %s;\n' % self.package)

        superclass, prototype = self.superclass, self.prototype
        if superclass is not None and superclass != 'Ljava/lang/Object;':
            superclass = superclass[1:-1].replace('/', '.')
            prototype += ' extends %s' % superclass

        if len(self.interfaces) > 0:
            prototype += ' implements %s' % ', '.join(
                        [n[1:-1].replace('/', '.') for n in self.interfaces])

        source.append('%s {\n' % prototype)
        for field in self.fields:
            name = field.get_name()
            access = util.get_access_field(field.get_access_flags())
            f_type = util.get_type(field.get_descriptor())
            source.append('    ')
            if access:
                source.append(' '.join(access))
                source.append(' ')
            if field.init_value:
                value = field.init_value.value
                if f_type == 'String':
                    value = '"%s"' % value
                elif field.proto == 'B':
                    value = '0x%x' % struct.unpack('b', value)[0]
                source.append('%s %s = %s;\n' % (f_type, name, value))
            else:
                source.append('%s %s;\n' % (f_type, name))

        for klass in self.subclasses.values():
            source.append(klass.get_source())

        for method in self.methods:
            if isinstance(method, DvMethod):
                source.append(method.get_source())
        source.append('}\n')
        return ''.join(source)