109 lines
3.4 KiB
Python
109 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""rtdeep2.py — find DSP ctx object via phase-table pointer beacon, then dump window 0x540658 & neighbors."""
|
|
import subprocess, time, glob, os, struct, sys
|
|
import numpy as np
|
|
|
|
RPP = sys.argv[1] if len(sys.argv) > 1 else '/home/m/soothe-bt/dual300.rpp'
|
|
BEACON = 0x182615608 # VA of phase_table_1024 (static .data)
|
|
|
|
|
|
def vst_base(pid):
|
|
lo = None
|
|
for line in open(f'/proc/{pid}/maps').read().splitlines():
|
|
if 'soothe2' not in line:
|
|
continue
|
|
a = int(line.split()[0].split('-')[0], 16)
|
|
lo = a if lo is None else min(lo, a)
|
|
return lo
|
|
|
|
|
|
def readable_regions(pid):
|
|
out = []
|
|
for line in open(f'/proc/{pid}/maps').read().splitlines():
|
|
p = line.split()[0]
|
|
lo, hi = int(p.split('-')[0], 16), int(p.split('-')[1], 16)
|
|
if 'vst3' in line:
|
|
continue # skip module itself
|
|
out.append((lo, hi))
|
|
return out
|
|
|
|
|
|
def find_beacon(pid):
|
|
try:
|
|
mem = os.open(f'/proc/{pid}/mem', os.O_RDONLY)
|
|
except Exception:
|
|
return []
|
|
res = []
|
|
for lo, hi in readable_regions(pid):
|
|
sz = (hi - lo) & ~7
|
|
if sz <= 0 or sz > 0x200000000:
|
|
continue
|
|
try:
|
|
buf = os.pread(mem, sz, lo)
|
|
except Exception:
|
|
continue
|
|
arr = np.frombuffer(buf, dtype='<u8')
|
|
idx = np.where(arr == BEACON)[0]
|
|
for i in idx:
|
|
res.append(lo + int(i) * 8)
|
|
os.close(mem)
|
|
return res
|
|
|
|
|
|
def main():
|
|
proc = subprocess.Popen(['reaper', '-nosplash', '-renderproject', RPP],
|
|
stdout=open('/tmp/rtdeep2.log', 'w'), stderr=subprocess.STDOUT)
|
|
t0 = time.time()
|
|
host = None
|
|
while time.time() - t0 < 60:
|
|
for p in glob.glob('/proc/[0-9]*'):
|
|
try:
|
|
maps = open(f'/proc/{p}/maps').read()
|
|
except Exception:
|
|
continue
|
|
if 'soothe2' not in maps:
|
|
continue
|
|
host = int(os.path.basename(p))
|
|
break
|
|
if host:
|
|
break
|
|
time.sleep(0.05)
|
|
print(f'host={host}')
|
|
if not host:
|
|
proc.kill()
|
|
return
|
|
base = vst_base(host)
|
|
# allow module load: plugin init first
|
|
mem = os.open(f'/proc/{host}/mem', os.O_RDONLY)
|
|
t1 = time.time()
|
|
while time.time() - t1 < 50:
|
|
hits = find_beacon(host)
|
|
ctxs = set()
|
|
for p in hits:
|
|
for d in (0x540548, 0x540550, 0x540598):
|
|
ctxc = p - d
|
|
if 0x10000000 < ctxc < 0x7fff00000000:
|
|
ctxs.add(ctxc)
|
|
if ctxs:
|
|
print(f't={time.time()-t1:.1f}s hits={len(hits)} ctx_cands={sorted(hex(c) for c in ctxs)}', flush=True)
|
|
for ctx in sorted(ctxs):
|
|
d = os.pread(mem, 4096, ctx + 0x540658)
|
|
if len(d) < 4096:
|
|
continue
|
|
fl = np.frombuffer(d, dtype='<f4')
|
|
if np.all(np.isfinite(fl)) and fl.min() >= -1 and fl.max() <= 2:
|
|
print(f' ctx={hex(ctx)} WIN@+0x540658 head={[round(float(x),4) for x in fl[:8]]} mid={[round(float(x),4) for x in fl[1024:1032]]}', flush=True)
|
|
blk = os.pread(mem, 0x8000, ctx + 0x540000)
|
|
open(f'/tmp/ctx_{ctx:x}_win.bin', 'wb').write(blk)
|
|
break
|
|
time.sleep(0.2)
|
|
os.close(mem)
|
|
try:
|
|
proc.wait(timeout=5)
|
|
except Exception:
|
|
proc.kill()
|
|
print('done', flush=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |