Skip to content

Instantly share code, notes, and snippets.

@krrr
Created June 29, 2026 15:03
Show Gist options
  • Select an option

  • Save krrr/50ba8d9f2b0cbf24f093b8f9e3450849 to your computer and use it in GitHub Desktop.

Select an option

Save krrr/50ba8d9f2b0cbf24f093b8f9e3450849 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
strip_safety_strings.py
Scan language_server.exe (a Go-compiled binary) for occurrences of a string
block starting with "Core Safety Principles" and ending with
"seek user clarification.", then replace every non-whitespace byte in that
range with space (0x20), preserving file length exactly and keeping newline
characters intact.
Usage:
python strip_safety_strings.py [--dry-run] [path\\to\\language_server.exe]
Defaults to looking for language_server.exe in the same directory as the
script when no path is given.
"""
import sys
import os
START_MARKER = b"**Core Safety Principles"
END_MARKER = b"seek user clarification."
def find_ranges(data: bytes) -> list[tuple[int, int]]:
"""Return (start, end) byte ranges covering each marker-delimited block."""
ranges: list[tuple[int, int]] = []
pos = 0
while True:
s = data.find(START_MARKER, pos)
if s == -1:
break
e = data.find(END_MARKER, s)
if e == -1:
break
e += len(END_MARKER) # include the end marker itself
ranges.append((s, e))
pos = e
return ranges
def strip_block(block: bytearray) -> None:
"""Replace every byte in *block* that is not a newline with space."""
for i in range(len(block)):
block[i] = 0x20 # space
def process(exe_path: str, dry_run: bool = False) -> int:
"""Read *exe_path*, find & strip target strings, write back.
Returns the number of blocks stripped (0 means nothing was found).
"""
if not os.path.isfile(exe_path):
print(f"Error: file not found -> {exe_path}", file=sys.stderr)
return -1
with open(exe_path, "rb") as f:
data = bytearray(f.read())
ranges = find_ranges(data)
if not ranges:
print("No matching strings found -- nothing to do.")
return 0
original_len = len(data)
for s, e in ranges:
block = data[s:e]
strip_block(block)
data[s:e] = block
print(
f" Stripped {e - s:>5} bytes at offset 0x{s:08x} - 0x{e:08x}"
)
assert len(data) == original_len, "BUG: file length changed!"
if dry_run:
print(f"\nDry-run mode -- {exe_path} was NOT modified.")
else:
with open(exe_path, "wb") as f:
f.write(data)
print(f"\nWritten to {exe_path}")
return len(ranges)
def main() -> None:
dry_run = False
args = [a for a in sys.argv[1:] if a != "--dry-run"]
if len(args) < len(sys.argv[1:]):
dry_run = True
exe_path = args[0] if args else os.path.join(
"C:\\Users\\krrr\\AppData\\Local\\Programs\\antigravity\\resources\\bin\\language_server.exe"
)
result = process(exe_path, dry_run=dry_run)
sys.exit(0 if result >= 0 else 1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment