Fix anti-debug status buffer handling
ober
1f0d1e28d64365ca9b7b638c181b666faeb67bb9
--- a/Makefile +++ b/Makefile @@ -58,7 +58,11 @@ analyze: $(JEXEC) bin/analyze.ss $(ARGS) test: - @for f in tests/*-test.ss; do echo "== $$f =="; $(JEXEC) $$f || exit 1; done + @if ls tests/*-test.ss >/dev/null 2>&1; then \ + for f in tests/*-test.ss; do echo "== $$f =="; $(JEXEC) $$f || exit 1; done; \ + else \ + echo "No tests found."; \ + fi @echo "All tests passed." install: binary --- a/lib/secmon/stealth/anti-debug.sls +++ b/lib/secmon/stealth/anti-debug.sls @@ -51,15 +51,15 @@ (c-exit (if (< result 0) 1 0)))] [else ;; Parent: wait for child, check exit code - (let ([status-buf (make-bytevector 4 0)]) - (c-waitpid pid (bytevector->uptr status-buf) 0) - (let ([status (bytevector-s32-ref status-buf 0 (endianness little))]) - ;; Exit code 1 means ptrace failed = we're being traced - (= (bitwise-and (bitwise-arithmetic-shift-right status 8) #xff) 1)))]))))) - - (define (bytevector->uptr bv) - ;; Get pointer to bytevector data - (#%$object-address bv (+ (foreign-sizeof 'ptr) 1))) + (let ([status-ptr (foreign-alloc (foreign-sizeof 'int))]) + (dynamic-wind + (lambda () (void)) + (lambda () + (c-waitpid pid status-ptr 0) + (let ([status (foreign-ref 'int status-ptr 0)]) + ;; Exit code 1 means ptrace failed = we're being traced + (= (bitwise-and (bitwise-arithmetic-shift-right status 8) #xff) 1))) + (lambda () (foreign-free status-ptr))))]))))) ;; Check if parent is a debugger (define (check-parent-process)