-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportObjDefs.py
52 lines (41 loc) · 1.36 KB
/
ExportObjDefs.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
#Export ObjDef structs to XML.
#@author
#@category StarFox
#@keybinding
#@menupath
#@toolbar
# OBSOLETE, added to UpdateDllsXml
import xml.etree.ElementTree as ET
AF = currentProgram.getAddressFactory()
DT = currentProgram.getDataTypeManager()
def addrToInt(addr):
return int(str(addr), 16)
def intToAddr(addr):
return AF.getAddress("0x%08X" % addr)
def run():
outPath = str(askFile("Export ObjDefs", "Export"))
objDefs = []
structs = list(DT.allStructures)
for struct in structs:
if struct.displayName.startswith('ObjDef_'):
objDefs.append(struct)
monitor.initialize(len(objDefs))
eRoot = ET.Element('objdefs')
tree = ET.ElementTree(eRoot)
for objDef in objDefs:
monitor.checkCanceled()
monitor.incrementProgress(1)
eDef = ET.SubElement(eRoot, 'objdef', {
'name': str(objDef.name)[7:], # cut off "ObjDef_"
'size': '0x%X' % objDef.length
})
for comp in filter(lambda c: c.offset >= 0x18, objDef.components):
eField = ET.SubElement(eDef, 'field', {
'offset': '0x%X' % comp.offset,
'type': str(comp.dataType.displayName),
'name': str(comp.fieldName),
})
if comp.comment:
ET.SubElement(eField, 'description').text = str(comp.comment)
tree.write(outPath)
run()