41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Binary-grep the whole QMT install for the strategy instance name.
|
|
Searches UTF-8, GBK, UTF-16LE encodings of the anchor string."""
|
|
import os
|
|
|
|
d = open(r"C:\sanguo_bigqmt\qmt_install_dir.txt", encoding="utf-8").read().strip()
|
|
root = os.path.dirname(d)
|
|
|
|
name = "\u65b0\u5efa\u7b56\u7565\u6587\u4ef63" # 新建策略文件3
|
|
needles = {
|
|
"utf8": name.encode("utf-8"),
|
|
"gbk": name.encode("gbk"),
|
|
"u16": name.encode("utf-16-le"),
|
|
}
|
|
|
|
skip_dirs = {"log", "__pycache__", "malldown"}
|
|
found = 0
|
|
for dirpath, dirnames, files in os.walk(root):
|
|
dirnames[:] = [x for x in dirnames if x not in skip_dirs]
|
|
for f in files:
|
|
p = os.path.join(dirpath, f)
|
|
try:
|
|
if os.path.getsize(p) > 60 * 1024 * 1024:
|
|
continue
|
|
raw = open(p, "rb").read()
|
|
except OSError:
|
|
continue
|
|
hit = [enc for enc, nd in needles.items() if nd in raw]
|
|
if hit:
|
|
rel = os.path.relpath(p, root)
|
|
print("HIT %-60s %s size=%d" % (
|
|
rel.encode("unicode_escape").decode("ascii")[:60],
|
|
",".join(hit), len(raw)))
|
|
found += 1
|
|
if found > 30:
|
|
print("...TRUNC")
|
|
break
|
|
if found > 30:
|
|
break
|
|
print("FOUND", found)
|