/* UnHide v0.0.3 Ver.:OK (c) 06/09 - Ch Iossif */
/*
   Name:         UnHide
   Version:      0.0.3
   Author:       Ch Iossif <chiossif@yahoo.com>
   Date:         27/06/09 09:12
   Modified:     20090627104127-20090627110229 Coding finished in 21'02"
   Description:  UnHides an image from a BIP/BIL/BSQ much bigger image
   Usage:        $UnHide bigimage image image_size
   Compile line: $gcc -o UnHide UnHide.c

   Copyright (C) June 2009 Ch Iossif <chiossif@yahoo.com>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <stdio.h>
#include <stdlib.h>

void error(const char *);

int main(int argc, char *argv[]) {
    FILE *fp1, *fp2;
    int sint, filesize;
    register int i;

    if (argc!=4)
        error("Usage:\t$UnHide bigimage image");
    if ((fp1=fopen(argv[1],"rb"))==NULL)
        error("Bad filename 1");
    if ((fp2=fopen(argv[2],"wb"))==NULL)
        error("Bad filename 2");
    for (filesize=atoi(argv[3]);filesize>0;filesize--) {
        sint=0;
        for (i=0;i<8;i++) {
            sint<<=1;
            if (fgetc(fp1)&0x01)
                sint++;
        }
        if (fputc(sint,fp2)<0)
            error("Bad write");
    }

    fclose(fp2);
    fclose(fp1);
    fprintf(stderr,"UnHide v0.0.3 Ver.:OK -(C) June 2009 Ch Iossif <chiossif@yahoo.com> - GPLv3\n");
    return 0;
}

void error(const char *s) {
    printf("UnHide reports: Error: %s.\n",s);
    exit(1);
}

