Guest User

EOS Decrypt

a guest
Mar 13th, 2017
171
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <Wincrypt.h>
  6.  
  7. #ifdef _MSC_VER
  8. #pragma warning( push )
  9.  #pragma warning( disable : 4996 )
  10. #endif
  11.  
  12. #define NBYTE(x) (*((BYTE*)&(x)))
  13.  
  14. static const BYTE pKey[8] = {0xFF, 0x41, 0x54, 0x73, 0x84, 0x9A, 0xC8, 0xA6};
  15.  
  16. int nDecryptBlock(HCRYPTKEY hKey, unsigned char* pBuffer)
  17. {
  18.   signed int i = 0;
  19.   int dwCheck;
  20.   int result;
  21.   DWORD dwBlockSize = 8;
  22.  
  23.   CryptDecrypt(hKey, 0, 1, 0, (BYTE *)pBuffer + i, &dwBlockSize);
  24.   i = 0;
  25.   do
  26.   {
  27.     NBYTE(dwCheck) = *(BYTE *)(i + pBuffer);
  28.     if ((BYTE)dwCheck == 0x7F)
  29.     {
  30.       result = 0;
  31.     }
  32.     else if ((BYTE)dwCheck == 0x80u)
  33.     {
  34.       result = 0xFF;
  35.     }
  36.     else
  37.     {
  38.       dwCheck = (unsigned __int8)dwCheck;
  39.       if ((unsigned __int8)dwCheck >= 0x80u)
  40.         result = dwCheck - 1;
  41.       else
  42.         result = dwCheck + 1;
  43.     }
  44.     *(BYTE *)(i++ + pBuffer) = result;
  45.   }
  46.   while ( i < 8 );
  47.   *(DWORD *)pBuffer ^= 0xA4A7FF88;
  48.   *(DWORD *)(pBuffer + 4) ^= 0xA0447823;
  49.  
  50.   return result;
  51. }
  52.  
  53. int _tmain(int argc, _TCHAR* argv[])
  54. {
  55.     if(argc != 3)
  56.     {
  57.       printf("Echo of Soul Files Decryptor\n");
  58.       printf("(c) 2015 / Ekey (h4x0r) / v0.1a\n\n");
  59.       printf("[Usage]\n");
  60.       printf("\tEOSDecryptor <pScrFile> <pDstFile>\n");
  61.       printf("[Examples]\n");
  62.       printf("\tEOSDecryptor EOS.ini EOS.ini.dec\n\n");
  63.       return -1;
  64.     }
  65.  
  66.     FILE * fi = fopen(argv[1], "rb");
  67.     FILE * fo = fopen(argv[2], "wb");
  68.  
  69.     if (fi == NULL)
  70.     {
  71.       printf("[ERROR]: Can't open file %s\n", argv[1]);
  72.       return -1;
  73.     }
  74.  
  75.     if (fo == NULL)
  76.     {
  77.       printf("[ERROR]: Can't write output file %s\n", argv[2]);
  78.       return -1;
  79.     }
  80.  
  81.     fseek(fi, 0, SEEK_END);
  82.     size_t dwSize = ftell(fi);
  83.     fseek(fi, 0, SEEK_SET);
  84.  
  85.     dwSize -= 4;
  86.     fseek(fi, 4, SEEK_SET);
  87.  
  88.     unsigned char *pBuffer = new unsigned char[dwSize];
  89.     memset(pBuffer, 0, dwSize);
  90.  
  91.     fread((char*)pBuffer, dwSize, 1, fi);
  92.  
  93.     HCRYPTPROV hCryptProv = 0;
  94.     HCRYPTKEY hKey = 0;
  95.     HCRYPTHASH hHash = 0;
  96.  
  97.     if (!CryptAcquireContextW(&hCryptProv, L"SBENCRYPTIONKEYCONTAINER10", L"Microsoft Enhanced Cryptographic Provider v1.0", 1u, 0) && GetLastError() == 0x80090016)
  98.         CryptAcquireContextW(&hCryptProv, L"SBENCRYPTIONKEYCONTAINER10", 0, 1u, 8u);
  99.  
  100.     CryptCreateHash(hCryptProv, 0x8003u, 0, 0, &hHash);
  101.     CryptHashData(hHash, pKey, 8u, 0);
  102.     CryptDeriveKey(hCryptProv, 0x6801u, hHash, 0x800000, &hKey);
  103.  
  104.     int i = 0;
  105.     int dwBlocks = dwSize >> 3;
  106.  
  107.     do
  108.     {
  109.        nDecryptBlock(hKey, pBuffer + i);
  110.        i += 8;
  111.        --dwBlocks;
  112.     }
  113.     while (dwBlocks);
  114.  
  115.     fwrite(pBuffer, dwSize, 1, fo);
  116.  
  117.     fclose(fi);
  118.     fclose(fo);
  119.     printf("Done!\n");
  120.     return 0;
  121. }
RAW Paste Data