Download | Plain Text | No Line Numbers
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include "global.h"
-
- typedef enum
- {
- NONE,
- FIND,
- HIDE
- } stegit_mode_t;
-
- static void sighandler(int signum)
- {
- #ifdef DEBUG
- #endif
- error = 1;
- }
-
- static void usage(void)
- {
- }
-
- static void hide(FILE *in, FILE *out)
- {
- int ch;
- char *word;
- int insertdot, wordcount = 0;
-
- insertdot = 5 + (int)(11.0 * (random() / (RAND_MAX + 1.0)));
- {
- if (ch < 0 || ch >= (sizeof(charmap) / sizeof(charmap[0])))
- continue;
-
- word = charmap[ch];
- if (word == NULL)
- continue;
-
- {
- (void) printferr("Error while writing to output");
- return;
- }
-
- {
- (void) printferr("Error while writing to output");
- return;
- }
-
- ++wordcount;
-
- if (insertdot <= wordcount)
- {
- {
- (void) printferr("Error while writing to output");
- return;
- }
- insertdot = wordcount + 5 + (int)(11.0 * (random() / (RAND_MAX + 1.0)));
- }
- }
-
- {
- (void) printferr("Error while writing to output");
- return;
- }
- }
-
- static char lookup(char *str)
- {
- int i;
- char *str2;
-
- for(i = 0; !error && i < sizeof(charmap) / sizeof(charmap[0]); ++i)
- {
- str2 = charmap[i];
- if (str2 == NULL)
- continue;
- return i;
- }
- return -1;
- }
-
- static void find(FILE *in, FILE *out)
- {
- char buf[80]; /* increase that for more speed */
- size_t bufsize = sizeof(buf) / sizeof(buf[0]);
- size_t read, off = 0;
- char ch, *sep = " .\r\n", *word, *brkt;
- int wordcount = 0;
-
- buf[0] = '\0';
- {
- if (off >= bufsize - 1)
- {
- errno = 0;
- (void) printferr("Unable to read input words. buffer is too small.");
- return;
- }
-
- {
- (void) printferr("Error while reading from output");
- return;
- }
- buf[read + off] = '\0';
-
- for(word = strtok_r(buf, sep, &brkt);
- !error && word;
- word = strtok_r(NULL, sep, &brkt))
- {
- ch = lookup(word);
- if (ch >= 0)
- {
- {
- (void) printferr("Error while writing to output");
- return;
- }
-
- ++wordcount;
- buf[0] = '\0';
- continue;
- }
-
- if (brkt == NULL)
- }
-
- if (read < bufsize - off - 1 || read == 0)
- break;
- }
-
- {
- (void) printferr("Error while writing to output");
- return;
- }
- }
-
- int main(int argc, char *argv[])
- {
- int opt;
- char *outfile = NULL;
- FILE *fp = NULL;
- struct sigaction new_action, old_action;
- stegit_mode_t mode = NONE;
-
- me = argv[0];
-
- /* install signal handler */
- new_action.sa_handler = sighandler;
- sigemptyset(&new_action.sa_mask);
- new_action.sa_flags = 0; /* to avoid restart of blocking syscalls */
- INSTALL_SIGNAL(SIGINT, new_action, old_action)
- INSTALL_SIGNAL(SIGQUIT, new_action, old_action)
- INSTALL_SIGNAL(SIGTERM, new_action, old_action)
-
- while ((opt = getopt(argc, argv, "fho:")) != -1)
- {
- switch(opt)
- {
- case 'f':
- if (mode != NONE)
- (void) usage();
- mode = FIND;
- break;
- case 'h':
- if (mode != NONE)
- (void) usage();
- mode = HIDE;
- break;
- case 'o':
- outfile = optarg;
- break;
- default:
- (void) usage();
- break;
- }
- }
-
- if (mode == NONE || (mode == FIND && outfile != NULL))
- (void) usage();
-
- #ifdef DEBUG
- #endif
-
- if (mode == HIDE)
- {
- (void) bailout("%s", outfile);
- if (!error)
- (void) hide(stdin, (fp != NULL) ? fp : stdout);
- }
- else
- {
- if (!error)
- (void) find(stdin, stdout);
- }
-
- if (fp != NULL)
-
- return (error) ? 1 : 0;
- }
-