2 * Stand-alone tool to access the Puzzles obfuscation algorithm.
4 * To deobfuscate, use "obfusc -d":
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
10 * To obfuscate, "obfusc -e":
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
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
21 * Data read from standard input is assumed always to be binary;
22 * data provided on the command line is taken to be hex.
33 int main(int argc
, char **argv
)
35 enum { BINARY
, DEFAULT
, HEX
} outputmode
= DEFAULT
;
40 int doing_opts
= TRUE
;
45 if (doing_opts
&& *p
== '-') {
46 if (!strcmp(p
, "--")) {
66 fprintf(stderr
, "obfusc: unrecognised option '-%c'\n",
76 fprintf(stderr
, "obfusc: expected at most one argument\n");
83 fprintf(stderr
, "usage: obfusc < -e | -d > [ -b | -h ] [hex data]\n");
87 if (outputmode
== DEFAULT
)
88 outputmode
= (decode
? BINARY
: HEX
);
91 datalen
= strlen(inhex
) / 2;
92 data
= hex2bin(inhex
, datalen
);
96 data
= snewn(datasize
, unsigned char);
98 int ret
= fread(data
+ datalen
, 1, datasize
- datalen
, stdin
);
100 fprintf(stderr
, "obfusc: read: %s\n", strerror(errno
));
102 } else if (ret
== 0) {
106 if (datasize
- datalen
< 4096) {
107 datasize
= datalen
* 5 / 4 + 4096;
108 data
= sresize(data
, datasize
, unsigned char);
114 obfuscate_bitmap(data
, datalen
* 8, decode
);
116 if (outputmode
== BINARY
) {
117 int ret
= fwrite(data
, 1, datalen
, stdout
);
119 fprintf(stderr
, "obfusc: write: %s\n", strerror(errno
));
124 for (i
= 0; i
< datalen
; i
++)
125 printf("%02x", data
[i
]);