Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Garc.dll
- * by Reisyukaku
- *
- * Set of functions to handle GARC files in the RomFS.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "garc_dll.h"
- EXPORT int* getgarcs(char* file){
- FILE* fp;
- fp = fopen(file, "rb");
- if (!fp) {
- fclose(fp);
- fprintf(stderr, "Error while opening file %s for reading\n", file);
- return NULL;
- }
- fseek(fp, 0, SEEK_SET);
- unsigned char magic[4];
- int currOff = 0, cnt = 1;
- int* list = malloc(sizeof(int));
- list[0] = 0;
- while(!(feof(fp) || ferror(fp))){
- currOff += fread(magic, 1, 4, fp);
- if(magic[0] == 0x43 && magic[1] == 0x52 && magic[2] == 0x41 && magic[3] == 0x47){
- printf("0x%08x\n", currOff - 0x4);
- list = realloc(list, sizeof(int) * (cnt + 1));
- list[cnt++] = currOff - 0x4;
- }
- }
- list[0] = cnt - 1;
- fclose(fp);
- return list;
- }
- EXPORT void writegarc(char* inFile, char* outFile, int garcOff, int len){
- FILE* fi, *fo;
- fi = fopen(inFile, "rb");
- fo = fopen(outFile, "wb");
- if (!fi) {
- fclose(fi);
- fprintf(stderr, "Error while opening file %s for reading\n", inFile);
- return;
- }
- fseek(fi, garcOff, SEEK_SET);
- fseek(fo, 0, SEEK_SET);
- int i = 0;
- while(!(feof(fi) || ferror(fi) || ferror(fo)) && i < len){
- char romfsBytes[0x10];
- fread(romfsBytes, 1, 0x10, fi);
- fwrite(romfsBytes, 1, 0x10, fo);
- i+=0x10;
- }
- fclose(fi);
- fclose(fo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement