Jean Labrosse (22.11.2005 14:18, просмотров: 1) ответил forger на Как-то делал из HEX шифрованный bin для бутзагрузчика на PIC18
I have written exactly the same (PIC18, 3DES-CBC), but in Perl. # hex2bin (stripped version w/o crypt)
use strict;
use integer;
my $inpfile = shift();
my $outfile = $inpfile;
$outfile =~ s/\.hex$/.bin/;
my $flash = "\xFF" x 0x7DC0;
open(INP, "< $inpfile") || die($!);
while(my $inpline = <INP>)
{
chomp($inpline);
$inpline = reverse($inpline);
chop($inpline);
$inpline = reverse($inpline);
my $binline = pack('H*', $inpline);
my $len = unpack('C', substr($binline, 0, 1));
my $addr = unpack('n', substr($binline, 1, 2));
my $type = unpack('C', substr($binline, 3, 1));
my $data = substr($binline, 4);
chop($data);
substr($flash, $addr, $len, $data) if $type == 0 && $addr < length($flash);
}
close(INP);
open(OUT, "> $outfile") || die($!);
binmode(OUT);
print(OUT $flash);
close(OUT);