$item = caschex(1, $item); #A->H if($debug == 1) { print "HEX: \"$item\"\n"; } $item = caschex(2, $item); #H->A if($debug == 1) { print "ASCII: \"$item\"\n"; } $item =~ s/^\s+//; #remove Leading whitespace $item =~ s/\s+$//; #remove trailing whitespace $item =~ s/\s+/ /g; #replace multiple spaces with one chomp($item); #remove newline character ######################################################## # Sub caschex # # USAGE: Removes hidden strings in variables.. Addition to Clean # # v1.0.0 -> 2006-04-20 # Born # ###### # my ($item) = cipdec(1, $ip); #1 = A->H, 2 = H->A ###### # sub caschex { # 1 = ASCII TO HEX # 2 = HEX TO ASCII ########## my $debug = 0; ########## if($debug == 1) { print "---------------------------------- ENTERED SUB: \"caschex\"\n"; } my $opt = undef; my $item = undef; my $ret = undef; my $val = undef; $opt = shift(@_); $item = shift(@_); if($debug == 1) { print "\n\n"; print "OPT: \"$opt\"\n"; print "ITEM: \"$item\"\n"; } ############################# OPT 1 if($opt == 1) { if($debug == 1) { print "CONVERT ASCII TO HEX\n"; } $key = undef; $val = undef; foreach $key (split//,$item) { if($debug == 1) { print "KEY: \"$key\"\n"; } ($key) = sprintf("%02lx", ord $key); if($debug == 1) { print "HEX KEY: \"$key\"\n"; } if(($key eq "00") || ($key eq "1b")) { if($debug == 1) { print "FOUND NULL IN ASCII VARIABLE... REPLACE WITH SPACE\n"; } $key = " "; #NOTE: A SPACE IN HEX IS "20" ($key) = sprintf("%02lx", ord $key); if($debug == 1) { print "HEX KEY: \"$key\"\n"; } } $val .= $key; if($debug == 1) { print "VAL: \"$val\"\n"; } } if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; } } ############################# EO OPT 1 ############################# OPT 2 if($opt == 2) { if($debug == 1) { print "CONVERT HEX TO ASCII\n"; } $key = undef; $val = undef; foreach $key ($item =~ /[a-fA-F0-9]{2}/g) { if($debug == 1) { print "HEX KEY: \"$key\"\n"; } if(($key eq "00") || ($key eq "1b")) { if($debug == 1) { print "FOUND NULL IN HEX.. REPLACE WITH SPACE\n"; } $key = 20; if($debug == 1) { print "HEX KEY: \"$key\"\n"; } } ($key) = chr(hex $key); if($debug == 1) { print "ASC KEY: \"$key\"\n"; } $val .= $key; if($debug == 1) { print "VAL: \"$val\"\n"; } } if($debug == 1) { print "COMPLETE VAL: \"$val\"\n"; } } ############################# EO OPT 2 $ret = $val; if($debug == 1) { print "RET: \"$ret\"\n"; } if($debug == 1) { print "---------------------------------- LEAVING SUB: \"caschex\"\n"; } $debug = 0; return($ret); } # # ############################################## EO SUB CASCHEX