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

Enable Outlining of Inlined Standard Functions #3349

Open
op2786 opened this issue Aug 3, 2022 · 4 comments
Open

Enable Outlining of Inlined Standard Functions #3349

op2786 opened this issue Aug 3, 2022 · 4 comments
Labels
Component: Core Issue needs changes to the core Effort: Medium Issue should take < 1 month Impact: High Issue adds or blocks important functionality Type: Enhancement Issue is a small enhancement to existing functionality

Comments

@op2786
Copy link
Contributor

op2786 commented Aug 3, 2022

Compilers sometimes makes standard functions (strlen, memcpy, strcat, memset, strcmp, memcmp etc) inline. I guess their code pattern can be recognized and replaced with pseudo call to function.

Example disassembly:

1800382a2  488dbda0120000     lea     rdi, [rbp+0x12a0 {Dst}]
1800382a9  33c0               xor     eax, eax  {0x0}
1800382ab  b90c010000         mov     ecx, 0x10c
1800382b0  f3aa               rep stosb byte [rdi]  {0x0}  {0x0}  {0x0}

Output in HLIL:

1800382a2          char (* rdi_1)[0x110] = &Dst
1800382b0          for (int64_t rcx_4 = 0x10c; rcx_4 != 0; rcx_4 = rcx_4 - 1) {
1800382b0              *rdi_1 = 0
1800382b0              rdi_1 = &(*rdi_1)[1]
1800382b0          }

Which can be replaced memset(Dst, 0, 0x10c). It may be related to #2185.

@op2786 op2786 added the Type: Enhancement Issue is a small enhancement to existing functionality label Aug 3, 2022
@fuzyll fuzyll added Impact: High Issue adds or blocks important functionality Effort: Medium Issue should take < 1 month labels Aug 8, 2022
@fuzyll
Copy link
Contributor

fuzyll commented Aug 8, 2022

This is a subset of the functionality that would be required for #2185, so we're leaving this issue to track automatically resolving standard library calls that get inlined. The other issue tracks being able to make any HLIL code into an inlined function.

@plafosse plafosse added the Component: Core Issue needs changes to the core label Jun 26, 2023
@bpotchik bpotchik changed the title Show inlined standard functions as function call Enable Outlining of Inlined Standard Functions Jun 26, 2023
@plafosse
Copy link
Member

plafosse commented Jun 26, 2023

Currently we have partial support for this feature. It is currently limited to "Constant Data" i.e. When a string or data is "usually" written to sequential stack locations. We recover these and display them as one of:

  • __builtin_strcpy
  • __builtin_strncpy
  • __builtin_memcpy
  • __builtin_wcscpy
  • __builtin_memset

TODO:

  • __builtin_ memcmp
  • __builtin_ strcmp
  • __builtin_ strcat

Recovery of non-"Constant Data" functions:

  • strlen
  • strcpy
  • strncpy
  • memcpy
  • memcmp
  • wcscpy
  • strcmp

@0xdevalias
Copy link

0xdevalias commented Jun 7, 2024

Specific strcat related issue here:

And a (potentially more complicated) issue for C++ things like std::string:

@xusheng6
Copy link
Member

There are also other common routines like rdtsc that can be outlined. See #6265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Issue needs changes to the core Effort: Medium Issue should take < 1 month Impact: High Issue adds or blocks important functionality Type: Enhancement Issue is a small enhancement to existing functionality
Projects
None yet
Development

No branches or pull requests

5 participants