home *** CD-ROM | disk | FTP | other *** search
- /*
- * eexec.c -- decrypt an Adobe font file encrypted for eexec
- *
- * Chris B. Sears
- */
- #include <stdio.h>
- #include <strings.h>
-
- #define TRUE 1
- #define FALSE 0
-
- #define EEXEC_SKIP_BYTES 4
-
- unsigned short int er = 55665;
- unsigned short int ec1 = 52845;
- unsigned short int ec2 = 22719;
-
- unsigned char
- DeCrypt(ch1, ch2)
- unsigned char ch1, ch2;
- {
- unsigned char plain, cipher;
-
- /*
- * Decode hex.
- */
- if ('A' <= ch1 && ch1 <= 'F')
- ch1 -= 'A' - 10;
- else if ('a' <= ch1 && ch1 <= 'f')
- ch1 -= 'a' - 10;
- else
- ch1 -= '0';
-
- if ('A' <= ch2 && ch2 <= 'F')
- ch2 -= 'A' - 10;
- else if ('a' <= ch2 && ch2 <= 'f')
- ch2 -= 'a' - 10;
- else
- ch2 -= '0';
-
- /*
- * Decode cipher.
- */
- cipher = ch1 * 16 + ch2;
-
- plain = (cipher ^ (er >> 8));
- er = (cipher + er) * ec1 + ec2;
-
- return plain;
- }
-
- void
- main(argc, argv)
- int argc;
- char **argv;
- {
- FILE *in;
- char in_buff[BUFSIZ], out_buff[BUFSIZ];
- int i, o, in_size;
- int skip_salt = TRUE;
-
- if (argc != 2) {
- fprintf(stderr, "Usage: %s input\n", argv[0]);
- exit(0);
- }
-
- if ((in = fopen(argv[1], "r")) == NULL) {
- fprintf(stderr, "%s: can't open %s\n", argv[0], argv[1]);
- exit(0);
- }
-
- /*
- * Just copy to output until we see an eexec.
- */
- while (fgets(in_buff, BUFSIZ, in) != NULL) {
- if (strcmp(in_buff, "currentfile eexec\n") == 0)
- break;
- fprintf(stdout, "%s", in_buff);
- }
-
- for (;;) {
- if (fgets(in_buff, BUFSIZ, in) == NULL)
- break;
- in_size = strlen(in_buff) - 1;
-
- /*
- * Decrypt a line of hex.
- */
- for (i = o = 0; i < in_size; i += 2)
- out_buff[o++] = DeCrypt(in_buff[i], in_buff[i + 1]);
-
- /*
- * Skip the salt if this is the first cypher line.
- */
- if (skip_salt) {
- fwrite(out_buff + EEXEC_SKIP_BYTES, o - EEXEC_SKIP_BYTES, 1, stdout);
- skip_salt = FALSE;
- } else
- fwrite(out_buff, o, 1, stdout);
- }
-
- fclose(in);
-
- exit(0);
- }
-