Example #1
0
    def __init__(self, node_id: int, obj_ea: int, func_name: t.Optional[str]):
        self.node_id = node_id
        self.obj_ea = obj_ea

        if func_name is None:
            func_name = ida.get_func_name(self.obj_ea)

        self.func_name = func_name if func_name else None
Example #2
0
    def activate(self, ctx) -> int:
        """Collects types, user-defined variables, their locations in addition to the
        AST and raw code.
        """
        print("Collecting vars and types.")
        for ea in (ea for ea in idautils.Functions()
                   if ea in self.debug_functions):
            # Decompile
            f = ida.get_func(ea)
            cfunc = None
            try:
                cfunc = ida.decompile(f)
            except ida.DecompilationFailure:
                continue
            if cfunc is None:
                continue

            # Function info
            name: str = ida.get_func_name(ea)

            self.type_lib.add_ida_type(cfunc.type.get_rettype())
            return_type = TypeLib.parse_ida_type(cfunc.type.get_rettype())

            arguments = self.collect_variables(f.frsize,
                                               cfunc.get_stkoff_delta(),
                                               cfunc.arguments)
            local_vars = self.collect_variables(
                f.frsize,
                cfunc.get_stkoff_delta(),
                [v for v in cfunc.get_lvars() if not v.is_arg_var],
            )
            raw_code = ""
            for line in cfunc.get_pseudocode():
                raw_code += f"{' '.join(ida_lines.tag_remove(line.line).split())}\n"
            ast = AST(function=cfunc)
            decompiler = Function(
                ast=ast,
                name=name,
                return_type=return_type,
                arguments=arguments,
                local_vars=local_vars,
                raw_code=raw_code,
            )
            self.functions.append(
                CollectedFunction(
                    ea=ea,
                    debug=self.debug_functions[ea],
                    decompiler=decompiler,
                ))
        self.write_info()
        return 1
Example #3
0
    def __init__(
        self,
        function: t.Optional[ida.cfunc_t] = None,
        root: t.Optional["Statement"] = None,
    ):
        self._next_id = 0
        self.function = function

        self.root: t.Optional["Statement"]
        if root is None and self.function is not None:
            print(ida.get_func_name(self.function.entry_ea))
            self.root = parse_hexrays_statement(self.function.body, self)
        else:
            self.root = root
Example #4
0
    def activate(self, ctx) -> int:
        """Collects types, user-defined variables, and their locations"""
        print("Collecting vars and types.")
        # `ea` is the start address of a single function
        for ea in idautils.Functions():
            # Decompile
            f = ida.get_func(ea)
            cfunc = None
            try:
                cfunc = ida.decompile(f)
            except ida.DecompilationFailure:
                continue
            if cfunc is None:
                continue

            # Function info
            name: str = ida.get_func_name(ea)
            self.type_lib.add_ida_type(cfunc.type.get_rettype())
            return_type = TypeLib.parse_ida_type(cfunc.type.get_rettype())

            arguments = self.collect_variables(f.frsize,
                                               cfunc.get_stkoff_delta(),
                                               cfunc.arguments)
            local_vars = self.collect_variables(
                f.frsize,
                cfunc.get_stkoff_delta(),
                [v for v in cfunc.get_lvars() if not v.is_arg_var],
            )
            self.functions[ea] = Function(
                name=name,
                return_type=return_type,
                arguments=arguments,
                local_vars=local_vars,
            )

        self.write_type_lib()
        self.write_functions()
        return 1
Example #5
0
 def from_item(cls, item: ida.cexpr_t, ast: "AST") -> "Obj":  # type: ignore
     node_id = ast.next_id()
     func_name = ida.get_func_name(item.obj_ea)
     return cls(node_id=node_id, obj_ea=item.obj_ea, func_name=func_name)