| 1 | #!/usr/bin/perl | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 4 | ▶ | use Crypt::Rijndael; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | ▶ | use Digest::SHA qw( sha1_hex ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 4 | my $blocksize = 16; | |||||||||||
| 11 | 4 | my $headersize = 6; | |||||||||||
| 12 | 4 | my $fingerprint = pack( 'C*', 0x5b, 0xaa, 0xdd, 0x6d, 0xbb, 0x99 ); | |||||||||||
| 13 | |||||||||||||
| 14 | 4 | my $cipher = Crypt::Rijndael->new( | |||||||||||
| 15 | pack( 'C*', 0xed, 0xca, 0x6d, 0x42, 0x42, 0x54, 0x2f, 0x92, 0x61, 0x4d, 0x3c, 0x54, 0x4d, 0x80, 0xa3, 0x5e, 0x12, 0xec, 0x5e, 0x5a, 0x9a, 0x93, 0x31, 0x56, 0x5e, 0x56, 0x7b, 0x37, 0xed, 0x06, 0x57, 0x4e ), | ||||||||||||
| 16 | Crypt::Rijndael::MODE_CBC() | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | 4 | my $module_name = 'Filter::Rijndael'; | |||||||||||
| 19 | |||||||||||||
| 20 | 4 | ▶ | die sprintf( "Usage: $0 <file>\n" ) if( ! scalar( @ARGV ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | |||||||||||||
| 22 | 4 | my $infile = $ARGV[0]; | |||||||||||
| 23 | 4 | ▶ | my $outfile = $ARGV[1] // sprintf( '%s.pe', $infile ); | ||||||||||
|
Condition50%1/2
$ARGV[1] // sprintf('%s.pe', $infile)
MC/DC0%0/1
$ARGV[1] // sprintf('%s.pe', $infile)
$ARGV[1]
Truth table50%1/2
A
A= $ARGV[1]
| |||||||||||||
| 24 | |||||||||||||
| 25 | 4 | ▶ | if ( ! -T $infile ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 2 | ▶ | print "Skipping directory $infile\n" if( -d $infile ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 2 | ▶ | print "Skipping non-text $infile\n" if( ! -d $infile ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 2 | exit; | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 2 | my $module = "use $module_name;\n"; | |||||||||||
| 32 | # Encrypt the file | ||||||||||||
| 33 | { | ||||||||||||
| 34 | 2 | ▶ | open( my $read_fh, '<', $infile ) || die sprintf( "Cannot open %s: %s\n", $infile, $! ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 2 | ▶ | open( my $write_fh, '>', $outfile ) || die sprintf( "Cannot open %s: %s\n", $outfile, $! ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | 2 | binmode $write_fh; | |||||||||||
| 37 | |||||||||||||
| 38 | # Check for "#!perl" line | ||||||||||||
| 39 | 2 | my $line = <$read_fh>; | |||||||||||
| 40 | |||||||||||||
| 41 | 2 | ▶ | if( $line =~ /^#!/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 2 | print $write_fh $line; | |||||||||||
| 43 | } else { | ||||||||||||
| 44 | 0 | seek( $read_fh, 0, 0 ); | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 2 | print $write_fh $module; | |||||||||||
| 48 | 2 | print $write_fh $fingerprint; | |||||||||||
| 49 | |||||||||||||
| 50 | 2 | my $block = ''; | |||||||||||
| 51 | 2 | ▶ | while ( my $size = read( $read_fh, $block, $blocksize ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | # If data is not multiple of $blocksize ( 16 ) add "\n" | ||||||||||||
| 53 | 4108 | ▶ | while( $size % $blocksize ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | 17 | $block .= "\n"; | |||||||||||
| 55 | 17 | $size++; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 4108 | print $write_fh $cipher->encrypt( $block ); | |||||||||||
| 59 | } | ||||||||||||
| 60 | 2 | close $write_fh; | |||||||||||
| 61 | 2 | close $read_fh; | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | { | ||||||||||||
| 65 | 2 | undef $/; | |||||||||||
| 66 | 2 | ▶ | open( my $read_fh, '<', $outfile ) || die "Cannot open $outfile: $!\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 2 | binmode $read_fh; | |||||||||||
| 68 | 2 | my $file_contents = <$read_fh>; | |||||||||||
| 69 | 2 | close( $read_fh ); | |||||||||||
| 70 | |||||||||||||
| 71 | 2 | my $cksum = Digest::SHA::sha1_hex( substr( $file_contents, index( $file_contents, $module ) + length( $module ) + length( $fingerprint ) ) ); | |||||||||||
| 72 | 2 | substr( $file_contents, index( $file_contents, $module ) + length( $module ) + length( $fingerprint ), 0 ) = join('', map { chr( hex($_) ) } unpack( '(A2)*', $cksum ) ); | |||||||||||
| 73 | |||||||||||||
| 74 | 2 | ▶ | open( my $write_fh, '>', $outfile ) || die "Cannot open $outfile: $!\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | 2 | binmode $write_fh; | |||||||||||
| 76 | 2 | print $write_fh $file_contents; | |||||||||||
| 77 | 2 | close( $write_fh ); | |||||||||||
| 78 | } | ||||||||||||