1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
CIMGFile* CIMGManager::parseIMG_Version1(string strIMGPath)
{
string strDIRPath = CPathUtility::replaceExtension(strIMGPath, "dir");
CIMGFile *pIMGFile = new CIMGFile;
pIMGFile->m_eVersion = IMG_1;
pIMGFile->m_strPath = strIMGPath;
CFileParser::getInstance()->setReadAllAtOnce(true);
CFileParser::getInstance()->setEndian(LITTLE_ENDIAN);
pIMGFile->m_bFileFound = CFileParser::getInstance()->open(strDIRPath, true);
if (!pIMGFile->m_bFileFound)
{
return pIMGFile;
}
do
{
CIMGEntry *pEntry = new CIMGEntry;
pIMGFile->m_vecEntries.push_back(pEntry);
pEntry->m_uiFileOffset = CFileParser::getInstance()->readULong();
pEntry->m_uiFileSize = CFileParser::getInstance()->readULong() * 2048;
pEntry->m_strFileName = CStringUtility::rtrimFromLeft(CFileParser::getInstance()->readString(24));
}
while (!CFileParser::getInstance()->isEOF());
CFileParser::getInstance()->close();
// fetch RW version for entries in IMG file
CFileParser::getInstance()->setEndian(LITTLE_ENDIAN);
CFileParser::getInstance()->setReadAllAtOnce(false);
pIMGFile->m_bFileFound = CFileParser::getInstance()->open(strIMGPath, true);
//pIMGFile->m_strIMGContent = CFileParser::getInstance()->getFileContent();
//pIMGFile->m_pIMGContent = CFileParser::getInstance()->getFileContent();
for (auto pEntry : pIMGFile->m_vecEntries)
{
CFileParser::getInstance()->seek(pEntry->m_uiFileOffset * 2048);
string strData = CFileParser::getInstance()->readString(2, true);
//CDebugger::log("b0: " + CStringUtility::toString((unsigned char)strData.c_str()[0]));
//CDebugger::log("b1: " + CStringUtility::toString((unsigned char)strData.c_str()[1]));
if (((unsigned char)strData.c_str()[0] & 0xFF) == 206 && ((unsigned char)strData.c_str()[1] & 0xFF) == 161)
{
///*
// the entry data is compressed with LZO1X-999 compression
size_t uiCompressedSize = pEntry->m_uiFileSize;
size_t uiUncompressedSize = uiCompressedSize + uiCompressedSize / 16 + 64 + 3;
CDebugger::log("uiCompressedSize: " + CStringUtility::toString(uiCompressedSize));
CDebugger::log("uiUncompressedSize: " + CStringUtility::toString(uiUncompressedSize));
//uiUncompressedSize *= 200;
CFileParser::getInstance()->seek(pEntry->m_uiFileOffset * 2048);
string strEntryData = CFileParser::getInstance()->readString(uiCompressedSize);
//strEntryData.append(1, '\0');
lzo_bytep pOutData = new lzo_byte[uiUncompressedSize];
lzo_uint *length = new lzo_uint;
*length = (lzo_uint) uiUncompressedSize;
lzo_bytep pEntryData = (lzo_bytep)strEntryData.c_str();
lzo1x_decompress(pEntryData, uiCompressedSize, pOutData, length, NULL);
delete length;
delete [] pOutData;
//*/
/*
unsigned char pOutData2[2048];
unsigned long uiLength = 2048;
unsigned char ucChars[1024];
for (int i = 0; i < 1024; i++)
{
ucChars[i] = 'a';
}
lzo1x_decompress(ucChars, 1024, pOutData2, &uiLength, NULL);
*/
//delete length;
//string strDecompressedEntryData((char*)pOutData, strEntryData.length());
//pEntry->m_uiRWVersion = CStringUtility::unpackULong(strDecompressedEntryData.substr(8, 4), false);
//delete pOutData;
}
else
{
CFileParser::getInstance()->seek((pEntry->m_uiFileOffset * 2048) + 8);
pEntry->m_uiRWVersion = CFileParser::getInstance()->readULong();
}
}
CFileParser::getInstance()->close();
return pIMGFile;
}
|