New issue
Advanced search Search tips

Issue 77 attachment: file_to_jsstr.py (452 bytes)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys

def print_ln(bytes, out):
ln = 'payload += "'
for b in bytes:
ln += "\\x%02x" % ord(b);
out.write(ln + '";')

bytes = open(sys.argv[1]).read()
out = open(sys.argv[2], 'w')

out.write("payload_len = %d;\n" % len(bytes))
out.write("payload = '';\n")

while len(bytes) > 16:
print_ln(bytes[:16], out)
bytes = bytes[16:]
if len(bytes) == 0:
out.write(';')
else:
out.write('\n');

if len(bytes):
print_ln(bytes, out)