summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-01-13 16:47:22 -0500
committerjakob <jakob@memeware.net>2017-01-13 16:47:22 -0500
commitb51100b3330605a6c9bdb3e07e7f9981ff73f6ec (patch)
tree4b59fc4b93746435d2ce5bc9e4d4da51f79d0c21 /src
parent43e539561a4ea95274468b78735555d6e89fdfd9 (diff)
Removed debugging information and fixed filenames from being cut off.
Diffstat (limited to 'src')
-rw-r--r--src/decompress.c2
-rw-r--r--src/extract.c14
-rw-r--r--src/file.c37
-rw-r--r--src/write.c2
4 files changed, 12 insertions, 43 deletions
diff --git a/src/decompress.c b/src/decompress.c
index 12f6848..dd19958 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -63,7 +63,7 @@ Bytef *inflate_chunk(Bytef *chunk, uint64_t chunk_size,
} while (data_stream.avail_out == 0);
} while (status_code != Z_STREAM_END);
- // inflateEnd(&data_stream);
+ inflateEnd(&data_stream);
return decompressed_data;
}
diff --git a/src/extract.c b/src/extract.c
index 1dad149..3b6828b 100644
--- a/src/extract.c
+++ b/src/extract.c
@@ -65,15 +65,13 @@ void extract(FILE *archive, uint64_t table_offset) {
free(compressed_data.start);
} else {
data_stream = compressed_data;
- }
+ }
uint32_t entry_magic;
uint64_t entry_size;
do {
read_stream(&entry_magic, &data_stream.data, sizeof(uint32_t));
read_stream(&entry_size, &data_stream.data, sizeof(uint64_t));
- printf("entry at 0x%lx\n", data_stream.data - data_stream.start - 12);
- printf("Magic: %" PRIx32 " Size: %" PRIx64 "\n", entry_magic, entry_size);
switch (entry_magic) {
/* hnfn, neko, and eliF entries are all identical.
@@ -92,7 +90,6 @@ void extract(FILE *archive, uint64_t table_offset) {
defer_file_node(file_new, file_root);
break;
default:
- printf("End of archive reached.\n");
stream_ended = 1;
}
} while (!stream_ended);
@@ -125,13 +122,18 @@ elif_node *read_elif_entry(memory_stream *data_stream) {
/* Strings are terminated by null bytes,
which aren't counted in the name size. */
char *input_buffer = malloc(name_size * 2 + 2);
- file_name = malloc(name_size + 1);
read_stream(input_buffer, &data_stream->data, name_size * 2 + 2);
+ /* name_size + 1 is unreliable since we're going back to UTF-8
+ and some characters (especially Japanese ones) can be wide.
+ To compensate we just allocate a buffer that could fit the
+ UTF-16LE data and utilize null-bytes to terminate names. */
+ file_name = malloc(name_size * 2 + 2);
+
/* iconv is the less-portable glibc way of doing it. It seems to
be in the OpenBSD manpages, though, so I'm not worried. */
+ size_t in_size = name_size * 2 + 2, out_size = name_size * 2 + 2;
char *in_start = input_buffer, *out_start = file_name;
- size_t in_size = name_size * 2 + 2, out_size = name_size + 1;
iconv_t conversion = iconv_open("UTF-8", "UTF-16LE");
iconv(conversion, &in_start, &in_size, &out_start, &out_size);
iconv_close(conversion);
diff --git a/src/file.c b/src/file.c
index 0c5751a..12e5432 100644
--- a/src/file.c
+++ b/src/file.c
@@ -45,27 +45,22 @@ file_node *read_file_entry(memory_stream *data_stream, Bytef *section_end) {
read_stream(&entry_size, &data_stream->data, sizeof(uint64_t));
switch (entry_magic) {
case ADLR_MAGIC:
- printf("[ADLR found at 0x%lx]\n", data_stream->data - data_stream->start - 12);
read_adlr_chunk(data_stream, parsed);
break;
case SEGM_MAGIC:
- printf("[SEGM found at 0x%lx]\n", data_stream->data - data_stream->start - 12);
/* Segments are 28 bytes each. */
read_segm_chunk(data_stream, parsed, entry_size / 28);
break;
case INFO_MAGIC:
- printf("[INFO found at 0x%lx]\n", data_stream->data - data_stream->start - 12);
read_info_chunk(data_stream, parsed);
break;
case TIME_MAGIC:
- printf("[TIME found at 0x%lx]\n", data_stream->data - data_stream->start - 12);
read_time_chunk(data_stream, parsed);
break;
default:
- printf("Unknown magic: %" PRIx32 " size: %" PRIx64 "\n", entry_magic, entry_size); // Debug.
+ printf("Unknown magic: %" PRIx32 "\n", entry_magic);
}
}
- printf("\n\n\n\n"); // Debug.
return parsed;
}
@@ -79,24 +74,10 @@ void read_info_chunk(memory_stream *data_stream, file_node *parsed) {
read_stream(&decompressed_size, &data_stream->data, sizeof(uint64_t));
read_stream(&compressed_size, &data_stream->data, sizeof(uint64_t));
read_stream(&file_name_size, &data_stream->data, sizeof(uint16_t));
-
- char *file_name = malloc(file_name_size * 2);
- read_stream(file_name, &data_stream->data, file_name_size * 2);
- printf("\nINFO SEGMENT\n");
- printf("------------\n");
- printf("%s\n", encrypted ? "ENCRYPTED": "PLAINTEXT");
- printf("COMPRESSED_SIZE: %" PRIx64 "\n", compressed_size);
- printf("DECOMPRESSED_SIZE: %" PRIx64 "\n", decompressed_size);
- printf("MD5: ");
- for (int i = 0; i < file_name_size * 2; i++) {
- if (file_name[i] >= 0x20 && file_name[i] < 0x7f)
- printf("%c", file_name[i]);
- }
- printf("\n");
-
parsed->encrypted = encrypted;
- data_stream->data += 2;
+ char *file_name = malloc(file_name_size * 2 + 2);
+ read_stream(file_name, &data_stream->data, file_name_size * 2 + 2);
}
@@ -121,15 +102,6 @@ void read_segm_chunk(memory_stream *data_stream, file_node *parsed,
sizeof(uint64_t));
parsed->file_size += segments[i]->decompressed_size;
}
- printf("\nSEGMENT SECTION\n---------------\n\n");
- printf("SEGMENT_COUNT: %" PRIu64 "\n", segment_count);
- for (uint64_t i = 0; i < segment_count; i++) {
- printf("\nSEGMENT %" PRIu64 "\n----------\n", i);
- printf("%s\n", segments[i]->compressed ? "COMPRESSED" : "DECOMPRESSED");
- printf("FILE_OFFSET: %" PRIu64 "\n", segments[i]->offset);
- printf("COMPRESSED_SIZE: %" PRIu64 "\n", segments[i]->compressed_size);
- printf("DECOMPRESSED_SIZE: %" PRIu64 "\n", segments[i]->decompressed_size);
- }
parsed->segment_count = segment_count;
parsed->segments = segments;
}
@@ -147,7 +119,4 @@ void read_adlr_chunk(memory_stream *data_stream, file_node *parsed) {
void read_time_chunk(memory_stream *data_stream, file_node *parsed) {
uint64_t timestamp;
read_stream(&timestamp, &data_stream->data, sizeof(uint64_t));
- printf("\nTIME SEGMENT\n");
- printf("------------\n");
- printf("TIMESTAMP: %" PRIx64 "\n\n", timestamp);
}
diff --git a/src/write.c b/src/write.c
index f54d2f7..e011504 100644
--- a/src/write.c
+++ b/src/write.c
@@ -134,8 +134,6 @@ void free_elif_nodes(elif_node *base) {
if (base->next != NULL) {
free_elif_nodes(base->next);
}
- if (base->file_name)
- printf("%s\n", base->file_name);
free(base->file_name);
free(base);
}