EterPack.cpp error

Indította XeronWork, 2022-03-30, 16:09:09

2022-03-30, 16:09:09 Utolsó szerkesztés: 2022-03-31, 17:52:34 Szerző: XeronWork
Sziasztok!

A mminap épp az eterpack.cpp-n dolgoztam és egy hibába ütköztem.
Mivel elég régen foglalkoztam vele eléggé ki estem a rutinból és ezt a hibát is oldottam már meg, de rettenetesen halványak az emlékek....

A segítséget előre is köszönöm!






Build error:
1>------ Build started: Project: EterPack, Configuration: Debug Win32 ------
1>  EterPack.cpp
1>..\..\source\EterPack\EterPack.cpp(348): error C2660: 'CLZO::CompressEncryptedMemory' : function does not take 5 arguments
1>..\..\source\EterPack\EterPack.cpp(430): error C2660: 'CLZO::Decompress' : function does not take 4 arguments
1>..\..\source\EterPack\EterPack.cpp(575): error C2660: 'CLZO::Decompress' : function does not take 4 arguments
1>..\..\source\EterPack\EterPack.cpp(688): error C2660: 'CLZO::Decompress' : function does not take 4 arguments
1>..\..\source\EterPack\EterPack.cpp(802): error C2660: 'CLZO::Decompress' : function does not take 4 arguments
1>..\..\source\EterPack\EterPack.cpp(975): error C2660: 'CLZO::CompressEncryptedMemory' : function does not take 5 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========









Eterpack.cpp:

bool CEterPack::EncryptIndexFile()
{
   CMappedFile file;
   LPCVOID pvData;

   if (NULL == file.Create(m_indexFileName, &pvData, 0, 0))
   {
      TraceError("EncryptIndex: Cannot open pack index file! %s", m_dbName);
      return false;
   }

   BYTE * pbData = new BYTE[file.Size()];
   memcpy(pbData, pvData, file.Size());

   CLZObject zObj;

   if (!CLZO::Instance().CompressEncryptedMemory(zObj, pbData, file.Size(), 1, s_adwEterPackKey))
   {
      TraceError("EncryptIndex: Cannot encrypt! %s", m_dbName);
      SAFE_DELETE_ARRAY(pbData);
      return false;
   }

   file.Destroy();

   while (!DeleteFile(m_indexFileName));

   FILE * fp;

   fp = fopen(m_indexFileName, "wb");

   if (!fp)
   {
      TraceError("EncryptIndex: Cannot open file for writing! %s", m_dbName);
      SAFE_DELETE_ARRAY(pbData);
      return false;
   }

   if (1 != fwrite(zObj.GetBuffer(), zObj.GetSize(), 1, fp))
   {
      TraceError("Encryptindex: Cannot write to file! %s", m_indexFileName);
      SAFE_DELETE_ARRAY(pbData);
      fclose(fp);
      return false;
   }

   fclose(fp);

   m_bEncrypted = true;
   delete[] pbData;
   return true;
}

bool CEterPack::__BuildIndex(CEterFileDict& rkFileDict, bool bOverwrite)
{
   //DWORD dwBeginTime = ELTimer_GetMSec();
   CMappedFile file;
   LPCVOID pvData;
   CLZObject zObj;

   if (NULL == file.Create(m_indexFileName, &pvData, 0, 0))
   {
      TraceError("Cannot open pack index file! %s", m_dbName);
      return false;
   }

   if (file.Size() < eterpack::c_HeaderSize)
   {
      TraceError("Pack index file header error! %s", m_dbName);
      return false;
   }
   //---------------------------
   char* tData = (char*)pvData;
   DWORD twocc = *(WORD *)tData;
   if (twocc != TWOCC)
   {
      TraceError("Pack file header error! (TWOCC MISMATCH) %s", m_dbName);
      return false;
   }
   tData += sizeof(WORD);
   m_dataOff = ((*(DWORD*)tData) ^ OFFSET_KEY) + sizeof(WORD)+sizeof(DWORD);
   tData += sizeof(DWORD);
   pvData = (LPCVOID)tData;
   //---------------------------
   DWORD fourcc = *(DWORD *)pvData;

   BYTE * pbData;
   UINT uiFileSize;

   if (fourcc == eterpack::c_IndexCC)
   {
      pbData = (BYTE *)pvData;
      uiFileSize = file.Size();
   }
   else if (fourcc == CLZObject::ms_dwFourCC)
   {
      m_bEncrypted = true;

      if (!CLZO::Instance().Decompress(zObj, (const BYTE *)pvData, 1, s_adwEterPackKey))
         return false;

      if (zObj.GetSize() < eterpack::c_HeaderSize)
         return false;

      pbData = zObj.GetBuffer();
      uiFileSize = zObj.GetSize();
   }
   else
   {
      TraceError("Pack index file fourcc error! %s", m_dbName);
      return false;
   }

   pbData += sizeof(DWORD);

   DWORD ver = *(DWORD *)pbData;
   pbData += sizeof(DWORD);

   if (ver != eterpack::c_Version)
   {
      TraceError("Pack index file version error! %s", m_dbName);
      return false;
   }

   m_indexCount = *(long *)pbData;
   pbData += sizeof(long);

   if (uiFileSize < eterpack::c_HeaderSize + sizeof(TEterPackIndex)* m_indexCount)
   {
      TraceError("Pack index file size error! %s, indexCount %d", m_dbName, m_indexCount);
      return false;
   }

   //Tracef("Loading Pack file %s elements: %d ... ", m_dbName, m_indexCount);

   m_indexData = new TEterPackIndex[m_indexCount];
   memcpy(m_indexData, pbData, sizeof(TEterPackIndex)* m_indexCount);

   TEterPackIndex * index = m_indexData;

   for (int i = 0; i < m_indexCount; ++i, ++index)
   {
      if (!index->filename_crc)
      {
         PushFreeIndex(index);
      }
      else
      {
         if (index->real_data_size > index->data_size)
            m_FragmentSize += index->real_data_size - index->data_size;

         m_DataPositionMap.insert(TDataPositionMap::value_type(index->filename_crc, index));

         if (bOverwrite) // ¼­¹ö ¿¬µ¿ ÆÐÅ· ÆÄÀÏÀº ³ªÁß¿¡ µé¾î¿ÀÁö¸¸ ÃÖ»óÀ§·Î µî·ÏÇؾßÇÑ´Ù
            rkFileDict.UpdateItem(this, index);
         else
            rkFileDict.InsertItem(this, index);
      }
   }

   //Tracef("Done. (spent %dms)\n", ELTimer_GetMSec() - dwBeginTime);
   return true;
}
//
//void CEterPack::UpdateLastAccessTime()
//{
//   m_tLastAccessTime = time(NULL);
//}
//
//void CEterPack::ClearDataMemoryMap()
//{
//   // m_fileÀÌ data fileÀÌ´Ù...
//   m_file.Destroy();
//   m_tLastAccessTime = 0;
//   m_bIsDataLoaded = false;
//}

bool CEterPack::Get(CMappedFile& out_file, const char * filename, LPCVOID * data)
{
   TEterPackIndex * index = FindIndex(filename);

   if (!index)
   {
      return false;
   }

   //UpdateLastAccessTime();
   //if (!m_bIsDataLoaded)
   //{
   //   if (!m_file.Create(m_stDataFileName.c_str(), (const void**)&m_file_data, 0, 0))
   //      return false;
   //   
   //   m_bIsDataLoaded = true;
   //}

   // ±âÁ¸¿¡´Â CEterPack¿¡¼­ epk¸¦ memory map¿¡ ¿Ã·Á³õ°í, ¿äûÀÌ ¿À¸é ±× ºÎºÐÀ» ¸µÅ©Çؼ­ ³Ñ°Ü Áá¾ú´Âµ¥,
   // ÀÌÁ¦´Â ¿äûÀÌ ¿À¸é, ÇÊ¿äÇÑ ºÎºÐ¸¸ memory map¿¡ ¿Ã¸®°í, ¿äûÀÌ ³¡³ª¸é ÇØÁ¦ÇÏ°Ô ÇÔ.
   out_file.Create(m_stDataFileName.c_str(), data, index->data_position + m_dataOff, index->data_size);

   bool bIsSecurityCheckRequired = (index->compressed_type == COMPRESSED_TYPE_SECURITY ||
      index->compressed_type == COMPRESSED_TYPE_PANAMA);

   if (bIsSecurityCheckRequired)
   {
#ifdef CHECKSUM_CHECK_MD5
      MD5_CTX context;
      GenerateMD5Hash((BYTE*)(*data), index->data_size, context);

      if (memcmp(index->MD5Digest, context.digest, 16) != 0)
      {
         return false;
      }
#else
#ifdef ENABLE_CRC32_CHECK
      DWORD dwCrc32 = GetCRC32((const char*)(*data), index->data_size);

      if (index->data_crc != dwCrc32)
      {
         return false;
      }
#endif
#endif
   }


   if (COMPRESSED_TYPE_COMPRESS == index->compressed_type)
   {
      CLZObject * zObj = new CLZObject;

      if (!CLZO::Instance().Decompress(*zObj, static_cast<const BYTE *>(*data), 0))
      {
         TraceError("Failed to decompress : %s", filename);
         delete zObj;
         return false;
      }

      out_file.BindLZObject(zObj);
      *data = zObj->GetBuffer();
   }
   else if (COMPRESSED_TYPE_SECURITY == index->compressed_type)
   {
      CLZObject * zObj = new CLZObject;

      if (!CLZO::Instance().Decompress(*zObj, static_cast<const BYTE *>(*data), 2, s_adwEterPackSecurityKey))
      {
         TraceError("Failed to encrypt : %s", filename);
         delete zObj;
         return false;
      }

      out_file.BindLZObject(zObj);
      *data = zObj->GetBuffer();
   }
   else if (COMPRESSED_TYPE_PANAMA == index->compressed_type)
   {
      CLZObject * zObj = new CLZObject;
      __Decrypt_Panama(filename, static_cast<const BYTE*>(*data), index->data_size, *zObj);
      out_file.BindLZObjectWithBuffer edSize(zObj);
      *data = zObj->GetBuffer();
   }
   else if (COMPRESSED_TYPE_HYBRIDCRYPT == index->compressed_type || COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB == index->compressed_type)
   {
#ifdef __THEMIDA__
      VM_START
#endif

         CLZObject * zObj = new CLZObject;

      if (!m_pCSHybridCryptPolicy->DecryptMemory(string(filename), static_cast<const BYTE*>(*data), index->data_size, *zObj))
      {
         return false;
      }

      out_file.BindLZObjectWithBuffer edSize(zObj);
      if (COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB == index->compressed_type)
      {
         BYTE* pSDBData;
         int   iSDBSize;

         if (!m_pCSHybridCryptPolicy->GetSupplementaryDataBlock(string(filename), pSDBData, iSDBSize))
         {
            return false;
         }

         *data = out_file.AppendDataBlock(pSDBData, iSDBSize);
      }
      else
      {
         *data = zObj->GetBuffer();
      }
#ifdef __THEMIDA__
      VM_END
#endif
   }
   return true;
}

bool CEterPack::Get2(CMappedFile& out_file, const char * filename, TEterPackIndex * index, LPCVOID * data)
{
   if (!index)
   {
      return false;
   }

   //UpdateLastAccessTime();
   //if (!m_bIsDataLoaded)
   //{
   //   if (!m_file.Create(m_stDataFileName.c_str(), (const void**)&m_file_data, 0, 0))
   //      return false;
   //   
   //   m_bIsDataLoaded = true;
   //}
   out_file.Create(m_stDataFileName.c_str(), data, index->data_position + m_dataOff, index->data_size);

   bool bIsSecurityCheckRequired = (index->compressed_type == COMPRESSED_TYPE_SECURITY ||
      index->compressed_type == COMPRESSED_TYPE_PANAMA);

   if (bIsSecurityCheckRequired)
   {
#ifdef CHECKSUM_CHECK_MD5
      MD5_CTX context;
      GenerateMD5Hash((BYTE*)(*data), index->data_size, context);

      if (memcmp(index->MD5Digest, context.digest, 16) != 0)
      {
         return false;
      }
#else
      DWORD dwCrc32 = GetCRC32((const char*)(*data), index->data_size);

      if (index->data_crc != dwCrc32)
      {
         return false;
      }
#endif
   }


   if (COMPRESSED_TYPE_COMPRESS == index->compressed_type)
   {
      CLZObject * zObj = new CLZObject;

      if (!CLZO::Instance().Decompress(*zObj, static_cast<const BYTE *>(*data), 0))
      {
         TraceError("Failed to decompress : %s", filename);
         delete zObj;
         return false;
      }

      out_file.BindLZObject(zObj);
      *data = zObj->GetBuffer();
   }
   else if (COMPRESSED_TYPE_SECURITY == index->compressed_type)
   {
      CLZObject * zObj = new CLZObject;

      if (!CLZO::Instance().Decompress(*zObj, static_cast<const BYTE *>(*data), 2, s_adwEterPackSecurityKey))
      {
         TraceError("Failed to encrypt : %s", filename);
         delete zObj;
         return false;
      }

      out_file.BindLZObject(zObj);
      *data = zObj->GetBuffer();
   }
   else if (COMPRESSED_TYPE_PANAMA == index->compressed_type)
   {
      CLZObject * zObj = new CLZObject;
      __Decrypt_Panama(filename, static_cast<const BYTE*>(*data), index->data_size, *zObj);
      out_file.BindLZObjectWithBuffer edSize(zObj);
      *data = zObj->GetBuffer();
   }
   else if (COMPRESSED_TYPE_HYBRIDCRYPT == index->compressed_type || COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB == index->compressed_type)
   {
#ifdef __THEMIDA__
      VM_START
#endif

         CLZObject * zObj = new CLZObject;

      if (!m_pCSHybridCryptPolicy->DecryptMemory(string(filename), static_cast<const BYTE*>(*data), index->data_size, *zObj))
      {
         return false;
      }

      out_file.BindLZObjectWithBuffer edSize(zObj);

      if (COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB == index->compressed_type)
      {
         BYTE* pSDBData;
         int   iSDBSize;

         if (!m_pCSHybridCryptPolicy->GetSupplementaryDataBlock(string(filename), pSDBData, iSDBSize))
         {
            return false;
         }

         *data = out_file.AppendDataBlock(pSDBData, iSDBSize);
      }
      else
      {
         *data = zObj->GetBuffer();
      }
#ifdef __THEMIDA__
      VM_END
#endif
   }

   return true;
}


bool CEterPack::Delete(TEterPackIndex * pIndex)
{
   CFileBase fileIndex;

   if (!fileIndex.Create(m_indexFileName, CFileBase::FILEMODE_WRITE))
      return false;

   PushFreeIndex(pIndex);
   WriteIndex(fileIndex, pIndex);
   return true;
}

bool CEterPack::Delete(const char * filename)
{
   TEterPackIndex * pIndex = FindIndex(filename);

   if (!pIndex)
      return false;

   return Delete(pIndex);
}

bool CEterPack::Extract()
{
   CMappedFile dataMapFile;
   LPCVOID      data;

   if (!dataMapFile.Create(m_stDataFileName.c_str(), &data, 0, 0))
      return false;

   CLZObject zObj;

   for (TDataPositionMap::iterator i = m_DataPositionMap.begin();
      i != m_DataPositionMap.end();
      ++i)
   {
      TEterPackIndex* index = i->second;
      CFileBase writeFile;

      inlinePathCreate(index->filename);
      printf("%s\n", index->filename);

      writeFile.Create(index->filename, CFileBase::FILEMODE_WRITE);

      if (COMPRESSED_TYPE_COMPRESS == index->compressed_type)
      {
         if (!CLZO::Instance().Decompress(zObj, (const BYTE *)data + index->data_position, 0))
         {
            printf("cannot decompress");
            return false;
         }

         writeFile.Write(zObj.GetBuffer(), zObj.GetSize());
         zObj.Clear();
      }
      else if (COMPRESSED_TYPE_SECURITY == index->compressed_type)
      {
         if (!CLZO::Instance().Decompress(zObj, (const BYTE *)data + index->data_position, 2, s_adwEterPackSecurityKey))
         {
            printf("cannot decompress");
            return false;
         }

         writeFile.Write(zObj.GetBuffer(), zObj.GetSize());
         zObj.Clear();
      }
      else if (COMPRESSED_TYPE_PANAMA == index->compressed_type)
      {
         __Decrypt_Panama(index->filename, (const BYTE *)data + index->data_position, index->data_size, zObj);
         writeFile.Write(zObj.GetBuffer(), zObj.GetBufferSize());
         zObj.Clear();
      }
      else if (COMPRESSED_TYPE_HYBRIDCRYPT == index->compressed_type || COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB == index->compressed_type)
      {
#ifdef __THEMIDA__
         VM_START
#endif
         if (!m_pCSHybridCryptPolicy->DecryptMemory(string(index->filename), (const BYTE *)data + index->data_position, index->data_size, zObj))
            return false;

         if (COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB == index->compressed_type)
         {
            dataMapFile.BindLZObjectWithBuf feredSize(&zObj);

            BYTE* pSDBData;
            int   iSDBSize;

            if (!m_pCSHybridCryptPolicy->GetSupplementaryDataBlock(string(index->filename), pSDBData, iSDBSize))
               return false;

            dataMapFile.AppendDataBlock(pSDBData, iSDBSize);
            writeFile.Write(dataMapFile.AppendDataBlock(pSDBData, iSDBSize), dataMapFile.Size());
         }
         else
         {
            writeFile.Write(zObj.GetBuffer(), zObj.GetBufferSize());
         }
         zObj.Clear();
#ifdef __THEMIDA__
         VM_END
#endif
      }
      else if (COMPRESSED_TYPE_NONE == index->compressed_type)
         writeFile.Write((const char *)data + index->data_position, index->data_size);

      writeFile.Destroy();
   }
   return true;
}

bool CEterPack::GetNames(std::vector<std::string>* retNames)
{
   CMappedFile dataMapFile;
   LPCVOID      data;

   if (!dataMapFile.Create(m_stDataFileName.c_str(), &data, 0, 0))
      return false;

   CLZObject zObj;

   for (TDataPositionMap::iterator i = m_DataPositionMap.begin();
      i != m_DataPositionMap.end();
      ++i)
   {
      TEterPackIndex* index = i->second;

      inlinePathCreate(index->filename);

      retNames->push_back(index->filename);
   }
   return true;
}

bool CEterPack::Put(const char * filename, const char * sourceFilename, BYTE packType, const std::string& strRelateMapName)
{
   CMappedFile mapFile;
   LPCVOID      data;

   if (sourceFilename)
   {
      if (!mapFile.Create(sourceFilename, &data, 0, 0))
      {
         return false;
      }
   }
   else if (!mapFile.Create(filename, &data, 0, 0))
   {
      return false;
   }

   BYTE*  pMappedData = (BYTE*)data;
   int      iMappedDataSize = mapFile.Size();

   if (packType == COMPRESSED_TYPE_HYBRIDCRYPT || packType == COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB)
   {
#ifdef __THEMIDA__
      VM_START
#endif
         m_pCSHybridCryptPolicy->GenerateCryptKey(string(filename));

      if (packType == COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB)
      {
         if (!m_pCSHybridCryptPolicy->GenerateSupplementaryDataBlock(string(filename), strRelateMapName, (const BYTE*)data, mapFile.Size(), pMappedData, iMappedDataSize))
         {
            return false;
         }
      }
#ifdef __THEMIDA__
      VM_END
#endif
   }

   return Put(filename, pMappedData, iMappedDataSize, packType);
}

#ifdef CHECKSUM_CHECK_MD5
void CEterPack::GenerateMD5Hash(BYTE* pData, int nLength, IN OUT MD5_CTX& mdContext)
{
   MD5Init(&mdContext);

   const int nBlockSize = 1024;

   int nLoopCnt = nLength / nBlockSize;
   int nRemainder = nLength % nBlockSize;
   int i;

   for (i = 0; i < nLoopCnt; ++i)
   {
      MD5Update(&mdContext, reinterpret_cast<BYTE*>(pData + i*nBlockSize), nBlockSize);
   }

   if (nRemainder > 0)
      MD5Update(&mdContext, reinterpret_cast<BYTE*>(pData + i*nBlockSize), nRemainder);

   MD5Final(&mdContext);
}
#endif
bool CEterPack::Put(const char * filename, LPCVOID data, long len, BYTE packType)
{
   if (m_bEncrypted)
   {
      TraceError("EterPack::Put : Cannot put to encrypted pack (filename: %s, DB: %s)", filename, m_dbName);
      return false;
   }

   CFileBase fileIndex;

   if (!fileIndex.Create(m_indexFileName, CFileBase::FILEMODE_WRITE))
   {
      return false;
   }

   CFileBase fileData;

   if (!fileData.Create(m_stDataFileName.c_str(), CFileBase::FILEMODE_WRITE))
   {
      return false;
   }

   TEterPackIndex * pIndex;
   pIndex = FindIndex(filename);

   CLZObject zObj;
   std::string encryptStr;

   if (packType == COMPRESSED_TYPE_SECURITY ||
      packType == COMPRESSED_TYPE_COMPRESS)
   {
      if (packType == COMPRESSED_TYPE_SECURITY)
      {
         if (!CLZO::Instance().CompressEncryptedMemory(zObj, data, len, 2, s_adwEterPackSecurityKey))
         {
            return false;
         }
      }
      else
      {
         if (!CLZO::Instance().CompressMemory(zObj, data, len))
         {
            return false;
         }
      }

      data = zObj.GetBuffer();
      len = zObj.GetSize();
   }
   else if (packType == COMPRESSED_TYPE_PANAMA)
   {
      if (!__Encrypt_Panama(filename, (const BYTE *)data, len, zObj))
      {
         return false;
      }

      data = zObj.GetBuffer();
      len = zObj.GetBufferSize();
   }
   else if (packType == COMPRESSED_TYPE_HYBRIDCRYPT || packType == COMPRESSED_TYPE_HYBRIDCRYPT_WIT HSDB)
   {
#ifdef __THEMIDA__
      VM_START
#endif

      if (!m_pCSHybridCryptPolicy->EncryptMemory(string(filename), (const BYTE *)data, len, zObj))
      {
         return false;
      }

      data = zObj.GetBuffer();
      len = zObj.GetBufferSize();
#ifdef __THEMIDA__
      VM_END
#endif

   }





Probléma megoldódott!

lzo.cpp

bool CLZO::Decompress(CLZObject & rObj, const BYTE * pbBuf, int type, DWORD * pdwKey)
{

DWORD *New_Key;

if (type == 1) New_Key = PackKey; //Pack Key
else if (type == 2) New_Key = SecurityKey; //Sec Key
else if (type == 3) New_Key = ItemProto; //Item Proto
else if (type == 4) New_Key = MobProto; //Mob Proto

if (!rObj.BeginDecompress(pbBuf)) return false;

if (!rObj.Decompress(New_Key)) return false;

return true;
}