28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Per power: code bytes executed in that run, not in baseline, and in <= K other power runs.
|
|
usage: pw2_unique.py K (reads re/runs/pw2_all_*/cdl.bin)"""
|
|
import sys, glob, os
|
|
K=int(sys.argv[1])
|
|
root=os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
base=open(f'{root}/re/runs/pw2_all_none/cdl.bin','rb').read()
|
|
runs={}
|
|
for p in sorted(glob.glob(f'{root}/re/runs/pw2_all_[0-9A-F][0-9A-F]/cdl.bin')):
|
|
runs[p.split('pw2_all_')[1][:2]]=open(p,'rb').read()
|
|
N=len(base)
|
|
cnt=bytearray(N)
|
|
for d in runs.values():
|
|
for i in range(N):
|
|
if d[i]&1 and not base[i]&1: cnt[i]+=1
|
|
def cpu(o): return 0x800000|((o//0x8000)<<16)|0x8000|(o%0x8000)
|
|
for pid,d in runs.items():
|
|
rng=[];s=None
|
|
for i in range(N):
|
|
u=bool(d[i]&1) and not base[i]&1 and cnt[i]<=K+1
|
|
if u and s is None: s=i
|
|
if not u and s is not None: rng.append((s,i-1)); s=None
|
|
m=[]
|
|
for a,b in rng:
|
|
if m and a-m[-1][1]<=8: m[-1]=(m[-1][0],b)
|
|
else: m.append((a,b))
|
|
print(pid+': '+' '.join(f'{cpu(a)>>16:02X}:{cpu(a)&0xffff:04X}-{cpu(b)&0xffff:04X}' for a,b in m))
|