2002-08-13 06:56:57 +00:00
|
|
|
/*
|
|
|
|
* Written 1999 Jan 29 by Josh Cogliati
|
|
|
|
* I grant this program to public domain.
|
|
|
|
*/
|
2002-08-13 06:45:00 +00:00
|
|
|
|
2002-08-13 06:56:57 +00:00
|
|
|
#include <stdio.h>
|
2002-08-13 07:12:00 +00:00
|
|
|
#include <stdlib.h>
|
2002-08-13 06:56:57 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2002-08-13 06:45:00 +00:00
|
|
|
|
2002-08-13 07:12:00 +00:00
|
|
|
int
|
2002-08-13 06:56:57 +00:00
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
FILE *hogfile, *writefile;
|
2002-08-13 07:12:00 +00:00
|
|
|
int len;
|
2002-08-13 06:56:57 +00:00
|
|
|
char filename[13];
|
|
|
|
char *buf;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: hogextract hogfile\n"
|
|
|
|
"extracts all the files in hogfile into the current directory\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
hogfile = fopen(argv[1], "r");
|
|
|
|
stat(argv[1], &statbuf);
|
2002-08-13 07:12:00 +00:00
|
|
|
printf("%i\n", (int)statbuf.st_size);
|
2002-08-13 06:56:57 +00:00
|
|
|
buf = (char *)malloc(3);
|
|
|
|
fread(buf, 3, 1, hogfile);
|
|
|
|
printf("Extracting from: %s\n", argv[1]);
|
|
|
|
free(buf);
|
|
|
|
while(ftell(hogfile)<statbuf.st_size) {
|
|
|
|
fread(filename, 13, 1, hogfile);
|
|
|
|
fread(&len, sizeof(int), 1, hogfile);
|
|
|
|
printf("Filename: %s \tLength: %i\n", filename, len);
|
|
|
|
buf = (char *)malloc(len);
|
|
|
|
if (buf == NULL) {
|
|
|
|
printf("Unable to allocate memory\n");
|
|
|
|
} else {
|
|
|
|
fread(buf, len, 1, hogfile);
|
|
|
|
writefile = fopen(filename, "w");
|
|
|
|
fwrite(buf, len, 1, writefile);
|
|
|
|
fclose(writefile);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(hogfile);
|
2002-08-13 07:12:00 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-08-13 06:45:00 +00:00
|
|
|
}
|