def parse_function_args(ea: int) -> str: local_variables = [] arguments = [] current = local_variables frame = idc.get_func_attr(ea, FUNCATTR_FRAME) arg_string = "" if frame is None: return "" start = idc.get_first_member(frame) end = idc.get_last_member(frame) count = 0 max_count = 10000 args_str = "" while start <= end and count <= max_count: size = idc.get_member_size(frame, start) count = count + 1 if size is None: start = start + 1 continue name = idc.get_member_name(frame, start) start += size if name in [" r", " s"]: # Skip return address and base pointer current = arguments continue arg_string += f" {name}" current.append(name) args_str = ", ".join(arguments) if len(args_str) == 0: args_str = "void" return f"({args_str})"
def get_stack_arg(func_addr): print func_addr args = [] stack = idc.get_frame_id(func_addr) if not stack: return [] firstM = idc.get_first_member(stack) lastM = idc.get_last_member(stack) i = firstM while i <= lastM: mName = idc.get_member_name(stack, i) mSize = idc.get_member_size(stack, i) if mSize: i = i + mSize else: i = i + 4 if mName not in args and mName and ' s' not in mName and ' r' not in mName: args.append(mName) return args
def get_stackVariables(func_addr): #print func_addr args = [] stack = idc.get_frame_id(func_addr) if not stack: return 0 firstM = idc.get_first_member(stack) lastM = idc.get_last_member(stack) i = firstM while i <=lastM: mName = idc.get_member_name(stack,i) mSize = idc.get_member_size(stack,i) if mSize: i = i + mSize else: i = i+4 if mName not in args and mName and 'var_' in mName: args.append(mName) return len(args)
def write_vtbl_struct(self, vtbl_name, struct_member_names): struct_name = "{0}_struct".format(vtbl_name) sid = idc.get_struc_id(struct_name) if sid == idc.BADADDR: # Doesn't exist sid = idc.add_struc(-1, struct_name, is_union=0) else: # Clear existing member_offset = idc.get_first_member(sid) while member_offset != idc.BADADDR: idc.del_struc_member(sid, member_offset) member_offset = idc.get_first_member(sid) for member_name in struct_member_names: idc.add_struc_member(sid, member_name, offset=-1, flag=idc.FF_DATA | idc.FF_QWORD, typeid=-1, nbytes=8, reftype=idc.REF_OFF64) member_offset = idc.get_last_member(sid) member_id = idc.get_member_id(sid, member_offset) idc.SetType(member_id, "void*")