TUCoPS :: Crypto :: apx.pl

AppendX Simple steganography in Perl

#!/usr/bin/perl -w
#####################################
# appendX 0.3
# Written by Michael Bauer <mihi@ch3cooh.org>
#####################################

use strict;
no strict 'refs';
use vars qw(%params %commands %options);	#params contains all parameters of 
			#the command-line and is Global.

%commands=(append=>'append',
   	   extract=>'extract',
           restore=>'restore',
	   help=>'help',
	   -a=>'append',
	   -e=>'extract',
	   -r=>'restore',
	   -h=>'help');


sub filesize{
	my @a=stat($_[0]);
	my $size=$a[7];
	return ($size);
	}

sub append{
	open (FILE, $params{infile}) or die $params{infile};
	binmode FILE;
	my ($bluff, $num, @buff);
	$num=500;
	while ($num==500){
		$num=read (FILE,$bluff,500);
		push @buff,$bluff;
		}
	close (FILE);
	open (FL, ">$params{outfile}")or die $params{outfile};
	binmode FL;
	
	print FL @buff;
	print STDERR "Your ... please:\n";
	my @text=<stdin>;
	if ($params{strip_pgp}) {@text=strippgp(@text);};
	print FL @text;
	close (FL);
	my $length=filesize($params{outfile})-filesize($params{infile});
	open (FL, ">>$params{outfile}");
	binmode FL;
	my $h=sprintf("%10x",$length);
	print FL $h;
	close (FL);
	}

sub sizeoftext {
	open (FILE,$_[0]) or die $_[0];
	binmode FILE;
	seek FILE,-10,2 or die "Seek";
	my ($he,$dd);
	if (10 !=read FILE, $he ,10) { die "read";};
	close (FILE);
	my @he=split '',$he;
	foreach (@he)  {
		if ($_ eq ' ') { $dd.='0'; }
		else {
			$dd.=sprintf("%x",hex($_));
			}
		}
	return hex($dd);
	}

sub extract {
	my $text;
	my $size=sizeoftext($params{infile});
	open (FILE, "$params{infile}");
	seek FILE,-10-$size,2;
	read FILE,$text,$size;
	if ($params{strip_pgp}) {print "-----BEGIN PGP MESSAGE-----\n";
		                 print "Version: apX 0.3\n";
		                 print "Comment: see http://unet.univie.ac.at/~a9900470\n";
             			 };
	print $text;
	if ($params{strip_pgp}) {
                		 print "-----END PGP MESSAGE-----\n";
				};
	close (FILE);
	}

sub help {
	print "appendX 0.3 \n";
	print "syntax apX [command] [option] [infile] [outfile]\n";
	print "Commands are: ";
        foreach (keys %commands) {print "$_ " if ($_ !~ /-/)};
        print "\n";
        
	print "Options:\n";
 	print "\t-s strips/adds the pgp header (can be combined with -e or -a)\n";
 	print "written by mihi, i don't care what you use it for\n";
 	print "ABSOLUTLY NO WARRANTIES OF WHAT THIS SKRIPT DOES OR DOESN'T\n";
}
sub restore {
	open (FL,">>$params{infile}");
 	binmode FL;
 	truncate FL, filesize($params{infile})-sizeoftext($params{infile})-10;
 	close FL;
 	} 

sub strippgp {
	my @ret; 
	foreach (@_){
		if (($_ !~ "-----")and ($_ !~ "omment:") and ($_!~ "ersion:")){
			push(@ret,$_);
		}
	}
	return @ret;
	}

# main
my ($op); 
if (!$ARGV[0]) {help; 
               exit;};
my $command=shift;
while ($op=shift){ #here the params are read in
	if ($op eq "-s" ){ $params{strip_pgp}=1; }
	elsif (!$params{infile}) {$params{infile}=$op}
	elsif (!$params{outfile}) {$params{outfile}=$op}
	elsif ($op eq "-h") {help; exit;}
	}


if ($commands{$command}) {
	if (((!$params{infile}) and ($commands{$command} ne 'help')) or ((!$params{outfile}) and ($commands{$command} eq 'append')) ) { print "Specify Infile or infile and outfile\n"; help; exit(0); }

	my $cmd=$commands{$command};
	&$cmd(%params);
}
else { print "Unknown command:$command\n"; }



TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2024 AOH