#include #include #include #define BLOCK 2048 int main(int argc, char *argv[]) { FILE *img, *dir; int i; int offset; int size; char filename[24]; FILE *file; char temp[BLOCK]; if (argc < 3) { printf("Usage: %s img dir\n", argv[0]); exit(1); } if ((img = fopen(argv[1], "r")) == NULL) { printf("Couldn't open file: %s\n", argv[1]); exit(1); } if ((dir = fopen(argv[2], "r")) == 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 ((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; }