63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
import subprocess, os, glob, sys, time, struct
|
|
|
|
RPP = "/home/m/soothe-bt/render_short.rpp"
|
|
proc = subprocess.Popen(['reaper', '-nosplash', '-renderproject', RPP],
|
|
stdout=open('/tmp/rtsig.log', 'w'), stderr=subprocess.STDOUT)
|
|
print('reaper', proc.pid, flush=True)
|
|
|
|
|
|
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
|
|
|
|
N_POW2 = {2:1,4:1,8:1,16:1,32:1,64:1,128:1,256:1,512:1,1024:1,2048:1,4096:1,8192:1,16384:1,32768:1,65536:1}
|
|
|
|
def scan(pid):
|
|
mem = os.open(f'/proc/{pid}/mem', os.O_RDONLY)
|
|
found = []
|
|
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
|
|
if lo < 0x180000000 or lo >= 0x183000000:
|
|
# heap/stack chunk. scan qword-aligned for N signature
|
|
for o in range(0, len(d) - (0x1ac + 8), 8):
|
|
n0 = struct.unpack_from('<I', d, o + 0x19c)
|
|
n1 = struct.unpack_from('<I', d, o + 0x1a0)
|
|
u = struct.unpack_from('<I', d, o + 0x1ac)
|
|
if n0[0] and n1[0] == n0[0] and n0[0] in N_POW2 and u[0] in (2,4,8,16):
|
|
ws = struct.unpack_from('<d', d, o + 0x1a4)
|
|
found.append((lo + o, n0[0], u[0], ws[0]))
|
|
os.close(mem)
|
|
return found
|
|
|
|
done = set()
|
|
t0 = time.time()
|
|
while time.time() - t0 < 70:
|
|
for pid in find_hosts():
|
|
if pid in done:
|
|
continue
|
|
f = scan(pid)
|
|
done.add(pid)
|
|
print('PID', pid, 'sig hits:', len(f), flush=True)
|
|
for x in f[:20]:
|
|
print(' obj', hex(x[0]), 'N', x[1], 'ups', x[2], 'win', x[3], flush=True)
|
|
time.sleep(0.3)
|
|
proc.kill()
|
|
print('done', flush=True) |