#include #include #include #define BLOCK 2048 int main(int argc, char *argv[]) { FILE *img, *dir; char dirname[32]; int i; int offset; int size; char filename[24]; FILE *file; char temp[BLOCK]; if (argc < 2) { printf("Usage: %s img\n", argv[0]); exit(1); } if ((img = fopen(argv[1], "r")) == NULL) { printf("Couldn't open file: %s\n", argv[1]); exit(1); } i = strlen(argv[1]); strncpy(dirname, argv[1], i); dirname[i-1] = dirname[i-2] = dirname[i-3] = '\0'; strcat(dirname, "dir"); if ((dir = fopen(dirname, "r")) == NULL) { printf("Couldn't open file: %s\n", dirname); exit(1); } while (fread(&offset, 4, 1, dir) == 1) { fread(&size, 4, 1, dir); fread(filename, 1, 24, dir); if ((file = fopen(filename, "w")) == NULL) { printf("Couldn't open file: %s\n", filename); exit(1); } fseek(img, offset*BLOCK, 0); for (i = 0; i < size; i++) { fread(temp, BLOCK, 1, img); fwrite(temp, BLOCK, 1, file); } fclose(file); } fclose(img); fclose(dir); return 0; }