45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import hashlib
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
PURE = os.path.join(HERE, "upstream", "pure")
|
|
CAP = os.path.join(HERE, "captures")
|
|
os.makedirs(CAP, exist_ok=True)
|
|
|
|
SPEC = ",".join(["G:511:0x137"] * 14 + ["G:400:0x137", "G:511:0x137", "X:900"])
|
|
|
|
targets = {}
|
|
|
|
a1 = os.path.join(CAP, "up_a1.bin")
|
|
subprocess.run([sys.executable, os.path.join(PURE, "mk_a1.py"),
|
|
"--out", a1, "--big", "78"], check=True, stdout=subprocess.DEVNULL)
|
|
targets["a1"] = a1
|
|
|
|
a2 = os.path.join(CAP, "up_a2.bin")
|
|
sys.path.insert(0, PURE)
|
|
import cheap_oom_a # noqa: E402
|
|
|
|
body = cheap_oom_a.build_body(880, 64, 115, b"a" * 32, b"k0", b"C" * 10)
|
|
open(a2, "wb").write(body)
|
|
targets["a2"] = a2
|
|
|
|
b1 = os.path.join(CAP, "up_b1.bin")
|
|
subprocess.run([sys.executable, os.path.join(PURE, "mk_leak_b.py"),
|
|
"--out", b1, "--spec", SPEC, "--fake-len", "0xC8000", "--tag"],
|
|
check=True, stdout=subprocess.DEVNULL)
|
|
targets["b1"] = b1
|
|
|
|
golden = {}
|
|
for key, path in targets.items():
|
|
data = open(path, "rb").read()
|
|
golden[key] = hashlib.sha256(data).hexdigest()
|
|
print("%s bytes=%d sha256=%s" % (key, len(data), golden[key]))
|
|
|
|
out = os.path.join(HERE, "..", "tests", "golden", "bodies.json")
|
|
os.makedirs(os.path.dirname(out), exist_ok=True)
|
|
json.dump(golden, open(out, "w"), indent=2)
|
|
print("wrote", os.path.abspath(out))
|