def parse_function_type(ea: int, end: Optional[int] = None) -> str: frame = idc.get_func_attr(ea, FUNCATTR_FRAME) if frame is None: return "" if end is None: # try to find end func = function_at(ea) if not func: return "?" end = prev_addr(get_func_attr(func, FUNCATTR_END)) end_addr = end mnem = GetDisasm(end_addr) if "ret" not in mnem: # it's not a real end, get instruction before... end_addr = prev_addr(end) if end_addr == BADADDR: # cannot get the real end return "" mnem = GetDisasm(end_addr) if "ret" not in mnem: # cannot get the real end return "" op = get_operand_type(end_addr, 0) if op == o_void: # retn has NO parameters return "__cdecl" # retn has parameters return "__stdcall"
def _loadLocals(self) -> None: """Enumerates functions using IDA API and loads them into the internal mapping. """ self._loadImports() for func in Functions(): start = get_func_attr(func, FUNCATTR_START) end = prev_addr(get_func_attr(func, FUNCATTR_END)) is_import = self._isImportStart(start) refs_list = self._listRefsTo(start) calling_list = self._listRefsFrom(func, start, end) func_info = FunctionInfo_t(start, end, refs_list, calling_list, is_import) self._functionsMap[va_to_rva(start)] = func_info self._functionsMap[va_to_rva(end)] = func_info self.funcList.append(func_info)
def _getCallingOffset(self, func, called_list) -> List[Tuple[int, int]]: """Lists the offsets from where the given function references the list of other function. """ start = get_func_attr(func, FUNCATTR_START) end = prev_addr(get_func_attr(func, FUNCATTR_END)) # func_name = _getFunctionNameAt(start) curr = start calling_list = [] while (True): if curr >= end: break op = get_operand_value(curr, 0) if op in called_list: calling_list.append((curr, op)) curr = next_addr(curr) return calling_list