def __can_be_part_of_assert(cfunc, ctree_item): # type: (idaapi.cfunc_t, idaapi.ctree_item_t) -> bool """ Returns true if expression we clicked is an argument passed to a function and this argument is a string that can be a valid function name """ if ctree_item.citype != idaapi.VDI_EXPR: return False expression = ctree_item.it.to_specific_type if expression.op != idaapi.cot_obj: return False parent = cfunc.body.find_parent_of(expression).to_specific_type if parent.op != idaapi.cot_call or parent.x.op != idaapi.cot_obj: return False obj_ea = expression.obj_ea if not helper.is_code_ea(obj_ea) and idc.get_str_type( obj_ea) == idc.STRTYPE_C: str_potential_name = idc.get_strlit_contents(obj_ea) if type(str_potential_name) is not str: # convert bytes to str (python 3) str_potential_name = str_potential_name.decode('ascii') return idaapi.is_valid_typename(str_potential_name) return False
def extract_recast_info(self, cfunc, ctree_item): if ctree_item.citype != idaapi.VDI_EXPR: return expression = ctree_item.it result = RecastItemRight._check_potential_array(cfunc, expression) if result: return result # Look through parents until we found Cast while expression and expression.op != idaapi.cot_cast: expression = expression.to_specific_type expression = cfunc.body.find_parent_of(expression) if not expression: return expression = expression.to_specific_type # Find `(TYPE) something;` or `(TYPE *) &something;` and calculate appropriate type for recast if expression.x.op == idaapi.cot_ref: tinfo = expression.type.get_pointed_object() expression = expression.x else: tinfo = expression.type if expression.x.op == idaapi.cot_var: # (TYPE) var; variable = cfunc.get_lvars()[expression.x.v.idx] return RecastLocalVariable(tinfo, variable) elif expression.x.op == idaapi.cot_obj: # (TYPE) g_var; if helper.is_code_ea(expression.x.obj_ea) and tinfo.is_funcptr(): # (TYPE) sub_XXXXXX; tinfo = tinfo.get_pointed_object() gvar_ea = expression.x.obj_ea return RecastGlobalVariable(tinfo, gvar_ea) elif expression.x.op == idaapi.cot_call: # (TYPE) call(); idaapi.update_action_label(RecastItemRight.name, "Recast Return") func_ea = expression.x.x.obj_ea return RecastReturn(tinfo, func_ea) elif expression.x.op == idaapi.cot_memptr: # (TYPE) var->member; idaapi.update_action_label(RecastItemRight.name, "Recast Field") struct_name = expression.x.x.type.get_pointed_object().dstr() struct_offset = expression.x.m return RecastStructure(tinfo, struct_name, struct_offset)