Skip to content

Instantly share code, notes, and snippets.

@CoolOppo
Created June 23, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoolOppo/a65c262db26329099ab4 to your computer and use it in GitHub Desktop.
Save CoolOppo/a65c262db26329099ab4 to your computer and use it in GitHub Desktop.
Testing the Hex-Rays decompiler's ability
/* This file has been generated by the Hex-Rays decompiler.
Copyright (c) 2007-2011 Hex-Rays <info@hex-rays.com>
Detected compiler: Visual C++
*/
#include <windows.h>
#include <defs.h>
//-------------------------------------------------------------------------
// Data declarations
// extern int ___dcrt_initial_wide_environment; weak
// extern void *std::cout; weak
extern _UNKNOWN __xc_a; // weak
extern _UNKNOWN __xc_z; // weak
extern void (__cdecl *_xd_z)();
extern _UNKNOWN __xi_a; // weak
extern _UNKNOWN __xi_z; // weak
extern int (__stdcall *__dyn_tls_init_callback)(_DWORD, _DWORD, _DWORD); // weak
extern _EXCEPTION_POINTERS GS_ExceptionPointers;
extern char Val[]; // idb
extern unsigned __int64 MantissaMask;
extern unsigned __int64 IntegerBit;
extern unsigned __int64 MaxInt64;
extern unsigned __int64 MinSubInexact;
extern unsigned int i1075;
extern _UNKNOWN __rtc_izz; // weak
extern _UNKNOWN __rtc_tzz; // weak
extern int __scrt_default_matherr; // weak
extern int __security_cookie_complement; // weak
extern int __security_cookie; // weak
extern _onexit_table_t module_local_onexit_table;
extern _SLIST_HEADER __type_info_root_node; // idb
extern int __scrt_current_native_startup_state; // weak
extern _UNKNOWN __scrt_native_startup_lock; // weak
extern int __scrt_debugger_hook_flag; // weak
extern _EXCEPTION_RECORD GS_ExceptionRecord;
extern _CONTEXT GS_ContextRecord;
//-------------------------------------------------------------------------
// Function declarations
#define __thiscall __cdecl // Test compile in C mode
int __cdecl wmain(int argc, wchar_t **argv);
// std::basic_ostream<char,std::char_traits<char> > *__usercall std::operator<<<std::char_traits<char>><eax>(std::basic_ostream<char,std::char_traits<char> > *_Ostr<ecx>, const char *_Val<edx>);
int __cdecl pre_c_initialization();
int pre_cpp_initialization(); // weak
int __cdecl _scrt_common_main_seh();
int __cdecl invoke_main();
bool __cdecl __scrt_acquire_startup_lock();
bool __cdecl __scrt_initialize_onexit_table(__scrt_module_type module_type);
void __cdecl __scrt_release_startup_lock(bool is_nested);
bool __cdecl __scrt_initialize_crt(bool is_terminating, bool from_exit);
int (__cdecl *__cdecl _onexit(int (__cdecl *const function)()))();
int __cdecl atexit(void (__cdecl *function)());
int (__cdecl *__cdecl call_imported_onexit(int (__cdecl *const function)()))();
signed int __cdecl __security_init_cookie();
_crt_argv_mode __cdecl _get_startup_argv_mode();
// int __cdecl _set_app_type(_DWORD); weak
// int __cdecl _configure_wide_argv(_DWORD); weak
// int __cdecl __setusermatherr(_DWORD); weak
// int __cdecl _initterm(_DWORD, _DWORD); weak
// int __cdecl _initterm_e(_DWORD, _DWORD); weak
int __cdecl _get_startup_file_mode();
int __cdecl __scrt_initialize_winrt();
void __cdecl __scrt_initialize_type_info(); // idb
errno_t __cdecl _initialize_default_precision();
int _initialize_denormal_control(void); // weak
_IMAGE_SECTION_HEADER *__cdecl find_pe_section(char *const image_base, const unsigned int rva);
bool __cdecl __scrt_is_nonwritable_in_current_image(const void *target);
int __cdecl __scrt_is_user_matherr_present();
void __cdecl __scrt_fastfail(unsigned int code);
bool __cdecl __scrt_is_managed_app();
LPTOP_LEVEL_EXCEPTION_FILTER __cdecl __scrt_set_unhandled_exception_filter();
int __stdcall __scrt_unhandled_exception_filter(_EXCEPTION_POINTERS *const pointers);
// int __cdecl _configthreadlocale(_DWORD); weak
// int __cdecl _set_new_mode(_DWORD); weak
void __cdecl exit_0(int Code);
// void __cdecl _cexit();
void __cdecl _RTC_Initialize();
void __cdecl _RTC_Terminate(); // idb
// int __p__commode(void); weak
// errno_t __cdecl _set_fmode(int Mode);
// int __p___argc(void); weak
// int __p___wargv(void); weak
_EXCEPTION_DISPOSITION __cdecl _except_handler4(_EXCEPTION_RECORD *ExceptionRecord, _EXCEPTION_REGISTRATION_RECORD *EstablisherFrame, _CONTEXT *ContextRecord, void *DispatcherContext);
void __stdcall __dyn_tls_init(void *__formal, unsigned int dwReason, void *__formal);
// int __cdecl _initialize_onexit_table(_DWORD); weak
// int __cdecl _register_onexit_function(_DWORD, _DWORD); weak
// errno_t __cdecl _controlfp_s(unsigned int *CurrentState, unsigned int NewValue, unsigned int Mask);
void __cdecl terminate(); // idb
// void *__cdecl memset(void *Dst, int Val, size_t Size);
void __fastcall __security_check_cookie(unsigned int cookie);
// int __cdecl _except_handler4_common(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD); weak
void __cdecl __raise_securityfailure(_EXCEPTION_POINTERS *ExceptionPointers);
// void __usercall __report_gsfailure(unsigned int a1<ebx>, unsigned int a2<edi>, unsigned int a3<esi>, char a4);
// int __cdecl __vcrt_TerminateProcess(_DWORD); weak
// int __cdecl __vcrt_UnhandledException(_DWORD); weak
// BOOL __stdcall IsProcessorFeaturePresent(DWORD ProcessorFeature);
// int __CxxFrameHandler3(void); weak
// void __usercall _ftoui3(__m128i a1<xmm0>);
// void __usercall _ftoul3(__m128i a1<xmm0>);
void __cdecl _ftol3();
// void __usercall _ftol3_NaN(__m128i a1<xmm0>);
// signed __int64 __usercall _ftol3_work<edx:eax>(char a1<al>, int a2<ecx>, __m128i a3<xmm0>, __int64 a4<xmm5>);
// int __usercall _ftol3_common<eax>(int a1<ecx>, __m128i a2<xmm0>, __m128i a3<xmm1>);
signed __int64 __thiscall _ftol3_arg_error(int this);
void __fastcall _ftol3_except(int a1, int a2);
// void __usercall _dtoui3(__m128i a1<xmm0>);
// void __usercall _dtoul3(__m128i a1<xmm0>);
void __cdecl _dtol3();
// void __usercall _dtol3_NaN(__m128i a1<xmm0>);
// int __usercall _dtol3_work<eax>(int a1<ecx>, __m128d a2<xmm0>, __int64 a3<xmm5>);
int __fastcall _ultod3(int a1, int _EDX);
signed int __fastcall _ltod3(signed int a1, unsigned int a2);
// double __cdecl _except1(_DWORD); weak
int __cdecl _ehhandler_____6U__char_traits_D_std___std__YQAAV__basic_ostream_DU__char_traits_D_std___0_AAV10_PBD_Z();
// _onexit_t __cdecl __onexit(_onexit_t Func);
// int ___dcrt_initialize_wide_environment_nolock(void); weak
// int ___dcrt_get_or_create_wide_environment_nolock(void); weak
// LPTOP_LEVEL_EXCEPTION_FILTER __stdcall SetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
// LONG __stdcall UnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo);
// BOOL __stdcall IsDebuggerPresent();
// void __stdcall GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime);
// DWORD __stdcall GetCurrentThreadId();
// DWORD __stdcall GetCurrentProcessId();
// PVOID __stdcall DecodePointer(PVOID Ptr);
// PVOID __stdcall EncodePointer(PVOID Ptr);
// HMODULE __stdcall GetModuleHandleW(LPCWSTR lpModuleName);
// void __stdcall InitializeSListHead(PSLIST_HEADER ListHead);
// BOOL __stdcall QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency);
// BOOL __stdcall QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount);
// int std::uncaught_exception(void); weak
// int __thiscall std::basic_streambuf<char_std::char_traits<char>>::sputc(_DWORD, _DWORD); weak
// int std::basic_ostream<char_std::char_traits<char>>::_Osfx(void); weak
// int __thiscall std::basic_ostream<char_std::char_traits<char>>::operator<<(_DWORD, _DWORD, _DWORD); weak
// int std::basic_ostream<char_std::char_traits<char>>::flush(void); weak
// int __thiscall std::basic_ios<char_std::char_traits<char>>::setstate(_DWORD, _DWORD, _DWORD); weak
// int __thiscall std::basic_ostream<char_std::char_traits<char>>::operator<<(_DWORD, _DWORD, _DWORD); weak
// int __thiscall std::basic_streambuf<char_std::char_traits<char>>::sputn(_DWORD, _DWORD, _DWORD, _DWORD); weak
//----- (00401000) --------------------------------------------------------
int __cdecl wmain(int argc, wchar_t **argv)
{
double v2; // xmm0_8@0
double v3; // xmm1_8@1
__int128 v4; // xmm0@1
unsigned __int64 v5; // qdi@1
int v6; // ecx@6
int v7; // eax@6
std::basic_ostream<char,std::char_traits<char> > *v8; // eax@7
unsigned __int64 v9; // kr00_8@7
std::basic_ostream<char,std::char_traits<char> > *v10; // eax@8
double x; // [sp+38h] [bp-13898h]@1
LARGE_INTEGER PerformanceCount; // [sp+40h] [bp-13890h]@1
LARGE_INTEGER Frequency; // [sp+48h] [bp-13888h]@6
__int64 fib[10000]; // [sp+50h] [bp-13880h]@3
QueryPerformanceCounter(&PerformanceCount);
QueryPerformanceFrequency((LARGE_INTEGER *)&x);
_ltod3(PerformanceCount._s0.LowPart, PerformanceCount._s0.HighPart);
PerformanceCount = *(LARGE_INTEGER *)&v2;
_ltod3(SLODWORD(x), HIDWORD(x));
v3 = *(double *)&PerformanceCount._s0.LowPart / v2;
v4 = 0;
_mm_storel_pd(&x, 0);
v5 = __PAIR__(LODWORD(x), HIDWORD(x));
PerformanceCount = *(LARGE_INTEGER *)&v3;
do
{
if ( v5 )
{
if ( v5 == 4294967296i64 )
{
fib[1] = 1i64;
}
else
{
v6 = *(&PerformanceCount._s0.LowPart + 2 * HIDWORD(v5));
v7 = *(&Frequency._s0.HighPart + 2 * HIDWORD(v5))
+ __CFADD__(*(&Frequency._s0.LowPart + 2 * HIDWORD(v5)), v6)
+ *(&PerformanceCount._s0.HighPart + 2 * HIDWORD(v5));
LODWORD(fib[HIDWORD(v5)]) = *(&Frequency._s0.LowPart + 2 * HIDWORD(v5)) + v6;
HIDWORD(fib[HIDWORD(v5)]) = v7;
}
}
else
{
v4 = 0;
_mm_storel_pd((double *)fib, 0);
}
v8 = (std::basic_ostream<char,std::char_traits<char> > *)std::basic_ostream<char_std::char_traits<char>>::operator<<(
std::cout,
LODWORD(fib[HIDWORD(v5)]),
HIDWORD(fib[HIDWORD(v5)]));
std::operator<<<std::char_traits<char>>(v8, "\n");
v9 = __PAIR__(v5, HIDWORD(v5)) + 1;
LODWORD(v5) = (__PAIR__(v5, HIDWORD(v5)) + 1) >> 32;
HIDWORD(v5) = v9;
}
while ( __PAIR__(v5, (unsigned int)v9) < 0x2710 );
QueryPerformanceCounter((LARGE_INTEGER *)&x);
QueryPerformanceFrequency(&Frequency);
_ltod3(SLODWORD(x), HIDWORD(x));
*(_QWORD *)&x = v4;
_ltod3(Frequency._s0.LowPart, Frequency._s0.HighPart);
v10 = (std::basic_ostream<char,std::char_traits<char> > *)std::basic_ostream<char_std::char_traits<char>>::operator<<(
std::cout,
COERCE_UNSIGNED_INT64(x / *(double *)&v4 - *(double *)&PerformanceCount._s0.LowPart),
COERCE_UNSIGNED_INT64(x / *(double *)&v4 - *(double *)&PerformanceCount._s0.LowPart) >> 32);
std::operator<<<std::char_traits<char>>(v10, "\n");
return 0;
}
// 4030A4: using guessed type void *std::cout;
// 4030B0: using guessed type int __thiscall std::basic_ostream<char,std::char_traits<char>>::operator<<(_DWORD, _DWORD, _DWORD);
// 4030BC: using guessed type int __thiscall std::basic_ostream<char,std::char_traits<char>>::operator<<(_DWORD, _DWORD, _DWORD);
//----- (00401150) --------------------------------------------------------
std::basic_ostream<char,std::char_traits<char> > *__usercall std::operator<<<std::char_traits<char>><eax>(std::basic_ostream<char,std::char_traits<char> > *_Ostr<ecx>, const char *_Val<edx>)
{
const char *v2; // eax@1
std::basic_ostream<char,std::char_traits<char> > *v3; // edx@1
__int64 v4; // qcx@1
const char *v5; // ecx@3
int v6; // esi@3
char v7; // al@4
int v8; // eax@6
unsigned int v9; // esi@6
unsigned int v10; // edi@6
int v11; // edi@12
int v12; // esi@12
unsigned __int64 v13; // kr00_8@12
int v14; // ecx@14
int v15; // eax@16
std::basic_ostream<char,std::char_traits<char> > *v16; // ecx@17
int v17; // ecx@26
int v18; // eax@26
int v19; // eax@29
int v20; // edx@29
int v21; // eax@34
unsigned __int8 v22; // cf@36
int v23; // eax@41
char v24; // al@42
std::basic_ostream<char,std::char_traits<char> > *v25; // esi@42
int v26; // ecx@44
int v28; // [sp+0h] [bp-48h]@1
std::basic_ostream<char,std::char_traits<char> >::sentry _Ok; // [sp+10h] [bp-38h]@14
__int64 _Pad; // [sp+18h] [bp-30h]@13
int v31; // [sp+24h] [bp-24h]@1
int v32; // [sp+28h] [bp-20h]@26
int v33; // [sp+2Ch] [bp-1Ch]@6
int _State; // [sp+30h] [bp-18h]@1
std::basic_ostream<char,std::char_traits<char> > *v35; // [sp+34h] [bp-14h]@1
int *v36; // [sp+38h] [bp-10h]@1
int v37; // [sp+44h] [bp-4h]@22
v36 = &v28;
v2 = _Val;
v31 = (int)_Val;
v3 = _Ostr;
v35 = _Ostr;
HIDWORD(v4) = 0;
_State = 0;
if ( *(_BYTE *)v31 )
{
v5 = v2;
v6 = (int)(v2 + 1);
do
v7 = *v5++;
while ( v7 );
LODWORD(v4) = v4 - v6;
}
else
{
LODWORD(v4) = 0;
}
v33 = v4;
v8 = *(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4);
v9 = *(_DWORD *)&v3->dummy[v8 + 32];
v10 = *(_DWORD *)&v3->dummy[v8 + 36];
if ( (v10 & 0x80000000u) == 0
&& ((signed int)v10 > 0 || v9 && (v10 & 0x80000000u) == 0 && ((signed int)v10 > 0 || v9 > (unsigned int)v4)) )
{
v13 = __PAIR__(v10, v9) - v4;
v11 = (__PAIR__(v10, v9) - v4) >> 32;
v12 = v13;
}
else
{
_mm_storel_pd((double *)&_Pad, 0);
v11 = HIDWORD(_Pad);
v12 = _Pad;
}
_Ok.baseclass_0._Myostr = v3;
v14 = *(_DWORD *)&v3->dummy[v8 + 56];
if ( v14 )
{
(*(void (**)(void))(*(_DWORD *)v14 + 4))();
v3 = v35;
}
v15 = *(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4);
if ( !*(_DWORD *)&v3->dummy[v15 + 12] )
{
v16 = *(std::basic_ostream<char,std::char_traits<char> > **)&v3->dummy[v15 + 60];
if ( v16 )
{
if ( v16 != v3 )
{
std::basic_ostream<char_std::char_traits<char>>::flush();
v3 = v35;
}
}
}
if ( *(_DWORD *)&v3->dummy[*(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4) + 12] == 0 )
{
v37 = 0;
if ( (*(_DWORD *)&v3->dummy[*(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4) + 20] & 0x1C0) == 64 )
goto LABEL_49;
while ( v11 >= 0 && (v11 > 0 || v12) )
{
v17 = *(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4);
LOBYTE(v32) = v3->dummy[v17 + 64];
v18 = std::basic_streambuf<char_std::char_traits<char>>::sputc(*(_DWORD *)&v3->dummy[v17 + 56], v32);
v3 = v35;
if ( v18 == -1 )
{
HIDWORD(v4) = 4;
_State = 4;
break;
}
v22 = __CFADD__(v12--, -1);
LODWORD(_Pad) = v12;
v11 = v22 + v11 - 1;
HIDWORD(_Pad) = v11;
}
if ( !HIDWORD(v4) )
{
LABEL_49:
v19 = std::basic_streambuf<char_std::char_traits<char>>::sputn(
*(_DWORD *)&v3->dummy[*(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4) + 56],
v31,
v33,
0);
if ( v19 != v33 || v20 )
{
HIDWORD(v4) = 4;
LABEL_39:
_State = HIDWORD(v4);
}
else
{
while ( v11 >= 0 && (v11 > 0 || v12) )
{
v21 = *(_DWORD *)(*(_DWORD *)&v35->dummy[0] + 4);
LOBYTE(v31) = v35->dummy[v21 + 64];
if ( std::basic_streambuf<char_std::char_traits<char>>::sputc(*(_DWORD *)&v35->dummy[v21 + 56], v31) == -1 )
{
HIDWORD(v4) |= 4u;
goto LABEL_39;
}
v22 = __CFADD__(v12--, -1);
LODWORD(_Pad) = v12;
v11 = v22 + v11 - 1;
HIDWORD(_Pad) = v11;
}
}
v3 = v35;
}
v23 = *(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4);
*(_DWORD *)&v3->dummy[v23 + 32] = 0;
*(_DWORD *)&v3->dummy[v23 + 36] = 0;
v37 = -1;
}
else
{
HIDWORD(v4) = 4;
}
std::basic_ios<char_std::char_traits<char>>::setstate(
(char *)v3 + *(_DWORD *)(*(_DWORD *)&v3->dummy[0] + 4),
HIDWORD(v4),
0);
v24 = std::uncaught_exception();
v25 = _Ok.baseclass_0._Myostr;
if ( !v24 )
std::basic_ostream<char_std::char_traits<char>>::_Osfx();
v26 = *(_DWORD *)&v25->dummy[*(_DWORD *)(*(_DWORD *)&v25->dummy[0] + 4) + 56];
if ( v26 )
(*(void (**)(void))(*(_DWORD *)v26 + 8))();
return v35;
}
// 4030A0: using guessed type int std::uncaught_exception(void);
// 4030A8: using guessed type int __thiscall std::basic_streambuf<char,std::char_traits<char>>::sputc(_DWORD, _DWORD);
// 4030AC: using guessed type int std::basic_ostream<char,std::char_traits<char>>::_Osfx(void);
// 4030B4: using guessed type int std::basic_ostream<char,std::char_traits<char>>::flush(void);
// 4030B8: using guessed type int __thiscall std::basic_ios<char,std::char_traits<char>>::setstate(_DWORD, _DWORD, _DWORD);
// 4030C0: using guessed type int __thiscall std::basic_streambuf<char,std::char_traits<char>>::sputn(_DWORD, _DWORD, _DWORD, _DWORD);
//----- (0040137A) --------------------------------------------------------
int __cdecl pre_c_initialization()
{
int v0; // eax@1
int v1; // esi@1
_crt_argv_mode v2; // eax@2
int v3; // eax@5
_set_app_type(1);
v0 = _get_startup_file_mode();
_set_fmode(v0);
v1 = __p__commode();
*(_DWORD *)v1 = __scrt_initialize_winrt();
if ( !__scrt_initialize_onexit_table(dll) )
goto LABEL_10;
__asm { fnclex }
_RTC_Initialize();
atexit(_RTC_Terminate);
v2 = _get_startup_argv_mode();
if ( _configure_wide_argv(v2) )
{
LABEL_10:
__scrt_fastfail(7u);
__debugbreak();
JUMPOUT(*(int *)pre_cpp_initialization);
}
__scrt_initialize_type_info();
if ( __scrt_is_user_matherr_present() )
__setusermatherr(__scrt_initialize_winrt);
_initialize_denormal_control();
_initialize_denormal_control();
_initialize_default_precision();
v3 = __scrt_initialize_winrt();
_configthreadlocale(v3);
__scrt_initialize_winrt();
return 0;
}
// 40137A: could not find valid save-restore pair for esi
// 401410: using guessed type int pre_cpp_initialization();
// 401722: using guessed type int __cdecl _set_app_type(_DWORD);
// 401728: using guessed type int __cdecl _configure_wide_argv(_DWORD);
// 40172E: using guessed type int __cdecl __setusermatherr(_DWORD);
// 401776: using guessed type int _initialize_denormal_control(void);
// 401A00: using guessed type int __cdecl _configthreadlocale(_DWORD);
// 401A64: using guessed type int __p__commode(void);
//----- (00401410) --------------------------------------------------------
int __cdecl pre_cpp_initialization()
{
int v0; // eax@1
__scrt_set_unhandled_exception_filter();
v0 = __scrt_initialize_winrt();
return _set_new_mode(v0);
}
// 401410: using guessed type int pre_cpp_initialization();
// 401A06: using guessed type int __cdecl _set_new_mode(_DWORD);
//----- (00401422) --------------------------------------------------------
int __cdecl _scrt_common_main_seh()
{
char v0; // bl@3
int v2; // esi@12
bool v3; // [sp+0h] [bp-34h]@0
bool is_nested; // [sp+10h] [bp-24h]@3
if ( __scrt_initialize_crt(1, v3) )
goto $LN24;
do
{
__scrt_fastfail(7u);
$LN24:
v0 = 0;
is_nested = __scrt_acquire_startup_lock();
}
while ( __scrt_current_native_startup_state == 1 );
if ( __scrt_current_native_startup_state )
{
v0 = 1;
}
else
{
__scrt_current_native_startup_state = 1;
if ( _initterm_e(&__xi_a, &__xi_z) )
return 255;
_initterm(&__xc_a, &__xc_z);
__scrt_current_native_startup_state = 2;
}
__scrt_release_startup_lock(is_nested);
if ( __dyn_tls_init_callback && __scrt_is_nonwritable_in_current_image(&__dyn_tls_init_callback) )
__dyn_tls_init_callback(0, 2, 0);
v2 = invoke_main();
if ( !__scrt_is_managed_app() )
exit_0(v2);
if ( !v0 )
_cexit();
__scrt_initialize_crt(1, 0);
return v2;
}
// 401734: using guessed type int __cdecl _initterm(_DWORD, _DWORD);
// 40173A: using guessed type int __cdecl _initterm_e(_DWORD, _DWORD);
// 40315C: using guessed type int (__stdcall *__dyn_tls_init_callback)(_DWORD, _DWORD, _DWORD);
// 404038: using guessed type int __scrt_current_native_startup_state;
//----- (00401555) --------------------------------------------------------
int __cdecl invoke_main()
{
wchar_t ***v0; // esi@1
int *v1; // eax@1
___dcrt_initialize_wide_environment_nolock();
___dcrt_initial_wide_environment = ___dcrt_get_or_create_wide_environment_nolock();
v0 = (wchar_t ***)__p___wargv();
v1 = (int *)__p___argc();
return wmain(*v1, *v0);
}
// 401A70: using guessed type int __p___argc(void);
// 401A76: using guessed type int __p___wargv(void);
// 403058: using guessed type int ___dcrt_initialize_wide_environment_nolock(void);
// 40305C: using guessed type int ___dcrt_get_or_create_wide_environment_nolock(void);
// 403060: using guessed type int ___dcrt_initial_wide_environment;
//----- (00401596) --------------------------------------------------------
bool __cdecl __scrt_acquire_startup_lock()
{
signed __int32 v0; // edx@1
signed __int32 v1; // eax@3
v0 = *(_DWORD *)(__readfsdword(24) + 4);
do
{
v1 = _InterlockedCompareExchange((signed __int32 *)&__scrt_native_startup_lock, v0, 0);
if ( !v1 )
return 0;
}
while ( v0 != v1 );
return 1;
}
//----- (004015BF) --------------------------------------------------------
bool __cdecl __scrt_initialize_onexit_table(__scrt_module_type module_type)
{
bool result; // al@2
PVOID v2; // eax@5
void (__cdecl **v3)(); // ST0C_4@5
void (__cdecl **v4)(); // ST10_4@5
void (__cdecl **v5)(); // ST14_4@5
if ( module_type )
{
if ( module_type != 1 )
{
__scrt_fastfail(5u);
__debugbreak();
JUMPOUT(*(int *)__scrt_release_startup_lock);
}
v2 = EncodePointer((PVOID)0xFFFFFFFF);
v3 = (void (__cdecl **)())v2;
v4 = (void (__cdecl **)())v2;
v5 = (void (__cdecl **)())v2;
result = 1;
module_local_onexit_table._first = v3;
module_local_onexit_table._last = v4;
module_local_onexit_table._end = v5;
}
else
{
result = _initialize_onexit_table(&module_local_onexit_table) == 0;
}
return result;
}
// 401B28: using guessed type int __cdecl _initialize_onexit_table(_DWORD);
//----- (00401612) --------------------------------------------------------
void __cdecl __scrt_release_startup_lock(bool is_nested)
{
if ( !is_nested )
_InterlockedExchange((signed __int32 *)&__scrt_native_startup_lock, 0);
}
//----- (00401626) --------------------------------------------------------
bool __cdecl __scrt_initialize_crt(bool is_terminating, bool from_exit)
{
return 1;
}
//----- (00401629) --------------------------------------------------------
int (__cdecl *__cdecl _onexit(int (__cdecl *const function)()))()
{
int (__cdecl *result)(); // eax@2
if ( DecodePointer(module_local_onexit_table._first) == (PVOID)-1 )
result = call_imported_onexit(function);
else
result = (int (__cdecl *)())(_register_onexit_function(&module_local_onexit_table, function) == 0 ? (int)function : 0);
return result;
}
// 401B2E: using guessed type int __cdecl _register_onexit_function(_DWORD, _DWORD);
//----- (0040165D) --------------------------------------------------------
int __cdecl atexit(void (__cdecl *function)())
{
return (_onexit((int (__cdecl *const )())function) != NULL) - 1;
}
//----- (00401672) --------------------------------------------------------
int (__cdecl *__cdecl call_imported_onexit(int (__cdecl *const function)()))()
{
return __onexit(function);
}
//----- (0040167C) --------------------------------------------------------
signed int __cdecl __security_init_cookie()
{
signed int result; // eax@3
unsigned int v1; // ecx@4
_LARGE_INTEGER perfctr; // [sp+8h] [bp-14h]@4
FT systime; // [sp+10h] [bp-Ch]@1
int cookie; // [sp+18h] [bp-4h]@4
systime.ft_scalar = 0i64;
if ( __security_cookie != -1153374642 && __security_cookie & 0xFFFF0000 )
{
result = ~__security_cookie;
__security_cookie_complement = ~__security_cookie;
}
else
{
GetSystemTimeAsFileTime((LPFILETIME)&systime);
cookie = systime.ft_scalar ^ HIDWORD(systime.ft_scalar);
cookie = GetCurrentThreadId() ^ systime.ft_scalar ^ HIDWORD(systime.ft_scalar);
cookie ^= GetCurrentProcessId();
QueryPerformanceCounter(&perfctr);
result = (signed int)&cookie;
v1 = (unsigned int)&cookie ^ cookie ^ perfctr._s0.LowPart ^ perfctr._s0.HighPart;
if ( v1 == -1153374642 )
{
v1 = -1153374641;
}
else
{
if ( !(v1 & 0xFFFF0000) )
{
result = (v1 | 0x4711) << 16;
v1 |= result;
}
}
__security_cookie = v1;
__security_cookie_complement = ~v1;
}
return result;
}
// 404014: using guessed type int __security_cookie_complement;
// 404018: using guessed type int __security_cookie;
//----- (00401718) --------------------------------------------------------
_crt_argv_mode __cdecl _get_startup_argv_mode()
{
return 1;
}
//----- (00401740) --------------------------------------------------------
int __cdecl _get_startup_file_mode()
{
return 16384;
}
//----- (00401746) --------------------------------------------------------
int __cdecl __scrt_initialize_winrt()
{
return 0;
}
//----- (00401749) --------------------------------------------------------
void __cdecl __scrt_initialize_type_info()
{
InitializeSListHead(&__type_info_root_node);
}
//----- (00401755) --------------------------------------------------------
errno_t __cdecl _initialize_default_precision()
{
errno_t result; // eax@1
result = _controlfp_s(NULL, 0x10000u, 0x30000u);
if ( result )
{
__scrt_fastfail(7u);
__debugbreak();
JUMPOUT(*(int *)_initialize_denormal_control);
}
return result;
}
// 401776: using guessed type int _initialize_denormal_control(void);
//----- (00401777) --------------------------------------------------------
_IMAGE_SECTION_HEADER *__cdecl find_pe_section(char *const image_base, const unsigned int rva)
{
char *v2; // ecx@1
int v3; // edx@1
int v4; // esi@1
_IMAGE_SECTION_HEADER *result; // eax@5
v2 = &image_base[*((_DWORD *)image_base + 15)];
v3 = (int)&v2[*((_WORD *)v2 + 10) + 24];
v4 = v3 + 40 * *((_WORD *)v2 + 3);
if ( v3 == v4 )
{
LABEL_5:
result = NULL;
}
else
{
while ( rva < *(_DWORD *)(v3 + 12) || rva >= *(_DWORD *)(v3 + 12) + *(_DWORD *)(v3 + 8) )
{
v3 += 40;
if ( v3 == v4 )
goto LABEL_5;
}
result = (_IMAGE_SECTION_HEADER *)v3;
}
return result;
}
//----- (004017BB) --------------------------------------------------------
bool __cdecl __scrt_is_nonwritable_in_current_image(const void *target)
{
_IMAGE_SECTION_HEADER *v1; // eax@4
return *(_WORD *)&v400000 == 23117
&& *(_DWORD *)(v40003C + 4194304) == 17744
&& *(_WORD *)(v40003C + 4194328) == 267
&& (v1 = find_pe_section((char *const )0x400000, (const unsigned int)((char *)target - 4194304))) != NULL
&& !(v1->Characteristics & 0x80000000);
}
//----- (00401848) --------------------------------------------------------
int __cdecl __scrt_is_user_matherr_present()
{
return __scrt_default_matherr == 0;
}
// 404000: using guessed type int __scrt_default_matherr;
//----- (00401854) --------------------------------------------------------
void __cdecl __scrt_fastfail(unsigned int code)
{
unsigned int v1; // ebx@0
unsigned int v2; // edi@0
void *v3; // eax@3
unsigned int v8; // ecx@3
unsigned int v9; // edx@3
unsigned int v10; // ST08_4@3
BOOL v11; // eax@3
bool v12; // bl@3
char v13; // [sp-Ch] [bp-338h]@3
int v14; // [sp+0h] [bp-32Ch]@3
_CONTEXT context_record; // [sp+8h] [bp-324h]@3
_EXCEPTION_RECORD exception_record; // [sp+2D4h] [bp-58h]@3
_EXCEPTION_POINTERS exception_pointers; // [sp+324h] [bp-8h]@3
unsigned int v18; // [sp+32Ch] [bp+0h]@3
void *v19; // [sp+330h] [bp+4h]@3
if ( IsProcessorFeaturePresent(0x17u) )
__asm { int 29h ; Win8: RtlFailFast(ecx) }
__scrt_debugger_hook_flag = 0;
v3 = memset(&context_record, 0, 0x2CCu);
_CF = __CFADD__(&v13, 12);
_OF = __OFADD__(12, &v13);
_ZF = &v14 == NULL;
_SF = (signed int)&v14 < 0;
context_record.Eax = (unsigned int)v3;
context_record.Ecx = v8;
context_record.Edx = v9;
context_record.Ebx = v1;
context_record.Esi = 0;
context_record.Edi = v2;
LOWORD(context_record.SegSs) = __SS__;
LOWORD(context_record.SegCs) = __CS__;
LOWORD(context_record.SegDs) = __DS__;
LOWORD(context_record.SegEs) = __ES__;
LOWORD(context_record.SegFs) = __FS__;
LOWORD(context_record.SegGs) = __GS__;
__asm { pushf }
context_record.EFlags = v10;
context_record.Eip = (unsigned int)v19;
context_record.Esp = (unsigned int)&v19;
context_record.ContextFlags = 65537;
context_record.Ebp = v18;
memset(&exception_record, 0, 0x50u);
exception_record.ExceptionCode = 1073741845;
exception_record.ExceptionFlags = 1;
exception_record.ExceptionAddress = v19;
v11 = IsDebuggerPresent();
exception_pointers.ExceptionRecord = &exception_record;
exception_pointers.ContextRecord = &context_record;
v12 = v11 == 1;
SetUnhandledExceptionFilter(NULL);
if ( !UnhandledExceptionFilter(&exception_pointers) )
__scrt_debugger_hook_flag = v12 != 0 ? __scrt_debugger_hook_flag : 0;
}
// 404040: using guessed type int __scrt_debugger_hook_flag;
//----- (0040196F) --------------------------------------------------------
bool __cdecl __scrt_is_managed_app()
{
HMODULE v0; // ecx@1
bool result; // al@2
int v2; // eax@4
v0 = GetModuleHandleW(NULL);
if ( v0
&& LOWORD(v0->unused) == 23117
&& (v2 = (int)((char *)v0 + v0[15].unused), *(_DWORD *)v2 == 17744)
&& *(_WORD *)(v2 + 24) == 267
&& *(_DWORD *)(v2 + 116) > 0xEu )
result = *(_DWORD *)(v2 + 232) != 0;
else
result = 0;
return result;
}
//----- (004019B3) --------------------------------------------------------
LPTOP_LEVEL_EXCEPTION_FILTER __cdecl __scrt_set_unhandled_exception_filter()
{
return SetUnhandledExceptionFilter(__scrt_unhandled_exception_filter);
}
//----- (004019BF) --------------------------------------------------------
int __stdcall __scrt_unhandled_exception_filter(_EXCEPTION_POINTERS *const pointers)
{
_EXCEPTION_RECORD *v1; // eax@1
unsigned int v2; // eax@3
v1 = pointers->ExceptionRecord;
if ( pointers->ExceptionRecord->ExceptionCode == -529697949 )
{
if ( v1->NumberParameters == 3 )
{
v2 = v1->ExceptionInformation[0];
if ( v2 == 429065504 || v2 == 429065505 || v2 == 429065506 || v2 == 26820608 )
terminate();
}
}
return 0;
}
//----- (00401A24) --------------------------------------------------------
void __cdecl _RTC_Initialize()
{
unsigned int i; // esi@1
for ( i = (unsigned int)&__rtc_izz; i < (unsigned int)&__rtc_izz; i += 4 )
{
if ( *(_DWORD *)i )
(*(void (**)(void))i)();
}
}
//----- (00401A44) --------------------------------------------------------
void __cdecl _RTC_Terminate()
{
unsigned int i; // esi@1
for ( i = (unsigned int)&__rtc_tzz; i < (unsigned int)&__rtc_tzz; i += 4 )
{
if ( *(_DWORD *)i )
(*(void (**)(void))i)();
}
}
//----- (00401AD9) --------------------------------------------------------
_EXCEPTION_DISPOSITION __cdecl _except_handler4(_EXCEPTION_RECORD *ExceptionRecord, _EXCEPTION_REGISTRATION_RECORD *EstablisherFrame, _CONTEXT *ContextRecord, void *DispatcherContext)
{
return _except_handler4_common(
&__security_cookie,
__security_check_cookie,
ExceptionRecord,
EstablisherFrame,
ContextRecord,
DispatcherContext);
}
// 401B56: using guessed type int __cdecl _except_handler4_common(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD);
// 404018: using guessed type int __security_cookie;
//----- (00401AFC) --------------------------------------------------------
void __stdcall __dyn_tls_init(void *__formal, unsigned int dwReason, void *a3)
{
void (__cdecl **i)(); // esi@2
if ( dwReason == 2 )
{
for ( i = &_xd_z; i != &_xd_z; ++i )
{
if ( *i )
(*i)();
}
}
}
//----- (00401B5C) --------------------------------------------------------
void __cdecl __raise_securityfailure(_EXCEPTION_POINTERS *ExceptionPointers)
{
__vcrt_UnhandledException(ExceptionPointers);
__vcrt_TerminateProcess(-1073740791);
}
// 401C70: using guessed type int __cdecl __vcrt_TerminateProcess(_DWORD);
// 401C76: using guessed type int __cdecl __vcrt_UnhandledException(_DWORD);
//----- (00401B75) --------------------------------------------------------
void __usercall __report_gsfailure(unsigned int a1<ebx>, unsigned int a2<edi>, unsigned int a3<esi>, char a4)
{
unsigned int v4; // eax@1
unsigned int v5; // edx@1
unsigned int v6; // ecx@1
unsigned int v11; // [sp-4h] [bp-328h]@1
unsigned int v12; // [sp+324h] [bp+0h]@0
void *v13; // [sp+328h] [bp+4h]@3
v4 = IsProcessorFeaturePresent(0x17u);
_CF = 0;
_OF = 0;
_ZF = v4 == 0;
_SF = (v4 & 0x80000000u) != 0;
if ( v4 )
{
v6 = 2;
__asm { int 29h ; Win8: RtlFailFast(ecx) }
}
GS_ContextRecord.Eax = v4;
GS_ContextRecord.Ecx = v6;
GS_ContextRecord.Edx = v5;
GS_ContextRecord.Ebx = a1;
GS_ContextRecord.Esi = a3;
GS_ContextRecord.Edi = a2;
LOWORD(GS_ContextRecord.SegSs) = __SS__;
LOWORD(GS_ContextRecord.SegCs) = __CS__;
LOWORD(GS_ContextRecord.SegDs) = __DS__;
LOWORD(GS_ContextRecord.SegEs) = __ES__;
LOWORD(GS_ContextRecord.SegFs) = __FS__;
LOWORD(GS_ContextRecord.SegGs) = __GS__;
__asm { pushf }
GS_ContextRecord.EFlags = v11;
GS_ContextRecord.Ebp = v12;
GS_ContextRecord.Eip = (unsigned int)v13;
GS_ContextRecord.Esp = (unsigned int)&a4;
GS_ContextRecord.ContextFlags = 65537;
GS_ExceptionRecord.ExceptionAddress = v13;
GS_ExceptionRecord.ExceptionCode = -1073740791;
GS_ExceptionRecord.ExceptionFlags = 1;
GS_ExceptionRecord.NumberParameters = 1;
GS_ExceptionRecord.ExceptionInformation[0] = 2;
__raise_securityfailure(&GS_ExceptionPointers);
}
//----- (00401CC0) --------------------------------------------------------
void __usercall _ftoui3(__m128i a1<xmm0>)
{
_ftol3_NaN(a1);
}
//----- (00401CCF) --------------------------------------------------------
void __usercall _ftoul3(__m128i a1<xmm0>)
{
_ftol3_NaN(a1);
}
//----- (00401CDE) --------------------------------------------------------
void __cdecl _ftol3()
{
JUMPOUT(*(int *)_ftol3_NaN);
}
//----- (00401CEB) --------------------------------------------------------
void __usercall _ftol3_NaN(__m128i a1<xmm0>)
{
JUMPOUT(_mm_cvtsi128_si32(a1) & 0x7FFFFFFF, 2139095040, _ftol3_arg_error);
JUMPOUT(*(int *)_ftol3_work);
}
//----- (00401D03) --------------------------------------------------------
signed __int64 __usercall _ftol3_work<edx:eax>(char a1<al>, int a2<ecx>, __m128i a3<xmm0>, __int64 a4<xmm5>)
{
__m128i v4; // xmm1@4
if ( a2 == 2 && *(double *)&a3.m128i_i8[0] > 1.547425049106725e26 )
_ftol3_except(2, 16);
JUMPOUT(*(_QWORD *)&a3, a4, _ftol3_arg_error);
JUMPOUT(*(_QWORD *)&a3, -9.223372036854776e18, _ftol3_arg_error);
v4 = _mm_srl_epi64(_mm_sll_epi64(a3, 1u), 1u);
JUMPOUT(a2, 1, _ftol3_common);
JUMPOUT(*(_QWORD *)&v4, 1.175494315789826e-38, _ftol3_common);
JUMPOUT(*(_QWORD *)&v4, 0.0, _ftol3_common);
JUMPOUT(a1 & 0x10, 0, _ftol3_common);
_ftol3_except(a2, 2);
return 9223372036854775808i64;
}
//----- (00401D89) --------------------------------------------------------
int __usercall _ftol3_common<eax>(int a1<ecx>, __m128i a2<xmm0>, __m128i a3<xmm1>)
{
__m128i v3; // xmm6@1
__m128i v4; // xmm5@2
__m128i v5; // xmm6@2
__m128i v6; // xmm2@2
__m128i v7; // xmm1@2
__m128i v8; // xmm3@2
__m128i v9; // xmm4@2
__m128i v10; // xmm7@2
__m128i v11; // xmm1@2
__m128i v12; // xmm1@2
__m128i v13; // xmm1@2
__m128i v14; // xmm2@3
v3 = 0;
if ( *(double *)&a3.m128i_i8[0] != 0.0 )
{
v4 = _mm_cvtsi32_si128(i1075);
v5 = a2;
*(_QWORD *)&v5.m128i_i8[0] = -(signed __int64)(*(double *)&v5.m128i_i8[0] == *(double *)&a3.m128i_i8[0]);
v6 = _mm_or_si128(_mm_and_si128(a3, (__m128i)MantissaMask), (__m128i)IntegerBit);
v7 = _mm_srl_epi64(a3, 0x34u);
v8 = _mm_sll_epi64(v6, _mm_sub_epi64(v7, v4));
v9 = _mm_sub_epi64(v4, v7);
v10 = _mm_srl_epi64(v6, v9);
v11 = _mm_cmpgt_epi32(v7, v4);
v12 = _mm_unpacklo_epi32(v11, v11);
v13 = _mm_or_si128(_mm_andnot_si128(v12, v10), _mm_and_si128(v8, v12));
v3 = _mm_or_si128(_mm_andnot_si128(v5, _mm_sub_epi64(0, v13)), _mm_and_si128(v13, v5));
if ( _mm_cvtsi128_si32(v9) > 0 )
{
v14 = _mm_xor_si128(v6, _mm_sll_epi64(v10, v9));
if ( _mm_cvtsi128_si32(_mm_srli_si128(v14, 4)) | _mm_cvtsi128_si32(v14) )
_ftol3_except(a1, 16);
}
}
return _mm_cvtsi128_si32(v3);
}
//----- (00401E4B) --------------------------------------------------------
signed __int64 __thiscall _ftol3_arg_error(int this)
{
_ftol3_except(this, 8);
return 9223372036854775808i64;
}
//----- (00401E5D) --------------------------------------------------------
void __fastcall _ftol3_except(int a1, int a2)
{
unsigned __int8 v2; // [sp+0h] [bp-20h]@0
if ( a2 == 8 || !(v2 & *((_BYTE *)&MinSubInexact + a2 + 7)) )
_except1(a2);
}
// 402090: using guessed type double __cdecl _except1(_DWORD);
//----- (00401EA1) --------------------------------------------------------
void __usercall _dtoui3(__m128i a1<xmm0>)
{
_dtol3_NaN(a1);
}
//----- (00401EB0) --------------------------------------------------------
void __usercall _dtoul3(__m128i a1<xmm0>)
{
_dtol3_NaN(a1);
}
//----- (00401EBF) --------------------------------------------------------
void __cdecl _dtol3()
{
JUMPOUT(*(int *)_dtol3_NaN);
}
//----- (00401ECC) --------------------------------------------------------
void __usercall _dtol3_NaN(__m128i a1<xmm0>)
{
JUMPOUT(_mm_cvtsi128_si32(_mm_srli_si128(a1, 4)) & 0x7FFFFFFF, 2146435072, _ftol3_arg_error);
JUMPOUT(*(int *)_dtol3_work);
}
//----- (00401EE9) --------------------------------------------------------
int __usercall _dtol3_work<eax>(int a1<ecx>, __m128d a2<xmm0>, __int64 a3<xmm5>)
{
__m128i v3; // xmm1@1
int v4; // ecx@6
int v5; // ecx@6
int result; // eax@6
__m128i v7; // xmm3@7
JUMPOUT(a1, 1, _ftol3_work);
v3 = _mm_srl_epi64(_mm_sll_epi64((__m128i)a2, 1u), 1u);
if ( *(double *)&v3.m128i_i8[0] > 3.402823567797337e38 )
{
if ( a1 == 4 )
{
_ftol3_except(4, 16);
_ftol3_except(a1, 1);
}
else
{
_ftol3_except(a1, 1);
_ftol3_except(a1, 16);
}
}
if ( *(double *)&v3.m128i_i8[0] >= 1.175494315789826e-38 )
{
v7 = (__m128i)a2;
if ( a1 == 4 && *(double *)&v7.m128i_i8[0] >= 9.223372036854776e18 )
v7 = (__m128i)_mm_sub_pd(a2, (__m128d)MaxInt64);
if ( _mm_cvtsi128_si32(_mm_srl_epi64(_mm_sll_epi64(v7, 0x23u), 0x23u)) )
_ftol3_except(a1, 16);
JUMPOUT((_QWORD)a2.m128d_f64[0], a3, _ftol3_arg_error);
JUMPOUT((_QWORD)a2.m128d_f64[0], -9.223372036854776e18, _ftol3_arg_error);
result = _ftol3_common(a1, (__m128i)a2, v3);
}
else
{
JUMPOUT(*(_QWORD *)&v3, 0.0, _ftol3_common);
_ftol3_except(a1, 2);
_ftol3_except(v4, 16);
result = _ftol3_common(v5, (__m128i)a2, v3);
}
return result;
}
//----- (00401FCE) --------------------------------------------------------
int __fastcall _ultod3(int a1, int _EDX)
{
int result; // eax@2
if ( _EDX )
{
__asm { bsr ecx, edx }
result = 32 - _ECX;
}
return result;
}
//----- (0040205F) --------------------------------------------------------
signed int __fastcall _ltod3(signed int a1, unsigned int a2)
{
signed int result; // eax@1
result = a1 >> 31;
if ( a1 >> 31 != a2 )
{
JUMPOUT((a2 & 0x80000000u) == 0, _ultod3);
result = _ultod3(-a1, (unsigned __int64)-(signed __int64)__PAIR__(a2, -a1) >> 32);
}
return result;
}
//----- (004020A0) --------------------------------------------------------
int __cdecl _ehhandler_____6U__char_traits_D_std___std__YQAAV__basic_ostream_DU__char_traits_D_std___0_AAV10_PBD_Z()
{
return __CxxFrameHandler3();
}
// 401C82: using guessed type int __CxxFrameHandler3(void);
// ALL OK, 48 function(s) have been successfully decompiled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment