Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Technique:Recognizing compiler-generated code/Inlined library idioms

From ReverseEngineering.wiki

Compiler-inlined memcpy, memset and strlen (rep movs/stos, SIMD loops, repne scasb) and C++ new/delete pairs with their cleanup funclets: how to read them as the library call they replace.

At -O1 and above, compilers replace small or constant-size library calls with instructions and sometimes add C++ unwinding code. These are unverified recognition notes from common compiler output; they were not checked against compiler sources for this page.

Inlined memory operations

  • memcpy / memset with a small constant size: a few mov pairs (load, store) of 8, 16, 32 bytes; sizes that are not a multiple get an overlapping final store. Four movups/movdqu loads and stores = a 64-byte copy; zeroing is xor eax, eax then stores or pxor xmm0, xmm0; movups [..], xmm0.
  • rep movsb / rep movsd / rep movsq with ECX/RCX as count, RSI source, RDI destination: memcpy (MSVC /O1 or /Os, Clang -Os, and any size on CPUs with fast-string support). rep stosb/d/q with AL/EAX/RAX as the value: memset. The count register holds bytes divided by the element size.
  • strlen: repne scasb with xor eax, eax (AL = 0), then not ecx / dec ecx (the classic old MSVC form), or a loop comparing 16 bytes at a time with pcmpeqb/pmovmskb/bsf.
  • Large constant memcpy/memset usually remain calls to the CRT or libc (memcpy, __memcpy_chk in fortified builds, _memset). __memcpy_chk / __strcpy_chk come from _FORTIFY_SOURCE.

C++ new and delete

  • operator new(size) is ??2@YAPAXI@Z (MSVC x86; x64 ??2@YAPEAX_K@Z) or _Znwm/_Znwj (Itanium) followed by a constructor call; a null check is absent for throwing new. operator delete is ??3@YAXPAX@Z / _ZdlPv; sized delete adds the size argument (_ZdlPvm).
  • A new whose constructor can throw gets a cleanup funclet that frees the memory if the constructor throws; MSVC x64 places such funclets in .text$x (dtor$N, catch$N) reached through the UNWIND_INFO tables, so they look like unreachable functions with no callers. See Platform:Microsoft Visual C++ ABI/C++ exception handling; Itanium landing pads are reached from the LSDA call-site table (Platform:Itanium C++ ABI).
  • The scalar deleting destructor (??_G, vftable slot 0) calls the destructor and then operator delete when bit 0 of its argument is set.

See the overview: Technique:Recognizing compiler-generated code.