import struct
D=open('extracted/assets/bin/Data/Managed/Metadata/global-metadata.dat','rb').read()
H=struct.unpack('<68i',D[:272])
SO,SS=H[6],H[7]
def isname(i):
    # must start exactly at a string boundary
    if i<0 or i>=SS: return False
    if i>0 and D[SO+i-1]!=0: return False
    e=D.index(b'\0',SO+i)
    t=D[SO+i:e]
    return 0<len(t)<250 and all(32<=c<127 for c in t)
def s(i):
    e=D.index(b'\0',SO+i); return D[SO+i:e].decode('utf-8','replace')
def probe(off,size,name,slot=0):
    res=[]
    for st in range(8,148,4):
        if size%st: continue
        n=size//st
        if n<8: continue
        hit=0; N=min(n,600)
        for i in range(N):
            v=struct.unpack_from('<i',D,off+i*st)[0]
            if isname(v): hit+=1
        res.append((hit/N,st,n))
    res.sort(reverse=True)
    print('== %-22s size=%-9d'%(name,size), ' | '.join('st=%d n=%d sc=%.2f'%(b,c,a) for a,b,c in res[:3]))
    return res[0][1]
st_ev=probe(H[8],H[9],'events')
st_pr=probe(H[10],H[11],'properties')
st_me=probe(H[12],H[13],'methods')
st_pa=probe(H[22],H[23],'parameters')
st_fi=probe(H[24],H[25],'fields')
st_td=probe(H[40],H[41],'typeDefs')
st_im=probe(H[44],H[45],'images')
