Code:
*/
#include <windows.h>
#include <defs.h>
//-------------------------------------------------------------------------
// Data declarations
extern char Operation[]; // idb
extern char aFailedToLaunch[]; // idb
extern char aSucceededToLau[36]; // weak
extern char aCombatarms_exe[15]; // weak
extern char Parameters[]; // idb
extern char aMicrosoftVisua[37]; // weak
extern char asc_4071D0[]; // idb
extern char a___[]; // idb
extern char aProgramNameUnk[]; // idb
extern char aUnknownSecurit[35]; // weak
extern char byte_407398[]; // weak
extern char aRuntimeErrorPr[]; // idb
extern const WCHAR SrcStr; // idb
extern _UNKNOWN unk_407E8C; // weak
extern _UNKNOWN unk_407E94; // weak
extern int dword_409040; // weak
extern int dword_409048; // weak
extern char *off_40904C; // weak
extern wchar_t *off_409050; // weak
extern int dword_409058[]; // weak
extern char off_40905C[148]; // idb
extern int (__cdecl *off_409420)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD); // weak
extern wchar_t *off_409438; // weak
extern char byte_409440[]; // weak
extern int dword_409448; // weak
extern char aVyv[6]; // weak
extern char aJ[3]; // weak
extern int dword_4096C8; // weak
extern int dword_4096D0; // weak
extern int dword_4096D4; // weak
extern int dword_409898; // weak
extern int dword_4098A0; // idb
extern LCID dword_4098AC; // idb
extern UINT CodePage; // idb
extern int dword_4098C4; // weak
extern int dword_4098D8; // weak
extern LCID Locale; // idb
extern int dword_4098EC; // weak
extern _UNKNOWN unk_409900; // weak
extern char byte_409901[]; // weak
extern UINT dword_409A04; // idb
extern _DWORD dword_409A10[4]; // idb
extern char byte_409A20[]; // weak
extern HANDLE hHeap; // idb
extern int dword_40AB48; // weak
extern UINT uNumber; // idb
extern int dword_40AB60[]; // weak
//-------------------------------------------------------------------------
// Function declarations
HINSTANCE __cdecl sub_401000(const char *a1, LPCSTR lpParameters);
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
signed int __cdecl sub_40118A();
// int sprintf(char *, const char *, ...);
signed int __cdecl sub_4014A6();
// void __usercall sub_4014AA(int a1<ebp>);
// int __fastcall write_char(FILE *); idb
// int __cdecl write_multi_char(char, int, FILE *); idb
// int __cdecl write_string(_DWORD); weak
int __cdecl sub_4018B1(FILE *a1, int a2, int a3);
int __cdecl loc_401D06(int, int, int); // weak
// void __cdecl _exit(int);
BOOL __cdecl sub_402208(int a1);
void __cdecl sub_402B29();
void __cdecl sub_402B6D(); // idb
// _DWORD __cdecl __crtMessageBoxA(_DWORD, _DWORD, __int16); weak
// char *__cdecl strcpy(char *, const char *);
// char *__cdecl strcat(char *, const char *);
// char *__cdecl strncpy(char *, const char *, size_t);
// size_t __cdecl strlen(const char *);
int __cdecl sub_4033BF(int a1, LPCVOID lpBuffer, int nNumberOfBytesToWrite);
// void __cdecl free(void *);
// void *__cdecl malloc(size_t);
// int __cdecl wctomb(char *, wchar_t);
// int CPtoLCID(void); weak
// int setSBCS(void); weak
unsigned int __cdecl sub_4039CD();
int __cdecl sub_403B68(UINT CodePage); // idb
// void *__cdecl memcpy(void *, const void *, size_t);
// _DWORD __cdecl __sbh_find_block(_DWORD); weak
// _DWORD __cdecl __sbh_free_block(_DWORD, _DWORD); weak
// _DWORD __cdecl __sbh_resize_block(_DWORD, _DWORD, _DWORD); weak
// _DWORD __cdecl __sbh_alloc_block(_DWORD); weak
// _DWORD __cdecl _dosmaperr(_DWORD); weak
// __int64 __cdecl _lseeki64(int, __int64, int);
LPVOID __cdecl sub_404D84(unsigned int a1, unsigned int a2);
// _DWORD __cdecl flsall(_DWORD); weak
int __cdecl sub_404F72();
// _DWORD __cdecl _callnewh(_DWORD); weak
void *__cdecl sub_404F9F(LPVOID lpMem, size_t dwBytes);
int __cdecl sub_40513F(LCID Locale, DWORD dwMapFlags, LPCSTR lpMultiByteStr, int cchSrc, void *lpDestStr, int cbMultiByte, UINT CodePage, int a8);
// int __cdecl __crtGetStringTypeA(DWORD dwInfoType, LPCSTR lpSrcStr, int cchSrc, LPWORD lpCharType, UINT CodePage, LCID Locale, int); idb
// void *__cdecl memset(void *, int, size_t);
__int32 __cdecl sub_405B1D(LCID Locale);
void *__cdecl sub_405B64(UINT CodePage, UINT a2, const CHAR *a3, int *a4, int a5, int a6);
// __int32 __cdecl atol(const char *);
// DWORD __stdcall GetModuleFileNameA(HMODULE hModule, LPCH lpFilename, DWORD nSize);
// HMODULE __stdcall GetModuleHandleA(LPCSTR lpModuleName);
// void __stdcall OutputDebugStringA(LPCSTR lpOutputString);
// int __stdcall GetLocaleInfoA(LCID Locale, LCTYPE LCType, LPSTR lpLCData, int cchData);
// BOOL __stdcall WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
// HANDLE __stdcall GetStdHandle(DWORD nStdHandle);
// int __stdcall WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);
// DWORD __stdcall GetLastError();
// LPVOID __stdcall HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
// UINT __stdcall GetACP();
// UINT __stdcall GetOEMCP();
// BOOL __stdcall GetCPInfo(UINT CodePage, LPCPINFO lpCPInfo);
// LPVOID __stdcall HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
// int __stdcall LCMapStringA(LCID Locale, DWORD dwMapFlags, LPCSTR lpSrcStr, int cchSrc, LPSTR lpDestStr, int cchDest);
// int __stdcall MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
// int __stdcall LCMapStringW(LCID Locale, DWORD dwMapFlags, LPCWSTR lpSrcStr, int cchSrc, LPWSTR lpDestStr, int cchDest);
// HINSTANCE __stdcall ShellExecuteA(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd);
// HWND __stdcall GetDesktopWindow();
//----- (00401000) --------------------------------------------------------
HINSTANCE __cdecl sub_401000(const char *a1, LPCSTR lpParameters)
{
HMODULE v2; // eax@1
unsigned int i; // eax@2
int v4; // eax@5
CHAR v5; // cl@6
unsigned int v6; // eax@7
void *v7; // edi@7
char v8; // cl@8
HINSTANCE result; // eax@9
HWND v10; // eax@9
char v11; // [sp+7h] [bp-80Dh]@7
CHAR File[1028]; // [sp+8h] [bp-80Ch]@1
const CHAR Directory[1028]; // [sp+40Ch] [bp-408h]@6
unsigned int v14; // [sp+810h] [bp-4h]@1
v14 = (unsigned int)File ^ dword_409040;
v2 = GetModuleHandleA(0);
if ( v2 )
{
for ( i = (unsigned int)&File[GetModuleFileNameA(v2, File, 0x401u)]; i >= (unsigned int)File; --i )
{
if ( *(_BYTE *)i == 92 )
break;
}
*(_BYTE *)(i + 1) = 0;
v4 = 0;
do
{
v5 = File[v4];
Directory[v4++] = v5;
}
while ( v5 );
v6 = strlen(a1) + 1;
v7 = &v11;
do
{
v8 = *((_BYTE *)v7 + 1);
v7 = (char *)v7 + 1;
}
while ( v8 );
memcpy(v7, a1, v6);
v10 = GetDesktopWindow();
result = ShellExecuteA(v10, "open", File, lpParameters, Directory, 1);
}
else
{
result = (HINSTANCE)-1;
}
return result;
}
// 409040: using guessed type int dword_409040;
// 401000: using guessed type CHAR File[1028];
// 401000: using guessed type const CHAR Directory[1028];
//----- (00401100) --------------------------------------------------------
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HINSTANCE v4; // eax@1
int v5; // esi@1
const CHAR *v7; // [sp-4h] [bp-110h]@2
const CHAR OutputString; // [sp+4h] [bp-108h]@1
unsigned int v9; // [sp+108h] [bp-4h]@1
v9 = (unsigned int)&OutputString ^ dword_409040;
v4 = sub_401000("CombatArms.exe", "/Direct");
v5 = (int)v4;
if ( (signed int)v4 <= 32 )
{
sprintf((char *)&OutputString, "Failed to launch CombatArms.exe, ErrorCode[%d]\n", v4);
v7 = &OutputString;
}
else
{
v7 = "Succeeded to launch CombatArms.exe\n";
}
OutputDebugStringA(v7);
return v5;
}
// 409040: using guessed type int dword_409040;
//----- (0040118A) --------------------------------------------------------
signed int __cdecl sub_40118A()
{
return 1;
}
//----- (004014A6) --------------------------------------------------------
signed int __cdecl sub_4014A6()
{
return 1;
}
//----- (004014AA) --------------------------------------------------------
void __usercall sub_4014AA(int a1<ebp>)
{
*(_DWORD *)(a1 - 4) = -1;
_exit(3);
}
//----- (004018B1) --------------------------------------------------------
int __cdecl sub_4018B1(FILE *a1, int a2, int a3)
{
int v3; // ecx@1
unsigned __int8 v4; // bl@1
int v5; // edi@2
int v6; // edi@4
int v7; // eax@7
char v8; // al@37
signed int v9; // ecx@63
int v10; // eax@65
int v11; // eax@68
char *v12; // esi@70
__int64 v13; // qax@83
int v14; // eax@86
int v15; // ecx@87
signed int v16; // eax@88
void *v17; // eax@98
int v18; // ecx@101
int j; // eax@117
int v20; // eax@128
int v21; // ebx@144
int v22; // edi@144
char *i; // esi@152
int v24; // eax@153
signed int v25; // ecx@155
unsigned __int64 v26; // ST04_8@155
char *v27; // eax@158
int v28; // esi@158
char v29; // bl@164
int v30; // esi@172
wchar_t *v31; // ebx@179
int v32; // eax@180
int v34; // [sp+4h] [bp-80h]@101
int v35; // [sp+8h] [bp-7Ch]@101
int v36; // [sp+10h] [bp-74h]@155
int v37; // [sp+14h] [bp-70h]@3
char *v38; // [sp+18h] [bp-6Ch]@10
int v39; // [sp+1Ch] [bp-68h]@110
int v40; // [sp+20h] [bp-64h]@10
void *v41; // [sp+24h] [bp-60h]@1
int v42; // [sp+28h] [bp-5Ch]@10
int v43; // [sp+2Ch] [bp-58h]@10
FILE *v44; // [sp+30h] [bp-54h]@1
int v45; // [sp+34h] [bp-50h]@1
int v46; // [sp+38h] [bp-4Ch]@10
char v47; // [sp+3Ch] [bp-48h]@125
char v48; // [sp+3Dh] [bp-47h]@125
int v49; // [sp+40h] [bp-44h]@1
unsigned int v50; // [sp+44h] [bp-40h]@1
char *v51; // [sp+48h] [bp-3Ch]@65
int v52; // [sp+4Ch] [bp-38h]@10
int v53; // [sp+50h] [bp-34h]@1
int v54; // [sp+54h] [bp-30h]@10
char v55; // [sp+58h] [bp-2Ch]@70
char v56; // [sp+84h] [bp+0h]@1
char v57; // [sp+257h] [bp+1D3h]@152
char v58; // [sp+258h] [bp+1D4h]@180
unsigned int v59; // [sp+260h] [bp+1DCh]@1
v59 = (unsigned int)&v56 ^ dword_409040;
v44 = a1;
v4 = *(_BYTE *)a2;
v53 = a3;
v3 = 0;
v45 = a2;
v50 = 0;
v49 = 0;
v41 = 0;
if ( v4 )
{
v5 = a2;
while ( 1 )
{
v6 = v5 + 1;
v45 = v6;
if ( v49 < 0 )
return v49;
if ( (char)v4 < 32 || (char)v4 > 120 )
v7 = 0;
else
v7 = aUnknownSecurit[(char)v4 + 20] & 0xF;
v37 = *(&byte_407398[8 * v7] + v3) >> 4;
switch ( v37 )
{
case 1:
v52 = -1;
v38 = 0;
v40 = 0;
v43 = 0;
v46 = 0;
v54 = 0;
v42 = 0;
goto LABEL_188;
case 2:
switch ( v4 )
{
case 32u:
v54 |= 2u;
break;
case 35u:
LOBYTE(v54) = v54 | 0x80;
break;
case 43u:
v54 |= 1u;
break;
case 45u:
v54 |= 4u;
break;
case 48u:
v54 |= 8u;
break;
}
goto LABEL_188;
case 3:
if ( v4 == 42 )
{
v53 += 4;
v43 = *(_DWORD *)(v53 - 4);
if ( v43 < 0 )
{
v54 |= 4u;
v43 = -v43;
}
}
else
{
v43 = (char)v4 + 10 * v43 - 48;
}
goto LABEL_188;
case 4:
v52 = 0;
goto LABEL_188;
case 5:
if ( v4 == 42 )
{
v53 += 4;
v52 = *(_DWORD *)(v53 - 4);
if ( v52 < 0 )
v52 = -1;
}
else
{
v52 = (char)v4 + 10 * v52 - 48;
}
goto LABEL_188;
case 6:
switch ( v4 )
{
case 0x49u:
v8 = *(_BYTE *)v6;
if ( *(_BYTE *)v6 != 54 || *(_BYTE *)(v6 + 1) != 52 )
{
if ( v8 != 51 || *(_BYTE *)(v6 + 1) != 50 )
{
if ( v8 != 100 && v8 != 105 && v8 != 111 && v8 != 117 && v8 != 120 && v8 != 88 )
{
v37 = 0;
LABEL_50:
v42 = 0;
if ( HIBYTE(off_409438[v4]) & 0x80 )
{
write_char(v44);
v45 = v6 + 1;
}
write_char(v44);
}
}
else
{
BYTE1(v54) &= 0x7Fu;
v45 = v6 + 2;
}
}
else
{
BYTE1(v54) |= 0x80u;
v45 = v6 + 2;
}
break;
case 0x68u:
v54 |= 0x20u;
break;
case 0x6Cu:
v54 |= 0x10u;
break;
case 0x77u:
BYTE1(v54) |= 8u;
break;
}
goto LABEL_188;
case 0:
goto LABEL_50;
case 7:
if ( (char)v4 <= 103 )
{
if ( (char)v4 >= 101 )
goto LABEL_70;
if ( (char)v4 > 88 )
{
if ( (char)v4 == 90 )
{
v53 += 4;
v14 = *(_DWORD *)(v53 - 4);
if ( v14 && (v15 = *(_DWORD *)(v14 + 4)) != 0 )
{
v16 = *(_WORD *)v14;
v51 = (char *)v15;
if ( BYTE1(v54) & 8 )
{
v16 /= 2;
v42 = 1;
}
else
{
v42 = 0;
}
}
else
{
v51 = off_40904C;
v16 = strlen(off_40904C);
}
goto LABEL_162;
}
if ( (char)v4 != 99 )
{
if ( (char)v4 != 100 )
goto LABEL_163;
LABEL_80:
v54 |= 0x40u;
goto LABEL_81;
}
}
else
{
if ( (char)v4 == 88 )
goto LABEL_123;
if ( (char)v4 != 67 )
{
if ( (char)v4 == 69 || (char)v4 == 71 )
{
v38 = (char *)1;
v4 += 32;
LABEL_70:
v54 |= 0x40u;
v12 = &v55;
v51 = &v55;
if ( v52 >= 0 )
{
if ( v52 )
{
if ( v52 > 512 )
v52 = 512;
if ( v52 > 163 )
{
v17 = malloc(v52 + 349);
v41 = v17;
if ( v17 )
{
v51 = (char *)v17;
v12 = (char *)v17;
}
else
{
v52 = 163;
}
}
}
else
{
if ( v4 == 103 )
v52 = 1;
}
}
else
{
v52 = 6;
}
v18 = *(_DWORD *)v53;
v53 += 8;
v35 = *(_DWORD *)(v53 - 4);
v34 = v18;
off_409420(&v34, v12, (char)v4, v52, v38);
JUMPOUT(*(int *)loc_401D06);
}
if ( (char)v4 != 83 )
goto LABEL_163;
if ( !(v54 & 0x830) )
BYTE1(v54) |= 8u;
goto LABEL_63;
}
if ( !(v54 & 0x830) )
BYTE1(v54) |= 8u;
}
v53 += 4;
if ( v54 & 0x810 )
{
v50 = wctomb(&v55, *(_WORD *)(v53 - 4));
if ( (signed int)v50 < 0 )
v40 = 1;
}
else
{
v55 = *(_BYTE *)(v53 - 4);
v50 = 1;
}
v51 = &v55;
goto LABEL_163;
}
if ( (char)v4 == 105 )
goto LABEL_80;
if ( (char)v4 != 110 )
{
if ( (char)v4 == 111 )
{
v50 = 8;
if ( v54 & 0x80 )
BYTE1(v54) |= 2u;
goto LABEL_82;
}
if ( (char)v4 != 112 )
{
if ( (char)v4 != 115 )
{
if ( (char)v4 != 117 )
{
if ( (char)v4 == 120 )
{
v39 = 39;
LABEL_124:
v50 = 16;
if ( v54 & 0x80 )
{
v47 = 48;
v48 = v39 + 81;
v46 = 2;
}
LABEL_82:
if ( v54 & 0x8000 )
{
v13 = *(_QWORD *)v53;
v53 += 8;
goto LABEL_139;
}
v53 += 4;
if ( v54 & 0x20 )
{
LODWORD(v13) = v54 & 0x40 ? *(_WORD *)(v53 - 4) : (unsigned int)*(_WORD *)(v53 - 4);
LABEL_135:
v13 = (signed int)v13;
}
else
{
LODWORD(v13) = *(_DWORD *)(v53 - 4);
if ( v54 & 0x40 )
goto LABEL_135;
HIDWORD(v13) = 0;
}
LABEL_139:
if ( v54 & 0x40 )
{
if ( HIDWORD(v13) <= 0 )
{
if ( HIDWORD(v13) < 0 )
{
v13 = -v13;
BYTE1(v54) |= 1u;
}
}
}
v21 = v13;
v22 = HIDWORD(v13);
if ( !(v54 & 0x8000) )
v22 = 0;
if ( v52 >= 0 )
{
v54 &= 0xFFFFFFF7u;
if ( v52 > 512 )
v52 = 512;
}
else
{
v52 = 1;
}
if ( !(v22 | (_DWORD)v13) )
v46 = 0;
for ( i = &v57; ; --i )
{
v24 = v52--;
if ( v24 <= 0 )
{
if ( !(v22 | v21) )
break;
}
HIDWORD(v26) = v22;
LODWORD(v26) = v21;
v25 = v26 % (signed int)v50 + 48;
v36 = v26 % (signed int)v50 >> 32;
v21 = v26 / (signed int)v50;
v22 = v26 / (signed int)v50 >> 32;
if ( v25 > 57 )
v25 += v39;
*i = v25;
}
v27 = (char *)(&v57 - i);
v28 = (int)(i + 1);
v50 = (unsigned int)v27;
v51 = (char *)v28;
if ( BYTE1(v54) & 2 )
{
if ( *(_BYTE *)v28 != 48 || !v27 )
{
--v51;
*v51 = 48;
v16 = (signed int)(v27 + 1);
goto LABEL_162;
}
}
}
LABEL_163:
if ( v40 )
goto LABEL_186;
v29 = v54;
if ( v54 & 0x40 )
{
if ( BYTE1(v54) & 1 )
{
v47 = 45;
goto LABEL_171;
}
if ( v54 & 1 )
{
v47 = 43;
goto LABEL_171;
}
if ( v54 & 2 )
{
v47 = 32;
LABEL_171:
v46 = 1;
}
}
v30 = v43 - v46 - v50;
if ( !(v54 & 0xC) )
write_multi_char(32, v43 - v46 - v50, v44);
write_string(v46);
if ( v29 & 8 )
{
if ( !(v29 & 4) )
write_multi_char(48, v30, v44);
}
if ( v42 && (signed int)v50 > 0 )
{
v31 = (wchar_t *)v51;
v36 = v50;
do
{
--v36;
v32 = wctomb(&v58, *v31);
++v31;
if ( v32 <= 0 )
break;
write_string(v32);
}
while ( v36 );
}
else
{
write_string(v50);
}
if ( v54 & 4 )
write_multi_char(32, v30, v44);
goto LABEL_186;
}
LABEL_81:
v50 = 10;
goto LABEL_82;
}
LABEL_63:
v9 = v52;
if ( v52 == -1 )
v9 = 2147483647;
v53 += 4;
v10 = *(_DWORD *)(v53 - 4);
v51 = *(char **)(v53 - 4);
if ( v54 & 0x810 )
{
if ( !v10 )
v51 = (char *)off_409050;
v11 = (int)v51;
v42 = 1;
while ( v9 )
{
--v9;
if ( !*(_WORD *)v11 )
break;
v11 += 2;
}
v16 = (v11 - (_DWORD)v51) >> 1;
}
else
{
if ( !v10 )
v51 = off_40904C;
for ( j = (int)v51; ; ++j )
{
if ( v9 )
{
--v9;
if ( *(_BYTE *)j )
continue;
}
break;
}
v16 = j - (_DWORD)v51;
}
LABEL_162:
v50 = v16;
goto LABEL_163;
}
v52 = 8;
LABEL_123:
v39 = 7;
goto LABEL_124;
}
v53 += 4;
v20 = *(_DWORD *)(v53 - 4);
if ( v54 & 0x20 )
*(_WORD *)v20 = v49;
else
*(_DWORD *)v20 = v49;
v40 = 1;
LABEL_186:
if ( v41 )
{
free(v41);
v41 = 0;
}
LABEL_188:
v5 = v45;
v4 = *(_BYTE *)v45;
if ( !*(_BYTE *)v45 )
return v49;
v3 = v37;
break;
default:
goto LABEL_188;
}
}
}
return v49;
}
// 40187A: using guessed type int __cdecl write_string(_DWORD);
// 401D06: using guessed type int __cdecl(int, int, int);
// 409040: using guessed type int dword_409040;
// 40904C: using guessed type char *off_40904C;
// 409050: using guessed type wchar_t *off_409050;
// 409420: using guessed type int (__cdecl *off_409420)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD);
// 409438: using guessed type wchar_t *off_409438;
//----- (00402208) --------------------------------------------------------
BOOL __cdecl sub_402208(int a1)
{
BOOL result; // eax@1
int v2; // esi@4
char *v3; // edi@11
size_t v4; // eax@13
void *v5; // esp@13
char *v6; // ST00_4@13
const char **v7; // esi@14
HANDLE v8; // eax@14
char v9; // [sp-2Bh] [bp-B7h]@12
const char *v10; // [sp-1Ch] [bp-A8h]@13
const void *v11; // [sp-10h] [bp-9Ch]@14
DWORD v12; // [sp-Ch] [bp-98h]@14
const char *v13; // [sp-8h] [bp-94h]@13
int v14; // [sp-4h] [bp-90h]@14
char v15; // [sp+0h] [bp-8Ch]@13
DWORD NumberOfBytesWritten; // [sp+Ch] [bp-80h]@14
CHAR Filename; // [sp+10h] [bp-7Ch]@9
char v18; // [sp+8Ch] [bp+0h]@1
char v19; // [sp+114h] [bp+88h]@9
unsigned int v20; // [sp+118h] [bp+8Ch]@1
v20 = (unsigned int)&v18 ^ dword_409040;
result = 0;
do
{
if ( a1 == dword_409058[2 * result] )
break;
++result;
}
while ( (unsigned int)result < 0x13 );
v2 = 8 * result;
if ( a1 == dword_409058[2 * result] )
{
result = dword_4096C8;
if ( dword_4096C8 != 1 && (dword_4096C8 || dword_409048 != 1) )
{
if ( a1 != 252 )
{
v19 = 0;
if ( !GetModuleFileNameA(0, &Filename, 0x104u) )
strcpy(&Filename, "<program name unknown>");
v3 = &Filename;
if ( strlen(&Filename) + 1 > 0x3C )
{
v3 = &v9 + strlen(&Filename);
strncpy(v3, "...", 3u);
}
v4 = strlen(v3);
v13 = *(const char **)&off_40905C[v2];
v5 = alloca(v4 + strlen(v13) + 28);
strcpy(&v15, "Runtime Error!\n\nProgram: ");
strcat(&v15, v3);
strcat(&v15, "\n\n");
v10 = *(const char **)&off_40905C[v2];
strcat(&v15, v10);
v6 = &v15;
result = __crtMessageBoxA(v6, "Microsoft Visual C++ Runtime Library", 8208);
}
}
else
{
v14 = 0;
v13 = (const char *)&NumberOfBytesWritten;
v7 = (const char **)&off_40905C[v2];
v12 = strlen(*v7);
v11 = *v7;
v8 = GetStdHandle(0xFFFFFFF4u);
result = WriteFile(v8, v11, v12, &NumberOfBytesWritten, 0);
}
}
return result;
}
// 402C5D: using guessed type _DWORD __cdecl __crtMessageBoxA(_DWORD, _DWORD, __int16);
// 409040: using guessed type int dword_409040;
// 409048: using guessed type int dword_409048;
// 409058: using guessed type int dword_409058[];
// 4096C8: using guessed type int dword_4096C8;
//----- (00402B29) --------------------------------------------------------
void __cdecl sub_402B29()
{
unsigned int i; // [sp+Ch] [bp-1Ch]@1
for ( i = (unsigned int)&unk_407E8C; i < (unsigned int)&unk_407E8C; i += 4 )
{
if ( *(_DWORD *)i )
(*(void (**)(void))i)();
}
}
//----- (00402B6D) --------------------------------------------------------
void __cdecl sub_402B6D()
{
unsigned int i; // [sp+Ch] [bp-1Ch]@1
for ( i = (unsigned int)&unk_407E94; i < (unsigned int)&unk_407E94; i += 4 )
{
if ( *(_DWORD *)i )
(*(void (**)(void))i)();
}
}
//----- (004033BF) --------------------------------------------------------
int __cdecl sub_4033BF(int a1, LPCVOID lpBuffer, int nNumberOfBytesToWrite)
{
LPCVOID v3; // edi@1
char v4; // al@2
int v5; // ebx@2
int v6; // esi@2
int v8; // eax@7
char *v9; // eax@9
int v10; // ecx@9
signed int v11; // edi@9
char v12; // dl@11
int v13; // edx@11
int v14; // edi@14
int v15; // [sp+10h] [bp-7Ch]@3
DWORD NumberOfBytesWritten; // [sp+18h] [bp-74h]@14
int v17; // [sp+1Ch] [bp-70h]@3
LPCVOID v18; // [sp+20h] [bp-6Ch]@8
DWORD v19; // [sp+24h] [bp-68h]@8
char Buffer; // [sp+28h] [bp-64h]@9
char v21; // [sp+8Ch] [bp+0h]@1
unsigned int v22; // [sp+42Ch] [bp+3A0h]@1
v3 = lpBuffer;
v22 = (unsigned int)&v21 ^ dword_409040;
if ( a1 < uNumber )
{
v5 = 4 * (a1 >> 5) + 4238176;
v6 = 8 * (a1 & 0x1F);
v4 = *(_BYTE *)(dword_40AB60[a1 >> 5] + v6 + 4);
if ( v4 & 1 )
{
v17 = 0;
v15 = 0;
if ( !nNumberOfBytesToWrite )
return 0;
if ( v4 & 0x20 )
_lseeki64(a1, 0i64, 2);
v8 = v6 + dword_40AB60[a1 >> 5];
if ( *(_BYTE *)(v8 + 4) & 0x80 )
{
v19 = 0;
v18 = lpBuffer;
if ( !nNumberOfBytesToWrite )
{
LABEL_27:
if ( *(_BYTE *)(*(_DWORD *)v5 + v6 + 4) & 0x40 && *(_BYTE *)v3 == 26 )
return 0;
dword_4096D0 = 28;
goto LABEL_32;
}
while ( 1 )
{
v11 = 0;
v10 = v18 - lpBuffer;
v9 = &Buffer;
do
{
if ( v10 >= (unsigned int)nNumberOfBytesToWrite )
break;
v13 = (int)v18++;
v12 = *(_BYTE *)v13;
++v10;
if ( v12 == 10 )
{
++v15;
*v9++ = 13;
++v11;
}
v5 = 4 * (a1 >> 5) + 4238176;
*v9++ = v12;
++v11;
}
while ( v11 < 1024 );
v14 = v9 - &Buffer;
if ( !WriteFile(*(HANDLE *)(*(_DWORD *)v5 + v6), &Buffer, v9 - &Buffer, &NumberOfBytesWritten, 0) )
break;
v17 += NumberOfBytesWritten;
if ( (signed int)NumberOfBytesWritten < v14 || v18 - lpBuffer >= nNumberOfBytesToWrite )
goto LABEL_21;
}
}
else
{
if ( WriteFile(*(HANDLE *)v8, lpBuffer, nNumberOfBytesToWrite, &NumberOfBytesWritten, 0) )
{
v19 = 0;
v17 = NumberOfBytesWritten;
LABEL_21:
if ( v17 )
return v17 - v15;
if ( v19 )
{
if ( v19 == 5 )
{
dword_4096D0 = 9;
dword_4096D4 = 5;
}
else
{
_dosmaperr(v19);
}
return -1;
}
v3 = lpBuffer;
goto LABEL_27;
}
}
v19 = GetLastError();
goto LABEL_21;
}
}
dword_4096D0 = 9;
LABEL_32:
dword_4096D4 = 0;
return -1;
}
// 404BD0: using guessed type _DWORD __cdecl _dosmaperr(_DWORD);
// 409040: using guessed type int dword_409040;
// 4096D0: using guessed type int dword_4096D0;
// 4096D4: using guessed type int dword_4096D4;
// 40AB60: using guessed type int dword_40AB60[];
//----- (004039CD) --------------------------------------------------------
unsigned int __cdecl sub_4039CD()
{
unsigned int v0; // eax@2
int v1; // eax@4
int v2; // edx@5
unsigned int v3; // ecx@6
int i; // ecx@7
const CHAR *v5; // edi@7
unsigned int v6; // ecx@7
char v7; // bl@7
int v8; // edx@10
unsigned int result; // eax@11
WORD v10; // cx@12
char v11; // cl@13
char v12; // cl@23
struct _cpinfo CPInfo; // [sp+4h] [bp-80h]@1
WORD CharType[256]; // [sp+18h] [bp-6Ch]@11
char v15; // [sp+84h] [bp+0h]@1
char v16[256]; // [sp+218h] [bp+194h]@11
_BYTE DestStr[256]; // [sp+318h] [bp+294h]@11
const CHAR MultiByteStr[256]; // [sp+418h] [bp+394h]@3
unsigned int v19; // [sp+518h] [bp+494h]@1
v19 = (unsigned int)&v15 ^ dword_409040;
if ( GetCPInfo(dword_409A04, &CPInfo) == 1 )
{
v0 = 0;
do
{
MultiByteStr[v0] = v0;
++v0;
}
while ( v0 < 0x100 );
LOBYTE(v1) = CPInfo.LeadByte[0];
MultiByteStr[0] = 32;
if ( CPInfo.LeadByte[0] )
{
v2 = (int)&CPInfo.LeadByte[1];
do
{
v3 = *(_BYTE *)v2;
v1 = (unsigned __int8)v1;
if ( (unsigned __int8)v1 <= v3 )
{
v6 = v3 - v1 + 1;
v7 = v6;
v6 >>= 2;
memset((void *)&MultiByteStr[v1], 538976288, 4 * v6);
v5 = &MultiByteStr[4 * v6] + v1;
for ( i = v7 & 3; i; --i )
*v5++ = 32;
}
v8 = v2 + 1;
LOBYTE(v1) = *(_BYTE *)v8;
v2 = v8 + 1;
}
while ( (_BYTE)v1 );
}
__crtGetStringTypeA(1u, MultiByteStr, 256, CharType, dword_409A04, Locale, 0);
sub_40513F(Locale, 0x100u, MultiByteStr, 256, DestStr, 256, dword_409A04, 0);
sub_40513F(Locale, 0x200u, MultiByteStr, 256, v16, 256, dword_409A04, 0);
result = 0;
while ( 1 )
{
v10 = CharType[result];
if ( v10 & 1 )
{
byte_409901[result] |= 0x10u;
v11 = DestStr[result];
}
else
{
if ( !(v10 & 2) )
{
byte_409A20[result] = 0;
goto LABEL_18;
}
byte_409901[result] |= 0x20u;
v11 = v16[result];
}
byte_409A20[result] = v11;
LABEL_18:
++result;
if ( result >= 0x100 )
return result;
}
}
result = 0;
do
{
if ( result >= 0x41 && result <= 0x5A )
{
byte_409901[result] |= 0x10u;
v12 = result + 32;
LABEL_24:
byte_409A20[result] = v12;
goto LABEL_29;
}
if ( result >= 0x61 && result <= 0x7A )
{
byte_409901[result] |= 0x20u;
v12 = result - 32;
goto LABEL_24;
}
byte_409A20[result] = 0;
LABEL_29:
++result;
}
while ( result < 0x100 );
return result;
}
// 409040: using guessed type int dword_409040;
// 4039CD: using guessed type const CHAR MultiByteStr[256];
// 4039CD: using guessed type WORD CharType[256];
// 4039CD: using guessed type char var_304[256];
//----- (00403B68) --------------------------------------------------------
signed int __cdecl sub_403B68(UINT CodePage)
{
UINT v1; // esi@1
UINT v2; // eax@2
unsigned int v3; // eax@10
int v4; // edx@10
char *v5; // ecx@16
unsigned int v6; // edx@17
unsigned int v7; // eax@18
char *v8; // ebx@19
unsigned int v9; // eax@20
char *i; // esi@20
char v11; // dl@21
unsigned int v12; // edi@22
char v13; // dl@23
int v14; // eax@28
int v15; // ecx@28
signed int v16; // eax@32
unsigned int v18; // [sp+Ch] [bp-1Ch]@19
struct _cpinfo CPInfo; // [sp+10h] [bp-18h]@13
unsigned int v20; // [sp+24h] [bp-4h]@1
int v21; // [sp+28h] [bp+0h]@1
v1 = CodePage;
v20 = (unsigned int)&v21 ^ dword_409040;
dword_409898 = 0;
if ( CodePage == -2 )
{
dword_409898 = 1;
v2 = GetOEMCP();
}
else
{
if ( CodePage == -3 )
{
dword_409898 = 1;
v2 = GetACP();
}
else
{
if ( CodePage != -4 )
goto LABEL_8;
v2 = ::CodePage;
dword_409898 = 1;
}
}
CodePage = v2;
v1 = v2;
LABEL_8:
if ( v1 == dword_409A04 )
return 0;
if ( !v1 )
{
LABEL_38:
setSBCS();
LABEL_39:
sub_4039CD();
return 0;
}
v4 = 0;
v3 = 0;
do
{
if ( *(int *)((char *)&dword_409448 + v3) == v1 )
{
memset(&unk_409900, 0, 0x100u);
v18 = 0;
*((_BYTE *)&unk_409900 + 256) = 0;
v8 = &aJ[48 * v4];
do
{
LOBYTE(v9) = *v8;
for ( i = v8; (_BYTE)v9; LOBYTE(v9) = *i )
{
v11 = i[1];
if ( !v11 )
break;
v9 = (unsigned __int8)v9;
v12 = (unsigned __int8)v11;
if ( (unsigned __int8)v9 <= (unsigned int)(unsigned __int8)v11 )
{
v13 = byte_409440[v18];
do
{
byte_409901[v9] |= v13;
++v9;
}
while ( v9 <= v12 );
}
i += 2;
}
++v18;
v8 += 8;
}
while ( v18 < 4 );
dword_409A04 = CodePage;
dword_4098EC = 1;
v14 = CPtoLCID();
dword_409A10[0] = *(_DWORD *)&aVyv[v15];
dword_409A10[1] = *(_DWORD *)&aVyv[v15 + 4];
Locale = v14;
dword_409A10[2] = *(_DWORD *)&aVyv[v15 + 8];
goto LABEL_39;
}
v3 += 48;
++v4;
}
while ( v3 < 0xF0 );
if ( GetCPInfo(v1, &CPInfo) == 1 )
{
memset(&unk_409900, 0, 0x100u);
*((_BYTE *)&unk_409900 + 256) = 0;
dword_409A04 = v1;
Locale = 0;
if ( (_DWORD)CPInfo.MaxCharSize <= 1u )
{
dword_4098EC = 0;
}
else
{
if ( CPInfo.LeadByte[0] )
{
v5 = (char *)&CPInfo.LeadByte[1];
do
{
LOBYTE(v6) = *v5;
if ( !*v5 )
break;
v7 = (unsigned __int8)*(v5 - 1);
v6 = (unsigned __int8)v6;
while ( v7 <= v6 )
{
byte_409901[v7] |= 4u;
++v7;
}
v5 += 2;
}
while ( *(v5 - 1) );
}
v16 = 1;
do
{
byte_409901[v16] |= 8u;
++v16;
}
while ( (unsigned int)v16 < 0xFF );
Locale = CPtoLCID();
dword_4098EC = 1;
}
dword_409A10[0] = 0;
dword_409A10[1] = 0;
dword_409A10[2] = 0;
goto LABEL_39;
}
if ( dword_409898 )
goto LABEL_38;
return -1;
}
// 403975: using guessed type int CPtoLCID(void);
// 4039A4: using guessed type int setSBCS(void);
// 409040: using guessed type int dword_409040;
// 409448: using guessed type int dword_409448;
// 409898: using guessed type int dword_409898;
// 4098EC: using guessed type int dword_4098EC;
//----- (00404D84) --------------------------------------------------------
LPVOID __cdecl sub_404D84(unsigned int a1, unsigned int a2)
{
LPVOID result; // eax@3
size_t v3; // ebx@4
int v4; // esi@4
LPVOID v5; // edi@6
void *v6; // eax@9
if ( a1 && 0xFFFFFFE0 / a1 < a2 )
return 0;
v4 = a2 * a1;
v3 = a2 * a1;
if ( !(a2 * a1) )
v4 = 1;
while ( 1 )
{
v5 = 0;
if ( (unsigned int)v4 > 0xFFFFFFE0 )
goto LABEL_11;
if ( dword_40AB48 == 3 )
{
v4 = (v4 + 15) & 0xFFFFFFF0;
if ( v3 <= dword_4098D8 )
{
v6 = (void *)__sbh_alloc_block(v3);
v5 = v6;
if ( v6 )
break;
}
}
v5 = HeapAlloc(hHeap, 8u, v4);
if ( v5 )
return v5;
LABEL_11:
if ( !dword_4098A0 )
return v5;
result = (LPVOID)_callnewh(v4);
if ( !result )
return result;
}
memset(v6, 0, v3);
return v5;
}
// 4048D4: using guessed type _DWORD __cdecl __sbh_alloc_block(_DWORD);
// 404F84: using guessed type _DWORD __cdecl _callnewh(_DWORD);
// 4098D8: using guessed type int dword_4098D8;
// 40AB48: using guessed type int dword_40AB48;
//----- (00404F72) --------------------------------------------------------
int __cdecl sub_404F72()
{
return flsall(1);
}
// 404F05: using guessed type _DWORD __cdecl flsall(_DWORD);
//----- (00404F9F) --------------------------------------------------------
void *__cdecl sub_404F9F(LPVOID lpMem, size_t dwBytes)
{
void *result; // eax@2
int v3; // esi@3
int v4; // eax@7
void *v5; // edi@10
size_t v6; // eax@12
size_t v7; // eax@19
int v8; // [sp+14h] [bp+Ch]@7
if ( !lpMem )
return malloc(dwBytes);
v3 = dwBytes;
if ( dwBytes )
{
if ( dword_40AB48 != 3 )
{
while ( (unsigned int)v3 <= 0xFFFFFFE0 )
{
if ( !v3 )
v3 = 1;
result = HeapReAlloc(hHeap, 0, lpMem, v3);
if ( result || !dword_4098A0 )
return result;
if ( !_callnewh(v3) )
return 0;
}
LABEL_38:
_callnewh(v3);
return 0;
}
while ( 1 )
{
if ( (unsigned int)v3 > 0xFFFFFFE0 )
goto LABEL_38;
v4 = __sbh_find_block(lpMem);
v8 = v4;
if ( v4 )
break;
LABEL_23:
if ( !v3 )
v3 = 1;
v3 = (v3 + 15) & 0xFFFFFFF0;
v5 = HeapReAlloc(hHeap, 0, lpMem, v3);
LABEL_26:
if ( v5 || !dword_4098A0 )
return v5;
if ( !_callnewh(v3) )
return 0;
}
if ( v3 <= (unsigned int)dword_4098D8 )
{
if ( __sbh_resize_block(v4, lpMem, v3) )
{
v5 = lpMem;
goto LABEL_15;
}
v5 = (void *)__sbh_alloc_block(v3);
if ( v5 )
{
v6 = *((_DWORD *)lpMem - 1) - 1;
if ( v6 >= v3 )
v6 = v3;
memcpy(v5, lpMem, v6);
v8 = __sbh_find_block(lpMem);
__sbh_free_block(v8, lpMem);
LABEL_15:
if ( v5 )
goto LABEL_22;
goto LABEL_16;
}
}
LABEL_16:
if ( !v3 )
v3 = 1;
v3 = (v3 + 15) & 0xFFFFFFF0;
v5 = HeapAlloc(hHeap, 0, v3);
if ( v5 )
{
v7 = *((_DWORD *)lpMem - 1) - 1;
if ( v7 >= v3 )
v7 = v3;
memcpy(v5, lpMem, v7);
__sbh_free_block(v8, lpMem);
}
LABEL_22:
if ( v8 )
goto LABEL_26;
goto LABEL_23;
}
free(lpMem);
return 0;
}
// 4040F5: using guessed type _DWORD __cdecl __sbh_find_block(_DWORD);
// 404120: using guessed type _DWORD __cdecl __sbh_free_block(_DWORD, _DWORD);
// 4045F5: using guessed type _DWORD __cdecl __sbh_resize_block(_DWORD, _DWORD, _DWORD);
// 4048D4: using guessed type _DWORD __cdecl __sbh_alloc_block(_DWORD);
// 404F84: using guessed type _DWORD __cdecl _callnewh(_DWORD);
// 4098D8: using guessed type int dword_4098D8;
// 40AB48: using guessed type int dword_40AB48;
//----- (0040513F) --------------------------------------------------------
int __cdecl sub_40513F(LCID Locale, DWORD dwMapFlags, LPCSTR lpMultiByteStr, int cchSrc, void *lpDestStr, int cbMultiByte, UINT CodePage, int a8)
{
LPCSTR v8; // eax@7
signed int v9; // ecx@7
int v10; // edi@15
int v11; // esi@17
void *v12; // esp@18
int v13; // eax@22
void *v14; // esp@27
CHAR *v16; // edi@40
__int32 v17; // eax@44
void *v18; // eax@47
int v19; // eax@48
void *v20; // esp@49
void *v21; // eax@50
int v22; // esi@53
CHAR *v23; // [sp-10h] [bp-68h]@32
int v24; // [sp-Ch] [bp-64h]@32
char v25; // [sp+0h] [bp-58h]@18
int v26; // [sp+Ch] [bp-4Ch]@55
char *v27; // [sp+10h] [bp-48h]@49
UINT v28; // [sp+14h] [bp-44h]@44
int v29; // [sp+18h] [bp-40h]@40
int v30; // [sp+1Ch] [bp-3Ch]@15
int v31; // [sp+20h] [bp-38h]@15
int v32; // [sp+24h] [bp-34h]@17
void *v33; // [sp+28h] [bp-30h]@40
int v34; // [sp+2Ch] [bp-2Ch]@15
void *v35; // [sp+30h] [bp-28h]@40
size_t cchDest; // [sp+34h] [bp-24h]@48
LPCWSTR lpWideCharStr; // [sp+38h] [bp-20h]@27
LPWSTR lpSrcStr; // [sp+3Ch] [bp-1Ch]@18
CPPEH_RECORD ms_exc; // [sp+40h] [bp-18h]@18
if ( !dword_4098C4 )
{
if ( LCMapStringW(0, 0x100u, &SrcStr, 1, 0, 0) )
{
dword_4098C4 = 1;
}
else
{
if ( GetLastError() == 120 )
dword_4098C4 = 2;
}
}
if ( cchSrc > 0 )
{
v9 = cchSrc;
v8 = lpMultiByteStr;
while ( 1 )
{
--v9;
if ( !*v8 )
break;
++v8;
if ( !v9 )
{
v9 = -1;
break;
}
}
cchSrc += -1 - v9;
}
if ( dword_4098C4 != 2 && dword_4098C4 )
{
if ( dword_4098C4 == 1 )
{
v10 = 0;
v34 = 0;
v30 = 0;
v31 = 0;
if ( !CodePage )
CodePage = ::CodePage;
v11 = MultiByteToWideChar(CodePage, 8 * (a8 != 0) + 1, lpMultiByteStr, cchSrc, 0, 0);
v32 = v11;
if ( v11 )
{
v12 = alloca(2 * v11);
ms_exc.old_esp = (DWORD)&v25;
lpSrcStr = (LPWSTR)&v25;
ms_exc.disabled = -1;
if ( &v25 )
{
LABEL_21:
if ( !MultiByteToWideChar(CodePage, 1u, lpMultiByteStr, cchSrc, lpSrcStr, v11)
|| (v13 = LCMapStringW(Locale, dwMapFlags, lpSrcStr, v11, 0, 0), v10 = v13, v34 = v13, !v13) )
goto LABEL_35;
if ( BYTE1(dwMapFlags) & 4 )
{
if ( cbMultiByte )
{
if ( v13 <= cbMultiByte )
LCMapStringW(Locale, dwMapFlags, lpSrcStr, v11, (LPWSTR)lpDestStr, cbMultiByte);
}
goto LABEL_35;
}
v14 = alloca(2 * v13);
ms_exc.old_esp = (DWORD)&v25;
lpWideCharStr = (LPCWSTR)&v25;
ms_exc.disabled = -1;
if ( !&v25 )
{
lpWideCharStr = (LPCWSTR)malloc(2 * v13);
if ( !lpWideCharStr )
{
LABEL_35:
if ( v31 )
free((void *)lpWideCharStr);
if ( v30 )
free(lpSrcStr);
return v10;
}
v31 = 1;
}
if ( LCMapStringW(Locale, dwMapFlags, lpSrcStr, v11, (LPWSTR)lpWideCharStr, v10) )
{
if ( cbMultiByte )
{
v24 = cbMultiByte;
v23 = (CHAR *)lpDestStr;
}
else
{
v24 = 0;
v23 = 0;
}
v10 = WideCharToMultiByte(CodePage, 0, lpWideCharStr, v10, v23, v24, 0, 0);
}
goto LABEL_35;
}
lpSrcStr = (LPWSTR)malloc(2 * v11);
if ( lpSrcStr )
{
v30 = 1;
goto LABEL_21;
}
}
}
return 0;
}
v35 = 0;
v16 = 0;
v33 = 0;
v29 = 0;
if ( !Locale )
Locale = dword_4098AC;
if ( !CodePage )
CodePage = ::CodePage;
v17 = sub_405B1D(Locale);
v28 = v17;
if ( v17 == -1 )
return 0;
if ( v17 != CodePage )
{
v18 = sub_405B64(CodePage, v17, lpMultiByteStr, &cchSrc, 0, 0);
v35 = v18;
if ( !v18 )
return 0;
v19 = LCMapStringA(Locale, dwMapFlags, (LPCSTR)v18, cchSrc, 0, 0);
cchDest = v19;
if ( v19 )
{
ms_exc.disabled = 0;
v20 = alloca(v19);
ms_exc.old_esp = (DWORD)&v25;
v16 = &v25;
v27 = &v25;
memset(&v25, 0, v19);
ms_exc.disabled = -1;
if ( !&v25 )
{
v21 = malloc(cchDest);
v16 = (CHAR *)v21;
if ( !v21 )
{
LABEL_53:
v22 = 0;
goto LABEL_56;
}
memset(v21, 0, cchDest);
v29 = 1;
}
cchDest = LCMapStringA(Locale, dwMapFlags, (LPCSTR)v35, cchSrc, v16, cchDest);
if ( !cchDest )
goto LABEL_53;
v33 = sub_405B64(v28, CodePage, v16, (int *)&cchDest, (int)lpDestStr, cbMultiByte);
v22 = v33 != 0 ? cchDest : 0;
}
else
{
v22 = v26;
}
LABEL_56:
if ( v29 )
free(v16);
goto LABEL_59;
}
v22 = LCMapStringA(Locale, dwMapFlags, lpMultiByteStr, cchSrc, (LPSTR)lpDestStr, cbMultiByte);
LABEL_59:
if ( v35 )
free(v35);
if ( v33 )
{
if ( lpDestStr != v33 )
free(v33);
}
return v22;
}
// 4098C4: using guessed type int dword_4098C4;
//----- (00405B1D) --------------------------------------------------------
__int32 __cdecl sub_405B1D(LCID Locale)
{
__int32 result; // eax@2
CHAR LCData; // [sp+0h] [bp-Ch]@1
char v3; // [sp+6h] [bp-6h]@1
unsigned int v4; // [sp+8h] [bp-4h]@1
int v5; // [sp+Ch] [bp+0h]@1
v4 = (unsigned int)&v5 ^ dword_409040;
v3 = 0;
if ( GetLocaleInfoA(Locale, 0x1004u, &LCData, 6) )
result = atol(&LCData);
else
result = -1;
return result;
}
// 409040: using guessed type int dword_409040;
//----- (00405B64) --------------------------------------------------------
void *__cdecl sub_405B64(UINT CodePage, UINT a2, const CHAR *a3, int *a4, int a5, int a6)
{
int v6; // ebx@1
int v7; // esi@9
const WCHAR *v8; // ebx@15
void *v9; // esp@15
void *v11; // eax@25
int v12; // eax@26
char v13; // [sp+0h] [bp-60h]@15
const WCHAR *v14; // [sp+Ch] [bp-54h]@15
int *v15; // [sp+10h] [bp-50h]@1
int v16; // [sp+14h] [bp-4Ch]@1
int cbMultiByte; // [sp+18h] [bp-48h]@1
LPCSTR lpMultiByteStr; // [sp+1Ch] [bp-44h]@1
void *v19; // [sp+20h] [bp-40h]@1
int v20; // [sp+24h] [bp-3Ch]@11
int v21; // [sp+28h] [bp-38h]@1
void *v22; // [sp+2Ch] [bp-34h]@1
struct _cpinfo CPInfo; // [sp+30h] [bp-30h]@2
unsigned int v24; // [sp+44h] [bp-1Ch]@1
CPPEH_RECORD ms_exc; // [sp+48h] [bp-18h]@15
int v26; // [sp+60h] [bp+0h]@1
v24 = (unsigned int)&v26 ^ dword_409040;
lpMultiByteStr = a3;
v15 = a4;
v19 = (void *)a5;
v22 = 0;
v16 = 0;
v6 = *a4;
cbMultiByte = *a4;
v21 = 0;
if ( CodePage == a2 )
{
v8 = v14;
}
else
{
if ( GetCPInfo(CodePage, &CPInfo) )
{
if ( CPInfo.MaxCharSize == 1 )
{
if ( GetCPInfo(a2, &CPInfo) )
{
if ( CPInfo.MaxCharSize == 1 )
v21 = 1;
}
}
}
if ( v21 )
{
if ( v6 == -1 )
v7 = strlen(a3) + 1;
else
v7 = v6;
v20 = v7;
}
else
{
v7 = v20;
}
if ( !v21 )
{
v7 = MultiByteToWideChar(CodePage, 1u, lpMultiByteStr, v6, 0, 0);
v20 = v7;
if ( !v7 )
return 0;
}
ms_exc.disabled = 0;
v9 = alloca(2 * v7);
ms_exc.old_esp = (DWORD)&v13;
v8 = (const WCHAR *)&v13;
v14 = (const WCHAR *)&v13;
memset(&v13, 0, 2 * v7);
ms_exc.disabled = -1;
if ( !&v13 )
{
v8 = (const WCHAR *)sub_404D84(2u, v7);
if ( !v8 )
return 0;
v16 = 1;
}
if ( MultiByteToWideChar(CodePage, 1u, lpMultiByteStr, cbMultiByte, (LPWSTR)v8, v7) )
{
if ( v19 )
{
if ( WideCharToMultiByte(a2, 0, v8, v7, (LPSTR)v19, a6, 0, 0) )
v22 = v19;
}
else
{
if ( v21 || (v7 = WideCharToMultiByte(a2, 0, v8, v7, 0, 0, 0, 0)) != 0 )
{
v11 = sub_404D84(1u, v7);
v22 = v11;
if ( v11 )
{
v12 = WideCharToMultiByte(a2, 0, v8, v7, (LPSTR)v11, v7, 0, 0);
if ( v12 )
{
if ( cbMultiByte != -1 )
*v15 = v12;
}
else
{
free(v22);
v22 = 0;
}
}
}
}
}
}
if ( v16 )
free((void *)v8);
return v22;
}
// 409040: using guessed type int dword_409040;
// ALL OK, 18 function(s) have been successfully decompiled