old-exhal/exhal.c
Devin Acker 23a609086f this is where I try out the github windows client
Ten years ago we had Steve Jobs, Johnny Cash, and Bob Hope. Now, we have
no jobs, no cash, and no hope.
2013-06-04 21:56:07 -04:00

64 lines
1.4 KiB
C

/*
exhal - HAL Laboratory decompression tool
by Devin Acker
Usage:
exhal romfile offset outfile
This code is released under the terms of the MIT license.
See copying.txt for details.
*/
#include <stdio.h>
#include "compress.h"
int main (int argc, char **argv) {
printf("exhal - %s %s\nby Devin Acker (Revenant)\n\n", __DATE__, __TIME__);
if (argc != 4) {
printf("Usage:\n%s romfile offset outfile\n", argv[0]);
printf("Example: %s kirbybowl.sfc 0x70000 test.bin\n\n", argv[0]);
printf("offset can be in either decimal or hex.\n");
exit(-1);
}
FILE *infile, *outfile;
// open ROM file for input
infile = fopen(argv[1], "rb");
if (!infile) {
printf("Error: unable to open %s\n", argv[1]);
exit(-1);
}
// open target file for output
outfile = fopen(argv[3], "wb");
if (!outfile) {
printf("Error: unable to open %s\n", argv[1]);
exit(-1);
}
size_t outputsize;
uint32_t fileoffset;
uint8_t unpacked[DATA_SIZE];
uint8_t packed[DATA_SIZE];
memset(packed, 0, DATA_SIZE);
fileoffset = strtol(argv[2], NULL, 0);
// read the file
fseek(infile, fileoffset, SEEK_SET);
fread(packed, sizeof(uint8_t), DATA_SIZE, infile);
// compress the file
outputsize = unpack(packed, unpacked);
// write the uncompressed data to the file
fseek(infile, 0, SEEK_SET);
fwrite((const void*)unpacked, 1, outputsize, outfile);
printf("\nUncompressed size: %d bytes\n", outputsize);
fclose(infile);
fclose(outfile);
}