Files
2026-11-23 03:28:32 +02:00

41 lines
2.3 KiB
Python

"""Read files by content key straight from the installed canonical client: encoding (cf2c) -> ekey -> selected idx -> data.NNN."""
import sys,struct,glob,os,zlib,hashlib
from pathlib import Path
sys.path.insert(0,'/mnt/Games/@project/gateway/ops')
import casc_local_archive as L, casc_asset_package as C
api,_=L.lookup3_api()
CL=Path('/mnt/Games/OctoWoW-Windows-Client'); D=CL/'Data/data'
ENC=Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/helm-alias-cb30-20261122/candidate/decoded/encoding.bin')
ROOT=Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/helm-alias-cb30-20261122/candidate/decoded/root.bin')
from bisect import bisect_right,bisect_left
enc=ENC.read_bytes(); el=C.encoding_layout(enc); cp=el['sections']['content']; firsts=[k for k,_ in cp]
def ekeys(ck):
b=bytes.fromhex(ck); i=bisect_right(firsts,b)-1
e=dict(C._encoding_entries(cp[i][1],'content')).get(b)
return [e[22+16*j:38+16*j] for j in range(e[0])] if e else []
idx={}
for b in range(16):
p=sorted(D.glob(f'{b:02x}*.idx'))[-1]; idx[b]=L.parse_index(p.read_bytes(),b,api)['rows']
def blte(d):
hs=struct.unpack('>I',d[4:8])[0]
if hs==0: return d[9:] if d[8:9]==b'N' else zlib.decompress(d[9:])
n=int.from_bytes(d[9:12],'big'); out=[]; p=hs
for i in range(n):
es,ds=struct.unpack_from('>II',d,12+24*i); c=d[p:p+es]; p+=es
m=c[:1]; out.append(c[1:] if m==b'N' else zlib.decompress(c[1:]) if m==b'Z' else bytes(ds) if m==b'E' else None)
if out[-1] is None: raise ValueError('mode '+str(m))
return b''.join(out)
def read_ck(ck):
for ek in ekeys(ck):
rows=idx[L.encoding_bucket(ek)]; j=bisect_left(rows,ek[:9])
if j<len(rows) and rows[j][:9]==ek[:9]:
r=rows[j]; pos=int.from_bytes(r[9:14],'big'); size=struct.unpack_from('<I',r,14)[0]
with open(D/f'data.{pos>>30:03d}','rb') as f: f.seek((pos&((1<<30)-1))+30); body=blte(f.read(size-30))
return body # md5 cannot match when encrypted chunks are zero-filled
return None
root=ROOT.read_bytes(); rl=C.root_groups(root)
def read_fdid(fdid):
r=C.root_controls_batch(root,rl,{fdid})[fdid]
cks={x['content_key'] for x in r if x['group']['locale']&2 and not x['group']['flags1']}
assert len(cks)==1,(fdid,cks); return read_ck(cks.pop())