Skip to content

tools: better hlil and mlil. add comments and identation - #13

Open
cybergrind wants to merge 2 commits into
MCPPhalanx:mainfrom
cybergrind:better_il
Open

cybergrind wants to merge 2 commits into
MCPPhalanx:mainfrom
cybergrind:better_il

Conversation

@cybergrind

@cybergrind cybergrind commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

It is an initial try to make IL representation better. This PR has only HLIL if it is ok, I can try to make the same for other representations.

I'm planning to add tool for comments, so it would be great to show comments alongside with code

What is has:

  • adds function comment if it have any
  • adds function definition and name at the beginning
  • adds internal comments if there were any
  • better do loops and maybe other constructions

Before:

0x141b42e0e: int32_t rbx = 0
0x141b42e1d: int32_t r12 = *__argc
0x141b42e2a: int64_t* r15 = *__wargv
0x141b42e43: data_141d2c2f8 = ai/get_environment_path()
0x141b42e4a: BOOL (* const var_50)(PWSTR lpName, PWSTR lpValue) = SetEnvironmentVariableW
0x141b42e4f: SetEnvironmentVariableW(u"PATH", &data_141c0567e)
0x141b42e54: ai/get_environment_path()
0x141b42e59: ai/get_python_home_path()
0x141b42e64: SetEnvironmentVariableW(u"PYTHONHOME", &data_141d2ccc0)
0x141b42e66: ai/get_python_home_path()
0x141b42e6e: SetDllDirectoryW(&data_141d2ccc0)
0x141b42e7b: int64_t* rsi = *PyImport_FrozenModules
0x141b42e81: if (rsi != 0)
0x141b42e87: int64_t* rax_1 = rsi
0x141b42e8a: if (*rsi != 0)
0x141b42e90: rax_1 = &rax_1[3]
0x141b42e98: do while (*rax_1 != 0)
0x141b42ea1: rbx = ((rax_1 - rsi) s>> 3).d * 0xaaaaaaab

After:

0x141b42df0: // probably python initialization is here
0x141b42df0: void my:maybe_init() __noreturn
0x141b42e0e:     int32_t rbx = 0
0x141b42e1d:     int32_t r12 = *__argc  // argc
0x141b42e2a:     int64_t* r15 = *__wargv
0x141b42e43:     data_141d2c2f8 = ai/get_environment_path()
0x141b42e4a:     BOOL (* const var_50)(PWSTR lpName, PWSTR lpValue) = SetEnvironmentVariableW
0x141b42e4f:     SetEnvironmentVariableW(u"PATH", &data_141c0567e)
0x141b42e54:     ai/get_environment_path()
0x141b42e59:     ai/get_python_home_path()
0x141b42e64:     SetEnvironmentVariableW(u"PYTHONHOME", &data_141d2ccc0)
0x141b42e66:     ai/get_python_home_path()
0x141b42e6e:     SetDllDirectoryW(&data_141d2ccc0)
0x141b42e7b:     int64_t* rsi = *PyImport_FrozenModules
0x141b42e7b:     
0x141b42e81:     if (rsi != 0)
0x141b42e87:         int64_t* rax_1 = rsi
0x141b42e87:         
0x141b42e8a:         if (*rsi != 0)  // sample comment
0x141b42e98:             do
0x141b42e90:                 rax_1 = &rax_1[3]
0x141b42e98:             while (*rax_1 != 0)
0x141b42e98:         
0x141b42ea1:         rbx = ((rax_1 - rsi) s>> 3).d * 0xaaaaaaab

@cybergrind cybergrind changed the title tools: better hlil. add comments and identation tools: better hlil and mlil. add comments and identation Apr 18, 2025
@cybergrind

Copy link
Copy Markdown
Contributor Author

Also added MLIL

@ttimasdf

Copy link
Copy Markdown
Member

Thanks, this resolves #8

@ttimasdf

ttimasdf commented Apr 30, 2025

Copy link
Copy Markdown
Member

I'll update the pytest snapshot to reflect the changes to these tools and add some comments to BNDB.

@cybergrind

Copy link
Copy Markdown
Contributor Author

@ttimasdf no pressure here, this definitely can wait. also, having tests would really help, so I would love to see refactoring branch merged <3

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.

2 participants