File size: 10,025 Bytes
a2b0af0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | ; SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
; Copyright (C) 2026 SnapKitty Collective
; ============================================================================
; TheVoidIntent Framework
; Network Containment & Reclamation Module
;
; x86-64 NASM / Linux
;
; TypeScript equivalent:
;
; NetworkAlertModule
; WARNING -> logDissonanceMarker()
; CONTAINMENT -> quarantineAgentRouting()
; TRUTHLOCK -> executeCoreReclamation()
;
; Build:
;
; nasm -f elf64 network_containment.asm -o network_containment.o
; ld network_containment.o -o network_containment
;
; Run:
;
; ./network_containment
; ============================================================================
BITS 64
global _start
; ============================================================================
; Isolation levels
; ============================================================================
%define WARNING 0
%define CONTAINMENT 1
%define TRUTHLOCK 2
; Linux syscalls
%define SYS_WRITE 1
%define SYS_EXIT 60
%define STDOUT 1
%define STDERR 2
; ============================================================================
; Read-only strings
; ============================================================================
section .rodata
msg_warning:
db "[CRITICAL ALERT]: Entering FIELD_WARN State!", 10
msg_warning_len equ $ - msg_warning
msg_containment:
db "[CRITICAL ALERT]: Entering AGENT_ISOLATE State!", 10
msg_containment_len equ $ - msg_containment
msg_truthlock:
db "[CRITICAL ALERT]: Entering CORE_RECLAMATION State!", 10
msg_truthlock_len equ $ - msg_truthlock
msg_dissonance:
db "[ALERT]: Dissonance marker recorded.", 10
msg_dissonance_len equ $ - msg_dissonance
msg_quarantine:
db "[CONTAINMENT]: Agent routing quarantined.", 10
msg_quarantine_len equ $ - msg_quarantine
msg_null_sink:
db "[CONTAINMENT]: Downstream vectors redirected to null sink.", 10
msg_null_sink_len equ $ - msg_null_sink
msg_reclamation:
db "[TRUTHLOCK]: Commencing core reclamation.", 10
msg_reclamation_len equ $ - msg_reclamation
msg_reset:
db "[TRUTHLOCK]: Resetting state machines to Stage 1.", 10
msg_reset_len equ $ - msg_reset
msg_unknown:
db "[ERROR]: Unknown isolation level. Fail-closed.", 10
msg_unknown_len equ $ - msg_unknown
; ============================================================================
; Mutable runtime state
; ============================================================================
section .bss
; Equivalent to:
;
; private activeFailsafe: boolean = false;
;
active_failsafe:
resb 1
; Event identifier storage
event_id:
resb 64
; Agent identifier storage
agent_id:
resb 64
; Measured drift
measured_drift:
resq 1
; Maximum allowed drift
max_allowed_limit:
resq 1
; Timestamp
event_timestamp:
resq 1
; ============================================================================
; Program
; ============================================================================
section .text
_start:
; ------------------------------------------------------------------------
; Initialize failsafe
; ------------------------------------------------------------------------
mov byte [active_failsafe], 0
; ------------------------------------------------------------------------
; Example WARNING event
; ------------------------------------------------------------------------
mov rdi, WARNING
call trigger_containment_protocol
; ------------------------------------------------------------------------
; Example CONTAINMENT event
; ------------------------------------------------------------------------
mov rdi, CONTAINMENT
call trigger_containment_protocol
; ------------------------------------------------------------------------
; Example TRUTHLOCK event
;
; This path terminates the process with exit code 13.
; ------------------------------------------------------------------------
mov rdi, TRUTHLOCK
call trigger_containment_protocol
; Should never reach here because TRUTHLOCK exits.
mov rax, SYS_EXIT
xor rdi, rdi
syscall
; ============================================================================
; trigger_containment_protocol
;
; Equivalent:
;
; triggerContainmentProtocol(
; level: IsolationLevel,
; payload: AlertPayload
; )
;
; Input:
; RDI = isolation level
;
; Side effect:
; activeFailsafe = true
;
; ============================================================================
trigger_containment_protocol:
; ------------------------------------------------------------------------
; activeFailsafe = true
; ------------------------------------------------------------------------
mov byte [active_failsafe], 1
; ------------------------------------------------------------------------
; Dispatch isolation level
; ------------------------------------------------------------------------
cmp rdi, WARNING
je .warning
cmp rdi, CONTAINMENT
je .containment
cmp rdi, TRUTHLOCK
je .truthlock
; Unknown state
jmp .unknown
; ============================================================================
; WARNING
;
; Equivalent:
;
; this.logDissonanceMarker(payload);
; ============================================================================
.warning:
mov rdi, msg_warning
mov rsi, msg_warning_len
call print_stderr
call log_dissonance_marker
ret
; ============================================================================
; CONTAINMENT
;
; Equivalent:
;
; this.quarantineAgentRouting(payload.eventId);
; ============================================================================
.containment:
mov rdi, msg_containment
mov rsi, msg_containment_len
call print_stderr
call quarantine_agent_routing
ret
; ============================================================================
; TRUTHLOCK
;
; Equivalent:
;
; this.executeCoreReclamation();
;
; ============================================================================
.truthlock:
mov rdi, msg_truthlock
mov rsi, msg_truthlock_len
call print_stderr
call execute_core_reclamation
; execute_core_reclamation does not return.
ret
; ============================================================================
; UNKNOWN STATE
; ============================================================================
.unknown:
mov rdi, msg_unknown
mov rsi, msg_unknown_len
call print_stderr
; Fail closed.
mov rax, SYS_EXIT
mov rdi, 13
syscall
; ============================================================================
; log_dissonance_marker
;
; TypeScript:
;
; console.log(
; `[ALERT]: Dissonance logged at ${payload.timestamp}.`
; );
;
; ============================================================================
log_dissonance_marker:
mov rdi, msg_dissonance
mov rsi, msg_dissonance_len
call print_stdout
ret
; ============================================================================
; quarantine_agent_routing
;
; TypeScript:
;
; console.warn(
; `[CONTAINMENT]: Severing socket bridges for Agent: ${agentId}.`
; );
;
; console.warn(
; `[CONTAINMENT]: Re-routing downstream data vectors
; to zero-entropy null sinks.`
; );
;
; This implementation records the containment state and emits the
; corresponding control-plane messages.
;
; Actual interface/socket manipulation should be implemented separately
; behind an explicitly authorized privileged syscall/service boundary.
; ============================================================================
quarantine_agent_routing:
mov rdi, msg_quarantine
mov rsi, msg_quarantine_len
call print_stderr
mov rdi, msg_null_sink
mov rsi, msg_null_sink_len
call print_stderr
ret
; ============================================================================
; execute_core_reclamation
;
; TypeScript:
;
; console.error(
; `[TRUTHLOCK]: Commencing total sovereign memory wipe.`
; );
;
; console.error(
; `[TRUTHLOCK]: Resetting operational state machines
; back to Stage 1 Calibration.`
; );
;
; process.exit(13);
;
; ============================================================================
execute_core_reclamation:
mov rdi, msg_reclamation
mov rsi, msg_reclamation_len
call print_stderr
mov rdi, msg_reset
mov rsi, msg_reset_len
call print_stderr
; ------------------------------------------------------------------------
; Clear selected runtime state before termination.
;
; This is ordinary process-state cleanup, not secure erasure of arbitrary
; system memory.
; ------------------------------------------------------------------------
xor eax, eax
mov byte [active_failsafe], 0
mov qword [measured_drift], 0
mov qword [max_allowed_limit], 0
mov qword [event_timestamp], 0
lea rdi, [event_id]
mov rcx, 64
rep stosb
lea rdi, [agent_id]
mov rcx, 64
rep stosb
; ------------------------------------------------------------------------
; Linux:
;
; process.exit(13)
;
; becomes:
;
; syscall
; RAX = 60 SYS_exit
; RDI = 13 status
; ------------------------------------------------------------------------
mov rax, SYS_EXIT
mov rdi, 13
syscall
; ============================================================================
; print_stdout
;
; RDI = pointer
; RSI = length
; ============================================================================
print_stdout:
mov rdx, rsi
mov rsi, rdi
mov rdi, STDOUT
mov rax, SYS_WRITE
syscall
ret
; ============================================================================
; print_stderr
;
; RDI = pointer
; RSI = length
; ============================================================================
print_stderr:
mov rdx, rsi
mov rsi, rdi
mov rdi, STDERR
mov rax, SYS_WRITE
syscall
ret
|