forked from samyk/samytools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp
executable file
·29 lines (22 loc) · 790 Bytes
/
exp
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
#!/usr/bin/perl
use strict;
use Term::ANSIColor;
my $B = 'bold blue';
my $B2 = 'bold white';
die colored("usage:", $B) . " $0 <code> <0 binary> <1 binary> [...]\n" .
colored("example:", $B) . " 101 1000 1110 (out: " . colored("1110", $B) . "1000" . colored("1110", $B) . ")\n" unless @ARGV >= 3;
my ($code, @elems) = @ARGV;
print "Length: " . length($code) . "\n";
my $i = 1;
my $ccode = $code;
$ccode =~ s/(.)/$elems[$1]/eg;
$code =~ s/(.)/colored($elems[$1], $i++ % 2 ? $B : $B2)/eg;
print "New length: " . length($ccode) . "\n";
print "New code:\n\n";
print $code . "\n";
$ccode = (("0" x (8 - (length($ccode) % 8))) . $ccode);
$ccode =~ s/^0{8}//;
$ccode = unpack("H*", pack("B*", $ccode));
my $i = 1;
$ccode =~ s/(..)/colored($1, $i++ % 2 ? $B : $B2)/eg;
print "0x$ccode\n\n";