尝试进行 Qt 测试,增加了 AI 人机调试工具 _console,以及 TransPyV 进行修正

This commit is contained in:
2026-07-21 14:41:22 +08:00
parent a277ded8d4
commit 135aa05485
311 changed files with 7084 additions and 2131 deletions

View File

@@ -171,7 +171,6 @@ def compute_file_sha1(pool: memhub.MemBuddy | t.CPtr,
bytes_read: t.CInt64T = f.read_all(buf, BUF_SIZE)
f.close()
if bytes_read <= 0:
stdlib.free(buf)
return None
# 原地去除 \rCRLF → LF与 Projectrans.py 文本模式读取一致
@@ -190,21 +189,17 @@ def compute_file_sha1(pool: memhub.MemBuddy | t.CPtr,
# 计算 SHA1
ctx: hashlib.sha1 | t.CPtr = hashlib.sha1()
if ctx is None:
stdlib.free(buf)
return None
ctx.update(buf)
digest: bytes = stdlib.malloc(hashlib.SHA1_DIGEST_LEN)
if digest is None:
stdlib.free(buf)
return None
ctx.final(digest)
# 转为十六进制字符串(取前 8 字节 = 16 个十六进制字符)
hex_buf: str = stdlib.malloc(17)
if hex_buf is None:
stdlib.free(buf)
stdlib.free(digest)
return None
for i in range(8):
hi: int = (digest[i] >> 4) & 0xF
@@ -218,9 +213,6 @@ def compute_file_sha1(pool: memhub.MemBuddy | t.CPtr,
else:
hex_buf[i * 2 + 1] = 'a' + (lo - 10)
hex_buf[16] = '\0'
# 释放临时缓冲区hex_buf 由调用者负责释放)
stdlib.free(buf)
stdlib.free(digest)
return hex_buf
@@ -253,8 +245,6 @@ def scan_directory_recursive(pool: memhub.MemBuddy | t.CPtr,
handle: win32base.HANDLE = win32file.FindFirstFileA(pattern, find_data)
if handle == win32base.INVALID_HANDLE_VALUE:
stdlib.free(pattern)
stdlib.free(find_data)
return 1
# 遍历所有文件和子目录
@@ -294,7 +284,6 @@ def scan_directory_recursive(pool: memhub.MemBuddy | t.CPtr,
prefix_len = string.strlen(rel_prefix)
rel_path: bytes = stdlib.malloc(prefix_len + fname_len + 2)
if rel_path is None:
stdlib.free(full_path)
break
if rel_prefix is not None and prefix_len > 0:
viperlib.snprintf(rel_path, prefix_len + fname_len + 2, "%s/%s", rel_prefix, fname)
@@ -323,21 +312,13 @@ def scan_directory_recursive(pool: memhub.MemBuddy | t.CPtr,
sha1: str = compute_file_sha1(pool, full_path)
if sha1 is not None:
add_file_entry(result, pool, full_path, rel_path, sha1)
# 释放 compute_file_sha1 返回的临时 hex_buf
stdlib.free(sha1)
# 释放本次迭代分配的路径缓冲区
stdlib.free(full_path)
stdlib.free(rel_path)
stdio.printf(" [scan] %s -> %s\n", rel_path, sha1)
# 继续搜索下一个文件
nxt: t.CInt = win32file.FindNextFileA(handle, find_data)
if nxt == 0:
if win32file.FindNextFileA(handle, find_data) == 0:
break
win32file.FindClose(handle)
stdlib.free(pattern)
stdlib.free(find_data)
return 0
@@ -360,8 +341,7 @@ def scan_includes(pool: memhub.MemBuddy | t.CPtr,
scan_directory_recursive(pool, includes_dir, None, result)
count: t.CInt = result.Count
stdio.printf("[Phase1] 扫描完成: %d 个 .py 文件\n", count)
stdio.printf("[Phase1] 扫描完成: %d 个 .py 文件\n", result.Count)
return result

View File

@@ -44,78 +44,47 @@ SRC_BUF_SIZE: t.CDefine = 1048576
def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
log: VLogger.Logger | t.CPtr) -> int:
"""Phase1: 扫描 includes 目录,按需翻译并生成 stub"""
stdio.printf("[P1 ENTER] mb=%p inc=%p temp=%p log=%p\n", mb, includes_dir, temp_dir, log)
stdio.fflush(0)
if includes_dir is None or temp_dir is None:
stdio.printf("[Phase1] includes_dir 或 temp_dir 为空,跳过\n")
return 1
stdio.printf("[P1] before log.banner\n")
stdio.fflush(0)
if log is not None:
log.banner("Phase1: 扫描 includes按需翻译")
stdio.printf("[P1] after log.banner\n")
stdio.fflush(0)
# 扫描 includes 目录
stdio.printf("[P1] before scan_includes: mb=%p inc=%s\n", mb, includes_dir)
stdio.fflush(0)
result: IncludesScanner.ScanResult | t.CPtr = IncludesScanner.scan_includes(mb, includes_dir)
stdio.printf("[P1] after scan_includes: result=%p\n", result)
stdio.fflush(0)
if result is None:
stdio.printf("[Phase1] 扫描失败\n")
return 1
stdio.printf("[P1] result.Count=%d\n", result.Count)
stdio.fflush(0)
stdio.printf("[Phase1] 共 %d 个文件\n", result.Count)
# 读取 _sha1_map.txt 获取需要的 includes SHA1 集合
# 优先使用 Projectrans.py 生成的 _sha1_map.txt含依赖分析只包含需要的 includes
# 若不存在,则从扫描结果生成(包含所有 includes可能导致结构体表溢出
sha1_set: str = stdlib.malloc(StubMerger.MAX_INCLUDES_SHA1 * 17)
stdio.printf("[P1] sha1_set=%p\n", sha1_set)
stdio.fflush(0)
if sha1_set is None:
stdio.printf("[Phase1] sha1_set 分配失败\n")
return 1
string.memset(sha1_set, 0, StubMerger.MAX_INCLUDES_SHA1 * 17)
stdio.printf("[P1] before _load_includes_sha1_set\n")
stdio.fflush(0)
set_count: int = StubMerger._load_includes_sha1_set(mb, temp_dir, sha1_set)
stdio.printf("[P1] set_count=%d\n", set_count)
stdio.fflush(0)
if set_count <= 0:
stdio.printf("[Phase1] _sha1_map.txt 不存在或为空,从扫描结果生成\n")
stdio.fflush(0)
stdio.printf("[P1] before WriteIncludesSha1Map\n")
stdio.fflush(0)
StubMerger.WriteIncludesSha1Map(mb, temp_dir, result, None, 0)
stdio.printf("[P1] after WriteIncludesSha1Map, before _load_includes_sha1_set\n")
stdio.fflush(0)
set_count = StubMerger._load_includes_sha1_set(mb, temp_dir, sha1_set)
stdio.printf("[P1] set_count2=%d\n", set_count)
stdio.fflush(0)
if set_count < 0:
stdio.printf("[Phase1] 无法加载 _sha1_map.txt跳过 Phase1\n")
return 1
stdio.printf("[Phase1] includes SHA1 集合: %d\n", set_count)
stdio.fflush(0)
# 构建模块 SHA1 映射(供跨模块函数调用名混淆使用)
td_len_p1map: t.CSizeT = string.strlen(temp_dir)
p1_sha1_arr: bytes = stdlib.malloc(StubMerger.MAX_INCLUDES * 17)
p1_mod_arr: bytes = stdlib.malloc(StubMerger.MAX_INCLUDES * 64)
p1_inc_count: int = 0
stdio.printf("[P1] before _BuildIncludesSha1Map\n")
stdio.fflush(0)
if p1_sha1_arr is not None and p1_mod_arr is not None:
p1_inc_count = StubMerger._BuildIncludesSha1Map(temp_dir, td_len_p1map, p1_sha1_arr, p1_mod_arr)
stdio.printf("[P1] after _BuildIncludesSha1Map: inc=%d\n", p1_inc_count)
stdio.fflush(0)
stdio.printf("[P1] before set_module_sha1_map\n")
stdio.fflush(0)
HandlesExprCall.set_module_sha1_map(p1_sha1_arr, p1_mod_arr, p1_inc_count)
stdio.printf("[P1] after set_module_sha1_map\n")
stdio.fflush(0)
# 初始化 AST 表(只需一次)
ast._init_tables(mb)

View File

@@ -8,7 +8,6 @@ import llvmlite
import w32.win32file as win32file
import w32.win32base as win32base
import w32.fileio as fileio
import w32.win32memory as win32memory
import viperlib
import sys
import ast
@@ -70,7 +69,6 @@ def _load_includes_sha1_set(pool: memhub.MemBuddy | t.CPtr,
f: fileio.File | t.CPtr = fileio.File(map_path, fileio.MODE.R)
if f.closed:
stdio.printf("[StubMerger] _sha1_map.txt 不存在: %s\n", map_path)
stdlib.free(map_path)
return -1
# 读取内容(使用 stdlib.malloc 避免 mbuddy 池耗尽)
@@ -78,13 +76,10 @@ def _load_includes_sha1_set(pool: memhub.MemBuddy | t.CPtr,
content: str = stdlib.malloc(MAP_BUF_SIZE)
if content is None:
f.close()
stdlib.free(map_path)
return -1
bytes_read: t.CInt64T = f.read_all(content, MAP_BUF_SIZE)
f.close()
stdlib.free(map_path)
if bytes_read <= 0:
stdlib.free(content)
return -1
content[bytes_read] = '\0'
@@ -117,7 +112,6 @@ def _load_includes_sha1_set(pool: memhub.MemBuddy | t.CPtr,
sha1_set[count * 17 + 16] = '\0'
count += 1
stdlib.free(content)
return count
@@ -195,8 +189,6 @@ def WriteIncludesSha1Map(mb: memhub.MemBuddy | t.CPtr, temp_dir: str,
written_count += 1
f.close()
stdlib.free(map_path)
stdlib.free(line_buf)
stdio.printf("[Phase1] 已写入 _sha1_map.txt (%d 个 includes)\n", written_count)
return 0
@@ -743,32 +735,14 @@ def _BuildIncludesSha1Map(temp_dir: str, td_len: t.CSizeT,
map_buf[map_br] = '\0'
else:
map_buf[STUB_READ_BUF_SIZE - 1] = '\0'
stdio.printf("[BISM] map_br=%lld\n", map_br)
stdio.fflush(0)
# 堆探针:测试堆是否已被之前的操作损坏
probe: bytes = stdlib.malloc(17)
stdio.printf("[BISM] probe malloc(17)=%p\n", probe)
stdio.fflush(0)
if probe is not None:
stdlib.free(probe)
stdio.printf("[BISM] probe free OK\n")
stdio.fflush(0)
count: int = 0
pos: t.CSizeT = 0
while pos < map_br and count < MAX_INCLUDES:
stdio.printf("[BISM] iter=%d pos=%d\n", count, pos)
stdio.fflush(0)
# 提取 SHA116 hex
sha1: t.CChar | t.CPtr = stdlib.malloc(17)
stdio.printf("[BISM] malloc(17)=%p\n", sha1)
stdio.fflush(0)
if sha1 is None:
break
hv: int = win32memory.HeapValidate(win32memory.GetProcessHeap(), 0, None)
stdio.printf("[BISM] HV after malloc(sha1)=%d\n", hv)
stdio.fflush(0)
string.strncpy(sha1, map_buf + pos, 16)
sha1[16] = '\0'
pos += 16
@@ -781,8 +755,6 @@ def _BuildIncludesSha1Map(temp_dir: str, td_len: t.CSizeT,
while pos < map_br and map_buf[pos] != '\n' and map_buf[pos] != '\r' and map_buf[pos] != '\0':
pos += 1
path_len: t.CSizeT = pos - path_start
stdio.printf("[BISM] path_len=%d\n", path_len)
stdio.fflush(0)
# 跳过 \r\n 或 \n
if pos < map_br and map_buf[pos] == '\r':
pos += 1
@@ -793,49 +765,25 @@ def _BuildIncludesSha1Map(temp_dir: str, td_len: t.CSizeT,
# 否则用户文件会被误判为 includes导致 is_module_imported 模块名不匹配而跳过加载
if path_len >= 9 and string.strncmp(map_buf + path_start, "includes/", 9) == 0:
path_buf: t.CChar | t.CPtr = stdlib.malloc(path_len + 1)
stdio.printf("[BISM] malloc(%d)=%p\n", path_len + 1, path_buf)
stdio.fflush(0)
if path_buf is not None:
string.strncpy(path_buf, map_buf + path_start, path_len)
path_buf[path_len] = '\0'
hv2: int = win32memory.HeapValidate(win32memory.GetProcessHeap(), 0, None)
stdio.printf("[BISM] HV after fill(path_buf)=%d\n", hv2)
stdio.fflush(0)
mod_name: str = _PathToModuleName(path_buf)
stdio.printf("[BISM] _PathToModuleName=%p\n", mod_name)
stdio.fflush(0)
hv3: int = win32memory.HeapValidate(win32memory.GetProcessHeap(), 0, None)
stdio.printf("[BISM] HV after _PathToModuleName=%d\n", hv3)
stdio.fflush(0)
stdlib.free(path_buf)
if mod_name is not None:
# 存储 sha1 和 mod_name 到数组中
idx: t.CSizeT = t.CSizeT(count) * 17
string.strcpy(sha1_list + idx, sha1)
hv4: int = win32memory.HeapValidate(win32memory.GetProcessHeap(), 0, None)
stdio.printf("[BISM] HV after strcpy(sha1_list)=%d\n", hv4)
stdio.fflush(0)
idx2: t.CSizeT = t.CSizeT(count) * 64
mn_len: t.CSizeT = string.strlen(mod_name)
stdio.printf("[BISM] mn_len=%d count=%d\n", mn_len, count)
stdio.fflush(0)
if mn_len < 64:
string.strcpy(mod_list + idx2, mod_name)
else:
string.strncpy(mod_list + idx2, mod_name, 63)
mod_list[idx2 + 63] = '\0'
hv5: int = win32memory.HeapValidate(win32memory.GetProcessHeap(), 0, None)
stdio.printf("[BISM] HV after strcpy(mod_list)=%d\n", hv5)
stdio.fflush(0)
stdlib.free(mod_name)
stdio.printf("[BISM] free(mod_name) OK\n")
stdio.fflush(0)
count += 1
stdio.printf("[BISM] before free(sha1=%p)\n", sha1)
stdio.fflush(0)
stdlib.free(sha1)
stdio.printf("[BISM] free(sha1) OK\n")
stdio.fflush(0)
stdlib.free(map_buf)
return count

View File

@@ -249,11 +249,7 @@ def main() -> int:
ph1_temp: str = Config.TempDir
if ph1_temp is None:
ph1_temp = "."
stdio.printf("[DBG MAIN] before Phase1: Inc=%s temp=%s\n", Config.IncludesDir, ph1_temp)
stdio.fflush(0)
Phase1.RunPhase1(mb, Config.IncludesDir, ph1_temp, log)
stdio.printf("[DBG MAIN] after Phase1\n")
stdio.fflush(0)
# 如果仅 Phase1不执行 Phase2直接退出
if do_phase2 == 0:
stdio.printf("[phase] Phase1 完成,退出\n")

View File

@@ -1,87 +1,11 @@
aba439b7882ad9d6:includes/argparse.py
3487a256b250bb74:includes/asm.py
4337fb260448bbe2:includes/ast/astaux.py
5dab8cb390496d22:includes/ast/base.py
47767b5026a8ee15:includes/ast/exprs.py
0c212981c180e7fb:includes/ast/lexer.py
4dd6b3f1427d1cc5:includes/ast/match.py
ee52c08239684346:includes/ast/parser.py
657e182b27c2a022:includes/ast/stmts.py
b547ac4f380bddb6:includes/ast/tokens.py
34548789d646f432:includes/ast/__init__.py
271ea3decb810db2:includes/atom.py
971e24c228377a9b:includes/base64.py
257e074b935c33b4:includes/binascii.py
ea80a4a724accbda:includes/builtins.py
ad6c853acfc0c146:includes/condition.py
9d8626a10208b8de:includes/event.py
96837bcc64032444:includes/hashlib/__init__.py
19f8024d10c828e8:includes/hashlib/__md5.py
0df65b8ed15664b0:includes/hashlib/__sha1.py
c9d54a4158f7f5a8:includes/hashlib/__sha256.py
6ff26590374ae6fc:includes/hashlib/__sha512.py
b8c66c8ff44eb874:includes/hashtable.py
6166aecc7fa7ad65:includes/hello.py
57288496f7c2d1ad:includes/json/__init__.py
240a9a4157959a9f:includes/json/__parser.py
20cd49775c100a38:includes/json/__writer.py
2d39c6c7d3557b3e:includes/linkedlist.py
946e087da91aaada:includes/llvmlite/__builder.py
89b3965176cd2407:includes/llvmlite/__function.py
95394ca8da0f655a:includes/llvmlite/__init__.py
21a7fcfc665f75ef:includes/llvmlite/__module.py
15f1ded02f3aa5bc:includes/llvmlite/__types.py
f9e36e2cd6fa659f:includes/llvmlite/__values.py
6b3bc463fd044545:includes/llvmlite/__verify.py
56d07ea7e30ef631:includes/lock.py
47775d5e50909338:includes/memhub.py
c3a6aed1f1fb8b1e:includes/numpy/__init__.py
13110effbb0bb06c:includes/os/path.py
d152115b49e50218:includes/os/_posix.py
a68b70f233541a7f:includes/os/_win32.py
76dd6c275aa72b3b:includes/os/__init__.py
93c1d18e35d188d6:includes/platmacro.py
e0f1d864a10b2e4d:includes/plist.py
6503c97dde0c79c4:includes/posix.py
b558d8d8f01f4825:includes/requests.py
da44924f0777c67a:includes/rwlock.py
abbcbd92436cc16a:includes/shutil.py
d7e3386b828acb66:includes/socket.py
b19a9e500f677f2e:includes/spinlock.py
71e0a3ffcb3ebfad:includes/stdarg.py
f5522571bcce7bcb:includes/stdint.py
6f62fe05c5ea1ceb:includes/stdio.py
90c53dd6db8d41cf:includes/stdlib.py
9474791561654346:includes/string.py
2da636c61863c815:includes/subprocess.py
b5a965302cded36b:includes/sys.py
85a6b24688da4405:includes/string.py
14d33679f7fadf1f:includes/testcheck.py
a7bc8c01684c0001:includes/this.py
285a822aa26bfbda:includes/vector.py
c9f4be41ca1cc2b4:includes/viperio.py
c3b259b4059f8668:includes/viperlib.py
3f7c5e78d8652535:includes/vipermath.py
c24f25b14b4bbd0a:includes/vipersimd.py
3624cfde3c5cb6cb:includes/viperstring.py
62cc01c2bb770ca3:includes/vrandom.py
87274c2b0190fb33:includes/vthreading.py
0035c95a18d4f8e8:includes/w32/fileio.py
7e529fe7a078cfef:includes/w32/win32base.py
bbdf3bbd4c3bc28c:includes/w32/win32console.py
f6b51804a0ba8ff0:includes/w32/win32file.py
72e2d5ccb7cedcf1:includes/w32/win32memory.py
067c78e9f121dce3:includes/w32/win32process.py
06f53cc594b4ac6c:includes/w32/win32sync.py
6446627d4f07a1b5:includes/w32/winsock2.py
1c46d554b3a3f9f3:includes/zlib/pyzlib.py
8ebed83a7817fa0c:includes/zlib/zchecksum.py
213348433fb01cc6:includes/zlib/zdef.py
90921d009fdd674c:includes/zlib/zdeflate.py
d541ade6afb689a5:includes/zlib/zhuff.py
451745df21e598af:includes/zlib/zinflate.py
d63d2c2a2bd9bd2a:includes/zlib/__init__.py
e3e7b6de8d7d8b03:includes/_dict.py
79b337e5ea8951e2:includes/_fakeduck.py
668790e6c9efdbae:includes/_list.py
b62eded2baf30423:includes/_variant.py
5b2e220c5bae60c9:includes/_withcontent.py

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -19,11 +19,12 @@
2da636c61863c815:includes/subprocess.py
2ed380190e9df89e:lib\core\Handles\HandlesAnnAssign.py
34548789d646f432:includes/ast\__init__.py
39daf57c7d4c5381:lib\constants\config.py
3a5e6e9aa900b2ca:lib\includes\t.py
3d3edda4a4e6c08b:lib\core\Handles\HandlesAssign.py
4020cac9bab5e9f1:lib\core\Handles\HandlesFunctions.py
4337fb260448bbe2:includes/ast\astaux.py
47767b5026a8ee15:includes/ast\exprs.py
47775d5e50909338:includes/memhub.py
48fa8cc758d3826b:lib\core\Handles\HandlesFor.py
49cf633017627a4a:lib\Projectrans\Config.py
4dd6b3f1427d1cc5:includes/ast\match.py
@@ -40,7 +41,7 @@
6f62fe05c5ea1ceb:includes/stdio.py
6ff26590374ae6fc:includes/hashlib\__sha512.py
71e0a3ffcb3ebfad:includes/stdarg.py
72e2d5ccb7cedcf1:includes/w32\win32memory.py
754640ce30cfebcc:includes/memhub.py
78bbe886bbe5ca8f:lib\core\Handles\HandlesImports.py
7e260c14d2712119:lib\core\Phase2.py
7e529fe7a078cfef:includes/w32\win32base.py
@@ -53,28 +54,30 @@
93c1d18e35d188d6:includes/platmacro.py
946e087da91aaada:includes/llvmlite\__builder.py
9474791561654346:includes/string.py
950028de389b7a7b:main.py
95394ca8da0f655a:includes/llvmlite\__init__.py
96837bcc64032444:includes/hashlib\__init__.py
9d90ff4bae201361:lib\core\StubMerger.py
a1a7dbafa49abfd1:lib\core\IncludesScanner.py
aba439b7882ad9d6:includes/argparse.py
ae0cc890f657076d:lib\core\Handles\HandlesExpr.py
af9484a65085bf4b:lib\core\Handles\HandlesNonlocal.py
b29b80b6106e4be7:lib\core\Handles\HandlesExprCall.py
b547ac4f380bddb6:includes/ast\tokens.py
b5a965302cded36b:includes/sys.py
b5d05dbd7fee36ef:lib\core\StubMerger.py
b8c66c8ff44eb874:includes/hashtable.py
bbdf3bbd4c3bc28c:includes/w32\win32console.py
bd82e3ca81546c76:lib\core\IncludesScanner.py
be12ff5e6da1b6ee:lib\includes\c.py
c3b259b4059f8668:includes/viperlib.py
c4f2d483ec0f4db5:lib\core\Handles\HandlesClassDef.py
c8d5323b1a4df063:lib\core\Phase1.py
c9d54a4158f7f5a8:includes/hashlib\__sha256.py
c9f4be41ca1cc2b4:includes/viperio.py
d1599ecbac5b6586:lib\core\BuildPipeline.py
d9322f0db660edd8:lib\core\Handles\HandlesReturn.py
db7c4a8f09d02a17:lib\core\Phase1.py
e3e7b6de8d7d8b03:includes/_dict.py
e5be27ae4fe7ce04:lib\core\Handles\HandlesEnum.py
ee52c08239684346:includes/ast\parser.py
f5522571bcce7bcb:includes/stdint.py
f6b51804a0ba8ff0:includes/w32\win32file.py
f8e903a99e1d0a57:main.py
f9e36e2cd6fa659f:includes/llvmlite\__values.py

Binary file not shown.