Guest User

Blocky Highway XPAK loader

a guest
Sep 29th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.56 KB | None | 0 0
  1. int __fastcall xGen::cPackage::loadHeader(xGen::cPackage *this)
  2. {
  3.   xGen::cPackage *v1; // r8@1
  4.   _DWORD *v2; // r5@1
  5.   xGen::cLowFile *v3; // r0@1
  6.   unsigned int v4; // r0@8
  7.   signed int v5; // r1@8
  8.   bool v6; // zf@9
  9.   signed int v7; // r4@9
  10.   void *v8; // r5@12
  11.   unsigned int v9; // r11@12
  12.   int v10; // r0@12
  13.   int i; // r1@14
  14.   int v12; // r4@17
  15.   int v13; // r6@17
  16.   _DWORD *v14; // r5@17
  17.   int *v15; // r5@17
  18.   int v16; // t1@17
  19.   int v17; // r11@17
  20.   int v18; // r10@17
  21.   int v19; // r5@18
  22.   int v20; // t1@18
  23.   _BYTE *v21; // r4@18
  24.   int v22; // r5@18
  25.   char v23; // r8@18
  26.   size_t v24; // r0@18
  27.   int v25; // r0@18
  28.   __int16 v26; // r2@18
  29.   int result; // r0@21
  30.   void *v28; // [sp+Ch] [bp-85Ch]@17
  31.   void *ptr; // [sp+10h] [bp-858h]@17
  32.   int v30; // [sp+18h] [bp-850h]@17
  33.   int v31; // [sp+1Ch] [bp-84Ch]@17
  34.   int v32; // [sp+20h] [bp-848h]@18
  35.   int v33; // [sp+24h] [bp-844h]@18
  36.   int v34; // [sp+28h] [bp-840h]@18
  37.   unsigned int v35; // [sp+30h] [bp-838h]@8
  38.   char v36; // [sp+34h] [bp-834h]@5
  39.   int v37; // [sp+38h] [bp-830h]@3
  40.   __int16 v38; // [sp+3Dh] [bp-82Bh]@18
  41.   char v39; // [sp+3Fh] [bp-829h]@18
  42.   int v40; // [sp+40h] [bp-828h]@2
  43.   char v41; // [sp+44h] [bp-824h]@2
  44.   char v42[2048]; // [sp+48h] [bp-820h]@18
  45.   int v43; // [sp+848h] [bp-20h]@1
  46.  
  47.   v1 = this;
  48.   v2 = &_stack_chk_guard;
  49.   v43 = _stack_chk_guard;
  50.   v3 = (xGen::cLowFile *)*((_DWORD *)this + 3);
  51.   if ( v3 )
  52.   {
  53.     v41 = 0;
  54.     v40 = 0;
  55.     xGen::cLowFile::Read(v3, &v40, 4);
  56.     if ( !strcmp((const char *)&v40, "XPAK") )
  57.     {
  58.       xGen::cLowFile::Read(*((xGen::cLowFile **)v1 + 3), &v37, 4);
  59.       if ( v37 < 2 )
  60.       {
  61.         xGen::cLowFile::Read(*((xGen::cLowFile **)v1 + 3), &v36, 4);
  62.         if ( v37 < 1 )
  63.         {
  64.           *(_DWORD *)((char *)v1 + 34) = 0;
  65.           *(_DWORD *)((char *)v1 + 30) = 0;
  66.           *(_DWORD *)((char *)v1 + 26) = 0;
  67.           *(_DWORD *)((char *)v1 + 22) = 0;
  68.         }
  69.         else
  70.         {
  71.           xGen::cLowFile::Read(*((xGen::cLowFile **)v1 + 3), (char *)v1 + 22, 16);
  72.         }
  73.         xGen::cLowFile::Read(*((xGen::cLowFile **)v1 + 3), (char *)v1 + 17, 5);
  74.         *(_DWORD *)((char *)v1 + 17) ^= 0xAC54DF34;
  75.         xGen::cLowFile::Read(*((xGen::cLowFile **)v1 + 3), &v35, 4);
  76.         v4 = v35;
  77.         v5 = 1;
  78.         do
  79.         {
  80.           v6 = v5 << 31 == 0;
  81.           v7 = v4;
  82.           v4 ^= 0xAC54DF34;
  83.           v5 = 0;
  84.         }
  85.         while ( !v6 );
  86.         v35 = v7;
  87.         if ( v7 >= 5 )
  88.         {
  89.           v8 = (void *)operator new[](v7);
  90.           xGen::cLowFile::Read(*((xGen::cLowFile **)v1 + 3), v8, v7);
  91.           v9 = v35;
  92.           v10 = 4;
  93.           if ( (signed int)v35 / 4 < 4 )
  94.             v10 = (signed int)v35 / 4;
  95.           for ( i = 0; i < v10; ++i )
  96.             *((_DWORD *)v8 + i) ^= 0xAC54DF34;
  97.           v28 = v8;
  98.           v13 = (int)v8 + 4;
  99.           v12 = *(_DWORD *)v8;
  100.           v14 = (_DWORD *)operator new[](*(_DWORD *)v8 | (*(_DWORD *)v8 >> 31));
  101.           j_LzmaDecompress(v13, v9, v14, v12);
  102.           ptr = v14;
  103.           v16 = *v14;
  104.           v15 = v14 + 1;
  105.           v31 = v16;
  106.           v17 = xGen::cLowFile::Tell(*((xGen::cLowFile **)v1 + 3));
  107.           v18 = 0;
  108.           v30 = (int)v1 + 40;
  109.           while ( v18 < v31 )
  110.           {
  111.             v20 = *v15;
  112.             v19 = (int)(v15 + 1);
  113.             _aeabi_memcpy(v42, v19, v20);
  114.             v42[v20] = 0;
  115.             v21 = (_BYTE *)(v19 + v20 + 4);
  116.             v22 = *(_DWORD *)(v19 + v20);
  117.             v34 = 0;
  118.             v23 = *v21;
  119.             v32 = 0;
  120.             v33 = 0;
  121.             v24 = strlen(v42);
  122.             std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>::__init(
  123.               &v32,
  124.               v42,
  125.               v24);
  126.             v25 = std::__ndk1::unordered_map<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>,xGen::cPackage::sFileInfo,std::__ndk1::hash<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>>,std::__ndk1::equal_to<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>>,std::__ndk1::allocator<std::__ndk1::pair<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>> const,xGen::cPackage::sFileInfo>>>::operator[](
  127.                     v30,
  128.                     &v32);
  129.             *(_BYTE *)(v25 + 8) = v23;
  130.             *(_DWORD *)v25 = v22;
  131.             *(_DWORD *)(v25 + 4) = v17;
  132.             v26 = v38;
  133.             *(_BYTE *)(v25 + 11) = v39;
  134.             *(_WORD *)(v25 + 9) = v26;
  135.             std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>::~basic_string(&v32);
  136.             v17 += v22;
  137.             ++v18;
  138.             v15 = (int *)(v21 + 1);
  139.           }
  140.           operator delete[](ptr);
  141.           operator delete[](v28);
  142.           v2 = &_stack_chk_guard;
  143.         }
  144.       }
  145.       else
  146.       {
  147.         xGen::cLogger::logInternal(4, "unsupported xpk version: %d");
  148.       }
  149.     }
  150.   }
  151.   result = *v2 - v43;
  152.   if ( *v2 != v43 )
  153.     _stack_chk_fail(result);
  154.   return result;
  155. }
  156.  
  157. signed int __fastcall xGen::cPackage::loadFile(xGen::cPackage *this, xGen::cFile *a2, const char *a3)
  158. {
  159.   xGen::cPackage *v3; // r10@1
  160.   xGen::cFile *v4; // r8@1
  161.   signed int v5; // r4@1
  162.   size_t v6; // r0@2
  163.   int v7; // r4@2
  164.   int v8; // r9@3
  165.   void *v9; // r6@3
  166.   int v10; // r0@3
  167.   int v11; // r1@3
  168.   int i; // r2@5
  169.   void *v13; // r4@10
  170.   signed int v14; // r5@10
  171.   signed int v15; // r0@14
  172.   int v17; // [sp+10h] [bp-430h]@2
  173.   int v18; // [sp+14h] [bp-42Ch]@2
  174.   int v19; // [sp+18h] [bp-428h]@2
  175.   char dest; // [sp+20h] [bp-420h]@2
  176.   int v21; // [sp+420h] [bp-20h]@1
  177.  
  178.   v3 = this;
  179.   v4 = a2;
  180.   v5 = 0;
  181.   v21 = _stack_chk_guard;
  182.   if ( *((_DWORD *)this + 3) )
  183.   {
  184.     strcpy(&dest, a3);
  185.     _strlwr_s<1024u>(&dest);
  186.     v19 = 0;
  187.     v17 = 0;
  188.     v18 = 0;
  189.     v6 = strlen(&dest);
  190.     std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>::__init(&v17, &dest, v6);
  191.     v7 = std::__ndk1::__hash_table<std::__ndk1::__hash_value_type<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>,xGen::cPackage::sFileInfo>,std::__ndk1::__unordered_map_hasher<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>,std::__ndk1::__hash_value_type<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>,xGen::cPackage::sFileInfo>,std::__ndk1::hash<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>>,true>,std::__ndk1::__unordered_map_equal<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>,std::__ndk1::__hash_value_type<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>,xGen::cPackage::sFileInfo>,std::__ndk1::equal_to<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>>,true>,std::__ndk1::allocator<std::__ndk1::__hash_value_type<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>,xGen::cPackage::sFileInfo>>>::find<std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>>(
  192.            (char *)v3 + 40,
  193.            &v17);
  194.     std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>::~basic_string(&v17);
  195.     if ( !v7 )
  196.     {
  197.       v5 = 0;
  198.       goto LABEL_17;
  199.     }
  200.     v8 = *(_DWORD *)(v7 + 20);
  201.     v9 = (void *)operator new[](v8 | (v8 >> 31));
  202.     xGen::cLowFile::Seek(*((xGen::cLowFile **)v3 + 3), *(_DWORD *)(v7 + 24));
  203.     v10 = xGen::cLowFile::Read(*((xGen::cLowFile **)v3 + 3), v9, v8);
  204.     v11 = 4;
  205.     if ( v8 / 4 < 4 )
  206.       v11 = v8 / 4;
  207.     for ( i = 0; i < v11; ++i )
  208.       *((_DWORD *)v9 + i) ^= 2891243316u;
  209.     if ( v10 )
  210.     {
  211.       if ( (signed int)*(_BYTE *)(v7 + 28) > -1 )
  212.       {
  213.         v13 = v9;
  214.         v14 = v8;
  215. LABEL_14:
  216.         xGen::cFile::setData(v4, v13, v14);
  217.         v15 = 2;
  218. LABEL_16:
  219.         *((_DWORD *)v4 + 5) = v15;
  220.         v5 = 1;
  221.         goto LABEL_17;
  222.       }
  223.       if ( v8 >= 4 )
  224.       {
  225.         v14 = *(_DWORD *)v9;
  226.         v13 = (void *)operator new[](v14 | (v14 >> 31));
  227.         j_LzmaDecompress((char *)v9 + 4, v8, v13, v14);
  228.         operator delete[](v9);
  229.         goto LABEL_14;
  230.       }
  231.     }
  232.     operator delete[](v9);
  233.     v15 = 0;
  234.     goto LABEL_16;
  235.   }
  236. LABEL_17:
  237.   if ( _stack_chk_guard != v21 )
  238.     _stack_chk_fail(_stack_chk_guard - v21);
  239.   return v5;
  240. }
Advertisement
Add Comment
Please, Sign In to add comment