# -*- coding: utf-8 -*-
# Toàn bộ strings quanh PAIRING trong dex: endpoints, DTO fields, session tạo thế nào
import io, sys, re, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
DEXDIR = r'E:\ios\vf_dex'

def scan(rx, label, b=120, a=260, maxn=10):
    print('')
    print('#' * 16, label, '#' * 16)
    rx = re.compile(rx)
    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 - b):i + a].decode('ascii', 'replace').replace('\x00', '·')
            print('--- %s@%d:' % (fn, i))
            print(chunk)
            print()
    if total == 0:
        print('(khong co match)')

scan(rb'pairing/app/[a-z-]+', 'MOI ENDPOINT pairing/app/*')
scan(rb'/pairing/[a-zA-Z0-9/_-]+', 'MOI path /pairing/*', maxn=12)
scan(rb'PairData', 'PairData lop', b=100, a=200, maxn=6)
scan(rb'pairSession|PairSession', 'pairSession', b=100, a=200, maxn=6)
