Skip to content

Instantly share code, notes, and snippets.

@wareya
Created May 12, 2017 22:16
Show Gist options
  • Select an option

  • Save wareya/10d523e28b25d336bfb15e7cfc00b512 to your computer and use it in GitHub Desktop.

Select an option

Save wareya/10d523e28b25d336bfb15e7cfc00b512 to your computer and use it in GitHub Desktop.
extract buriko arc20 archives (raw data only)
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
void fread_or_die(void * a, size_t b, size_t c, FILE * d)
{
size_t got = fread(a, b, c, d);
if(feof(d)) {puts("feof"); exit(0);}
if(ferror(d)) {puts("ferror"); exit(0);}
if(got != c) {exit(0);}
}
struct filedata
{
char filename[96];
uint32_t offset;
uint32_t size;
char padding[24];
};
int main(int argc, char ** argv)
{
if(argc < 2) return puts("Usage: unarc file.arc"), 0;
auto f = fopen(argv[1], "rb");
char magic[12];
fread_or_die(magic, 12, 1, f);
if(strncmp(magic, "BURIKO ARC20", 12) != 0) return puts("File is not supported or is invalid."), 0;
uint32_t numfiles;
fread_or_die(&numfiles, 4, 1, f);
std::vector<filedata> files;
for(uint64_t i = 0; i < numfiles; i++)
{
filedata newfile;
fread_or_die(&newfile.filename, 1, 96, f);
fread_or_die(&newfile.offset, 4, 1, f);
fread_or_die(&newfile.size, 4, 1, f);
fread_or_die(&newfile.padding, 1, 24, f);
files.push_back(newfile);
}
long int start = ftell(f);
for(auto file : files)
{
unsigned char * data = (unsigned char*)malloc(file.size);
fseek(f, start+file.offset, SEEK_SET);
fread_or_die(data, 1, file.size, f);
auto out = fopen(file.filename, "wb");
fwrite(data, 1, file.size, out);
fclose(out);
free(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment