Ghidra: API - How can i return Assembly/Decompiled Code

Created on 7 Apr 2019  路  2Comments  路  Source: NationalSecurityAgency/ghidra

From Jython APIs how can i retrieve raw assembly and/or decompiled code from a function?
I can't find anything related.

Thanks.

Question

Most helpful comment

Raw assembly:

listing = currentProgram.getListing()
currentFunction = listing.getFunctionContaining(currentAddress)
entryPoint = currentFunction.getEntryPoint()
instructions = listing.getInstructions(entryPoint, True)
for index, instruction in enumerate(instructions):
    print instruction
    if index > 5:
        break

Listing

Decompiled code:

decompInterface = ghidra.app.decompiler.DecompInterface()
decompInterface.openProgram(currentProgram)
decompileResults = decompInterface.decompileFunction(currentFunction, 30, monitor)
if decompileResults.decompileCompleted():
    decompiledFunction = decompileResults.getDecompiledFunction()
    decompiledFunction.getC()

DecompInterface

You can use also FlatAPI:
- FlatProgramAPI
- FlatDecompilerAPI

All 2 comments

Raw assembly:

listing = currentProgram.getListing()
currentFunction = listing.getFunctionContaining(currentAddress)
entryPoint = currentFunction.getEntryPoint()
instructions = listing.getInstructions(entryPoint, True)
for index, instruction in enumerate(instructions):
    print instruction
    if index > 5:
        break

Listing

Decompiled code:

decompInterface = ghidra.app.decompiler.DecompInterface()
decompInterface.openProgram(currentProgram)
decompileResults = decompInterface.decompileFunction(currentFunction, 30, monitor)
if decompileResults.decompileCompleted():
    decompiledFunction = decompileResults.getDecompiledFunction()
    decompiledFunction.getC()

DecompInterface

You can use also FlatAPI:
- FlatProgramAPI
- FlatDecompilerAPI

Thanks !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x6d696368 picture 0x6d696368  路  19Comments

progmboy picture progmboy  路  19Comments

mewmew picture mewmew  路  16Comments

Piruzzolo picture Piruzzolo  路  19Comments

ghost picture ghost  路  29Comments