Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cstdint>
- #include <cassert>
- struct Lba {
- uint64_t offset;
- uint64_t size;
- uint64_t uncompressedSize;
- uint32_t compressionMethod;
- uint32_t checksum[5]; // SHA-1
- uint8_t dummy[5];
- };
- uint64_t align(uint64_t offset, uint64_t alignment) {
- return offset - (offset - ((offset + alignment - 1) / alignment) * alignment);
- }
- int main() {
- char fileName[0x100];
- int bufferLen = 0x100000;
- void *buffer = malloc(bufferLen);
- FILE *f = fopen("tresgame-ps4.pak", "rb");
- assert(f != NULL);
- int index = 0;
- uint64_t pos = 0;
- Lba lba;
- while (fread(&lba, 0x35, 1, f) > 0) {
- printf("[%3i, %09X] ", index++, pos);
- if (lba.compressionMethod == 0 &&
- lba.dummy[0] == 0 &&
- lba.dummy[1] == 0 &&
- lba.dummy[2] == 0 &&
- lba.dummy[3] == 0 &&
- lba.dummy[4] == 0) {
- if (bufferLen < lba.size) {
- bufferLen = lba.size;
- free(buffer);
- buffer = malloc(bufferLen);
- }
- fread(buffer, lba.size, 1, f);
- const char *ext = "bin";
- // guess format
- if (*(uint8_t*)buffer == '{')
- ext = "json";
- else if (*(uint32_t*)buffer == 2653586369)
- ext = "upk";
- snprintf(fileName, sizeof(fileName), "out/%i.%s", index, ext);
- FILE *fOut = fopen(fileName, "wb");
- assert(fOut != NULL);
- fwrite(buffer, lba.size, 1, fOut);
- fclose(fOut);
- }
- uint64_t blockSize = align(lba.size, 0x10000);
- if (blockSize == 0)
- blockSize = 0x10000;
- pos += blockSize;
- _fseeki64(f, pos, SEEK_SET);
- printf("\n");
- }
- free(buffer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement