How to use the bytecode.Exit function in bytecode

To help you get started, we’ve selected a few bytecode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github androguard / androguard / core / bytecodes / jvm.py View on Github external
def insert_direct_method(self, name, ref_method) :
        """
            Insert a direct method (MethodInfo object) into the class

            @param name : the name of the new method
            @param ref_method : the MethodInfo Object
        """
        if ref_method == None :
            return

        # Change the name_index
        name_index = self.__CM.get_string_index( name )
        if name_index != -1 :
            bytecode.Exit( "method %s already exits" % name )

        name_index = self.__CM.add_string( name )
        ref_method.set_name_index( name_index )

        # Change the descriptor_index
        descriptor_index = self.__CM.get_string_index( ref_method.get_descriptor() )
        if descriptor_index == -1 :
            descriptor_index = self.__CM.add_string( ref_method.get_descriptor() )
        ref_method.set_descriptor_index( descriptor_index )

        # Change attributes name index
        self._fix_attributes_external( ref_method )

        # Change internal index
        self._fix_attributes_internal( ref_method )
github androguard / androguard / core / bytecodes / dvm.py View on Github external
elif self.__value_type == VALUE_ARRAY :
            self.value = EncodedArray( buff, cm )
        elif self.__value_type == VALUE_ANNOTATION :
            self.value = EncodedAnnotation( buff, cm )
        elif self.__value_type == VALUE_BYTE :
            self.value = buff.read( 1 )
        elif self.__value_type == VALUE_NULL :
            self.value = None
        elif self.__value_type == VALUE_BOOLEAN :
            if self.__value_arg:
                self.value = True
            else:
                self.value = False
            pass
        else :
            bytecode.Exit( "Unknown value 0x%x" % self.__value_type )
github androguard / androguard / core / bytecodes / dvm.py View on Github external
def get_class_data_item(self, off) :
        for i in self.__manage_item[ "TYPE_CLASS_DATA_ITEM" ] :
            if i.get_off() == off :
                return i

        bytecode.Exit( "unknown class data item @ 0x%x" % off )
github androguard / androguard / core / bytecodes / jvm.py View on Github external
raw_buff = pack( '>B', op_value )

        new_jbc = None

        # If it's an op_value with args, we must handle that !
        if len( JAVA_OPCODES[ op_value ] ) > 1 :

            # Find information about the op_value
            r_function, v_function, r_buff, r_format, f_function = EXTRACT_INFORMATION_SIMPLE( op_value )

            # Special values for this op_value (advanced bytecode)
            if len( JAVA_OPCODES[ op_value ] ) == 6 :

                value = getattr( self.__CM, JAVA_OPCODES[ op_value ][5] )( *byte_code[1:] )
                if value == -1 :
                    bytecode.Exit( "Unable to found " + str(byte_code[1:]) )

                raw_buff += pack(r_format, *v_function( value ) )
            else :
                raw_buff += pack(r_format, *v_function( *byte_code[1:] ) )

            new_jbc = JBC(self.__CM, op_name, raw_buff, ( r_function, v_function, r_buff, r_format, f_function ) )
        else :
            new_jbc = JBC(self.__CM, op_name, raw_buff)

        # Adjust each branch with the new insertion
        val_m = self.__maps[ idx ]
        for i in self.__branches :
            self.__bytecodes[i].adjust_i( self.__maps[i], val_m, new_jbc.get_length() )

        # Insert the new bytecode at the correct index
        # Adjust maps + branches
github androguard / androguard / core / bytecodes / jvm.py View on Github external
def set_string(self, idx, name) :
        if self.constant_pool[idx - 1].get_name() == "CONSTANT_Utf8" :
            self.constant_pool[idx - 1].set_bytes( name )
        else :
            bytecode.Exit( "invalid index %d to set string %s" % (idx, name) )
github androguard / androguard / core / bytecodes / dvm.py View on Github external
def get_string(self, idx) :
        off = self.__manage_item[ "TYPE_STRING_ID_ITEM" ][idx].get_data_off()
        try :
            return self.__strings_off[off].get()
        except KeyError :
            bytecode.Exit( "unknown string item @ 0x%x(%d)" % (off,idx) )
github androguard / androguard / core / bytecodes / jvm.py View on Github external
def __init__(self, class_manager, buff) :
        self.__CM = class_manager
        tag = SV( '>B', buff.read_b(1) ).get_value()

        if tag not in VERIFICATION_TYPE_INFO :
            bytecode.Exit( "tag not in VERIFICATION_TYPE_INFO" )

        format = VERIFICATION_TYPE_INFO[ tag ][1]
        self.format = SVs( format, VERIFICATION_TYPE_INFO[ tag ][2], buff.read( calcsize( format ) ) )
github androguard / androguard / core / bytecodes / jvm.py View on Github external
if value == -1 :
                    bytecode.Exit( "Unable to found method " + str(operands) )

                raw_buff += pack(r_format, *v_function( value ) )

                i.reload( raw_buff )

            elif "ldc" == i.get_name() :
                operands = i.get_operands()
                op_value = INVERT_JAVA_OPCODES[ i.get_name() ]
                raw_buff = pack( '>B', op_value )

                r_function, v_function, r_buff, r_format, f_function = EXTRACT_INFORMATION_SIMPLE( op_value )

                if operands[0] != "CONSTANT_Integer" and operands[0] != "CONSTANT_String" :
                    bytecode.Exit( "...." )

                if operands[0] == "CONSTANT_Integer" :
                    new_int_index = self.__CM.create_integer( operands[1] )
                    raw_buff += pack(r_format, *v_function( new_int_index ) )

                elif operands[0] == "CONSTANT_String" :
                    new_string_index = self.__CM.create_string( operands[1] )

                    raw_buff += pack(r_format, *v_function( new_string_index ) )

                i.reload( raw_buff )

            elif "new" == i.get_name() :
                operands = i.get_operands()
                op_value = INVERT_JAVA_OPCODES[ i.get_name() ]
                raw_buff = pack( '>B', op_value )