-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathphrank.py
102 lines (78 loc) · 2.49 KB
/
phrank.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Aggregator module for all underlying phrank API"""
from __future__ import annotations
import sys
# forward imports
from pyphrank.type_constructors.cpp_class_constructor import CppClassAnalyzer
from pyphrank.type_analyzer import TypeAnalyzer
from pyphrank.ast_analyzer import CTreeAnalyzer, get_var, get_var_use_chain, extract_vars
from pyphrank.cfunction_factory import CFunctionFactory
from pyphrank.containers.structure import Structure
from pyphrank.containers.union import Union
from pyphrank.containers.ida_struc_wrapper import IdaStrucWrapper
from pyphrank.containers.vtable import Vtable
from pyphrank.type_flow_graph import TFG
from pyphrank.ida_plugin import IDAPlugin
from pyphrank.analysis_state import AnalysisState
import pyphrank.settings as settings
from pyphrank.utils import *
from pyphrank.type_flow_graph_parts import *
def get_plugin_instance():
return IDAPlugin.get_instance()
def get_plugin_state() -> AnalysisState:
return get_plugin_instance().type_analyzer.state
def apply_plugin_state():
plugin = get_plugin_instance()
plugin.type_analyzer.apply_analysis()
def get_type_flow_graph(addr:int) -> TFG|None:
assert isinstance(addr, int)
func_ea = get_func_start(addr)
if func_ea == -1:
log_err(f"{hex(addr)} is not a function")
return None
return TypeAnalyzer().get_tfg(func_ea)
def print_type_flow_graph(addr:int):
aa = get_type_flow_graph(addr)
if aa is None:
return
func_ea = get_func_start(addr)
aa.print(f"{idaapi.get_name(func_ea)} TypeFlowGraph")
def __print_padded(*args, padlen=0):
padlen -= 1
print(' ' * padlen, *args, )
def __help_objects(name, objs):
if len(objs) == 0:
return
print(name)
for modname in sorted(objs.keys()):
m = objs[modname]
__print_padded(modname, padlen=4)
if m.__doc__:
__print_padded(m.__doc__, padlen=8)
print()
print()
def phrank_help():
"""Print this help"""
from inspect import isclass, isfunction, ismodule
mod = sys.modules[__name__]
funcs = {}
modules = {}
classes = {}
skips = {"sys", "idaapi", "typing", "ida_struct", "re", "logging", "idautils", "idc", "Any", "utils"}
for k, v in vars(mod).items():
if k.startswith("__"): continue
if k in skips:
continue
if isfunction(v):
funcs[k] = v
elif ismodule(v):
modules[k] = v
elif isclass(v):
classes[k] = v
else:
pass
print("DESCRIPTION")
__print_padded(mod.__doc__, padlen=4)
print()
__help_objects("MODULES", modules)
__help_objects("CLASSES", classes)
__help_objects("FUNCTIONS", funcs)