diff options
author | Franklin Wei <frankhwei536@gmail.com> | 2016-11-20 15:16:41 -0500 |
---|---|---|
committer | Franklin Wei <me@fwei.tk> | 2016-12-18 18:13:22 +0100 |
commit | 1a6a8b52f7aa4e2da6f4c34a0c743c760b8cfd99 (patch) | |
tree | 8e7f2d6b0cbdb5d15c13457b2c3e1de69f598440 /apps/plugins/puzzles/obfusc.c | |
parent | 3ee79724f6fb033d50e26ef37b33d3f8cedf0c5b (diff) | |
download | rockbox-1a6a8b52f7aa4e2da6f4c34a0c743c760b8cfd99.tar.gz rockbox-1a6a8b52f7aa4e2da6f4c34a0c743c760b8cfd99.zip |
Port of Simon Tatham's Puzzle Collection
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.
Currently builds one plugin per puzzle (about 40 in total, around 100K
each on ARM), but can easily be made to build a single monolithic
overlay (800K or so on ARM).
The following games are at least partially broken for various reasons,
and have been disabled on this commit:
Cube: failed assertion with "Icosahedron" setting
Keen: input issues
Mines: weird stuff happens on target
Palisade: input issues
Solo: input issues, occasional crash on target
Towers: input issues
Undead: input issues
Unequal: input and drawing issues (concave polys)
Untangle: input issues
Features left to do:
- In-game help system
- Figure out the weird bugs
Change-Id: I7c69b6860ab115f973c8d76799502e9bb3d52368
Diffstat (limited to 'apps/plugins/puzzles/obfusc.c')
-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 0000000000..e95fa3f397 --- /dev/null +++ b/apps/plugins/puzzles/obfusc.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * Stand-alone tool to access the Puzzles obfuscation algorithm. | ||
3 | * | ||
4 | * To deobfuscate, use "obfusc -d": | ||
5 | * | ||
6 | * obfusc -d reads binary data from stdin, writes to stdout | ||
7 | * obfusc -d <hex string> works on the given hex string instead of stdin | ||
8 | * obfusc -d -h writes a hex string instead of binary to stdout | ||
9 | * | ||
10 | * To obfuscate, "obfusc -e": | ||
11 | * | ||
12 | * obfusc -e reads binary from stdin, writes hex to stdout | ||
13 | * obfusc -e <hex string> works on the given hex string instead of stdin | ||
14 | * obfusc -e -b writes binary instead of text to stdout | ||
15 | * | ||
16 | * The default output format is hex for -e and binary for -d | ||
17 | * because that's the way obfuscation is generally used in | ||
18 | * Puzzles. Either of -b and -h can always be specified to set it | ||
19 | * explicitly. | ||
20 | * | ||
21 | * Data read from standard input is assumed always to be binary; | ||
22 | * data provided on the command line is taken to be hex. | ||
23 | */ | ||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <stdarg.h> | ||
28 | #include <string.h> | ||
29 | #include <errno.h> | ||
30 | |||
31 | #include "puzzles.h" | ||
32 | |||
33 | int main(int argc, char **argv) | ||
34 | { | ||
35 | enum { BINARY, DEFAULT, HEX } outputmode = DEFAULT; | ||
36 | char *inhex = NULL; | ||
37 | unsigned char *data; | ||
38 | int datalen; | ||
39 | int decode = -1; | ||
40 | int doing_opts = TRUE; | ||
41 | |||
42 | while (--argc > 0) { | ||
43 | char *p = *++argv; | ||
44 | |||
45 | if (doing_opts && *p == '-') { | ||
46 | if (!strcmp(p, "--")) { | ||
47 | doing_opts = 0; | ||
48 | continue; | ||
49 | } | ||
50 | p++; | ||
51 | while (*p) { | ||
52 | switch (*p) { | ||
53 | case 'e': | ||
54 | decode = 0; | ||
55 | break; | ||
56 | case 'd': | ||
57 | decode = 1; | ||
58 | break; | ||
59 | case 'b': | ||
60 | outputmode = BINARY; | ||
61 | break; | ||
62 | case 'h': | ||
63 | outputmode = HEX; | ||
64 | break; | ||
65 | default: | ||
66 | return 1; | ||
67 | } | ||
68 | p++; | ||
69 | } | ||
70 | } else { | ||
71 | if (!inhex) { | ||
72 | inhex = p; | ||
73 | } else { | ||
74 | return 1; | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | |||
79 | if (decode < 0) { | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | if (outputmode == DEFAULT) | ||
84 | outputmode = (decode ? BINARY : HEX); | ||
85 | |||
86 | if (inhex) { | ||
87 | datalen = strlen(inhex) / 2; | ||
88 | data = hex2bin(inhex, datalen); | ||
89 | } else { | ||
90 | int datasize = 4096; | ||
91 | datalen = 0; | ||
92 | data = snewn(datasize, unsigned char); | ||
93 | while (1) { | ||
94 | int ret = fread(data + datalen, 1, datasize - datalen, stdin); | ||
95 | if (ret < 0) { | ||
96 | fprintf(stderr, "obfusc: read: %s\n", strerror(errno)); | ||
97 | return 1; | ||
98 | } else if (ret == 0) { | ||
99 | break; | ||
100 | } else { | ||
101 | datalen += ret; | ||
102 | if (datasize - datalen < 4096) { | ||
103 | datasize = datalen * 5 / 4 + 4096; | ||
104 | data = sresize(data, datasize, unsigned char); | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | obfuscate_bitmap(data, datalen * 8, decode); | ||
111 | |||
112 | if (outputmode == BINARY) { | ||
113 | int ret = fwrite(data, 1, datalen, stdout); | ||
114 | if (ret < 0) { | ||
115 | fprintf(stderr, "obfusc: write: %s\n", strerror(errno)); | ||
116 | return 1; | ||
117 | } | ||
118 | } else { | ||
119 | int i; | ||
120 | for (i = 0; i < datalen; i++) | ||
121 | printf("%02x", data[i]); | ||
122 | printf("\n"); | ||
123 | } | ||
124 | |||
125 | return 0; | ||
126 | } | ||