-
Notifications
You must be signed in to change notification settings - Fork 38
/
load_structs.py
78 lines (58 loc) · 1.99 KB
/
load_structs.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
#import structures and typedefs from old kernelcache to a new one
#@author simo
#@category iOS.kernel
#@toolbar logos/load_structs.png
#@keybinding Meta Shift L
#@menupath
from ghidra.app.services import DataTypeManagerService
from ghidra.program.model.data import StructureDataType,PointerDataType
from ghidra.app.services import ProgramManager
"""
- Get all structures from source program and copy them into destination program
- It avoids taking "_vtable" structures because fix_kernelcache will handle it
- If struct is already there, just skip it
"""
src_prog_string = "<source program>"
dst_prog_string = "<destination program>"
def isThere(name,programDT):
if "MetaClass" in name:
return True
if "_vtable" in name:
return True
dataType = programDT.getDataType(name)
if dataType :
return True
return False
if __name__ == "__main__":
tool = state.getTool()
service = tool.getService(DataTypeManagerService)
dataTypeManagers = service.getDataTypeManagers();
programManager = state.getTool().getService(ProgramManager)
progs =programManager.getAllOpenPrograms()
if len(progs) < 2 :
popup ("You must open at least two programs")
exit(1)
src = dst = None
for prog in progs:
if src_prog_string == prog.getName():
src = prog
elif dst_prog_string == prog.getName():
dst = prog
if src == None or dst == None:
popup("Could not get src/dst program")
exit(0)
print src,dst
src_dtm = src.getDataTypeManager()
dst_dtm = dst.getDataTypeManager()
structs = src_dtm.getAllStructures()
for s in structs:
name = s.getName()
res = isThere('/'+name,dst_dtm)
if res == True:
continue
res = isThere('/Demangler/'+name,dst_dtm)
if res == True:
continue
struct = StructureDataType(name,0)
dst_dtm.addDataType(struct,None)
dst_dtm.addDataType(PointerDataType(struct),None)