omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / qualification / om2 / oracle / sha / entry.py
| 1 | #!/usr/bin/python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # ORACLE-side harness transform (outside the delivered closure), L836 phaseB/sha-f5d14cb2. |
| 4 | # leakscan seeds its analysis only at word 0 (or the direct B there). The S4 multi-export artifact |
| 5 | # starts with E entry words `b <export k>` (NATIVE-ABI.md "Multi-entry code"; the binding enters |
| 6 | # export k at byte 4k). For export k this writes a copy whose word 0 is the B that word k encodes, |
| 7 | # re-based to byte 0 (imm26 + k), so the scanner starts exactly where the binding enters export k. |
| 8 | # Every other byte is unchanged. Usage: entry.py ARTIFACT K OUT |
| 9 | import struct |
| 10 | import sys |
| 11 | |
| 12 | art = bytearray(open(sys.argv[1], "rb").read()) |
| 13 | k = int(sys.argv[2]) |
| 14 | w = struct.unpack_from("<I", art, 4 * k)[0] |
| 15 | if w & 0xFC000000 != 0x14000000: |
| 16 | sys.exit(f"word {k} is not B: {w:#010x}") |
| 17 | imm = w & 0x03FFFFFF |
| 18 | imm = imm - (1 << 26) if imm & (1 << 25) else imm |
| 19 | tgt = 4 * k + 4 * imm |
| 20 | new = 0x14000000 | ((tgt // 4) & 0x03FFFFFF) |
| 21 | struct.pack_into("<I", art, 0, new) |
| 22 | open(sys.argv[3], "wb").write(art) |
| 23 | print(f"export {k}: word {k} = {w:#010x} -> target byte {tgt:#x}; word 0 = {new:#010x}") |