void __cdecl _cinit ( void ) { /* * initialize floating point package, if present */ #if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) /* * MIPS compiler doesn't emit external reference to _fltused. Therefore, * must always force in the floating point initialization. */ _fpmath(); #else /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */ if ( _FPinit != NULL ) (*_FPinit)(); #endif /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */ /* * do initializations */ _initterm( __xi_a, __xi_z ); /* * do C++ initializations */ _initterm( __xc_a, __xc_z ); }
void _CALLTYPE4 doexit ( int code, int quick, int retcaller ) { #ifdef _MT _lockexit(); /* assure only 1 thread in exit path */ #endif /* _MT */ /* save callable exit flag (for use by terminators) */ _exitflag = (char) retcaller; /* 0 = term, !0 = callable exit */ if (!quick) { /* * do _onexit/atexit() terminators * (if there are any) */ if (__onexitbegin) _initterm(__onexitbegin, __onexitend); /* * do pre-terminators */ _initterm(&__xp_a, &__xp_z); } /* * do terminators */ _initterm(&__xt_a, &__xt_z); /* * Floating point termination should go here... */ #ifdef _DEBUG /* Dump all memory leaks */ if (_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & _CRTDBG_LEAK_CHECK_DF) _CrtDumpMemoryLeaks(); #endif /* _DEBUG */ /* return to caller */ if (retcaller) { #ifdef _MT _unlockexit(); /* unlock the exit code path */ #endif /* _MT */ return; } if (_pMPWBlock != NULL) { _pMPWBlock->retCode = code; } _ShellReturn(); }
/*** *_cinit - C initialization * *Purpose: * This routine performs the shared DOS and Windows initialization. * The following order of initialization must be preserved - * * ? 1. Check for devices for file handles 0 - 2 * ? 2. Integer divide interrupt vector setup * 3. General C initializer routines * *Entry: * No parameters: Called from __crtstart and assumes data * set up correctly there. * *Exit: * Initializes C runtime data. * *Exceptions: * *******************************************************************************/ int _CALLTYPE1 __cinit ( void ) { long lRespond; OSErr osErr; /* * do initializations */ _initterm( &__xi_a, &__xi_z ); /* * do C++ initializations */ _initterm( &__xc_a, &__xc_z ); //#ifdef _M_MPPC if (NGetTrapAddress((unsigned short)0xa1ad, OSTrap) != NGetTrapAddress((unsigned short)_Unimplemented, ToolTrap )) //#else // if (GetTrapAddress((unsigned short)0xa1ad) != GetTrapAddress((unsigned short)_Unimplemented)) //#endif { osErr = Gestalt(gestaltSystemVersion, &lRespond); if (!osErr) { _osver = lRespond; // _osversion = lRespond; // _osmajor = (0x0000ff00 & lRespond)>>8; // _osminor = (0x000000ff & lRespond); } } return 0; }
void __cdecl WinMainCRTStartup() { STARTUPINFO si; unsigned char *cl; int res; // check and init fpu if required, // exit if required, but not available if (_FPinit && (_FPinit() == 0)) ExitProcess(-2); // call c initialisers if (_initterm(__xi_a, __xi_z, 1)) ExitProcess(-3); // call c++ initialisers _initterm(__xc_a, __xc_z, 0); cl = GetCommandLine(); if (cl == NULL) cl = ""; // parse command line { unsigned char delim = ' '; // skip any leading whitespaces (just in case) while (*cl && *cl <= delim) ++cl; // skip one parameter, which should be the application filename for ( ; *cl > delim; ++cl) { if (*cl == '"') delim ^= ' '; } // skip any whitespaces before first command line argument while (*cl && *cl <= delim) ++cl; } // get startup info on how to show si.dwFlags = 0; GetStartupInfo(&si); // -WCRT- tag __asm { test eax, 0x0a0d0a0d sub eax, 0x54524357 sub eax, 0x0a0d0a0d } // call WinMain res = WinMain( (HINSTANCE)GetModuleHandle(NULL), NULL, (LPSTR)cl, (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOWDEFAULT ); exit(res); }
void __cdecl _DoExitSpecial(int code, int retcaller, PFV *pAppPreTermBegin, PFV *pAppPreTermEnd, PFV *pAppTermBegin, PFV *pAppTermEnd, PFV *pAppOnexitBeg, PFV *pAppOnexitEnd) { #ifdef _DEBUG static int fExit = 0; #endif /* _DEBUG */ /* * do _onexit/atexit() terminators * (if there are any) including C++ destructors */ if (pAppOnexitBeg) { _initterm(pAppOnexitBeg, pAppOnexitEnd); } //if (__onexitbegin) // _initterm(__onexitbegin, __onexitend); /* * do pre-terminators, do app's one first */ _initterm(pAppPreTermBegin, pAppPreTermEnd); _initterm(&__xp_a, &__xp_z); /* * do terminators, do app's first */ _initterm(pAppTermBegin, pAppTermEnd); _initterm(&__xt_a, &__xt_z); #ifdef _DEBUG /* Dump all memory leaks */ if (!fExit && _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & _CRTDBG_LEAK_CHECK_DF) { fExit = 1; _CrtDumpMemoryLeaks(); } #endif if (_pMPWBlock != NULL) { _pMPWBlock->retCode = code; } if (!retcaller) { _ShellReturn(); } else { return; } }
void exit(int status) { // call functions registered with atexit wcrt_perform_atexit(); // call C pre-termination functions _initterm(__xp_a, __xp_z, 0); // call C termination functions _initterm(__xt_a, __xt_z, 0); ExitProcess(status); }
// Clean up: Call all destructor and cleanup routines specified at atexit call. void _doexit() { if (curAtExitEntries) { _initterm(atExitList, atExitList + curAtExitEntries); } }
word64 fn00000001400012BC(word32 edx, word64 rdi, word64 r13, selector gs, word64 qwArg08, word64 qwArg10) { if (fn0000000140001600(0x01, edx, r13) == 0x00) { word64 rcx_362; byte bl_363; fn0000000140001974(0x07, qwLoc04, qwArg00, qwArg04, qwArg0C, out rcx_362, out bl_363); int3(); } Mem23[fp - 0x14 + 0x00:byte] = 0x00; word32 eax_25 = fn00000001400015C4(gs); word64 rax_28 = DPB(rax, eax_25, 0); byte bl_29 = (byte) eax_25; word32 ecx_33 = Mem23[0x00000001400035B0 + 0x00:word32]; if (ecx_33 == 0x01) { ecx_33 = 0x07; word64 rcx_355; rax_28 = DPB(rax, fn0000000140001974(0x07, qwLoc04, qwArg00, qwArg04, qwArg0C, out rcx_355, out bl_29), 0); } word64 rax_233; if (ecx_33 == 0x00) { Mem331[0x00000001400035B0 + 0x00:word32] = 0x01; word64 rax_334 = DPB(rax_28, _initterm_e(0x00000001400021B8, 0x00000001400021D0), 0); if (_initterm_e(0x00000001400021B8, 0x00000001400021D0) != 0x00) { rax_233 = DPB(rax_28, 0xFF, 0); return rax_233; } _initterm(0x00000001400021A0, 0x00000001400021B0); Mem344[0x00000001400035B0 + 0x00:word32] = 0x02; }
extern "C" void mainCRTStartup() { _init_atexit(); _initterm(__xc_a, __xc_z); main(); _doexit(); ExitProcess(0); }
// Call this function as soon as possible. Basically should be at the moment you // jump into your C/C++ kernel. But keep in mind that kernel is not yet initialized, // and you can't use a lot of stuff in your constructors! bool CallConstructors() { // Do C initialization int initret = _initterm_e(__xi_a, __xi_z); if (initret != 0) { return false; } // Do C++ initialization _initterm(__xc_a, __xc_z); return true; }
/*** *_cinit - C initialization * *Purpose: * This routine performs the shared DOS and Windows initialization. * The following order of initialization must be preserved - * * ? 1. Check for devices for file handles 0 - 2 * ? 2. Integer divide interrupt vector setup * 3. General C initializer routines * *Entry: * No parameters: Called from __crtstart and assumes data * set up correctly there. * *Exit: * Initializes C runtime data. * *Exceptions: * *******************************************************************************/ int _CALLTYPE1 __cinit ( void ) { long lRespond; OSErr osErr; /* * do initializations */ _initterm( &__xi_a, &__xi_z ); /* * do C++ initializations */ _initterm( &__xc_a, &__xc_z ); osErr = Gestalt(gestaltSystemVersion, &lRespond); if (!osErr) _osver = lRespond; return 0; }
void fn0040127B(word32 ebx, word32 esi, word32 edi) { fn00401561(); Eq_5 * ebp_10 = fn00401770(ebx, esi, edi, dwLoc0C, 4202984, 0x0C); ebp_10->dw0000 = 0; Eq_25 * esp_105 = fp - 8; word32 edx_17 = fs->ptr0018->dw0004; word32 edi_18 = 0; do { __lock(); word32 eax_24; __cmpxchg(globals->dw403368, edx_17, 0, out eax_24); if (eax_24 == 0) goto l00401151; } while (eax_24 != edx_17); edi_18 = 1; l00401151: if (globals->dw40336C == 1) { Mem185[fp - 0x0C:word32] = 31; _amsg_exit(); esp_105 = fp + 0xFFFFFFF4; l0040119D: if (globals->dw40336C == 1) { Eq_25 * esp_174 = esp_105 - 4; esp_174->dw0000 = 4202652; esp_174->dw0000 = 4202644; _initterm(); globals->dw40336C = 2; esp_105 = esp_174; } if (edi_18 == 0) globals->dw403368 = 0; if (globals->ptr403378 != null) { Eq_167 * esp_152 = esp_105 - 4; esp_152->dw0000 = 4207480; word32 eax_154 = fn00401470(dwArg00); esp_105 = esp_152 + 4; if (eax_154 != 0) { esp_152->dw0000 = 0; esp_152->t0004.dw0000 = 2; esp_152->t0004.dw0000 = 0; esp_105 = esp_152 - 8; Mem165[4207480:word32](); }
void __cdecl mainCRTStartup( void ) { // // Call C initializers. // _initterm_e(__xi_a, __xi_z); // // Call C++ initializers. // _initterm(__xc_a, __xc_z); // // Exit with whatever main will return. // create_argc_and_argv(); int exit_code = main(__argc, __argv); destroy_argc_and_argv(); exit(exit_code); }
__declspec(noinline) int __tmainCRTStartup (void) { _TCHAR *lpszCommandLine = NULL; STARTUPINFO StartupInfo; WINBOOL inDoubleQuote = FALSE; memset (&StartupInfo, 0, sizeof (STARTUPINFO)); if (mingw_app_type) GetStartupInfo (&StartupInfo); { void *lock_free = NULL; void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase; int nested = FALSE; while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock, fiberid, 0)) != 0) { if (lock_free == fiberid) { nested = TRUE; break; } Sleep(1000); } if (__native_startup_state == __initializing) { _amsg_exit (31); } else if (__native_startup_state == __uninitialized) { __native_startup_state = __initializing; _initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z); } else has_cctor = 1; if (__native_startup_state == __initializing) { _initterm (__xc_a, __xc_z); __native_startup_state = __initialized; } _ASSERTE(__native_startup_state == __initialized); if (! nested) (VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0); if (__dyn_tls_init_callback != NULL) __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL); _pei386_runtime_relocator (); __mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler); #ifdef _WIN64 __mingw_init_ehandler (); #endif __mingw_prepare_except_for_msvcr80_and_higher (); _fpreset (); if (mingw_app_type) { #ifdef WPRFLAG lpszCommandLine = (_TCHAR *) _wcmdln; #else lpszCommandLine = (char *) _acmdln; #endif while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine&&inDoubleQuote)) { if (*lpszCommandLine == DQUOTECHAR) inDoubleQuote = !inDoubleQuote; #ifdef _MBCS if (_ismbblead (*lpszCommandLine)) { if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */ lpszCommandLine++; } #endif ++lpszCommandLine; } while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) lpszCommandLine++; __mingw_winmain_hInstance = (HINSTANCE) &__ImageBase; __mingw_winmain_lpCmdLine = lpszCommandLine; __mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT; } duplicate_ppstrings (argc, &argv); #ifdef WPRFLAG __winitenv = envp; /* C++ initialization. gcc inserts this call automatically for a function called main, but not for wmain. */ __main (); mainret = wmain (argc, argv, envp); #else __initenv = envp; mainret = main (argc, argv, envp); #endif if (!managedapp) exit (mainret); if (has_cctor == 0) _cexit (); } return mainret; }
int __tmainCRTStartup( void ) { #ifdef _WINMAIN_ _TUCHAR* lpszCommandLine; STARTUPINFO StartupInfo; BOOL inDoubleQuote = FALSE; __try { /* Note: MSDN specifically notes that GetStartupInfo returns no error, and throws unspecified SEH if it fails, so the very general exception handler below is appropriate */ GetStartupInfo(&StartupInfo); } __except (EXCEPTION_EXECUTE_HANDLER) { return 255; } #endif /* _WINMAIN_ */ /* * Guard the initialization code and the call to user's main, or * WinMain, function in a __try/__except statement. */ __try { /* * There is a possiblity that the module where this object is * linked into is a mixed module. In all the cases we gurantee that * native initialization will occur before managed initialization. * Also in anycase this code should never be called when some other * code is initializing native code, that's why we exit in that case. * * Do runtime startup initializers. * * Note: the only possible entry we'll be executing here is for * __lconv_init, pulled in from charmax.obj only if the EXE was * compiled with -J. All other .CRT$XI* initializers are only * run as part of the CRT itself, and so for the CRT DLL model * are not found in the EXE. For that reason, we call _initterm, * not _initterm_e, because __lconv_init will never return failure, * and _initterm_e is not exported from the CRT DLL. * * Note further that, when using the CRT DLL, executing the * .CRT$XI* initializers is only done for an EXE, not for a DLL * using the CRT DLL. That is to make sure the -J setting for * the EXE is not overriden by that of any DLL. */ void* lock_free = 0; void* fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase; int nested = FALSE; while ((lock_free = InterlockedCompareExchangePointer((volatile PVOID*)&__native_startup_lock, fiberid, 0)) != 0) { if (lock_free == fiberid) { nested = TRUE; break; } /* some other thread is running native startup/shutdown during a cctor/domain unload. Should only happen if this DLL was built using the Everett-compat loader lock fix in vcclrit.h */ /* wait for the other thread to complete init before we return */ Sleep(1000); } if (__native_startup_state == __initializing) { _amsg_exit(_RT_CRT_INIT_CONFLICT); } else if (__native_startup_state == __uninitialized) { __native_startup_state = __initializing; #ifndef _SYSCRT if (_initterm_e(__xi_a, __xi_z) != 0) { return 255; } #else /* _SYSCRT */ _initterm((_PVFV*)(void*)__xi_a, (_PVFV*)(void*)__xi_z); #endif /* _SYSCRT */ } else { has_cctor = 1; } /* * do C++ constructors (initializers) specific to this EXE */ if (__native_startup_state == __initializing) { _initterm(__xc_a, __xc_z); __native_startup_state = __initialized; } _ASSERTE(__native_startup_state == __initialized); if (!nested) { /* For X86, the definition of InterlockedExchangePointer wrongly causes warning C4312 */ #pragma warning(push) #pragma warning(disable:4312) InterlockedExchangePointer((volatile PVOID*)&__native_startup_lock, 0); #pragma warning(pop) } /* * If we have any dynamically initialized __declspec(thread) * variables, then invoke their initialization for the primary * thread used to start the process, by calling __dyn_tls_init * through a callback defined in tlsdyn.obj. */ if (__dyn_tls_init_callback != NULL && _IsNonwritableInCurrentImage((PBYTE)&__dyn_tls_init_callback)) { __dyn_tls_init_callback(NULL, DLL_THREAD_ATTACH, NULL); } /* Enable buffer count checking if linking against static lib */ _CrtSetCheckCount(TRUE); #ifdef _WINMAIN_ /* * Skip past program name (first token in command line). * Check for and handle quoted program name. */ #ifdef WPRFLAG /* OS may not support "W" flavors */ if (_wcmdln == NULL) { return 255; } lpszCommandLine = (wchar_t*)_wcmdln; #else /* WPRFLAG */ lpszCommandLine = (unsigned char*)_acmdln; #endif /* WPRFLAG */ while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine && inDoubleQuote)) { /* * Flip the count from 1 to 0 or 0 to 1 if current character * is DOUBLEQUOTE */ if (*lpszCommandLine == DQUOTECHAR) { inDoubleQuote = !inDoubleQuote; } #ifdef _MBCS if (_ismbblead(*lpszCommandLine)) { if (lpszCommandLine) { lpszCommandLine++; } } #endif /* _MBCS */ ++lpszCommandLine; } /* * Skip past any white space preceeding the second token. */ while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) { lpszCommandLine++; } #ifdef WPRFLAG mainret = wWinMain( #else /* WPRFLAG */ mainret = WinMain( #endif /* WPRFLAG */ (HINSTANCE)&__ImageBase, NULL, lpszCommandLine, StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT ); #else /* _WINMAIN_ */ #ifdef WPRFLAG __winitenv = envp; mainret = wmain(argc, argv, envp); #else /* WPRFLAG */ __initenv = envp; mainret = main(argc, argv, envp); #endif /* WPRFLAG */ #endif /* _WINMAIN_ */ /* * Note that if the exe is managed app, we don't really need to * call exit or _c_exit. .cctor should be able to take care of * this. */ if (!managedapp) exit(mainret); if (has_cctor == 0) _cexit(); } __except (_XcptFilter(GetExceptionCode(), GetExceptionInformation())) { /* * Should never reach here */ mainret = GetExceptionCode(); /* * Note that if the exe is managed app, we don't really need to * call exit or _c_exit. .cctor should be able to take care of * this. */ if (!managedapp) { _exit(mainret); } if (has_cctor == 0) { _cexit(); } } /* end of try - except */ return mainret; }
// address: 0x4014ec void _start() { __size16 ax; // r0 __size16 cx; // r1 unsigned char dl; // r10 __size32 eax; // r24 __size32 *ebp; // r29 __size32 ebx; // r27 __size32 ecx; // r25 __size32 edi; // r31 int edx; // r26 __size32 esi; // r30 int esp; // r28 void *esp_1; // r28{8} void *esp_2; // r28{44} void *esp_3; // r28{191} int local0; // m[esp - 4] int local1; // m[esp - 24] int local2; // m[esp - 20] unsigned int local3; // m[esp - 12] int local4; // m[esp - 8] void *local5; // esp_3{191} esi = proc1(local1, local2, esi); /* Warning: also results in ebx, edi */ esp_1 = proc2(16, ebx, esi, edi); /* Warning: also results in ebp */ local5 = esp_1; ebx = 0; *(__size32*)(ebp - 4) = 0; eax = *24; esi = *(eax + 4); *(__size32*)(ebp - 28) = 0; edi = 0x403374; for(;;) { esp_3 = local5; *(__size32*)(esp_3 - 4) = 0; *(__size32*)(esp_3 - 8) = esi; *(__size32*)(esp_3 - 12) = 0x403374; eax = InterlockedCompareExchange(); /* Warning: also results in edx */ if (eax == 0) { goto L24; } if (eax == esi) { break; } *(__size32*)(esp_3 - 16) = 1000; esp_2 = Sleep(*(esp_3 - 16)); local5 = esp_2; } *(__size32*)(ebp - 28) = 1; L24: esi = 1; if (global61 != 1) { if (global61 != 0) { global68 = 1; L16: if (global61 == 1) { *(__size32*)(esp_3 - 16) = 0x4020cc; *(__size32*)(esp_3 - 20) = 0x4020c4; edx = _initterm(); global61 = 2; } if (*(ebp - 28) == 0) { *(__size32*)(esp_3 - 16) = 0; *(__size32*)(esp_3 - 20) = 0x403374; edx = InterlockedExchange(*(esp_3 - 20), *(esp_3 - 16)); } esp = esp_3 - 12; if (*0x403380 != 0) { *(__size32*)(esp_3 - 16) = 0x403380; eax = proc5(*(esp_3 - 16), dl, edx, 0); /* Warning: also results in ax, cx, dl, edx */ ecx = *(esp_3 - 16); esp = esp_3 - 12; if (eax != 0) { *(__size32*)(esp_3 - 16) = 0; *(__size32*)(esp_3 - 20) = 2; *(__size32*)(esp_3 - 24) = 0; (*global53)(local1, local2, pc, 0x4021d8, 16, ax, cx, dl, eax, ecx, edx, 0, ebp, 1, 0x403374, LOGICALFLAGS32(eax), LOGICALFLAGS32(eax), LOGICALFLAGS32(eax)); } } *(__size32*)0x23cc = global75; local0 = global75; local4 = global76; local3 = global77; eax = proc6(*(esp - 12), *(esp - 8), 0x23cc, ebx, esi, edi); /* Warning: also results in ebx */ global79 = eax; if (*0x403024 == ebx) { local0 = eax; exit(*(esp - 4)); } if (*0x403034 == ebx) { _cexit(); } *(__size32*)(ebp - 4) = -2; } else { global61 = 1; *(__size32*)(esp_3 - 16) = 0x4020dc; *(__size32*)(esp_3 - 20) = 0x4020d0; eax = _initterm_e(); /* Warning: also results in edx */ esp = esp_3 - 12; if (eax == 0) { goto L16; } else { *(__size32*)(ebp - 4) = -2; } } } else { *(__size32*)(esp_3 - 16) = 31; edx = _amsg_exit(); goto L16; } proc8(ebp); return; }
/* =================================== Executes all global dynamic initializers =================================== */ void _cdecl InitializeConstructors() { _atexit_init(); _initterm(__xc_a, __xc_z); }
void fn004019E0(word32 ebp, Eq_3 * fs) { word32 * eax_14 = fs->ptr0000; fs->ptr0000 = fp - 0x00000014; __set_app_type(); globals->dw40312C = 0xFFFFFFFF; globals->dw403130 = 0xFFFFFFFF; __p__fmode(); *eax_14 = globals->dw403120; __p__commode(); *eax_14 = globals->dw40311C; Mem46[0x00403128:word32] = Mem43[_adjust_fdiv:word32]; fn00401BE0(); word32 esp_193 = fp + 0xFFFFFF6C; if (globals->dw403040 == 0x00000000) { __setusermatherr(); esp_193 = fp + 0xFFFFFF68; } fn00401BB0(); Eq_51 * esp_54 = esp_193 - 0x00000004; esp_54->dw0000 = 0x00403014; esp_54->dw0000 = 0x00403010; _initterm(); esp_54->dw0000 = fp - 0x00000070; esp_54->dw0000 = globals->dw403114; esp_54->dw0000 = fp - 0x00000068; Mem74[esp_54 - 0x00000010:word32] = fp - 0x00000074; esp_54->dw0000 = fp - 0x00000064; __getmainargs(); esp_54->dwFFFFFFF8 = 0x0040300C; esp_54->dwFFFFFFF4 = 0x00403000; _initterm(); __p__acmdln(); Eq_85 * esi_161 = dwLoc74; if (dwLoc74->b0000 == 0x22) { do { esi_161 = esi_161 + 1; bcu8 al_169 = esi_161->b0000; } while (al_169 == 0x00 || al_169 == 0x22); if (esi_161->b0000 == 0x22) { esi_161 = esi_161 + 1; goto l00401AEE; } } while (esi_161->b0000 >u 0x20) esi_161 = esi_161 + 1; l00401AEE: bcu8 al_99 = esi_161->b0000; while (al_99 != 0x00 && al_99 <=u 0x20) { esi_161 = esi_161 + 1; al_99 = esi_161->b0000; } Eq_80 eax_117; esp_54->tFFFFFFF0 = fp - 0x00000060; GetStartupInfoA(esp_54->tFFFFFFF0); if (0x00 != 0x00) eax_117 = dwLoc30 & 0x0000FFFF; else eax_117.u0 = 0x0000000A; esp_54->tFFFFFFF0 = eax_117; esp_54->ptrFFFFFFEC = esi_161; esp_54->dwFFFFFFE8 = 0x00000000; esp_54->tFFFFFFE4.u0 = 0x00000000; Eq_80 eax_127 = GetModuleHandleA(esp_54->tFFFFFFE4); esp_54->tFFFFFFE4 = eax_127; fn00401BFC(ebp, dwArg00, dwArg04, dwArg08); esp_54->tFFFFFFF0 = eax_127; exit(esp_54->tFFFFFFF0); fp->dwFFFFFFF8 = 0xFFFFFFFF; fs->ptr0000 = eax_14; return; }
void __cdecl wmainCRTStartup() { wchar_t *cl; char *clbuffer; int argc; int res; // check and init fpu if required, // exit if required, but not available if (_FPinit && (_FPinit() == 0)) ExitProcess(-2); // call c initialisers if (_initterm(__xi_a, __xi_z, 1)) ExitProcess(-3); // call c++ initialisers _initterm(__xc_a, __xc_z, 0); // get command line cl = GetCommandLine(); if (cl == NULL) cl = L""; // parse command line into argv array { int clsize; clsize = wcrt_parse_argvw(cl, &argc, NULL, NULL); clbuffer = (char *) malloc(clsize); if (clbuffer) { wcrt_parse_argvw( cl, &argc, (wchar_t **) clbuffer, (wchar_t *) (clbuffer + (argc + 1)*sizeof(wchar_t *)) ); } else { argc = 0; } } // -WCRT- tag __asm { test eax, 0x0a0d0a0d sub eax, 0x54524357 sub eax, 0x0a0d0a0d } // call main if (clbuffer) { res = wmain(argc, (wchar_t **) clbuffer, 0); free(clbuffer); } else { res = wmain(0, 0, 0); } exit(res); }
WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { if (dwReason == DLL_PROCESS_DETACH) { if (__proc_attached > 0) __proc_attached--; else return FALSE; } if (dwReason == DLL_PROCESS_ATTACH) { void *lock_free = NULL; void *fiberid = ((PNT_TIB)NtCurrentTeb ())->StackBase; int nested = FALSE; while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock, fiberid, 0)) != 0) { if (lock_free == fiberid) { nested = TRUE; break; } Sleep(1000); } if (__native_startup_state != __uninitialized) { _amsg_exit(31); } else { __native_startup_state = __initializing; _initterm ((_PVFV *) (void *) __xi_a, (_PVFV *) (void *) __xi_z); _initterm (__xc_a,__xc_z); __native_startup_state = __initialized; } if (! nested) { (void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0); } if (__dyn_tls_init_callback != NULL) { __dyn_tls_init_callback (hDllHandle, DLL_THREAD_ATTACH, lpreserved); } __proc_attached++; } else if (dwReason == DLL_PROCESS_DETACH) { void *lock_free = NULL; while ((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock,(PVOID) 1, 0)) != 0) { Sleep(1000); } if(__native_startup_state!=__initialized) { _amsg_exit (31); } else { _PVFV * onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); if (onexitbegin) { _PVFV *onexitend = (_PVFV *) _decode_pointer (__onexitend); while (--onexitend >= onexitbegin) if (*onexitend != NULL) (**onexitend) (); free (onexitbegin); __onexitbegin = __onexitend = (_PVFV *) NULL; } __native_startup_state = __uninitialized; (void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0); } } return TRUE; }
//! execute all constructors and other dynamic initializers void _cdecl init_ctor() { _atexit_init(); _initterm(__xc_a, __xc_z); }
BOOL WINAPI _CRT_INIT( HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved ) { /* * If this is a process detach notification, check that there has * been a prior (successful) process attachment. */ if ( dwReason == DLL_PROCESS_DETACH ) { if ( __proc_attached > 0 ) __proc_attached--; else /* * no prior process attach. just return failure. */ return FALSE; } #ifdef _M_IX86 /* * Set the local copy of the Pentium FDIV adjustment flag */ _adjust_fdiv = * _imp___adjust_fdiv; #endif /* _M_IX86 */ /* * do C++ constructors (initializers) specific to this DLL */ if ( dwReason == DLL_PROCESS_ATTACH ) { /* * There is a possiblity that the module where this object is * linked into is a mixed module. In all the cases we gurantee * that native initialization will occur before managed * initialization. Also in anycase this code should never be * called when some other code is initializing native code, * that's why we exit in that case. * * The case that is illegal is when managed code is executed for * the first time in loader lock. But there can be case when dll is * loaded in LoadLibrary and CLR could be already loaded in this * case it is perfectly OK to execute .cctor. */ void *lock_free=0; void *fiberid=((PNT_TIB)NtCurrentTeb())->StackBase; int nested=FALSE; while((lock_free=InterlockedCompareExchangePointer((volatile PVOID *)&__native_startup_lock, fiberid, 0))!=0) { if(lock_free==fiberid) { nested=TRUE; break; } /* some other thread is running native startup/shutdown during a cctor/domain unload. Should only happen if this DLL was built using the Everett-compat loader lock fix in vcclrit.h */ /* wait for the other thread to complete init before we return */ Sleep(1000); } if (__native_startup_state != __uninitialized) { _amsg_exit( _RT_CRT_INIT_CONFLICT); } else { /* * Set the native startup state to initializing. */ __native_startup_state = __initializing; /* * Invoke C initializers. */ #ifndef _SYSCRT if (_initterm_e( __xi_a, __xi_z ) != 0) return FALSE; #else /* _SYSCRT */ _initterm((_PVFV *)(void *)__xi_a, (_PVFV *)(void *)__xi_z); #endif /* _SYSCRT */ /* * Invoke C++ constructors */ _initterm(__xc_a,__xc_z); /* * Set the native initialization state to initialized. */ __native_startup_state = __initialized; } if(!nested) { /* For X86, the definition of InterlockedExchangePointer wrongly causes warning C4312 */ #pragma warning(push) #pragma warning(disable:4312) InterlockedExchangePointer((volatile PVOID *)&__native_startup_lock,0); #pragma warning(pop) } /* * If we have any dynamically initialized __declspec(thread) * variables, then invoke their initialization for the thread on * which the DLL is being loaded, by calling __dyn_tls_init through * a callback defined in tlsdyn.obj. We can't rely on the OS * calling __dyn_tls_init with DLL_PROCESS_ATTACH because, on * Win2K3 and before, that call happens before the CRT is * initialized. */ if (__dyn_tls_init_callback != NULL && _IsNonwritableInCurrentImage((PBYTE)&__dyn_tls_init_callback)) { __dyn_tls_init_callback(hDllHandle, DLL_THREAD_ATTACH, lpreserved); } /* Enable buffer count checking if linking against static lib */ _CrtSetCheckCount(TRUE); /* * Increment the process attached flag. */ __proc_attached++; } else if ( dwReason == DLL_PROCESS_DETACH ) { /* * Any basic clean-up code that goes here must be * duplicated below in _DllMainCRTStartup for the * case where the user's DllMain() routine fails on a * Process Attach notification. This does not include * calling user C++ destructors, etc. */ /* * do _onexit/atexit() terminators * (if there are any) * * These terminators MUST be executed in * reverse order (LIFO)! * * NOTE: * This code assumes that __onexitbegin * points to the first valid onexit() * entry and that __onexitend points * past the last valid entry. If * __onexitbegin == __onexitend, the * table is empty and there are no * routines to call. */ void *lock_free=0; while((lock_free=InterlockedCompareExchangePointer((volatile PVOID *)&__native_startup_lock, (PVOID)1, 0))!=0) { /* some other thread is running native startup/shutdown during a cctor/domain unload. Should only happen if this DLL was built using the Everett-compat loader lock fix in vcclrit.h */ /* wait for the other thread to complete init before we return */ Sleep(1000); } if(__native_startup_state!=__initialized) { /* somehow we are in a very bad state running shutdown when we have not started */ _amsg_exit( _RT_CRT_INIT_CONFLICT); } else { _PVFV * onexitbegin = (_PVFV *)_decode_pointer(__onexitbegin); if (onexitbegin) { _PVFV * onexitend = (_PVFV *)_decode_pointer(__onexitend); while ( --onexitend >= onexitbegin ) /* * if current table entry is not * NULL, call thru it. */ if ( *onexitend != NULL ) (**onexitend)(); /* * free the block holding onexit table to * avoid memory leaks. Also zero the ptr * variables so that they are clearly cleaned up. */ _free_crt ( onexitbegin ) ; __onexitbegin = __onexitend = (_PVFV *)_encoded_null(); } __native_startup_state = __uninitialized; /* For X86, the definition of InterlockedExchangePointer wrongly causes warning C4312 */ #pragma warning(push) #pragma warning(disable:4312) InterlockedExchangePointer((volatile PVOID *)&__native_startup_lock,0); #pragma warning(pop) } } return TRUE; }
static void __cdecl doexit ( int code, int quick, int retcaller ) { #ifdef _DEBUG static int fExit = 0; #endif /* _DEBUG */ #ifdef _MT _lockexit(); /* assure only 1 thread in exit path */ #endif /* _MT */ if (_C_Exit_Done == TRUE) /* if doexit() is being called recursively */ TerminateProcess(GetCurrentProcess(),code); /* terminate with extreme prejudice */ _C_Termination_Done = TRUE; /* save callable exit flag (for use by terminators) */ _exitflag = (char) retcaller; /* 0 = term, !0 = callable exit */ if (!quick) { /* * do _onexit/atexit() terminators * (if there are any) * * These terminators MUST be executed in reverse order (LIFO)! * * NOTE: * This code assumes that __onexitbegin points * to the first valid onexit() entry and that * __onexitend points past the last valid entry. * If __onexitbegin == __onexitend, the table * is empty and there are no routines to call. */ if (__onexitbegin) { _PVFV * pfend = __onexitend; while ( --pfend >= __onexitbegin ) /* * if current table entry is non-NULL, * call thru it. */ if ( *pfend != NULL ) (**pfend)(); } /* * do pre-terminators */ _initterm(__xp_a, __xp_z); } /* * do terminators */ _initterm(__xt_a, __xt_z); #ifndef CRTDLL #ifdef _DEBUG /* Dump all memory leaks */ if (!fExit && _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & _CRTDBG_LEAK_CHECK_DF) { fExit = 1; _CrtDumpMemoryLeaks(); } #endif /* _DEBUG */ #endif /* CRTDLL */ /* return to OS or to caller */ if (retcaller) { #ifdef _MT _unlockexit(); /* unlock the exit code path */ #endif /* _MT */ return; } _C_Exit_Done = TRUE; ExitProcess(code); }
void fn1310E4E5(Eq_281 * fs) { word32 * eax_14 = fs->ptr0000; fs->ptr0000 = fp - 0x00000014; __set_app_type(); __p__fmode(); *eax_14 = 0x00000000; __p__commode(); *eax_14 = 0x00000000; word32 eax_51 = Mem49[_adjust_fdiv:word32]; fn1310E63E(); word32 esp_193 = fp + 0xFFFFFF68; if (eax_51 == 0x00000000) { __setusermatherr(); esp_193 = fp + 0xFFFFFF64; } fn1310E629(); Eq_318 * esp_59 = esp_193 - 0x00000004; esp_59->dw0000 = fp - 0x00000080; esp_59->dw0000 = fp - 0x00000080; _initterm(); esp_59->tFFFFFFF4 = fp - 0x00000070; esp_59->dwFFFFFFF0 = eax_51; esp_59->dwFFFFFFEC = fp - 0x00000068; esp_59->dwFFFFFFE8 = fp - 0x00000074; esp_59->dwFFFFFFE4 = fp - 0x00000064; __getmainargs(); esp_59->dwFFFFFFDC = fp - 0x00000080; esp_59->dwFFFFFFD8 = fp - 0x00000080; _initterm(); word32 esi_161 = Mem85[_acmdln:word32]; if (esi_161->b0000 == 0x22) { l1310E597: do { esi_161 = esi_161 + 1; bcu8 al_171 = esi_161->b0000; } while (al_171 == 0x00 || al_171 == 0x22); if (esi_161->b0000 == 0x22) { l1310E5AA: esi_161 = esi_161 + 1; l1310E5AE: bcu8 al_98 = esi_161->b0000; if (al_98 != 0x00 && al_98 <=u 0x20) goto l1310E5AA; } else goto l1310E5AE; } else while (esi_161->b0000 >u 0x20) esi_161 = esi_161 + 1; Eq_57 eax_113; esp_59->tFFFFFFF4 = fp - 0x00000060; GetStartupInfoA(esp_59->tFFFFFFF4); word32 esp_109 = &esp_59->tFFFFFFF4; if (0x00 != 0x00) eax_113 = (word32) wLoc30; else { esp_59->tFFFFFFF4.u0 = 0x0000000A; eax_113 = esp_59->tFFFFFFF4; esp_109 = &esp_59->tFFFFFFF4; } Eq_439 * esp_115 = esp_109 - 0x00000004; esp_115->t0000 = eax_113; Mem118[esp_115 - 0x00000004:word32] = esi_161; esp_115->t0000.u0 = 0x00000000; esp_115->t0000.u0 = 0x00000000; Mem126[esp_115 - 0x0000000C:word32] = GetModuleHandleA(esp_115->t0000); esp_115->dw0016 = fn1310E09B(); exit(esp_115->dw0016); word32 ecx_137 = **dwLoc18; esp_115->ptr0012 = dwLoc18; esp_115->dw000E = ecx_137; _XcptFilter(); return; }