import sys
def main():
try:
f = open(sys.argv[1],'rb')
except:
print "Usage: %s filename > var.h" %(sys.argv[0])
sys.exit(1)
x = f.read()
j = 0
filename = sys.argv[1].replace('.','_')
filename = filename.replace('\\','_')
sys.stdout.write("unsigned char __file[] = { \n\t")
for i in range(0,len(x)-1):
j+=1
t = "0x%02x," % ord(x[i])
sys.stdout.write(t)
if (j==16):
j=0
sys.stdout.write("\n\t")
t = "0x%02x" % ord(x[i])
sys.stdout.write(t)
sys.stdout.write("\n};")
f.close()
if __name__=='__main__':
main()
def main():
try:
f = open(sys.argv[1],'rb')
except:
print "Usage: %s filename > var.h" %(sys.argv[0])
sys.exit(1)
x = f.read()
j = 0
filename = sys.argv[1].replace('.','_')
filename = filename.replace('\\','_')
sys.stdout.write("unsigned char __file[] = { \n\t")
for i in range(0,len(x)-1):
j+=1
t = "0x%02x," % ord(x[i])
sys.stdout.write(t)
if (j==16):
j=0
sys.stdout.write("\n\t")
t = "0x%02x" % ord(x[i])
sys.stdout.write(t)
sys.stdout.write("\n};")
f.close()
if __name__=='__main__':
main()
2 комментария:
$columns = 16;
$file = $ARGV[0];
print "// " . $file . "\n";
open(IN, $file) or die "Can't open file: $!";
binmode(IN);
$bufname = $ARGV[1];
print "\nextern unsigned char " . $bufname . "[] = {\n";
$size = 0;
$column = 0;
while (!eof(IN))
{
++$size;
print ' ' unless $column;
printf "0x%02X,", ord(getc(IN));
$column = 0 if ++$column >= $columns;
print "\n" unless $column;
}
print "\n};\n\n";
print "extern unsigned $bufname" . "_size = $size;\n\n";
close(IN);
Короче и можно обрабатывать сразу несколько файлов :)
хэк +)
Отправить комментарий