import re
import sys
import os

sys.stdout.reconfigure(encoding='utf-8')

def search_strings(path, keywords):
    print(f"=== Searching in {path} ===")
    if not os.path.exists(path):
        print("File not found")
        return
    with open(path, 'rb') as f:
        data = f.read()
    
    # Check ASCII and TCVN3 or UTF-8
    strs = re.findall(b'[\x20-\xff]{4,}', data)
    found = set()
    for s in strs:
        s_lower = s.lower()
        for kw in keywords:
            if kw.lower().encode('latin1') in s_lower or kw.lower().encode('utf-8') in s_lower:
                try:
                    text = s.decode('utf-8', errors='ignore')
                except:
                    text = s.decode('latin1', errors='ignore')
                if len(text) < 150:
                    found.add(text.strip())
    print(f"Found {len(found)} strings matching {keywords}:")
    for f_str in sorted(found)[:30]:
        print("  *", f_str)

kw_general = ["nga my", "ngu doc", "bua", "curse", "buff", "tu hang", "luu thuy", "mong diep", "phat tam", "vo hinh", "van co", "hoa cot", "u hon", "thi doc", "party", "dong doi", "heal"]
search_strings(r'C:\JXVCTK\JxVoCongTruyenKy\_AutoVLBS\VLBS19\AutoVLBS.exe', kw_general)
search_strings(r'C:\JXVCTK\JxVoCongTruyenKy\_AutoVLBS\VLBS19\core.dll', kw_general)
