def name_and_type(name_index, descriptor_index):
    return u1(id_NameAndType) \
           + u2(name_index) \
           + u2(descriptor_index)
def string(utf8str):
    return u1(id_String) \
           + u2(utf8str)
def field_ref(class_index, name_and_type_index):
    return u1(id_Fieldref) \
           + u2(class_index) \
           + u2(name_and_type_index)
def utf8(text):
    return u1(id_Utf8) \
           + u2(len(text)) \
           + str_to_byte(text)
def class_ref(name_index):
    return u1(id_Class) \
           + u2(name_index)
def method_ref(class_index, name_and_type_index):
    return u1(id_Methodref) \
           + u2(class_index) \
           + u2(name_and_type_index)
Ejemplo n.º 7
0
def invokestatic(ref):
    return u1(0xB8) + u2(ref)
Ejemplo n.º 8
0
    def _write(self, stream):
        # Java java_class file header (constant bytes + versions).
        stream.write(u4(Exporter.JAVA_FILE_HEADER))
        stream.write(u2(self.output_class.version[1]))
        stream.write(u2(self.output_class.version[0]))

        # Pool table
        stream.write(u2(len(self.output_class.pool) + 1))
        for entry in self.output_class.pool:
            stream.write(entry)

        # Access modifiers
        stream.write(u2(reduce(operator.xor, self.output_class.access_modifiers)))

        # "This" and "Super" classes
        stream.write(u2(self.output_class.pool.this_index))
        stream.write(u2(self.output_class.pool.super_index))

        # Interface table (not implemented)
        stream.write(u2(0))

        # Field table
        stream.write(u2(len(self.output_class.fields)))
        for field in self.output_class.fields:
            stream.write(u2(field.access_flags))
            stream.write(u2(field.name_index))
            stream.write(u2(field.descriptor_index))
            stream.write(u2(0))  # Writing fields with attributes has not been implemented.

        # Methods table
        stream.write(u2(len(self.output_class.methods)))
        for name_index, descriptor_index, access_flags, attributes in self.output_class.methods:
            stream.write(u2(access_flags))
            stream.write(u2(name_index))
            stream.write(u2(descriptor_index))
            stream.write(u2(len(attributes)))

            # Attributes table within method table (e.g. contains "Code" attribute)
            for attribute in attributes:
                stream.write(u2(attribute["code_attribute_index"]))
                stream.write(u4(12 + attribute["code_length"]))
                stream.write(u2(attribute["max_stack"]))
                stream.write(u2(attribute["max_locals"]))
                stream.write(u4(attribute["code_length"]))
                for instruction in attribute["instructions"]:
                    stream.write(instruction)
                stream.write(u2(0))  # Exception table not implemented
                stream.write(u2(0))  # Attributes of attributes not implemented

        # Attributes table (not implemented)
        stream.write(u2(0))
Ejemplo n.º 9
0
def getstatic(field_index):
    return u1(0xB2) + u2(field_index)
Ejemplo n.º 10
0
def getfield(ref):
    return u1(0xB4) + u2(ref)
Ejemplo n.º 11
0
def putstatic(ref):
    return u1(0xB3) + u2(ref)
Ejemplo n.º 12
0
def putfield(ref):
    return u1(0xB5) + u2(ref)
Ejemplo n.º 13
0
def invokevirtual(method):
    return u1(0xB6) + u2(method)