This repository has been archived by the owner on Apr 7, 2023. It is now read-only.
forked from Learner0x5a/DataFlowAnalysis-miasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IDAGenDFG.py
49 lines (41 loc) · 1.75 KB
/
IDAGenDFG.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
import idaapi
import idautils
import idc
import ida_pro
import ida_auto
import os, sys
from libdataflow import ida_dataflow_analysis
from argparse import ArgumentParser
def main(OUTPUT_DIR:str) -> None:
os.makedirs(OUTPUT_DIR, exist_ok=True)
textStartEA = 0
textEndEA = 0
for seg in idautils.Segments():
if (idc.get_segm_name(seg)==".text"):
textStartEA = idc.get_segm_start(seg)
textEndEA = idc.get_segm_end(seg)
break
for func in idautils.Functions(textStartEA, textEndEA):
# Ignore Library Code
flags = idc.get_func_attr(func, idc.FUNCATTR_FLAGS)
if flags & idc.FUNC_LIB:
print(hex(func), "FUNC_LIB", idc.get_func_name(func))
continue
try:
ida_dataflow_analysis(func, idc.get_func_name(func), OUTPUT_DIR, defuse_only=True)
except Exception as e:
print('Skip function {} due to dataflow analysis error: {}'.format(idc.get_func_name(func),e))
if __name__ == '__main__':
if len(idc.ARGV) < 2:
print('\n\nGenerating DFG & Def-Use Graph with IDA Pro and MIASM')
print('\tNeed to specify the output dir with -o option')
print('\tUsage: /path/to/ida -A -Lida.log -S"{} -o <output_dir>" /path/to/binary\n\n'.format(idc.ARGV[0]))
ida_pro.qexit(1)
parser = ArgumentParser(description="IDAPython script for generating dataflow graph of each function in the given binary")
parser.add_argument("-o", "--output_dir", help="Output dir", default='./outputs', nargs='?')
# parser.add_argument("-s", "--symb", help="Symbolic execution mode",
# action="store_true")
args = parser.parse_args()
ida_auto.auto_wait()
main(args.output_dir)
ida_pro.qexit(0)