#!/usr/bin/env python3 import subprocess, os, glob, sys, time RPP = sys.argv[1] if len(sys.argv) > 1 else "/home/m/soothe-bt/render_rt.rpp" OUT = sys.argv[2] if len(sys.argv) > 2 else "/home/m/re-tools/rt.bin" proc = subprocess.Popen( ['reaper', '-nosplash', '-renderproject', RPP], stdout=open('/tmp/rtdump.log', 'w'), stderr=subprocess.STDOUT) print('reaper', proc.pid, flush=True) base = 0x180000000 extent = 0x7000000 host = None deadline = time.time() + 90 while time.time() < deadline and proc.poll() is None: for p in glob.glob('/proc/[0-9]*'): try: pid = int(os.path.basename(p)) cmd = open(p + '/cmdline', 'rb').read().replace(b'\0', b' ').decode('utf8', 'replace') if 'yabridge-host' not in cmd: continue maps = open(f'/proc/{pid}/maps').read() if 'soothe2' in maps: host = pid break except Exception: pass if host: break time.sleep(0.2) print('host', host, flush=True) if not host: proc.kill() sys.exit('no host') readable = [] maps = open(f'/proc/{host}/maps').read() for line in maps.splitlines(): parts = line.split() lo, hi = (int(x, 16) for x in parts[0].split('-')) if 'r' in parts[1] and base <= lo < base + extent: readable.append((lo, hi, parts[1])) print('regions:', len(readable), flush=True) mem = os.open(f'/proc/{host}/mem', os.O_RDONLY) outdir = OUT + '.regions' os.makedirs(outdir, exist_ok=True) with open(OUT, 'wb') as out: total = 0 for lo, hi, _ in readable: try: d = os.pread(mem, hi - lo, lo) out.write(d) total += len(d) with open(os.path.join(outdir, f'{lo:08x}_{hi:08x}.bin'), 'wb') as rf: rf.write(d) except Exception as e: print('fail', hex(lo), e, flush=True) os.close(mem) print('dumped', total, flush=True) proc.kill()