#include #include #include #define BLOCK 2048 /* Extract all files out of a IMG/DIR file (Vice City & III ) */ int main(int argc, char *argv[]) { FILE *img, *dir; FILE *outfile; int i; int offset; int size; char filename[24]; char temp[BLOCK]; if (argc < 3) { printf("Usage: %s dir img\n", argv[0]); exit(1); } if ((dir = fopen(argv[1], "rb")) == NULL) { printf("Couldn't open file: %s\n", argv[1]); exit(1); } if ((img = fopen(argv[2], "rb")) == NULL) { printf("Couldn't open file: %s\n", argv[2]); exit(1); } while (fread(&offset, 4, 1, dir) == 1) { fread(&size, 4, 1, dir); fread(filename, 1, 24, dir); if ((outfile = fopen(filename, "wb")) == NULL) { printf("Couldn't open file: %s\n", filename); exit(1); } printf("Extracting %s\n", filename); fseek(img, offset*BLOCK, 0); for (i = 0; i < size; i++) { fread(temp, BLOCK, 1, img); fwrite(temp, BLOCK, 1, outfile); } fclose(outfile); } fclose(img); fclose(dir); return 0; }