bin2c.pl
548 Bytes
#!/usr/bin/perl -w
die "Usage: bin2.pl <input binary file> <output file> <structure name>\n" unless $#ARGV==2;
$in = shift;
$out = shift;
$name = shift;
$idx=0;
open(INFILE, "<$in") or die "Can't open $in: $!";
binmode(INFILE);
open(OUTFILE, ">$out") or die "Can't open $out: $!";
printf OUTFILE "unsigned char %s[] = { \n", $name;
while( read(INFILE, $byte, 1) != 0 ) {
printf OUTFILE "0x%02x, ", vec($byte, 0, 8);
$idx++;
if ($idx%80==0) {
printf OUTFILE "\n";
}
}
printf OUTFILE "}; ";
close INFILE;
close OUTFILE;