redballoonsecurity / ofrak

OFRAK: unpack, modify, and repack binaries.
https://ofrak.com
Other
1.85k stars 127 forks source link

Running `ofrak gui` with `-f` results in incomplete script #288

Open whyitfor opened 1 year ago

whyitfor commented 1 year ago

What is the problem? (Here is where you provide a complete Traceback.) When running ofrak gui -f <file>, the generated script in the GUI does not include a line that creates the root resource.

Please provide some information about your environment. This happens when running on d991e3bdb0b320b98e83c24a3dfda609ff7d5980.

If you've discovered it, what is the root cause of the problem? The generated script does not include a line to create the root resource.

How often does the issue happen? All the time.

What are the steps to reproduce the issue? First, run:

% ofrak gui -f TinyCore-current.iso

Click "identify" in the GUI. The generated script will be:

from ofrak import *
from ofrak.core import *

async def main(ofrak_context: OFRAKContext):

    await root_resource.identify()

if __name__ == "__main__":
    ofrak = OFRAK()
    if False:
        import ofrak_angr
        import ofrak_capstone

        ofrak.discover(ofrak_capstone)
        ofrak.discover(ofrak_angr)

    if False:
        import ofrak_binary_ninja
        import ofrak_capstone

        ofrak.discover(ofrak_capstone)
        ofrak.discover(ofrak_binary_ninja)

    if False:
        import ofrak_ghidra

        ofrak.discover(ofrak_ghidra)

    ofrak.run(main)

How would you implement this fix? In this example, the main function should include:

    root_resource = await ofrak_context.create_root_resource_from_file("TinyCore-12.0.iso")

Speaking more abstractly, running ofrak gui should generate whatever commands are passed into it. It probably also makes sense for other commands, such as ofrak unpack --gui ... to similarly capture the resource creation and unpack step.

Are there any (reasonable) alternative approaches? Perhaps.