2002-08-13 06:56:57 +00:00
|
|
|
/*
|
|
|
|
* Written 1999 Jan 29 by Josh Cogliati
|
|
|
|
* I grant this program to public domain.
|
2002-08-26 07:51:24 +00:00
|
|
|
*
|
|
|
|
* Modified by Bradley Bell, 2002
|
|
|
|
* All modifications under GPL, version 2 or later
|
2002-08-13 06:56:57 +00:00
|
|
|
*/
|
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;
|
2002-08-26 07:51:24 +00:00
|
|
|
int v = 0;
|
|
|
|
|
|
|
|
if (argc > 1 && !strcmp(argv[1], "v")) {
|
|
|
|
v = 1;
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
2002-08-13 06:56:57 +00:00
|
|
|
|
2002-08-27 08:05:14 +00:00
|
|
|
if (argc < 2) {
|
|
|
|
printf("Usage: hogextract [v] hogfile [filename]\n"
|
2002-08-26 07:51:24 +00:00
|
|
|
"extracts all the files in hogfile into the current directory\n"
|
|
|
|
"Options:\n"
|
|
|
|
" v View files, don't extract\n");
|
2002-08-13 06:56:57 +00:00
|
|
|
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);
|
2002-08-27 08:05:14 +00:00
|
|
|
if (argc > 2 && strcmp(argv[2], filename))
|
2002-08-26 07:51:24 +00:00
|
|
|
fseek(hogfile, len, SEEK_CUR);
|
|
|
|
else {
|
2002-08-27 08:05:14 +00:00
|
|
|
printf("Filename: %s \tLength: %i\n", filename, len);
|
|
|
|
if (v)
|
|
|
|
fseek(hogfile, len, SEEK_CUR);
|
|
|
|
else {
|
|
|
|
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);
|
|
|
|
}
|
2002-08-26 07:51:24 +00:00
|
|
|
}
|
2002-08-13 06:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(hogfile);
|
2002-08-13 07:12:00 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-08-13 06:45:00 +00:00
|
|
|
}
|