Copy (user created) assembly comments to pseudocode

Currently you can “Copy to assembly” in the Pseudocode window, but there is no option to do the opposite for user created comments.

Usecase:

  1. Open foobar program version 1.0.0 in IDA.
  2. Goto “loadoptions” function.
  3. Add comments in the IDA-View window.
  4. Decompile.
  5. “Copy assembly comments to pseudeocode” to document the Pseudocode window.
  6. Push the functions metadata to Lumina (or Lumen).
  7. Save the IDB and close the version 1.0.0 file.
  8. Open foobar program version 1.0.1 in IDA.
  9. Pull metadata from Lumina (or Lumen).
  10. Goto “loadoptions” function.
  11. Decompile.
  12. “Copy assembly comments to pseudeocode”
  13. See comments in Pseudocode code window you made for version 1.0.0

This can save a lot of time if you want to document the Pseudocode output for multiple versions of a program.

IDA View - Text Mode with comments added by me:

.text:00498FB7 loadoptions     proc near               ; CODE XREF: loadini+C58↓p
.text:00498FB7                 push    ebx
.text:00498FB8                 push    esi
.text:00498FB9                 push    edi
.text:00498FBA                 push    ebp
// snip...
.text:00499006                 call    nextval
.text:0049900B                 mov     dword_557890, eax ; 01 - Example 1
.text:00499010                 push    0
.text:00499012                 call    nextval
.text:00499017                 mov     dword_557904, eax ; 02 - Foobar
.text:0049901C                 push    0
.text:0049901E                 call    nextval
.text:00499023                 mov     dword_5578F8, eax ; 03
.text:00499028                 push    0
.text:0049902A                 call    nextval
.text:0049902F                 mov     dword_551F68, eax ; 04
.text:00499034                 push    0
.text:00499036                 call    nextval
.text:0049903B                 mov     dword_551D40, eax ; 05
.text:00499040                 push    0
.text:00499042                 call    nextval
.text:00499047                 mov     dword_557248, eax ; 06
.text:0049904C                 push    12Ch
.text:00499051                 call    nextval
.text:00499056                 mov     dword_54F8BC, eax ; 07
.text:0049905B                 push    0
.text:0049905D                 call    nextval
.text:00499062                 mov     dword_557914, eax ; 08
...

Suggested Pseudocode output for “Copy assembly comments to pseudocode”:

int loadoptions()
{
  bool v0; // edi
  int result; // eax

  GetPrivateProfileStringA("options", "n0", byte_553647, byte_579826, 0x3E7u, (LPCSTR)"foobar.ini");
  dword_553524 = (int)byte_579826;
  v0 = byte_579826[0] == 0;
  dword_557890 = nextval(0);                    // 01 - Example 1
  dword_557904 = nextval(0);                    // 02 - Foobar
  dword_5578F8 = nextval(0);                    // 03
  dword_551F68 = nextval(0);                    // 04
  dword_551D40 = nextval(0);                    // 05
  dword_557248 = nextval(0);                    // 06
  dword_54F8BC = nextval(300);                  // 07
  dword_557914 = nextval(0);                    // 08
...

INI file format for reference:

[options]
n0=0,0,0,0,0,0,300,0

One thing you can do right now is to use the function comment; it is shared between disassembly and pseudocode.

self promotion:

I have written som code the might help you, it’s not very fast atm but you can refine it if speed is an issue: