int sub_10004730cpdv8format(void *pthis, HANDLE hFile)
{
int v3; // eax@10
int v4; // ecx@17
bool v5; // cf@21
int v6; // [sp-10h] [bp-A6A0h]@17
unsigned int v7; // [sp-Ch] [bp-A69Ch]@1
int v8; // [sp+0h] [bp-A690h]@69
int v9; // [sp+4h] [bp-A68Ch]@69
DWORD v10; // [sp+8h] [bp-A688h]@62
void *v11; // [sp+Ch] [bp-A684h]@36
int v12; // [sp+10h] [bp-A680h]@27
int v13; // [sp+14h] [bp-A67Ch]@25
unsigned __int8 v14; // [sp+1Ah] [bp-A676h]@23
unsigned __int8 v15; // [sp+1Bh] [bp-A675h]@21
char *v16; // [sp+1Ch] [bp-A674h]@20
char *v17; // [sp+20h] [bp-A670h]@20
int v18; // [sp+24h] [bp-A66Ch]@17
void *v19; // [sp+28h] [bp-A668h]@17
unsigned int v20; // [sp+2Ch] [bp-A664h]@14
char v21; // [sp+33h] [bp-A65Dh]@13
char *v22; // [sp+34h] [bp-A65Ch]@12
char *v23; // [sp+38h] [bp-A658h]@12
void *v24; // [sp+3Ch] [bp-A654h]@1
int v25; // [sp+40h] [bp-A650h]@73
void *v26; // [sp+44h] [bp-A64Ch]@73
void *v27; // [sp+48h] [bp-A648h]@35
size_t v28; // [sp+4Ch] [bp-A644h]@35
void *v29; // [sp+54h] [bp-A63Ch]@28
int v30; // [sp+58h] [bp-A638h]@18
void *v31; // [sp+5Ch] [bp-A634h]@18
int *v32; // [sp+60h] [bp-A630h]@17
int v33; // [sp+64h] [bp-A62Ch]@11
void *v34; // [sp+68h] [bp-A628h]@11
void *v35; // [sp+70h] [bp-A620h]@7
void *v36; // [sp+78h] [bp-A618h]@3
unsigned int j; // [sp+80h] [bp-A610h]@59
DWORD NumberOfBytesRead; // [sp+84h] [bp-A60Ch]@5
int v39; // [sp+8Ch] [bp-A604h]@8
int v40; // [sp+90h] [bp-A600h]@29
char v41; // [sp+94h] [bp-A5FCh]@29
char v42; // [sp+95h] [bp-A5FBh]@29
char v43; // [sp+114h] [bp-A57Ch]@64
__int16 v44; // [sp+A114h] [bp-57Ch]@33
__int16 v45; // [sp+A116h] [bp-57Ah]@33
char v46; // [sp+A118h] [bp-578h]@1
int v47; // [sp+A11Ch] [bp-574h]@31
char *v48; // [sp+A120h] [bp-570h]@33
LPVOID lpBuffer; // [sp+A124h] [bp-56Ch]@1
int v50; // [sp+A128h] [bp-568h]@1
char v51; // [sp+A12Ch] [bp-564h]@31
unsigned __int8 v52; // [sp+A15Ch] [bp-534h]@33
unsigned __int8 v53; // [sp+A15Dh] [bp-533h]@33
unsigned __int8 v54; // [sp+A15Eh] [bp-532h]@33
unsigned __int8 v55; // [sp+A15Fh] [bp-531h]@33
unsigned __int8 v56; // [sp+A160h] [bp-530h]@33
unsigned __int8 v57; // [sp+A161h] [bp-52Fh]@33
int v58; // [sp+A164h] [bp-52Ch]@33
int v59; // [sp+A168h] [bp-528h]@1
int v60; // [sp+A16Ch] [bp-524h]@31
int v61; // [sp+A170h] [bp-520h]@33
int v62; // [sp+A178h] [bp-518h]@53
char v63; // [sp+A17Ch] [bp-514h]@1
DWORD nNumberOfBytesToRead; // [sp+A180h] [bp-510h]@5
char Buffer; // [sp+A184h] [bp-50Ch]@33
char v66; // [sp+A185h] [bp-50Bh]@33
unsigned __int8 v67; // [sp+A18Ch] [bp-504h]@43
char v68; // [sp+A18Dh] [bp-503h]@43
int v69; // [sp+A208h] [bp-488h]@1
int v70; // [sp+A20Ch] [bp-484h]@33
int v71; // [sp+A210h] [bp-480h]@1
wchar_t Dst; // [sp+A214h] [bp-47Ch]@1
char v73; // [sp+A216h] [bp-47Ah]@1
int v74; // [sp+A618h] [bp-78h]@33
char v75; // [sp+A61Ch] [bp-74h]@53
char v76; // [sp+A61Dh] [bp-73h]@53
unsigned int v77; // [sp+A670h] [bp-20h]@1
char v78; // [sp+A674h] [bp-1Ch]@1
int v79; // [sp+A678h] [bp-18h]@1
__int16 v80; // [sp+A67Ch] [bp-14h]@33
int i; // [sp+A680h] [bp-10h]@57
int v82; // [sp+A68Ch] [bp-4h]@1
int v83; // [sp+A690h] [bp+0h]@1
v77 = (unsigned int)&v83 ^ __security_cookie;
v7 = (unsigned int)&v83 ^ __security_cookie;
v24 = this;
Dst = 0;
memset(&v73, 0, 0x3FEu);
sub_1000ABC0(&v63, (int)((char *)v24 + 616));//拷贝数据
v82 = 0;
sub_1000B850(&v78);//由全局变量unk_1005050C所指向的函数得到一个值
LOBYTE(v82) = 1;
v79 = 18;
lpBuffer = 0;
v71 = 0;
v69 = 0;
v50 = 0;
v59 = 1;
std::ios_base::ios_base(&v46);
LOBYTE(v82) = 2;
if ( hFile == (HANDLE)-1 )
{
sub_1000A790(&Dst, L"Fail to open CPB file!");
sub_10001C40(1, 3, (unsigned int)&Dst);
LOBYTE(v82) = 1;
std::locale::facet::_facet(&v46);
LOBYTE(v82) = 0;
sub_1000B710(&v78);
v82 = -1;
sub_1000B710(&v63);
return 0;
}
v36 = (void *)operator new(0x15Cu);
lpBuffer = v36;
if ( !v36 )
{
sub_10001C40(1, 3, (unsigned int)L"Fail to malloc head structure!");
LOBYTE(v82) = 1;
std::locale::facet::_facet(&v46);
LOBYTE(v82) = 0;
sub_1000B710(&v78);
v82 = -1;
sub_1000B710(&v63);
return 0;
}
memset(lpBuffer, 0, 0x15Cu);
nNumberOfBytesToRead = 344;
SetFilePointer(hFile, 0, 0, 0);
if ( !ReadFile(hFile, lpBuffer, nNumberOfBytesToRead, &NumberOfBytesRead, 0)
|| NumberOfBytesRead != nNumberOfBytesToRead )
{
sub_10001C40(1, 3, (unsigned int)L"Fail to read file head !");
v35 = lpBuffer;
operator delete(lpBuffer);
lpBuffer = 0;
LOBYTE(v82) = 1;
std::locale::facet::_facet(&v46);
LOBYTE(v82) = 0;
sub_1000B710(&v78);
v82 = -1;
sub_1000B710(&v63);
return 0;
}
sub_1000B650operator_(&v78, (LPCSTR)lpBuffer + 4);//分配内存
v39 = -1;
v39 = sub_1000A220(&v78, 35, 0);//在v78里面找字符#
if ( v39 != -1 )
sub_1000A160(&v78, v39, 32);
v3 = unknown_libname_123((char *)v24 + 624);//从this对象获取字符串指针
if ( sub_1000A100(&v78, v3) )//手机类型和包的类型做比较
{
sub_1000A790(&Dst, L"the CPB file is not used for the chosen project!");
sub_10001C40(1, 3, (unsigned int)&Dst);
v59 = 0;
v34 = lpBuffer;
operator delete(lpBuffer);
lpBuffer = 0;
v33 = v59;
LOBYTE(v82) = 1;
std::locale::facet::_facet(&v46);
LOBYTE(v82) = 0;
sub_1000B710(&v78);
v82 = -1;
sub_1000B710(&v63);
return v33;
}
v23 = (char *)v24 + 676;
v22 = (char *)v24 + 677;
do
v21 = *v23++;
while ( v21 );
v20 = v23 - v22;//字符串长度
if ( v23 == v22 )//字符串长度为0
{
strcpy_s((char *)v24 + 676, 0x20u, (const char *)lpBuffer + 4);//手机名字拷贝过去
if ( v39 != -1 )
*((_BYTE *)v24 + v39 + 676) = 0;//v39为长度
sub_1000B650operator_(&v78, (LPCSTR)v24 + 676);//内存分配
v6 = v4;
v32 = &v6;
v19 = sub_1000ABC0(&v6, (int)&v78);//拷贝
v18 = sub_10008870(v6);//判断是否在机型库
if ( !v18 )
{
v31 = lpBuffer;
operator delete(lpBuffer);
lpBuffer = 0;
v30 = 0;
LOBYTE(v82) = 1;
std::locale::facet::_facet(&v46);
LOBYTE(v82) = 0;
sub_1000B710(&v78);
v82 = -1;
sub_1000B710(&v63);
return v30;
}
}
else
{
v17 = (char *)lpBuffer + 4;
v16 = (char *)v24 + 676;
//比较v16 v17字符串是否相等 如果不相等v13不为0
while ( 1 )
{
v15 = *v16;
v5 = v15 < *v17;
if ( v15 != *v17 )
break;
if ( !v15 )
goto LABEL_25;
v14 = v16[1];
v5 = v14 < v17[1];
if ( v14 != v17[1] )
break;
v16 += 2;
v17 += 2;
if ( !v14 )
{
LABEL_25:
v13 = 0;
goto LABEL_27;
}
}
v13 = -v5 - (v5 - 1);
LABEL_27:
v12 = v13;
if ( v13 )//v16 v17字符串不相等
{
sub_10001C40(1, 3, (unsigned int)L"the CPB file is not used for the chosen project !!!");
v29 = lpBuffer;
operator delete(lpBuffer);
lpBuffer = 0;
LOBYTE(v82) = 1;
std::locale::facet::_facet(&v46);
LOBYTE(v82) = 0;
sub_1000B710(&v78);
v82 = -1;
sub_1000B710(&v63);
return 0;
}
}
//字符串判断结束,是正确的
v50 = sub_1000B9A0crc16(lpBuffer, nNumberOfBytesToRead - 4, v50);//计算crc
v41 = 0;
memset(&v42, 0, 0x7Fu);
v40 = 0;
sub_100054D0((char *)lpBuffer + 180, 80, &v41, &v40);
if ( v40 == 64 )
{
unknown_libname_20(&v51, &v41, 60);
v60 = 0;
v60 = *(int *)((char *)&v40 + v40);
v47 = sub_1000B9A0(&v51, v40 - 4, 0);
if ( v60 == v47 )
{
v80 = v57 + v56 + v55 + v54 + v53 + v52;
v44 = (unsigned __int16)(v57 + v56 + v55 + v54 + v53 + v52) / 5 - v55;
v45 = (unsigned __int16)(v57 + v56 + v55 + v54 + v53 + v52) / 5 - v56;
v70 = v58 - 344;
Buffer = 0;
memset(&v66, 0, 0x7Fu);
v48 = 0;
v61 = 0;
v74 = 0;
while ( v70 )
{
v28 = 140;
v27 = (void *)operator new(0x8Cu);
if ( v27 )
{
memset(v27, 0, v28);
v11 = v27;
}
else
{
v11 = 0;
}
v69 = (int)v11;
*((_DWORD *)v11 + 34) = 0;
if ( !v69 )
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Fail to allocate the memory!");
goto LABEL_71;
}
v61 = 9;
if ( !ReadFile(hFile, &Buffer, 9u, &NumberOfBytesRead, 0) || NumberOfBytesRead != v61 )
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Fail to read the file list head!");
goto LABEL_71;
}
v70 -= 9;
v61 = v67;
v48 = &v68;
if ( !ReadFile(hFile, &v68, v67, &NumberOfBytesRead, 0) || NumberOfBytesRead != v61 )
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Fail to read the file list!!");
goto LABEL_71;
}
v70 -= v61;
v50 = sub_1000B9A0(&Buffer, v61 + 9, v50);
unknown_libname_20(v69, &Buffer, v61 + 9);
sub_10011E70(v69, v74, &v44, (char *)lpBuffer + 100);
if ( v74 )
*(_DWORD *)(v71 + 136) = v69;
else
*((_DWORD *)v24 + 200) = v69;
v71 = v69;
++v74;
}
if ( v50 == *((_DWORD *)lpBuffer + 85) || v50 == *((_DWORD *)lpBuffer + 85) - 8 )
{
v62 = 0;
v75 = 0;
memset(&v76, 0, 0x4Fu);
sub_100054D0((char *)lpBuffer + 260, 80, &v75, &v62);
if ( v62 == 24 )
{
v60 = 0;
v60 = sub_1000B9A0(&v75, 20, 0);
v47 = *(int *)((char *)&v74 + v62);
if ( v47 == v60 )
{
sub_100129D0((char *)v24 + 836);
for ( i = *((_DWORD *)v24 + 200); i; i = *(_DWORD *)(i + 136) )
{
for ( j = *(_DWORD *)(i + 4); j; j -= nNumberOfBytesToRead )
{
if ( j <= 0xA000 )
v10 = j;
else
v10 = 40960;
nNumberOfBytesToRead = v10;
if ( !ReadFile(hFile, &v43, v10, &NumberOfBytesRead, 0) || NumberOfBytesRead != nNumberOfBytesToRead )
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Fail to read the file data!");
goto LABEL_71;
}
sub_10014680((char *)v24 + 836, &v43, nNumberOfBytesToRead);
}
}
sub_100147C0((char *)v24 + 836);
v9 = strncmp(&v75, (const char *)v24 + 860, 20);
v8 = v9;
if ( v9 )
v59 = 0;
}
else
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Check crc-data Error!");
}
}
else
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Check cpb data error!");
}
}
else
{
v59 = 0;
}
}
else
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Fail to check the file head!!");
}
}
else
{
v59 = 0;
sub_10001C40(1, 3, (unsigned int)L"Fail to decrypte the CPB head content!");
}
LABEL_71:
if ( !v59 )
{
v6 = *((_DWORD *)v24 + 200);
sub_1000C470(v6);
*((_DWORD *)v24 + 200) = 0;
}
v26 = lpBuffer;
operator delete(lpBuffer);
lpBuffer = 0;
v25 = v59;
LOBYTE(v82) = 1;
std::locale::facet::_facet(&v46);
LOBYTE(v82) = 0;
sub_1000B710(&v78);
v82 = -1;
sub_1000B710(&v63);
return v25;
}