def _assign_value_wide(self, instruction): """ For 64 bit, it has two register, which is vx and vx+1 """ reg = instruction[1] value = instruction[2] index = int(reg[1:]) reg_plus_one = f"v{index + 1}" variable_object = VarabileObject(reg, value) variable_object2 = VarabileObject(reg_plus_one, value) self.table_obj.insert(index, variable_object) self.table_obj.insert(index + 1, variable_object2)
def AGET_OBJECT(self, instruction): """ aget-object vx,vy,vz Gets an object reference value of an object reference array into vx. The array is referenced by vy and is indexed by vz. It means vx = vy[vz]. """ reg = instruction[1] index = int(reg[1:]) try: array_obj = self.table_obj.get_obj_list(int( instruction[2][1])).pop() array_index = self.table_obj.get_obj_list(int( instruction[3][1])).pop() variable_object = VarabileObject( reg, f"{array_obj.value}[{array_index.value}]") self.table_obj.insert(index, variable_object) except IndexError as e: log.exception(f"{e} in AGET_OBJECT")
def MOVE_RESULT_WIDE(self, instruction): """ move-result-wide vx Move the long/double result value of the previous method invocation into vx,vx+1. """ reg = instruction[1] index = int(reg[1:]) try: pre_ret = self.ret_stack.pop() variable_object = VarabileObject(reg, pre_ret) variable_object2 = VarabileObject(f"v{index + 1}", pre_ret) self.table_obj.insert(index, variable_object) self.table_obj.insert(index + 1, variable_object2) except IndexError as e: log.exception(f"{e} in MOVE_RESULT_WIDE")
def pyeval(): pyeval = PyEval() # mock_hash_table = [...[], [v4_mock_variable_obj], [], [], # [v9_mock_variable_obj]....] v4_mock_variable_obj = VarabileObject("v4", "Lcom/google/progress/SMSHelper;", None) v9_mock_variable_obj = VarabileObject("v9", "some_string", "java.io.file.close()") pyeval.table_obj.insert(4, v4_mock_variable_obj) pyeval.table_obj.insert(9, v9_mock_variable_obj) yield pyeval del pyeval
def test_move_result_object(self, pyeval): v6_mock_variable_obj = VarabileObject("v6", "some_string", None) pyeval.table_obj.insert(6, v6_mock_variable_obj) assert pyeval.table_obj.pop(6).register_name == "v6" assert pyeval.table_obj.pop(6).value == "some_string" assert pyeval.table_obj.pop(6).called_by_func == [] first_instruction = [ "invoke-virtual", "v6", "Lcom/google/progress/ContactsCollecter;->getContactList()Ljava/lang/String;", ] second_instruction = ["move-result-object", "v1"] pyeval.INVOKE_VIRTUAL(first_instruction) pyeval.MOVE_RESULT_OBJECT(second_instruction) assert pyeval.table_obj.pop(1).register_name == "v1" assert ( pyeval.table_obj.pop(1).value == "Lcom/google/progress/ContactsCollecter;->getContactList()Ljava/lang/String;(some_string)" ) assert pyeval.table_obj.pop(1).called_by_func == []
def _assign_value(self, instruction): reg = instruction[1] value = instruction[2] index = int(reg[1:]) variable_object = VarabileObject(reg, value) self.table_obj.insert(index, variable_object)
def test_init(self, variable_obj): with pytest.raises(TypeError): variable_obj_with_no_argu = VarabileObject() assert isinstance(variable_obj, VarabileObject) assert variable_obj.register_name == "v3" assert variable_obj.value == "append()" assert variable_obj.called_by_func == []
def test_aget_object(self, pyeval): """ aget-object vx,vy,vz It means vx = vy[vz]. """ v2_mock_variable_obj = VarabileObject("v2", "some_list_like[1,2,3,4]", "java.io.file.close()") v3_mock_variable_obj = VarabileObject("v3", "2", None) pyeval.table_obj.insert(2, v2_mock_variable_obj) pyeval.table_obj.insert(3, v3_mock_variable_obj) instruction = ["aget-object", "v1", "v2", "v3"] pyeval.AGET_OBJECT(instruction) pyeval.table_obj.pop(1).register_name == "v1" pyeval.table_obj.pop(1).value = "some_list_like[1,2,3,4][2]" assert pyeval.table_obj.pop(1).called_by_func == []
def _move(self, instruction): reg = instruction[1] index = int(reg[1:]) try: pre_ret = self.ret_stack.pop() variable_object = VarabileObject(reg, pre_ret) self.table_obj.insert(index, variable_object) except IndexError as e: log.exception(f"{e} in _move")
def test_called_by_func(self, variable_obj): variable_obj_with_called_by_func = VarabileObject( "v3", "append()", "toString()") assert variable_obj_with_called_by_func.called_by_func == [ "toString()" ] variable_obj.called_by_func = "file_list" variable_obj.called_by_func = "file_delete" assert variable_obj.called_by_func == ["file_list", "file_delete"]
def variable_obj(): variable_obj = VarabileObject("v3", "append()", None) yield variable_obj del variable_obj