# -*- coding: utf-8 -*-
# Quét dex: endpoint /ccaraccessmgmt + từ khoá pairing/keystore/publicKey/signature
import io, sys, re, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
DEXDIR = r'E:\ios\vf_dex'

def scan(pat_bytes, label, ctx_b=120, ctx_a=180, maxn=6):
    print(f'\n################ {label} ################')
    rx = re.compile(pat_bytes)
    total = 0
    for fn in sorted(os.listdir(DEXDIR)):
        if not fn.endswith('.dex'):
            continue
        data = open(os.path.join(DEXDIR, fn), 'rb').read()
        for m in rx.finditer(data):
            total += 1
            if total > maxn:
                return
            i = m.start()
            chunk = data[max(0, i - ctx_b):i + ctx_a].decode('ascii', 'replace').replace('\x00', '·')
            print(f'--- {fn}@{i}: {chunk}')
    if total == 0:
        print('(không có match)')

scan(rb'ccaraccessmgmt/api/v[0-9]+/remote[a-z0-9/_-]*', 'ENDPOINT remote /ccaraccessmgmt')
scan(rb'ccaraccessmgmt/api/v[0-9]+/pairing[a-z0-9/_-]*', 'ENDPOINT pairing')
scan(rb'ccaraccessmgmt/api/v[0-9]+/[a-z0-9/_-]{5,60}', 'TẤT CẢ ENDPOINT ccaraccessmgmt', maxn=10)
scan(rb'/ccar[a-z-]+/api/v[0-9.]+/[a-z0-9/_-]{5,60}', 'TẤT CẢ ENDPOINT ccar* (tham khảo)', maxn=10)
