From ae04636f8d883932f030976d6c976ff83c4f2b24 Mon Sep 17 00:00:00 2001 From: yato Date: Sun, 29 Nov 2026 15:41:14 +0300 Subject: [PATCH] Fix deleted sondib track reuse --- sondib/bin/sondibd | Bin 816680 -> 816680 bytes sondib/patch_sondibd.py | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 sondib/patch_sondibd.py diff --git a/sondib/bin/sondibd b/sondib/bin/sondibd index 423574db1190587fe48677941ee35a5b9605cd24..9958c74d6febf1802ca057e2f8232c305ea512b3 100755 GIT binary patch delta 101 zcmZ4S#&E?O!wm|K3Jp7DnHU%tN-aG)PaK|r2_`!@iZY&R4s&b|b7TZ!CLm@8Viq7~ a1!6WJW(Q&pAm#*OE+FRK9_Gk%$pipAt|iC- delta 72 zcmZ4S#&E?O!wm|KlNT&hob2c*!pPSg=GY$Q$OyztK+FupEI`Z(#B4y!4#XTl%n8I? NK+L^8%#r7k2>`3(7ta6y diff --git a/sondib/patch_sondibd.py b/sondib/patch_sondibd.py new file mode 100644 index 0000000..d7175ef --- /dev/null +++ b/sondib/patch_sondibd.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Apply the deleted-track guard to the bundled sondibd binary. + +The repository ships the service as a release binary. This patch reuses an +alignment NOP sled immediately before ``st_find_sid`` and makes a matching SID +return no result when the track's deleted byte (offset 0x21d) is set. +""" + +from __future__ import annotations + +import sys +from pathlib import Path + + +TEXT_VA_BASE = 0x400000 +GUARD_VA = 0x404120 +MATCH_VA = 0x404154 +GUARD_SIZE = 0x20 + +OLD_GUARD = bytes.fromhex( + "66 66 2e 0f 1f 84 00 00 00 00 00 " + "66 66 2e 0f 1f 84 00 00 00 00 00 " + "66 2e 0f 1f 84 00 00 00 00 00" +) +OLD_BRANCH = bytes.fromhex("74 0e") + + +def file_offset(virtual_address: int) -> int: + return virtual_address - TEXT_VA_BASE + + +def patch(path: Path) -> None: + data = bytearray(path.read_bytes()) + guard_offset = file_offset(GUARD_VA) + match_offset = file_offset(MATCH_VA) + guard = bytes(data[guard_offset:guard_offset + GUARD_SIZE]) + branch = bytes(data[match_offset:match_offset + len(OLD_BRANCH)]) + + if branch == bytes.fromhex("74 ca"): + return + if branch != OLD_BRANCH or guard != OLD_GUARD: + raise SystemExit(f"unexpected sondibd bytes in {path}") + + # je 0x404120; then reject track+0x21d when it is non-zero. + guard_code = bytes.fromhex( + "80 b9 1d 02 00 00 00 " # cmp byte ptr [rcx+0x21d], 0 + "75 39 " # jne 0x404162 (the existing null return) + "48 89 c8 c3" # mov rax, rcx; ret + ) + data[guard_offset:guard_offset + GUARD_SIZE] = guard_code.ljust(GUARD_SIZE, b"\x90") + data[match_offset:match_offset + len(OLD_BRANCH)] = bytes.fromhex("74 ca") + path.write_bytes(data) + + +if __name__ == "__main__": + patch(Path(sys.argv[1]) if len(sys.argv) == 2 else Path(__file__).with_name("bin") / "sondibd")