Files
WoW-Hybrid-gateway/ops/octo_social_capture.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

69 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""Extract our bounded official-client social observer; never execute saved Lua.
Payloads remain private local evidence. Public summaries contain event/API names
and counts, never messages, friend names, guild rosters or account paths.
"""
import argparse,collections,hashlib,json,os,re
from pathlib import Path
from console_report import parse
ROOT=Path(__file__).resolve().parents[1]
FIELD=re.compile(r'^\s*\["WoWHybridSocialCapture"\]\s*=\s*\{',re.M)
LEX=re.compile(r'"(?:\\.|[^"\\])*"|--[^\n]*|[{}]|[^"{}-]+|-(?!--)',re.S)
def extract(raw):
if not isinstance(raw,str)or len(raw)>32*1024*1024:raise ValueError('Bounded saved data required')
matches=list(FIELD.finditer(raw))
if len(matches)!=1:raise ValueError('Exactly one social observer table required; reload/logout must save it first')
start=matches[0].end()-1;position=start;depth=0;parts=[]
while position<len(raw):
token=LEX.match(raw,position)
if not token:raise ValueError('Unsupported saved-data syntax')
value=token.group();position=token.end()
if value.startswith('--'):continue
parts.append(value)
if value=='{':depth+=1
elif value=='}':
depth-=1
if depth==0:break
if position-start>24*1024*1024:raise ValueError('Saved capture exceeds parser bound')
else:raise ValueError('Truncated social capture')
capture=parse('GatewayDiagnosticsSaved = '+''.join(parts),max_tokens=500000)
rows=capture.get('rows')
if rows=={}:rows=[];capture['rows']=rows
if capture.get('schema')!=1 or not isinstance(rows,list)or len(rows)>8192:raise ValueError('Unknown social observer schema')
for row in rows:
if (not isinstance(row,dict)or row.get('direction')not in('outgoing-api','incoming-event','state','marker')
or not isinstance(row.get('name'),str)or not re.fullmatch(r'[A-Za-z][A-Za-z0-9_-]{0,63}',row['name'])
or not isinstance(row.get('args'),(list,dict))):raise ValueError('Malformed social observation row')
args=row['args'];values=args.values()if isinstance(args,dict)else args
if len(args)>9 or isinstance(args,dict)and any(type(k)is not int or not 1<=k<=9 for k in args):raise ValueError('Bounded positional arguments required')
if any(type(v)not in(str,int,float,bool)or isinstance(v,str)and len(v)>8192 for v in values):raise ValueError('Bounded scalar arguments required')
if type(capture.get('dropped'))is not int or capture['dropped']<0:raise ValueError('Missing loss count')
if type(capture.get('bytes'))is not int or not 0<=capture['bytes']<=8388608:raise ValueError('Capture byte bound')
return capture
def summarize(capture):
counts=collections.Counter((r['direction'],r['name'])for r in capture['rows'])
return dict(kind='official-octo-social-addon-observation',rows=len(capture['rows']),dropped=capture['dropped'],
observations=[dict(direction=d,name=n,count=c)for(d,n),c in sorted(counts.items())],
raw_wire_capture=False,all_client_actions_recorded=False,server_acceptance_verified=False,
limits=['Only hooked social API attempts, registered events and bounded friend snapshots are recorded.',
'An outgoing API call alone does not prove delivery or acceptance; state changes need matched returned evidence.',
'No authentication data, packet headers or complete opcode trace are captured by this observer.',
'Private payloads are separate; this summary omits chat text, player names and account paths.'])
def main():
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--input',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args()
source=a.input.resolve();out=a.output.resolve();official=Path.home()/'Games/octo/drive_c/Octowow/WTF'
if a.input.is_symlink()or not(source.is_relative_to(official)or source.is_relative_to(ROOT/'runtime')):p.error('Explicit official/private runtime saved data required')
if not out.is_relative_to(ROOT/'runtime')or out.exists():p.error('Fresh private runtime output required')
if source.stat().st_size>32*1024*1024:p.error('Saved data size bound')
raw=source.read_text();capture=extract(raw);summary=summarize(capture);summary['source_sha256']=hashlib.sha256(raw.encode()).hexdigest()
out.mkdir(mode=0o700,parents=True)
for name,data in [('capture.json',capture),('summary.json',summary)]:
fd=os.open(out/name,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
with os.fdopen(fd,'w')as f:json.dump(data,f,indent=2);f.write('\n')
print('Saved social observation:',summary['rows'],'rows;',summary['dropped'],'dropped. No raw-packet or acceptance claim.')
if __name__=='__main__':main()