forked from arti/vt1200
Isolated-netns test setup (a private tap-mess-0-0 so a second MAME can run without holding the owner's tap), the one-file/one-index TFTP servers, the trace/probe run wrappers, and the two server logs quoted in FONT_STORAGE_REPORT.md.
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""fontwork index-then-font server.
|
|
|
|
Serves a small (<512-byte, one-block) directory index for the font path, which
|
|
names 'evil.pcf', and serves the crafted font for that name. This isolates the
|
|
font fetch from the one-block index fetch so we can see whether a completed
|
|
multi-block font transfer parses.
|
|
|
|
python3 custom_serve3.py [bind-ip] [index-name]
|
|
"""
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
ROOT = "/home/arti/code/k-space/vt1200"
|
|
sys.path.insert(0, os.path.join(ROOT, "tools"))
|
|
import fontgen # noqa: E402
|
|
|
|
host = sys.argv[1] if len(sys.argv) > 1 else "192.168.99.1"
|
|
index_name = sys.argv[2] if len(sys.argv) > 2 else "evil.pcf"
|
|
with open(os.path.join(ROOT, "reference/fonts/evil-real.pcf"), "rb") as fh:
|
|
evil = fh.read()
|
|
index = (index_name + "\n").encode()
|
|
print(f"index={index!r} ({len(index)} bytes); font {index_name} = {len(evil)} bytes", flush=True)
|
|
|
|
|
|
def resolve(name):
|
|
if name == "69" or name.endswith("fonts.dir") or name.endswith("/"):
|
|
return index
|
|
if index_name in name or "evil" in name:
|
|
return evil
|
|
return index
|
|
|
|
|
|
srv = fontgen.TFTPServer((host, 69), {}, timeout=60.0, retries=10,
|
|
resolver=resolve).start()
|
|
try:
|
|
while True:
|
|
time.sleep(0.5)
|
|
while srv.log:
|
|
ts, name, addr = srv.log.pop(0)
|
|
stamp = time.strftime("%H:%M:%S", time.localtime(ts))
|
|
print(f"{stamp} {addr[0]}:{addr[1]} requested {name!r}", flush=True)
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
srv.stop()
|