n225-saved-pages/encode.py
Juhani Krekelä 4f22a2117a First commit
2024-12-04 19:44:14 +02:00

25 lines
659 B
Python

import struct
import sys
with open(sys.argv[1], 'rb') as f:
html = f.read()
unknown = 1
mimetype_trailer = '' # optional
url = 'about:blank' # required, will not open the page without
name = '' # optional
mimetype_trailer = mimetype_trailer.encode('utf-8')
url = url.encode('utf-8')
name = name.encode('utf-16-le')
mimetype_trailer_len = len(mimetype_trailer)
url_len = len(url)
name_len = len(name)
header_len = 20 + mimetype_trailer_len + url_len + name_len
header = struct.pack('<IIIII', header_len, unknown, mimetype_trailer_len, url_len, name_len) + mimetype_trailer + url + name
with open(sys.argv[2], 'wb') as f:
f.write(header)
f.write(html)