Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <fstream>
- #include <sstream>
- #include <stdint.h>
- #include <iostream>
- #include <string>
- #include <ostream>
- #include <algorithm>
- #include "lz4.h"
- int main()
- {
- // Hardcoded strings ftw.
- FILE* s_File = fopen("B:\\Games\\Battlefield 4\\lz4test.dat", "rb");
- if (s_File == NULL)
- return false;
- // Find the size of the file.
- _fseeki64(s_File, 0, SEEK_END);
- size_t s_Length = _ftelli64(s_File);
- _fseeki64(s_File, 0, SEEK_SET);
- // Read all the file data.
- char* s_Data = new char[s_Length];
- size_t s_ReadLength = fread(s_Data, 1, s_Length, s_File);
- fclose(s_File);
- // Read stuff.
- uint32_t s_DecompressedLength = *(uint32_t*) &s_Data[0x00];
- s_DecompressedLength = _byteswap_ulong(s_DecompressedLength);
- uint16_t s_Magic = *(uint16_t*) &s_Data[0x04];
- s_Magic = _byteswap_ushort(s_Magic);
- uint16_t s_CompressedLength = *(uint16_t*) &s_Data[0x06];
- s_CompressedLength = _byteswap_ushort(s_CompressedLength);
- // Make sure this payload is actually compressed.
- if (s_Magic != 0x0970)
- {
- printf("This crap isn't compressed.\n");
- return 1;
- }
- // Get the pointer to the compressed data.
- char* s_CompData = s_Data + 0x8;
- // Create a buffer to hold our decompressed data.
- char* s_DecompData = new char[s_DecompressedLength];
- // Decompress...
- LZ4_decompress_safe(s_CompData, s_DecompData, s_CompressedLength, s_DecompressedLength);
- // Write the decompressed data to an output file.
- FILE* s_Output = fopen("B:\\Games\\Battlefield 4\\lz4test.decomp.dat", "wb");
- fwrite(s_DecompData, s_DecompressedLength, 1, s_Output);
- fflush(s_Output);
- fclose(s_Output);
- // Delete this nonsense.
- delete[] s_DecompData;
- delete[] s_Data;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement