-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDumpFunctionAST.py
More file actions
22 lines (17 loc) · 814 Bytes
/
DumpFunctionAST.py
File metadata and controls
22 lines (17 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Licensed under Apache 2.0
#
# Dump a function AST, by leveraging DecompilerInterface.structureGraph method. Inspired by DecompilerNestedLayout class.
# As far as I know, there was no publicly available Ghidra code to recover Pcode AST before this, see issues:
# https://github.com/NationalSecurityAgency/ghidra/discussions/4314
# https://github.com/NationalSecurityAgency/ghidra/issues/2204
# https://github.com/NationalSecurityAgency/ghidra/discussions/6771
from ghidralib import *
def dump(graph, ind=""):
for block in graph.blocks:
print("{} ({}): ".format(ind, block))
if block.has_children:
dump(block, ind + " ")
else:
for op in block.pcode:
print("{} {:x} {}".format(ind + " ", op.address, op))
dump(Function("main").pcode_tree)