From 98b62f8906d4118511144e894c1a318068f5319e Mon Sep 17 00:00:00 2001 From: Eric-Joker <1277243150@qq.com> Date: Tue, 11 Feb 2025 22:42:50 +0800 Subject: [PATCH] fix: Not allow the first character of an obfuscated to be a number or a non-Ascll --- config.yaml | 2 +- main.py | 9 +++++++-- utils/obfuscator.py | 13 +++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index 3ac5000..b9fa2b7 100644 --- a/config.yaml +++ b/config.yaml @@ -46,7 +46,7 @@ obfuscator: # 用于生成实体系文件键值混淆后字符串的字符 # 必须全是 Ascll 字符 obfuscate_ascll: - - 'abcdefghijklmn' + - 'abcdefg' json_funs: # 依据自然顺序排序 Json 键值 diff --git a/main.py b/main.py index c232dab..0c5dcfc 100644 --- a/main.py +++ b/main.py @@ -84,8 +84,13 @@ def main(): != (len(cfg.path) if isinstance(cfg.path, list) else 1) ): raise ValueError("The namespace needs to correspond to the resource package.") - if (cfg.obfuscate_jsonui or cfg.obfuscate_entity) and len(cfg.obfuscate_strs) < 1: - raise ValueError("At least one set of obfuscated strings.") + if (cfg.obfuscate_jsonui or cfg.obfuscate_entity): + if len(cfg.obfuscate_strs) < 1: + raise ValueError("At least one set of obfuscated strings.") + if not any(any(s.isascii() for s in p) for p in cfg.obfuscate_strs): + raise ValueError("No ASCII characters present in obfuscate_strs.") + if any(any(not s.isascii() for s in p) for p in cfg.obfuscate_ascll): + raise ValueError("obfuscate_ascll must be full of ascll characters.") try: asyncio.run(async_start_obf(cfg)) diff --git a/utils/obfuscator.py b/utils/obfuscator.py index 55606bb..21f8b1c 100644 --- a/utils/obfuscator.py +++ b/utils/obfuscator.py @@ -198,6 +198,10 @@ def gen_obfstr(data: str, enum: OBFStrType, link=0): enum.bi_map[data] = (rdstr := rd.choice(available_items)) return rdstr + need_ascll = enum in ENUM_LINKS[0] + ascll_pool = ( + tuple(tuple(s for s in p if s.isascii() and not ("0" <= s <= "9")) for p in cfg.obfuscate_strs) if need_ascll else None + ) str_pool = cfg.obfuscate_ascll if enum in ENUM_LINKS[1] else cfg.obfuscate_strs long = 2 times = 0 @@ -211,8 +215,13 @@ def gen_obfstr(data: str, enum: OBFStrType, link=0): long = long if factor == 1 else next(i for i in range(long, computed) if len(enum.bi_map) < factor**i) # gen - rdstr = "".join(rd.choices(rd.choice(tuple(str_pool)), k=long)) * rd.randint(1, 3) - if (rdstr in enum.bi_map.backward or ("0" <= rdstr[0] <= "9")) and long < computed: + pool_index = rd.randint(0, len(str_pool) - 1) + rdstr = ( + (rd.choices(ascll_pool[pool_index])[0] + "".join(rd.choices(str_pool[pool_index], k=long - 1))) + if need_ascll + else ("".join(rd.choices(str_pool[pool_index], k=long))) + ) * rd.randint(1, 3) + if (rdstr in enum.bi_map.backward) and long < computed: times += 1 if all(c == data[0] for c in data): rd.seed(data * rd.randint(1, 3))