summaryrefslogtreecommitdiff
path: root/src/decompress.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-01-09 20:51:41 -0500
committerjakob <jakob@memeware.net>2017-01-09 20:51:41 -0500
commit8eaa3f0526d380afe422152fada2bea27b8d8f70 (patch)
treeeded2f25609b6d131a377233fb215efac2b31c18 /src/decompress.c
parent7d141c7e79bb9688a475b88722f6101ad01ef782 (diff)
Significant progress on implementing file decryption. Offsets as of now are trying to go from within the table, which is incorrect. A working commit should come tomorrow.
Diffstat (limited to 'src/decompress.c')
-rw-r--r--src/decompress.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/decompress.c b/src/decompress.c
index dba637f..0301cc8 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -24,7 +24,8 @@
#include "extract.h"
-/* Document and put in header. */
+/* Returns a pointer to a buffer containing the
+ inflated contents of a given memory chunk. */
Bytef *inflate_chunk(Bytef *chunk, uint64_t chunk_size,
uint64_t decompressed_size) {
Bytef *decompressed_data = malloc(decompressed_size);
@@ -77,7 +78,7 @@ memory_stream decompress_file(FILE *archive, uint64_t sizes_offset) {
fread(&decompressed_size, sizeof(uint64_t), 1, archive);
/* Decompression is done in memory because it's $CURRENT_YEAR. */
- Bytef *compressed_data = malloc(compressed_size);
+ Bytef *decompressed_data, *compressed_data = malloc(compressed_size);
/* This is a pretty shitty way of handling it, though. */
if (compressed_data == NULL) {
@@ -88,22 +89,13 @@ memory_stream decompress_file(FILE *archive, uint64_t sizes_offset) {
}
fread(compressed_data, compressed_size, 1, archive);
- /* if (ferror(archive)) { */
- /* fprintf(stderr, "File corrupt.\n"); */
- /* inflateEnd(&data_stream); */
- /* free(compressed_data); */
- /* free(decompressed_data); */
- /* exit(EXIT_FAILURE); */
- /* } */
- Bytef *decompressed_data = inflate_chunk(compressed_data, compressed_size,
- decompressed_size);
-
+ decompressed_data = inflate_chunk(compressed_data, compressed_size,
+ decompressed_size);
/* The compressed data is irrelevant at this point. */
free(compressed_data);
if (decompressed_data == NULL)
exit(EXIT_FAILURE);
- return (memory_stream) {decompressed_size,
- decompressed_data,
+ return (memory_stream) {decompressed_size, decompressed_data,
decompressed_data};
}