Reputation: 23
So i have this main function, and it produces alot of weird instructions. I am using Visual Studio 2019, and i am in debug mode, so optimizations are disabled. What are these instructions doing?
int main()
{
00D340E0 push ebp
00D340E1 mov ebp,esp
00D340E3 sub esp,104h
00D340E9 push ebx
00D340EA push esi
00D340EB push edi
00D340EC lea edi,[ebp-104h]
00D340F2 mov ecx,41h
00D340F7 mov eax,0CCCCCCCCh
00D340FC rep stos dword ptr es:[edi]
00D340FE mov eax,dword ptr [__security_cookie (0D3A024h)]
00D34103 xor eax,ebp
00D34105 mov dword ptr [ebp-4],eax
00D34108 mov ecx,offset _842A6236_main@cpp (0D3C012h)
00D3410D call @__CheckForDebuggerJustMyCode@4 (0D31208h)
(the rest of the file...)
EDIT: By weird, i meant i dont understand what is happening here, not that its not standard.
Upvotes: 2
Views: 451
Reputation: 25408
These are debugging helpers.
__security_cookie
is used to check for writes past the end of the stack (if you overflow a stack-based buffer, say). The actual check is performed when exiting the function.
__CheckForDebuggerJustMyCode
allows the debugger to step over "system, framework, library, and other non-user calls", see here.
And this code:
lea edi,[ebp-104h]
mov ecx,41h
mov eax,0CCCCCCCCh
rep stos dword ptr es:[edi]
Fills the stack frame with garbage bytes that will (for example) cause an exception if you dereference an uninitialised pointer.
None of this stuff is present in Release builds, only in Debug builds.
Upvotes: 1