尝试进行 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

@@ -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