Skip to content

Add Export disassembly of current function action - #3642

Open
andersendsa wants to merge 9 commits into
rizinorg:devfrom
andersendsa:add-export-disassembly
Open

Add Export disassembly of current function action#3642
andersendsa wants to merge 9 commits into
rizinorg:devfrom
andersendsa:add-export-disassembly

Conversation

@andersendsa

Copy link
Copy Markdown
Contributor

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've updated the documentation with the relevant information (if needed)
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Detailed description
Adds a new UI action to both the main File menu and the Disassembly context menu to allow users to export the disassembly of the currently selected function directly to a .txt file. It temporarily sets the scr.color to 0 to prevent ANSI color codes from being written into the output file.

Test plan (required)

  1. Open a binary in Cutter.

  2. Navigate to the Disassembly view and ensure you are inside a recognized function.

  3. Test Context Menu Export:

    • Right-click anywhere within the disassembly of the function.
    • Select the new option: "Export disassembly of current function".
    • A file save dialog will appear. Save it as export_context.txt (or any preferred name).
    • Open the saved file in a text editor and verify it contains the full disassembly of the function without any ANSI color escape sequences (e.g. \x1b[31m).
  4. Test Main Menu Export:

    • With the disassembly view active and focused inside a function, click on File → Export disassembly of current function in the main menu bar.
    • Save the file as export_main.txt.
    • Open the saved file and verify its contents match the context menu export.
  5. Test Invalid Offset/No Function:

    • Seek to an offset in the binary that is not part of any defined function.
    • Right-click and choose "Export disassembly of current function".
    • Verify that nothing is exported and a warning is appropriately suppressed/handled (no empty file should be created).

Closing issues
Closes:#3631

Adds a new UI action to both the main File menu and the Disassembly context menu to allow users to export the disassembly of the currently selected function directly to a .txt file. It temporarily sets the `scr.color` to `0` to prevent ANSI color codes from being written into the output file.
@andersendsa andersendsa changed the title feat: Add "Export disassembly of current function" action Add Export disassembly of current function action Jul 6, 2026
@andersendsa
andersendsa marked this pull request as draft July 7, 2026 12:59
@andersendsa
andersendsa marked this pull request as ready for review July 10, 2026 20:00
@andersendsa

Copy link
Copy Markdown
Contributor Author

Hi @PremadeS pls let me know if this pr needs any changes or if it is good to merge

Comment thread src/core/MainWindow.cpp Outdated
Comment thread src/core/MainWindow.cpp Outdated
@andersendsa
andersendsa requested a review from wargio July 16, 2026 07:39
@andersendsa

Copy link
Copy Markdown
Contributor Author

Hi @wargio I have done the requested changes pls let me know of there any more changes needed or if it is good to merge

@PremadeS PremadeS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to be exporting disassembly of a function correctly. It exports way more lines than a function contains

Comment thread src/core/MainWindow.cpp Outdated
Comment thread src/core/MainWindow.cpp Outdated
Comment thread src/core/MainWindow.cpp Outdated
if (!buf) {
return false;
}
rz_io_read_at_mapped(core->io, core->offset, buf, size);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be funcStart or actually the low address of the function?

Comment thread src/core/MainWindow.cpp Outdated
rz_io_read_at_mapped(core->io, core->offset, buf, size);
RzCoreDisasmOptions options = {};
options.cbytes = 1;
rz_core_print_disasm(core, core->offset, buf, size, 0, nullptr, &options);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

@andersendsa
andersendsa force-pushed the add-export-disassembly branch from efd9ce6 to 86ce61b Compare July 19, 2026 15:09
@andersendsa
andersendsa requested review from PremadeS and wargio July 19, 2026 15:44
@andersendsa

Copy link
Copy Markdown
Contributor Author

Hi @wargio , @PremadeS I have done the change could you pls let me know the pr needs any changes or if it is good to merge

Comment thread src/core/MainWindow.cpp
qWarning() << "No function at current offset.";
return;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the start address should not actually be the address at funcStart as the function start may be lower than the actual lowest address of the function.

I would say to maybe use rz_analysis_function_min_addr as start address since you use rz_analysis_function_linear_size for the size.

@andersendsa
andersendsa requested a review from wargio July 26, 2026 12:25
@andersendsa
andersendsa force-pushed the add-export-disassembly branch from 35cd900 to 22b6cdf Compare July 26, 2026 12:28
@andersendsa

Copy link
Copy Markdown
Contributor Author

Hi @wargio I have done the changes pls let me know if there any other changes needed

@wargio wargio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andersendsa

Copy link
Copy Markdown
Contributor Author

Hi @wargio this pr is good to merge ?

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

Successfully merging this pull request may close these issues.

3 participants