Files
soothe2-re/rtall.py
T

67 lines
1.9 KiB
Python

#!/usr/bin/env python3
import subprocess, os, glob, sys, time, struct
RPP = "/home/m/soothe-bt/render_long.rpp"
proc = subprocess.Popen(
['reaper', '-nosplash', '-renderproject', RPP],
stdout=open('/tmp/rtall.log', 'w'), stderr=subprocess.STDOUT)
print('reaper', proc.pid, flush=True)
start, end = 0x1824abb00, 0x1824abd00 # vtbl region
SLOTS = list(range(start, end, 8))
def find_hosts():
out = []
for p in glob.glob('/proc/[0-9]*'):
try:
pid = int(os.path.basename(p))
m = open(f'/proc/{pid}/maps').read()
c = open(f'/proc/{pid}/cmdline', 'rb').read().decode('utf8', 'replace')
if 'soothe2' in m and 'yabridge-host.exe' in c:
out.append(pid)
except Exception:
pass
return out
def scan_all(pid):
mem = os.open(f'/proc/{pid}/mem', os.O_RDONLY)
resc = {s: [] for s in SLOTS}
maps = open(f'/proc/{pid}/maps').read()
for line in maps.splitlines():
p = line.split()
lo, hi = (int(x, 16) for x in p[0].split('-'))
if 'r' not in p[1]:
continue
try:
d = os.pread(mem, hi - lo, lo)
except Exception:
continue
for s in SLOTS:
t = struct.pack('<Q', s)
i = 0
while True:
i = d.find(t, i)
if i < 0:
break
resc[s].append(lo + i)
i += 1
os.close(mem)
return resc
results = {}
t0 = time.time()
while time.time() - t0 < 75:
for pid in find_hosts():
if pid in results:
continue
r = scan_all(pid)
results[pid] = r
print('PID', pid, flush=True)
for s in SLOTS:
if r[s]:
print(f' {s:#x} hits={len(r[s])} @ {[hex(x) for x in r[s][:3]]}', flush=True)
time.sleep(0.4)
proc.kill()
print('done', flush=True)