def read_line(self, asmline, linenr=None): ''' Read a line of the asm file and process the information to keep track of the registers and stack. Parameters ---------- asmline: string a line of assembler linenr: int, optional the current line number in the file. If not given, it will not be used in the output. Raises ------ CpuException if any underlying exception has been raised ''' log.debug('reading line: %s', asmline) if linenr is not None: self.line_number = linenr self.address = ParseUtil.get_address_from_asmline(asmline) try: self._read_basic_block(asmline) self._read_meth_impl(asmline) self._read_assignment(asmline) self._read_call_line(asmline) except (ArgumentsException, VarAssignmentIvarRegisterWrongTypeException) as e: raise CpuException(self, e), None, sys.exc_info()[2]
def __init__(self, cpu): CpuException.__init__(self, cpu)
def _read_called(self, asmline, called): ''' Read a called line like e.g. "qword [ds:objc_msg_alloc] ; @selector(alloc)" and hand it on to the appropriate read method. Parameters ---------- asmline: string called: ImpStub, Selector or string Raises ------ IvarRefWrongTypeException if the ivar_ref has the wrong type CpuException if the value of the destination register could not be resolved CpuCouldNotReadLogFuncException if the NSLog could not be read CpuCouldNotReadMsgSendEception if the objc_msgsend() could not be read ''' # called does not have to be a string due to the fact that read_register() # will recall this method with register resolved and passed as called imp = selector = destination = None if isinstance(called, str): imp = self.parse_util.parse_imp(called) # called can be e.g. _foo or sub_foo if not imp: called_method = self.parse_util.parse_called_method_name( called) if called_method is not None: called = called_method else: if self.ignore_hex_addr_call( ) and self.parse_util.parse_hex(called): return # called can be Selector or Imp else: if isinstance(called, Imp): imp = called elif isinstance(called, Selector): selector = called try: # only pop from stack if really needed for a MsgSend if imp is not None and imp.is_any_msg_send( ) and self.fetches_all_arguments_from_stack( ) or not self.fetches_all_arguments_from_stack(): is_msg_send_stret = False if imp is not None: is_msg_send_stret = imp.is_any_msg_send_stret() destination = self.get_current_destination(is_msg_send_stret) return_register = self.return_register() # if selector is not None, it's already resolved if selector is None: selector = self.parse_util.parse_selector(asmline) register = None if isinstance(called, str): # same as above, called can be anything else than a string register = self.parse_util.parse_register(called) log.debug('destination is %s', destination) # destination is VarAssignment if isinstance(destination, VarAssignment): # get ivar value from VarAssignment destination = destination.get_ivar_value() if imp is not None: msgSend = self.objc_runtime.read_msg_send(imp, destination) if msgSend is None: if self.objc_runtime.read_return_important_objc_call( imp, destination, return_register): return if self._read_formatstring_log(imp): return else: self._read_remaining_stub(imp) else: if self._read_c_func(called): return else: self._read_register(register, asmline) if not self.objc_runtime.read_selector(selector, destination): # TODO: HOW TO HANDLE (fp)([NSURLRequest class], selx, YES, host); ??? # called can be something else due to recalling of `_read_register` if isinstance(called, str): own_c_method_call = ParseUtil.parse_own_c_method_called( called) if own_c_method_call is not None: self._read_own_c_func_call(own_c_method_call) except CpuCouldNotGetDestination as e: raise CpuException(self, e), None, sys.exc_info()[2]
def __init__(self, cpu, wrong_type): self._wrong_type = wrong_type CpuException.__init__(self, cpu)
def __init__(self, cpu, selfref_reg, current_meth_impl): self._current_meth_impl = current_meth_impl self._selfref_reg = selfref_reg CpuException.__init__(self, cpu)
def __init__(self, cpu, destination, selector): CpuException.__init__(self, cpu) self.destination = destination self.selector = selector
def __init__(self, cpu, log_func, nslog_string): CpuException.__init__(self, cpu, caused_by=None) self.nslog_string = nslog_string self.log_func = log_func
def __init__(self, cpu, looked_up_list): self._looked_up_list = looked_up_list CpuException.__init__(self, cpu)
def __init__(self, arguments_interface, cpu): ArgumentsException.__init__(self, arguments_interface) CpuException.__init__(self, cpu)
def __init__(self, addr, stack): CpuException.__init__(self, None) self._addr = addr self._stack = stack