Skip to content

Instantly share code, notes, and snippets.

@morimolymoly
Created July 22, 2022 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morimolymoly/6b8eee839ce1b2e482935c1ba5e62c0f to your computer and use it in GitHub Desktop.
Save morimolymoly/6b8eee839ce1b2e482935c1ba5e62c0f to your computer and use it in GitHub Desktop.
from ghidra.program.model.block import BasicBlockModel
from ghidra.util.task import ConsoleTaskMonitor
fm = currentProgram.getFunctionManager()
functions = fm.getFunctions(True)
blockModel = BasicBlockModel(currentProgram)
monitor = ConsoleTaskMonitor()
for func in functions:
print("Basic block details for function '{}':".format(func.getName()))
blocks = blockModel.getCodeBlocksContaining(func.getBody(), monitor)
# print firstblock
print("\t[*] {} ".format(func.getEntryPoint()))
bbnum = 1
edgenum = 0
# print any remaining blocks
while(blocks.hasNext()):
bb = blocks.next()
bbnum += 1
dest = bb.getDestinations(monitor)
while(dest.hasNext()):
dbb = dest.next()
edgenum += 1
print("bb: {} edge: {}".format(bbnum, edgenum))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment