-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathexport.py
More file actions
34 lines (27 loc) · 1.1 KB
/
Copy pathexport.py
File metadata and controls
34 lines (27 loc) · 1.1 KB
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
"""Export the current IDA database to a SMDA report.
For headless IDA 9.1+ export, use ``ida_domain_export.py`` instead.
"""
import json
from smda.Disassembler import Disassembler
from smda.ida.IdaInterface import getIdaSdkVersion
from smda.SmdaConfig import SmdaConfig
def detectBackend():
try:
return ("IDA", getIdaSdkVersion())
except ImportError:
return ("", "")
if __name__ == "__main__":
BACKEND, VERSION = detectBackend()
if BACKEND == "IDA":
config = SmdaConfig()
disassembler = Disassembler(config, backend=BACKEND)
ida_interface = disassembler.disassembler.ida_interface
binary = ida_interface.getBinary()
base_addr = ida_interface.getBaseAddr()
REPORT = disassembler.disassembleBuffer(binary, base_addr)
output_filepath = ida_interface.getIdbDir() + "ConvertedFromIdb.smda"
with open(output_filepath, "w") as fout:
json.dump(REPORT.toDict(), fout, indent=1, sort_keys=True)
print(f"Output saved to: {output_filepath}")
else:
raise Exception("Run this script from within IDA.")