custom_ascii2bin.pl (590B)
1 my $in = $ARGV[0]; 2 my $out = $ARGV[1]; 3 4 my $str_hex; 5 my $str_ascii; 6 my $num; 7 my $num2; 8 open(my $F, "<", "$in") or die "can't open in file"; 9 open(my $FF, ">:raw", "$out") or die "can't open out file"; 10 LOOP: while($str_ascii = <$F>) { 11 next LOOP if(($str_ascii =~ m/^#/) || ($str_ascii =~ m/^\s*$/)); # Discard comments or white lines 12 $str_ascii =~ m/0x(.*)/; 13 $num = $1; 14 $num2=join("",(split(//,$num))[6,7,4,5,2,3,0,1]); 15 print $num2; 16 print $FF pack('H8',$num2); 17 } 18 print "\n"; 19 close($F); 20 21 close($FF);