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 / security673 / relational / patchword.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Exact-once aligned u32 replacement in raw compiler output or full ELF, no instruction hiding. |
| 3 | text err "REFUSED patch: usage, size, word range or occurrence count\n" |
| 4 | global buf uchar 1048576 |
| 5 | global arg uchar 32 |
| 6 | fn number k ulong to ulong |
| 7 | n = argread k arg 0 32 |
| 8 | if or le n 0 gt n 10 |
| 9 | exit 90 |
| 10 | end |
| 11 | v = ulong 0 |
| 12 | for i ulong ulong n |
| 13 | c = get arg i |
| 14 | if or lt c 48 gt c 57 |
| 15 | exit 90 |
| 16 | end |
| 17 | v = add mul v 10 ulong sub c 48 |
| 18 | end |
| 19 | if gt v 4294967295 |
| 20 | exit 90 |
| 21 | end |
| 22 | ret v |
| 23 | end |
| 24 | fn word p ulong to ulong |
| 25 | v = ulong 0 |
| 26 | for k ulong 4 |
| 27 | v = or v shl ulong get buf add p k mul k 8 |
| 28 | end |
| 29 | ret v |
| 30 | end |
| 31 | fn main to int |
| 32 | if ne argcnt 3 |
| 33 | ret 90 |
| 34 | end |
| 35 | old = number 1 |
| 36 | fresh = number 2 |
| 37 | n = ulong 0 |
| 38 | while lt n len buf bound 100000 |
| 39 | r = read 0 buf n sub len buf n |
| 40 | if lt r 0 |
| 41 | ret 91 |
| 42 | end |
| 43 | if eq r 0 |
| 44 | break |
| 45 | end |
| 46 | n = add n ulong r |
| 47 | end |
| 48 | if or eq n len buf ne rem n 4 0 |
| 49 | ret 92 |
| 50 | end |
| 51 | hits = ulong 0 |
| 52 | at = ulong 0 |
| 53 | for i ulong div n 4 |
| 54 | if eq word mul i 4 old |
| 55 | hits = add hits 1 |
| 56 | at = mul i 4 |
| 57 | end |
| 58 | end |
| 59 | if ne hits 1 |
| 60 | r = write 2 err 0 len err |
| 61 | ret 93 |
| 62 | end |
| 63 | for k ulong 4 |
| 64 | put buf add at k uchar and shr fresh mul k 8 255 |
| 65 | end |
| 66 | at = 0 |
| 67 | while lt at n bound 100000 |
| 68 | r = write 1 buf at sub n at |
| 69 | if le r 0 |
| 70 | ret 94 |
| 71 | end |
| 72 | at = add at ulong r |
| 73 | end |
| 74 | ret 0 |
| 75 | end |