Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <fstream>
  4. #include <sstream>
  5. #include <stdint.h>
  6. #include <iostream>
  7. #include <string>
  8. #include <ostream>
  9. #include <algorithm>
  10.  
  11. #include "lz4.h"
  12.  
  13. int main()
  14. {
  15.     // Hardcoded strings ftw.
  16.     FILE* s_File = fopen("B:\\Games\\Battlefield 4\\lz4test.dat", "rb");
  17.  
  18.     if (s_File == NULL)
  19.         return false;
  20.  
  21.     // Find the size of the file.
  22.     _fseeki64(s_File, 0, SEEK_END);
  23.     size_t s_Length = _ftelli64(s_File);
  24.     _fseeki64(s_File, 0, SEEK_SET);
  25.  
  26.     // Read all the file data.
  27.     char* s_Data = new char[s_Length];
  28.     size_t s_ReadLength = fread(s_Data, 1, s_Length, s_File);
  29.  
  30.     fclose(s_File);
  31.  
  32.     // Read stuff.
  33.     uint32_t s_DecompressedLength = *(uint32_t*) &s_Data[0x00];
  34.     s_DecompressedLength = _byteswap_ulong(s_DecompressedLength);
  35.  
  36.     uint16_t s_Magic = *(uint16_t*) &s_Data[0x04];
  37.     s_Magic = _byteswap_ushort(s_Magic);
  38.  
  39.     uint16_t s_CompressedLength = *(uint16_t*) &s_Data[0x06];
  40.     s_CompressedLength = _byteswap_ushort(s_CompressedLength);
  41.  
  42.     // Make sure this payload is actually compressed.
  43.     if (s_Magic != 0x0970)
  44.     {
  45.         printf("This crap isn't compressed.\n");
  46.         return 1;
  47.     }
  48.  
  49.     // Get the pointer to the compressed data.
  50.     char* s_CompData = s_Data + 0x8;
  51.  
  52.     // Create a buffer to hold our decompressed data.
  53.     char* s_DecompData = new char[s_DecompressedLength];
  54.  
  55.     // Decompress...
  56.     LZ4_decompress_safe(s_CompData, s_DecompData, s_CompressedLength, s_DecompressedLength);
  57.  
  58.     // Write the decompressed data to an output file.
  59.     FILE* s_Output = fopen("B:\\Games\\Battlefield 4\\lz4test.decomp.dat", "wb");
  60.  
  61.     fwrite(s_DecompData, s_DecompressedLength, 1, s_Output);
  62.     fflush(s_Output);
  63.     fclose(s_Output);
  64.  
  65.     // Delete this nonsense.
  66.     delete[] s_DecompData;
  67.     delete[] s_Data;
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement