diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2016-11-20 15:16:41 -0500 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2016-11-24 16:23:09 -0500 |
| commit | 56c9984511f016eab7e1278ba9e40d88bb59a162 (patch) | |
| tree | 1bfa6d3aeb3bf2a6ffec71387ac073cd0b8b2a51 /apps/plugins/puzzles/obfusc.c | |
| parent | 29648f817677b84c03c2bcfe89eb8cf53653e7db (diff) | |
| download | rockbox-puzzles.zip rockbox-puzzles.tar.gz rockbox-puzzles.tar.bz2 rockbox-puzzles.tar.xz | |
[WIP] Port of Simon Tatham's Puzzle Collectionpuzzles
Original revision: 5123b1bf68777ffa86e651f178046b26a87cf2d9
MIT Licensed. Some games still crash and others are unplayable due to
issues with controls. Still need a "real" polygon filling algorithm.
The following games are at least partially broken for various reasons:
Cube: crash with certain settings
Galaxies: crash
Inertia: crash
Keen: input issues
Loopy: weird stuff happens
Map: crash on input
Mines: weird stuff happens on target
Palisade: input issues
Signpost: crash on input
Solo: input issues
Towers: input and drawing issues
Train Tracks: drawing issues
Twiddle: weird animation on target
Undead: input and drawing issues
Unequal: input and drawing issues
Untangle: input issues
All in all, about 40% of the games are at least partially broken.
Change-Id: I7c69b6860ab115f973c8d76799502e9bb3d52368
Diffstat (limited to '')
| -rw-r--r-- | apps/plugins/puzzles/obfusc.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/obfusc.c b/apps/plugins/puzzles/obfusc.c new file mode 100644 index 0000000..e95fa3f --- /dev/null +++ b/apps/plugins/puzzles/obfusc.c @@ -0,0 +1,126 @@ +/* + * Stand-alone tool to access the Puzzles obfuscation algorithm. + * + * To deobfuscate, use "obfusc -d": + * + * obfusc -d reads binary data from stdin, writes to stdout + * obfusc -d <hex string> works on the given hex string instead of stdin + * obfusc -d -h writes a hex string instead of binary to stdout + * + * To obfuscate, "obfusc -e": + * + * obfusc -e reads binary from stdin, writes hex to stdout + * obfusc -e <hex string> works on the given hex string instead of stdin + * obfusc -e -b writes binary instead of text to stdout + * + * The default output format is hex for -e and binary for -d + * because that's the way obfuscation is generally used in + * Puzzles. Either of -b and -h can always be specified to set it + * explicitly. + * + * Data read from standard input is assumed always to be binary; + * data provided on the command line is taken to be hex. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <errno.h> + +#include "puzzles.h" + +int main(int argc, char **argv) +{ + enum { BINARY, DEFAULT, HEX } outputmode = DEFAULT; + char *inhex = NULL; + unsigned char *data; + int datalen; + int decode = -1; + int doing_opts = TRUE; + + while (--argc > 0) { + char *p = *++argv; + + if (doing_opts && *p == '-') { + if (!strcmp(p, "--")) { + doing_opts = 0; + continue; + } + p++; + while (*p) { + switch (*p) { + case 'e': + decode = 0; + break; + case 'd': + decode = 1; + break; + case 'b': + outputmode = BINARY; + break; + case 'h': + outputmode = HEX; + break; + default: + return 1; + } + p++; + } + } else { + if (!inhex) { + inhex = p; + } else { + return 1; + } + } + } + + if (decode < 0) { + return 0; + } + + if (outputmode == DEFAULT) + outputmode = (decode ? BINARY : HEX); + + if (inhex) { + datalen = strlen(inhex) / 2; + data = hex2bin(inhex, datalen); + } else { + int datasize = 4096; + datalen = 0; + data = snewn(datasize, unsigned char); + while (1) { + int ret = fread(data + datalen, 1, datasize - datalen, stdin); + if (ret < 0) { + fprintf(stderr, "obfusc: read: %s\n", strerror(errno)); + return 1; + } else if (ret == 0) { + break; + } else { + datalen += ret; + if (datasize - datalen < 4096) { + datasize = datalen * 5 / 4 + 4096; + data = sresize(data, datasize, unsigned char); + } + } + } + } + + obfuscate_bitmap(data, datalen * 8, decode); + + if (outputmode == BINARY) { + int ret = fwrite(data, 1, datalen, stdout); + if (ret < 0) { + fprintf(stderr, "obfusc: write: %s\n", strerror(errno)); + return 1; + } + } else { + int i; + for (i = 0; i < datalen; i++) + printf("%02x", data[i]); + printf("\n"); + } + + return 0; +} |