Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/cortex/blob/main/tools/pincheck.om # cortex aien-dev/cortex Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `cortex / tools / pincheck.om` 379 lines ยท 6385 bytes Raw Blame History 1 note pincheck: the compiler pin is written in one place, PIN. build.sh compiles this unit with the 2 note pinned omc and runs it in the repository root as `git ls-files | build/pincheck`; a finding 3 note fails the build (pattern: omega-mcp gates/pincheck.om). 4 note It reads PIN (lines `omega-mv <40 hex>` and `omc-sha256 <64 hex>`) and a list of tracked paths 5 note on stdin, one per line, and reports every word in those files that restates the pin. A word is 6 note a run of 0-9 A-Z a-z _ between other characters; it restates the pin when it has 7 to 64 7 note characters and, with A-F read as a-f, equals that many first characters of the PIN revision or 8 note of the omc sha256. The rule compares against the values in PIN and asks nothing else of the word: 9 note a short revision made only of digits is found like any other, and a number that is not a prefix 10 note of the pin (a date, a count) is not. 7 is the shortest prefix git prints; 8, 12, 16 and the full 11 note 40 or 64 are the lengths written in practice. Such a copy goes stale when PIN moves; point at PIN 12 note (or derive the value from it) instead. Other hashes are not judged here. 13 note Not read: PIN itself, and records of past runs (evidence/), which name the compiler they ran with. 14 note Files and lines of any size are streamed; no limit of its own. 15 note Exit 0 no findings, 1 findings, 2 PIN malformed, a listed file unreadable or a write error. 16 17 global pin uchar 4096 18 global ib uchar 65536 19 global fb uchar 65536 20 global tok uchar 64 21 global pth uchar 4096 22 global ob uchar 32 23 global rev uchar 40 24 global sha uchar 64 25 global st ulong 16 26 27 note st cells: word length, hex only (after reading A-F as a-f), line, findings, path length, files read 28 const q_len ulong 0 29 const q_hex ulong 1 30 const q_line ulong 2 31 const q_bad ulong 3 32 const q_pl ulong 4 33 const q_nf ulong 5 34 35 text kpinf "PIN" 36 text kmvw "omega-mv " 37 text kshaw "omc-sha256 " 38 text m_pin "pincheck: PIN must hold `omega-mv <40 hex>` and `omc-sha256 <64 hex>`, one per line\n" 39 text m_open "pincheck: cannot read " 40 text m_long "pincheck: path longer than 4095 bytes\n" 41 text m_rest ": restates PIN: " 42 text m_hint "pincheck: the pin is written only in PIN; point at PIN (or derive the value from it) instead\n" 43 text m_sum "pincheck: files " 44 text m_fnd " findings " 45 text nl "\n" 46 text colon ":" 47 text x_ev "evidence/" 48 49 fn wt t view uchar * to void 50 n = len t 51 p = ulong 0 52 for it ulong `4611686018427387904` 53 if ge p n 54 ret 55 end 56 k = write 1 t p sub n p 57 if le k 0 58 exit 2 59 end 60 p = add p ulong k 61 end 62 end 63 fn wbuf k ulong to void 64 n = get st k 65 p = ulong 0 66 for it ulong `4611686018427387904` 67 if ge p n 68 ret 69 end 70 x = long 0 71 if eq k q_pl 72 x = write 1 pth p sub n p 73 else 74 x = write 1 tok p sub n p 75 end 76 if le x 0 77 exit 2 78 end 79 p = add p ulong x 80 end 81 end 82 fn putn v ulong to void 83 i = ulong 32 84 n = v 85 for it ulong 32 86 i = sub i 1 87 put ob i uchar add rem n 10 48 88 n = div n 10 89 if eq n 0 90 break 91 end 92 end 93 p = i 94 for it ulong `4611686018427387904` 95 if ge p 32 96 ret 97 end 98 k = write 1 ob p sub 32 p 99 if le k 0 100 exit 2 101 end 102 p = add p ulong k 103 end 104 end 105 fn ishex c uchar to bool 106 if and ge c 48 le c 57 107 ret true 108 end 109 ret and ge c 97 le c 102 110 end 111 fn isword c uchar to bool 112 if ishex c 113 ret true 114 end 115 if and ge c 65 le c 90 116 ret true 117 end 118 if and ge c 97 le c 122 119 ret true 120 end 121 ret eq c 95 122 end 123 124 note ---- PIN ---- 125 note the hex value after word w at the start of a line of pin[0 .. n) into rev (sel 0) or sha (sel 1) 126 fn pinval n ulong w view uchar * want ulong sel ulong to bool 127 p = ulong 0 128 for it ulong `4611686018427387904` 129 if ge p n 130 ret false 131 end 132 ok = true 133 for i ulong len w 134 if ge add p i n 135 ok = false 136 break 137 end 138 if ne get pin add p i get w i 139 ok = false 140 break 141 end 142 end 143 if ok 144 a = add p len w 145 if gt add a want n 146 ret false 147 end 148 for i ulong want 149 c = get pin add a i 150 if not ishex c 151 ret false 152 end 153 if eq sel 0 154 put rev i c 155 else 156 put sha i c 157 end 158 end 159 e = add a want 160 if lt e n 161 c = get pin e 162 if and ne c 10 ne c 13 163 ret false 164 end 165 end 166 ret true 167 end 168 for it2 ulong `4611686018427387904` 169 if ge p n 170 ret false 171 end 172 if eq get pin p 10 173 p = add p 1 174 break 175 end 176 p = add p 1 177 end 178 end 179 ret false 180 end 181 fn readpin to bool 182 fd = fopen kpinf 0 len kpinf 524288 0 183 if lt fd 0 184 ret false 185 end 186 n = read int fd pin 0 len pin 187 x = fclose int fd 188 if le n 0 189 ret false 190 end 191 if ge ulong n len pin 192 ret false 193 end 194 if not pinval ulong n kmvw 40 0 195 ret false 196 end 197 ret pinval ulong n kshaw 64 1 198 end 199 200 note ---- words ---- 201 note the word in tok (its first min(len, 64) bytes, A-F stored as a-f) is a prefix of rev or sha 202 fn restates to bool 203 n = get st q_len 204 if lt n 7 205 ret false 206 end 207 if gt n 64 208 ret false 209 end 210 if le n 40 211 r = true 212 for i ulong n 213 if ne get tok i get rev i 214 r = false 215 break 216 end 217 end 218 if r 219 ret true 220 end 221 end 222 for i ulong n 223 if ne get tok i get sha i 224 ret false 225 end 226 end 227 ret true 228 end 229 fn endword to void 230 n = get st q_len 231 if eq n 0 232 ret 233 end 234 if eq get st q_hex 1 235 if restates 236 wbuf q_pl 237 wt colon 238 putn get st q_line 239 wt m_rest 240 wbuf q_len 241 wt nl 242 put st q_bad add get st q_bad 1 243 end 244 end 245 put st q_len 0 246 end 247 fn onebyte c uchar to void 248 if isword c 249 n = get st q_len 250 if eq n 0 251 put st q_hex 1 252 end 253 d = c 254 if and ge c 65 le c 70 255 d = add c 32 256 end 257 if lt n 64 258 put tok n d 259 end 260 put st q_len add n 1 261 if not ishex d 262 put st q_hex 0 263 end 264 ret 265 end 266 endword 267 if eq c 10 268 put st q_line add get st q_line 1 269 end 270 end 271 272 note ---- files ---- 273 fn skipped to bool 274 n = get st q_pl 275 if and eq n len kpinf eq get pth 0 80 276 if and eq get pth 1 73 eq get pth 2 78 277 ret true 278 end 279 end 280 if lt n len x_ev 281 ret false 282 end 283 for i ulong len x_ev 284 if ne get pth i get x_ev i 285 ret false 286 end 287 end 288 ret true 289 end 290 fn scan to int 291 if skipped 292 ret 0 293 end 294 fd = fopen pth 0 get st q_pl 524288 0 295 if lt fd 0 296 wt m_open 297 wbuf q_pl 298 wt nl 299 ret 2 300 end 301 put st q_line 1 302 put st q_len 0 303 for it ulong `4611686018427387904` 304 r = read int fd fb 0 len fb 305 if lt r 0 306 x = fclose int fd 307 wt m_open 308 wbuf q_pl 309 wt nl 310 ret 2 311 end 312 if eq r 0 313 break 314 end 315 for i ulong ulong r 316 onebyte get fb i 317 end 318 end 319 endword 320 x = fclose int fd 321 put st q_nf add get st q_nf 1 322 ret 0 323 end 324 fn main to int 325 if not readpin 326 wt m_pin 327 ret 2 328 end 329 put st q_pl 0 330 rc = int 0 331 for it ulong `4611686018427387904` 332 r = read int 0 ib 0 len ib 333 if lt r 0 334 ret 2 335 end 336 if eq r 0 337 break 338 end 339 for i ulong ulong r 340 c = get ib i 341 if eq c 10 342 if gt get st q_pl 0 343 s = scan 344 if ne s 0 345 rc = s 346 end 347 end 348 put st q_pl 0 349 else 350 n = get st q_pl 351 if ge n sub len pth 1 352 wt m_long 353 ret 2 354 end 355 put pth n c 356 put st q_pl add n 1 357 end 358 end 359 end 360 if gt get st q_pl 0 361 s = scan 362 if ne s 0 363 rc = s 364 end 365 end 366 wt m_sum 367 putn get st q_nf 368 wt m_fnd 369 putn get st q_bad 370 wt nl 371 if ne rc 0 372 ret rc 373 end 374 if gt get st q_bad 0 375 wt m_hint 376 ret 1 377 end 378 ret 0 379 end