unsteg.cAboutThis is a tool I wrote to solve a problem given during my GDV2 lecture. The task was to find the message hidden in a image. One option to hide an image in another one, a steganogram, is to hide the information in the LSB of a pixel. Usageunsteg image.bmp 2>outout.log This will rewrite the input file image.bmp (make a backup first), and some debug information are directed into output.log. Codeunsteg.c /* * ===================================================================================== * * Filename: unsteg.c * * Description: This tool decrypts the hidden image/message of uncompressed * bitmap files. This tool has been tested with an image given * by my GDV2 lecturer. * * Version: 1.0 * Created: 04/18/07 23:01:59 CEST * Revision: none * Compiler: gcc * * Author: Julian Knauer (JPK), jpk@goatpron.de * Company: * * ===================================================================================== */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(int argc, char *argv[]) { int fp, mod; char *fname; char *buf; int i, s = 0x36, x, r = 0; fp = open(argv[1], O_RDONLY); if (!fp) { fprintf(stderr, "Error opening file.\n"); return -1; } i = strlen(argv[1]); fname = (char *)malloc(sizeof(char) * i + 4); sprintf(fname, "%s.bmp", argv[1]); mod = open(fname, O_WRONLY|O_CREAT|0444); if (!mod) { fprintf(stderr, "Error opening output header file.\n"); exit(-1); } buf = (char *)malloc(sizeof(char) * 2048); while ((i = read(fp, buf, s)) > 0) { if (s == 0x36) { write(mod, buf, i); // dump header directly to output s = 2048; // resize read blocks } else { for (x = 0; x < i; x++) { // Some "fancy" output fprintf(stderr, "%4d -> %d", (int)buf[x], (int)(buf[x] & 1)); if (!(++r % 9)) fprintf(stderr, "\n"); else fprintf(stderr, " | "); buf[x] = buf[x] & 1; if (buf[x] != 0x00) // if LSB is set, buf[x] = 0xff; // than maximize value } write(mod, buf, i); // write may modified buffer to file } } free(buf); close(mod); close(fp); return 0; } |