code wiki / _hdl_build / nx_ch_census_race_stage2.nx
nx_ch_census_race_stage2.nx source
↩ module page · 75 lines · 3079 B
1// nx_ch_census_race_stage2.nx -- race stager v2: the CH DECOMPOSITION step is now the TEAM's.
2// v1 hand-walked the ClientHello structure (Claude logic); v2 calls the STRUCT_WALK-authored
3// _pe_chwalk_locate (emit8, zero Claude logic) on the same real emitted CH and stages the same
4// three race inputs. Exit 0 iff locate succeeds with a non-empty block -- run after the emit89
5// demo has authored _pe_chwalk. license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_csprng.nx"
8import "nx_tls13_client_session.nx"
9import "_hdl_build/_pe_chwalk.nx"
10const K_MAGIC_1024: i64 = 1024
11
12func s2_dec(label0: i64, label1: i64, v: i64) -> i64 {
13 let lab: *u8 = sys_mmap(8)
14 lab[0] = label0 as u8; lab[1] = label1 as u8; lab[2] = 0x3D
15 sys_write(1, lab, 3)
16 var av: i64 = v
17 if av < 0 {
18 let neg: *u8 = sys_mmap(8); neg[0] = 0x2D; sys_write(1, neg, 1)
19 av = 0 - av
20 }
21 if av == 0 {
22 let z: *u8 = sys_mmap(8); z[0] = 0x30; sys_write(1, z, 1)
23 }
24 if av > 0 {
25 let buf: *u8 = sys_mmap(32)
26 var pos: i64 = 0
27 var x: i64 = av
28 while x > 0 { buf[pos] = (0x30 + (x % 10)) as u8; x = x / 10; pos = pos + 1 }
29 let out: *u8 = sys_mmap(32)
30 var oi: i64 = 0
31 while oi < pos { out[oi] = buf[pos - 1 - oi]; oi = oi + 1 }
32 sys_write(1, out, pos)
33 }
34 let nl: *u8 = sys_mmap(8); nl[0] = 0x0A; sys_write(1, nl, 1)
35 return 0
36}
37
38func s2_write_file(path: *u8, b: *u8, n: i64) -> i64 {
39 let fd: i64 = sys_openat_wr(path, 0x1a4)
40 if fd < 0 { return 0 - 1 }
41 if n > 0 { sys_write(fd, b, n) }
42 sys_close(fd)
43 return 0
44}
45
46func main() -> i64 {
47 let host: *u8 = "example.com\x00"
48 let cr: *u8 = sys_mmap(32)
49 let priv: *u8 = sys_mmap(32)
50 var i: i64 = 0
51 nx_csprng_fill(cr, 32); nx_csprng_fill(priv, 32) // CWE-330 (debt 1785970852): were the constants 0xC0../0xA0.. on EVERY session
52 let s: *Tls13ClientSession = nx_tls13_client_session_new(cr, priv)
53 let ch: *u8 = sys_mmap(K_MAGIC_1024)
54 let ch_n: i64 = nx_tls13_client_session_emit_ch(s, host, 11, ch, K_MAGIC_1024)
55 s2_dec(0x43, 0x48, ch_n) // CH=
56
57 // the TEAM's locate (STRUCT_WALK-authored, zero Claude logic)
58 let out: *i64 = sys_mmap(32) as *i64
59 let lv: i64 = _pe_chwalk_locate(ch, ch_n, out)
60 s2_dec(0x4C, 0x56, lv) // LV=
61 if lv != 0 { return 1 }
62 let boff: i64 = out[0]
63 let blen: i64 = out[1]
64 s2_dec(0x42, 0x4F, boff) // BO=
65 s2_dec(0x45, 0x4C, blen) // EL=
66 if blen < 1 { return 2 }
67
68 if s2_write_file("/tmp/race_block.bin\x00" as *u8, ch + boff, blen) != 0 { return 7 }
69 var tn: i64 = blen - 3
70 if tn < 0 { tn = 0 }
71 if s2_write_file("/tmp/race_trunc.bin\x00" as *u8, ch + boff, tn) != 0 { return 8 }
72 if s2_write_file("/tmp/race_empty.bin\x00" as *u8, ch + boff, 0) != 0 { return 9 }
73 s2_dec(0x4F, 0x4B, 1) // OK=
74 return 0
75}