TOOLS/fil2string.py: fix for use with binary files

The script was written to be able to deal with binary files, but it had
a bug corrupting some data: e.g. a byte sequence 0x1 0x37 was printed as
"\17" (0x1 = escaped as "\1", and 0x37 = kept as literal "7"), which
would be interpreted as single character 0xF.

Always pad octal literals to length 3, which makes the escape sequences
unambiguous.
This commit is contained in:
wm4 2012-07-28 23:02:52 +02:00
parent 85a3a0d5bc
commit 1ee740cceb
1 changed files with 1 additions and 1 deletions

View File

@ -8,7 +8,7 @@
import sys
def main(infile):
conv = ['\\' + oct(c)[2:] for c in range(256)]
conv = ['\\' + ("%03o" % c) for c in range(256)]
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
"0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ "
for c in safe_chars: