Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the decompiled output for specific functions from Ghidra #9

Closed
asmitaj08 opened this issue Mar 19, 2025 · 2 comments
Closed

Comments

@asmitaj08
Copy link

Hello,
I was trying to reproduce some of your work. I want to understand your approach of getting the decompiled output for specific functions from Ghidra. For example, in your dataset `libaudioflux.so.json' , you have certain key vars ""001426b0" and then corresponding decompiled output, can you explain your approach how you got this. I would really appreciate your help. Thank you!

@PeiweiHu
Copy link
Owner

Thanks for your comment. We achieved that by leveraging the headless mode of ghidra (as also ida). For example, the ghidra script we used is like this:

"""

Ghidra script - decompile and store the result in json format

{
    'addr': 'pesude c',
    ...,
}

"""

import json
from ghidra.app.decompiler import DecompInterface
from ghidra.util.task import ConsoleTaskMonitor


program = getCurrentProgram()
ifc = DecompInterface()
ifc.openProgram(program)


output = dict()
fm = currentProgram.getFunctionManager()
funcs = fm.getFunctions(True) # True means 'forward'
for func in funcs:
    # decompile the function and print the pseudo C
    results = ifc.decompileFunction(func, 0, ConsoleTaskMonitor())
    decompiled = results.getDecompiledFunction().getC()
    addr = str(func.getEntryPoint())
    output[addr] = decompiled

args = getScriptArgs()
with open(args[0], 'w') as w:
    w.write(json.dumps(output, indent=4))

@asmitaj08
Copy link
Author

asmitaj08 commented Mar 20, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants