Skip to content

Instantly share code, notes, and snippets.

@graphitemaster
Created January 16, 2018 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphitemaster/64a018f01492bc40bc4328dd6fc53475 to your computer and use it in GitHub Desktop.
Save graphitemaster/64a018f01492bc40bc4328dd6fc53475 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
struct header
{
char magic[4];
uint32_t version;
uint32_t entries;
};
#pragma pack(push, 1)
struct entry
{
uint32_t length;
uint32_t offset;
uint32_t unknown1;
uint32_t unknown2;
uint16_t name_length;
uint8_t flags;
};
#pragma pack(pop)
int main()
{
FILE *fp = fopen("game.toc", "rb");
fseek(fp, 0, SEEK_END);
long len = ftell(fp);
fseek(fp, 0, SEEK_SET);
unsigned char *data = malloc(len);
fread(data, len, 1, fp);
fclose(fp);
struct header* h = (struct header*)data;
printf("%c%c%c%c\n", h->magic[0],h->magic[1],h->magic[2],h->magic[3]);
printf("%u\n", h->version);
printf("%u\n", h->entries);
unsigned char* offset = data + 21548;
for(uint32_t i = 0; i < h->entries; i++)
{
struct entry* e = (struct entry *)offset;
char *name = malloc(e->name_length+1);
memcpy(name, e+1, e->name_length);
name[e->name_length] = '\0';
printf("length = %-15d, offset = %-15d, unknown1 = 0x%08x, unknown2 = 0x%08x, name_length = %-5d, flags = 0x%02x, name = %s\n",
(int)e->length,
(int)e->offset,
e->unknown1,
e->unknown2,
(int)e->name_length,
e->flags,
name);
free(name);
offset += sizeof *e + e->name_length;
//printf("%zu\n", offset - data);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment