1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
package STSupport;
require Exporter;
use File::Compare;
@ISA = qw(Exporter);
@EXPORT = qw(
DATADIR RND100
getArgString
startCategory endCategory startSubCategory endSubCategory addTestResult
runEmbExtCmp
);
#
# set this to 1 if you want the test script to print verbose output
#
$Arg_Verbosity = 0 ;
$curcategory = "";
$catstatus = 0 ;
$cursubcategory = "";
$subcatstatus = 0 ;
use constant DATADIR => "./data/" ;
use constant RND100 => "rnd100" ;
use constant TAB => " " ;
use constant STEGHIDE => "../src/steghide" ;
use constant DEFAULTSTGFN => "stgfile" ;
use constant DEFAULTEXTFN => "extfile" ;
use constant DEFEMBARGBASE => (command => "embed", f => "", "q" => "", p => "\"a passphrase\"", sf => DEFAULTSTGFN) ;
use constant DEFEXTARGBASE => (command => "extract", f => "", "q" => "", p => "\"a passphrase\"", sf => DEFAULTSTGFN, xf => DEFAULTEXTFN) ;
#
# parse arguments for a st_*.pl script
#
sub parseArgs {
while (@_) {
$ARGV = shift @_ ;
if ($ARGV eq "-v" || $ARGV eq "--verbose") {
$Arg_Verbosity = 1 ;
}
}
}
#
# create a string of arguments ready to be fed to steghide
# expects a hash containing a "command" => "something" and argument/argument value pairs
#
sub getArgString {
my %args = @_ ;
$retval = $args{command} ;
delete $args{command} ;
foreach $arg (keys %args) {
$retval .= " -$arg $args{$arg}" ;
}
return $retval ;
}
#
# start a category
# first argument: category name, rest of list: arguments for execution of this category script
#
sub startCategory {
$curcategory = shift @_ ;
parseArgs (@_) ;
print "$curcategory:\n" ;
$catstatus = 1 ;
}
#
#
# return value: 1 if an error occurred, 0 if everything was ok
sub endCategory {
$curcategory = "" ;
print "\n" ;
if ($catstatus) { # no error
return 0 ;
}
else { # an error occurred
return 1 ;
}
}
sub startSubCategory {
$cursubcategory = $_[0] ;
print TAB . $cursubcategory ;
$subcatstatus = 1 ;
}
sub endSubCategory {
$cursubcategory = "" ;
if ($subcatstatus) {
print "ok\n" ;
}
else {
print " !! FAILED !!\n" ;
}
}
sub addTestResult {
if ($_[0]) {
print ".";
}
else {
print "F";
$subcatstatus = 0 ;
$catstatus = 0 ;
}
}
#
# remove all files in the list passed to it
sub remove {
while (@_) {
$f = shift @_ ;
system "rm -f $f" ;
}
}
#
# run an embed-extract-compare test
# expects 1-4 arguments: cvrfn, embfn, callerembargs, callerextargs
sub runEmbExtCmp {
if ($Arg_Verbosity) {
print "\n\nrunning EmbExtCmp with...\n" ;
}
# evaluate arguments
$cvrfn = shift @_ ;
$embfn = DATADIR . RND100 ; # default
if (@_) { $embfn = shift @_ ; }
%callerembargs = () ;
if (@_) {
$ref = shift @_ ;
%callerembargs = %$ref ;
}
%callerextargs = () ;
if (@_) {
$ref = shift @_ ;
%callerextargs = %$ref ;
}
# prepare embedding
%embargs = (
DEFEMBARGBASE,
cf => $cvrfn,
ef => $embfn,
%callerembargs
) ;
$embcommand = STEGHIDE . " " . getArgString(%embargs) ;
# prepare extracting
%extargs = (
DEFEXTARGBASE,
%callerextargs
) ;
$extcommand = STEGHIDE . " " . getArgString(%extargs) ;
if ($Arg_Verbosity) {
print "embcommand: $embcommand\n" ;
print "extcommand: $extcommand\n" ;
}
# execute commands
`$embcommand 2>&1` ; # don't let it print to stderr or stdout
return 0 if $? ;
`$extcommand 2>&1` ; # don't let it print to stderr or stdout
return 0 if $? ;
# compare embfile and extfile
$filesequal = not compare ($embargs{ef}, $extargs{xf}) ;
remove ($embargs{sf}, $extargs{xf}) ;
return $filesequal ;
}
1;
|