summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-04-09 19:39:46 -0400
committerjakob <jakob@memeware.net>2017-04-09 19:39:46 -0400
commit411a40b5c077ca69e34c7016428eb9d856f8fe73 (patch)
treecff2ee6b0f6e4144a0041c53adfc8c542088781c /src
parent8a1fcff16e9ba8674c72011da7da5ad1bc133168 (diff)
Automated style checking and fixed unit tests.
Diffstat (limited to 'src')
-rw-r--r--src/cli.c42
-rw-r--r--src/cli.h12
-rw-r--r--src/crypto.c48
-rw-r--r--src/crypto.h8
-rw-r--r--src/encoding.c2
-rw-r--r--src/header.h12
-rw-r--r--src/io.c28
-rw-r--r--src/main.c42
-rw-r--r--src/table.c50
9 files changed, 122 insertions, 122 deletions
diff --git a/src/cli.c b/src/cli.c
index 74adbb8..532388a 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -79,27 +79,27 @@ struct params parse_args(int argc, char **argv) {
count++;
cur = getopt_long(argc, argv, "hVvelqo:g:", long_opts, &opt_index);
switch (cur) {
- case 'h':
- p.mode = HELP;
- return p;
- case 'V':
- p.mode = VERSION;
- return p;
- case 'v':
- p.verbose = true;
- break;
- case 'o':
- count++;
- parse_output_path(optarg, &p);
- break;
- case 'g':
- count++;
- parse_game_id(optarg, &p);
- case 'e':
- p.mode = EXTRACT;
- break;
- case 'l':
- p.mode = LIST;
+ case 'h':
+ p.mode = HELP;
+ return p;
+ case 'V':
+ p.mode = VERSION;
+ return p;
+ case 'v':
+ p.verbose = true;
+ break;
+ case 'o':
+ count++;
+ parse_output_path(optarg, &p);
+ break;
+ case 'g':
+ count++;
+ parse_game_id(optarg, &p);
+ case 'e':
+ p.mode = EXTRACT;
+ break;
+ case 'l':
+ p.mode = LIST;
}
} while (cur >= 0);
diff --git a/src/cli.h b/src/cli.h
index cf7a535..8189a9d 100644
--- a/src/cli.h
+++ b/src/cli.h
@@ -33,12 +33,12 @@ enum {
/* Structure for storing options set from the command-line. */
struct params {
- int mode; /* Current mode of operation. */
- int game; /* Which encryption keys to use. */
- bool verbose; /* Whether or not to output progress messages. */
- int vararg_index; /* Start index of paths in argv. */
- char *out; /* Path to extract files to. */
- size_t out_len; /* Length of the output path string. */
+ bool verbose; /* Whether or not to output progress messages. */
+ char *out; /* Path to extract files to. */
+ size_t out_len; /* Length of the output path string. */
+ int mode; /* Current mode of operation. */
+ int game; /* Which encryption keys to use. */
+ int vararg_index; /* Start index of paths in argv. */
};
/* Returns a params structure parsed from `argv`. */
diff --git a/src/crypto.c b/src/crypto.c
index 92c4032..5a91f39 100644
--- a/src/crypto.c
+++ b/src/crypto.c
@@ -28,30 +28,30 @@
struct game_key get_key(int game) {
struct game_key k = {0};
switch (game) {
- case NEKOPARA_VOLUME_0:
- k.master = 0x1548e29c;
- k.fallback_initial = 0x9c;
- k.fallback_primary = 0xd7;
- k.uses_initial = true;
- break;
- case NEKOPARA_VOLUME_0_STEAM:
- k.master = 0x44528b87;
- k.fallback_initial = 0x87;
- k.fallback_primary = 0x23;
- k.uses_initial = true;
- break;
- case NEKOPARA_VOLUME_1:
- k.master = 0x1548e29c;
- k.fallback_initial = 0x00;
- k.fallback_primary = 0xd7;
- k.uses_initial = false;
- break;
- case NEKOPARA_VOLUME_1_STEAM:
- k.master = 0x44528b87;
- k.fallback_initial = 0x00;
- k.fallback_primary = 0x23;
- k.uses_initial = false;
- break;
+ case NEKOPARA_VOLUME_0:
+ k.master = 0x1548e29c;
+ k.fallback_initial = 0x9c;
+ k.fallback_primary = 0xd7;
+ k.uses_initial = true;
+ break;
+ case NEKOPARA_VOLUME_0_STEAM:
+ k.master = 0x44528b87;
+ k.fallback_initial = 0x87;
+ k.fallback_primary = 0x23;
+ k.uses_initial = true;
+ break;
+ case NEKOPARA_VOLUME_1:
+ k.master = 0x1548e29c;
+ k.fallback_initial = 0x00;
+ k.fallback_primary = 0xd7;
+ k.uses_initial = false;
+ break;
+ case NEKOPARA_VOLUME_1_STEAM:
+ k.master = 0x44528b87;
+ k.fallback_initial = 0x00;
+ k.fallback_primary = 0x23;
+ k.uses_initial = false;
+ break;
}
return k;
}
diff --git a/src/crypto.h b/src/crypto.h
index e80531d..c5417c7 100644
--- a/src/crypto.h
+++ b/src/crypto.h
@@ -33,10 +33,10 @@ enum {
/* Structure containing game-specific encryption information. */
struct game_key {
- bool uses_initial; /* Whether or not to use an initial key. */
- uint32_t master; /* Master key specific to the game. */
- uint8_t fallback_initial; /* Fallback if initial key is 0. */
- uint8_t fallback_primary; /* Fallback if primary key is 0. */
+ bool uses_initial; /* Whether or not to use an initial key. */
+ uint32_t master; /* Master key specific to the game. */
+ uint8_t fallback_initial; /* Fallback if initial key is 0. */
+ uint8_t fallback_primary; /* Fallback if primary key is 0. */
};
/* Returns the game_key structure for a given game identifier, as
diff --git a/src/encoding.c b/src/encoding.c
index d50e503..23d38dc 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -22,7 +22,7 @@
/* Wrapper for iconv, using the conversion specified by `conv`. */
static void convert(char *in_buf, char *out_buf, size_t len, iconv_t conv) {
- size_t in_size = len, out_size = len;
+ size_t in_size = len, out_size = len;
char *in_start = in_buf, *out_start = out_buf;
iconv(conv, &in_start, &in_size, &out_start, &out_size);
}
diff --git a/src/header.h b/src/header.h
index 19f7fcd..8ccf930 100644
--- a/src/header.h
+++ b/src/header.h
@@ -27,12 +27,12 @@
/* Structure representing the header section of an XP3 archive. */
struct header {
- char magic[11]; /* Identifier for the archive. */
- uint64_t info_offset; /* Offset to `table_size`. */
- uint32_t version; /* Raw value containing the archive version. */
- uint64_t table_size; /* The size of the table section. (?) */
- uint8_t flags; /* A flags variable for the archive. (?) */
- uint64_t table_offset; /* Offset to the archive table. */
+ char magic[11]; /* Identifier for the archive. */
+ uint64_t info_offset; /* Offset to `table_size`. */
+ uint32_t version; /* Raw value containing the archive version. */
+ uint64_t table_size; /* The size of the table section. (?) */
+ uint8_t flags; /* A flags variable for the archive. (?) */
+ uint64_t table_offset; /* Offset to the archive table. */
};
/* Reads data from the given stream into a newly allocated header
diff --git a/src/io.c b/src/io.c
index 0bb2dfb..d282edc 100644
--- a/src/io.c
+++ b/src/io.c
@@ -67,8 +67,8 @@ struct stream *stream_from_file(char *path) {
stream, as well as the stream structure itself. */
void stream_free(struct stream *s) {
switch (s->_loc) {
- case HEAP:
- free(s->_start);
+ case HEAP:
+ free(s->_start);
}
free(s);
}
@@ -94,10 +94,10 @@ void stream_write(struct stream *s, void *src, size_t n) {
if (s->_cur + n > s->_start + s->len) {
ptrdiff_t dist = (uintptr_t) s->_cur - (uintptr_t) s->_start;
switch(s->_loc) {
- case HEAP:
- s->len *= 2;
- s->_start = realloc(s->_start, s->len);
- s->_cur = s->_start + dist;
+ case HEAP:
+ s->len *= 2;
+ s->_start = realloc(s->_start, s->len);
+ s->_cur = s->_start + dist;
}
}
memcpy(s->_cur, src, n);
@@ -125,14 +125,14 @@ size_t stream_tell(struct stream *s) {
end-of-file, respectively. */
void stream_seek(struct stream *s, size_t pos, int whence) {
switch (whence) {
- case SEEK_SET:
- s->_cur = s->_start + pos;
- break;
- case SEEK_CUR:
- s->_cur += pos;
- break;
- case SEEK_END:
- s->_cur = s->_start + s->len - pos;
+ case SEEK_SET:
+ s->_cur = s->_start + pos;
+ break;
+ case SEEK_CUR:
+ s->_cur += pos;
+ break;
+ case SEEK_END:
+ s->_cur = s->_start + s->len - pos;
}
}
diff --git a/src/main.c b/src/main.c
index ca47067..aaa1b63 100644
--- a/src/main.c
+++ b/src/main.c
@@ -177,16 +177,16 @@ static void map_entries(char *path, struct params p) {
struct header *h = read_header(archive);
stream_seek(archive, h->table_offset, SEEK_SET);
- struct stream *table = load_table(archive);
- struct table_entry *root = read_table(table);
+ struct stream *table = load_table(archive);
+ struct table_entry *root = read_table(table);
for (struct table_entry *cur = root->next; cur != NULL; cur = cur->next) {
switch (p.mode) {
- case LIST:
- list(cur);
- break;
- case EXTRACT:
- extract(archive, cur, p);
+ case LIST:
+ list(cur);
+ break;
+ case EXTRACT:
+ extract(archive, cur, p);
}
}
@@ -200,20 +200,20 @@ static void map_entries(char *path, struct params p) {
int main(int argc, char **argv) {
struct params p = parse_args(argc, argv);
switch (p.mode) {
- case USAGE:
- print_usage(argv[0]);
- params_free(p);
- return EXIT_FAILURE;
- case VERSION:
- print_version();
- break;
- case HELP:
- print_help();
- break;
- case LIST:
- case EXTRACT:
- for (int i = p.vararg_index; i < argc; i++)
- map_entries(argv[i], p);
+ case USAGE:
+ print_usage(argv[0]);
+ params_free(p);
+ return EXIT_FAILURE;
+ case VERSION:
+ print_version();
+ break;
+ case HELP:
+ print_help();
+ break;
+ case LIST:
+ case EXTRACT:
+ for (int i = p.vararg_index; i < argc; i++)
+ map_entries(argv[i], p);
}
params_free(p);
return EXIT_SUCCESS;
diff --git a/src/table.c b/src/table.c
index 5a0b262..7998295 100644
--- a/src/table.c
+++ b/src/table.c
@@ -80,16 +80,16 @@ struct table_entry *read_table(struct stream *s) {
stream_read(&size, s, sizeof(uint64_t));
switch (magic) {
- case ELIF_MAGIC:
- case HNFN_MAGIC:
- case NEKO_MAGIC:
- read_elif(s, root);
- break;
- case FILE_MAGIC:
- read_file(s, root);
- break;
- default:
- ended = 1;
+ case ELIF_MAGIC:
+ case HNFN_MAGIC:
+ case NEKO_MAGIC:
+ read_elif(s, root);
+ break;
+ case FILE_MAGIC:
+ read_file(s, root);
+ break;
+ default:
+ ended = 1;
}
} while (!ended);
@@ -112,21 +112,21 @@ void read_file(struct stream *s, struct table_entry *root) {
stream_read(&size, s, sizeof(uint64_t));
switch (magic) {
- case ADLR_MAGIC:
- read_adlr(s, tmp);
- break;
- case SEGM_MAGIC:
- read_segm(s, tmp, size / 28);
- break;
- case INFO_MAGIC:
- stream_seek(s, size, SEEK_CUR);
- break;
- case TIME_MAGIC:
- read_time(s, tmp);
- break;
- default:
- ended = true;
- stream_seek(s, -sizeof(uint32_t) - sizeof(uint64_t), SEEK_CUR);
+ case ADLR_MAGIC:
+ read_adlr(s, tmp);
+ break;
+ case SEGM_MAGIC:
+ read_segm(s, tmp, size / 28);
+ break;
+ case INFO_MAGIC:
+ stream_seek(s, size, SEEK_CUR);
+ break;
+ case TIME_MAGIC:
+ read_time(s, tmp);
+ break;
+ default:
+ ended = true;
+ stream_seek(s, -sizeof(uint32_t) - sizeof(uint64_t), SEEK_CUR);
}
} while (!ended);