Import CBB refresh verify r4 stability baseline

Preserve tested Verify source, authoritative READY checks, bounded bridge retries, diagnostics and failure-only reporting. Include 336-test suite and packaging assets; exclude live Mentor samples, field logs, backups and distributions.
This commit is contained in:
阿白叔 committed 2026-09-29 15:05:20 +08:00
commit 11a2b2e46e
130 files changed
+19267

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.20)
project(CbbStatusBridge32 LANGUAGES CXX)
set(CMAKE_MFC_FLAG 2)
add_executable(CbbStatusBridge32 CbbStatusBridge32.cpp)
target_compile_features(CbbStatusBridge32 PRIVATE cxx_std_17)
set_target_properties(CbbStatusBridge32 PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
if (MSVC)
target_compile_definitions(CbbStatusBridge32 PRIVATE _AFXDLL)
target_compile_options(CbbStatusBridge32 PRIVATE /EHsc /MD /utf-8)
endif()
add_executable(VerifyProbe32 VerifyProbe32.cpp)
target_compile_features(VerifyProbe32 PRIVATE cxx_std_17)
set_target_properties(VerifyProbe32 PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
if (MSVC)
target_compile_options(VerifyProbe32 PRIVATE /EHsc /MD /utf-8)
endif()
+243
View File
@@ -0,0 +1,243 @@
// CbbStatusBridge32 - read-only Mentor EE 7.9 Verify status probe.
//
// Build this file as a 32-bit /MD MFC application with the same toolchain
// family as Mentor EE 7.9 (mfc90). It is intentionally not built by the
// Python package on machines that only have a 64-bit compiler.
#include <windows.h>
#include <afx.h>
#include <afxstr.h>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using MentorString = ATL::CStringT<char, StrTraitMFC_DLL<char>>;
// The decorated export encodes the first CStringT by value; the library path
// is the only const reference parameter in the signature.
using IsVerifiedReuseBlock = bool(__cdecl*)(MentorString, int, const MentorString&);
static std::string jsonEscape(const std::string& value) {
std::ostringstream out;
for (const char ch : value) {
switch (ch) {
case '\\': out << "\\\\"; break;
case '"': out << "\\\""; break;
case '\n': out << "\\n"; break;
case '\r': out << "\\r"; break;
default: out << ch; break;
}
}
return out.str();
}
static std::string field(const std::string& json, const char* key) {
const std::string needle = std::string("\"") + key + "\"";
const auto keyPos = json.find(needle);
if (keyPos == std::string::npos) return {};
const auto colon = json.find(':', keyPos + needle.size());
if (colon == std::string::npos) return {};
const auto first = json.find('"', colon + 1);
if (first == std::string::npos) return {};
std::string result;
for (size_t index = first + 1; index < json.size(); ++index) {
const char ch = json[index];
if (ch == '"') return result;
if (ch != '\\') {
result.push_back(ch);
continue;
}
if (++index >= json.size()) return {};
switch (json[index]) {
case '"': result.push_back('"'); break;
case '\\': result.push_back('\\'); break;
case '/': result.push_back('/'); break;
case 'b': result.push_back('\b'); break;
case 'f': result.push_back('\f'); break;
case 'n': result.push_back('\n'); break;
case 'r': result.push_back('\r'); break;
case 't': result.push_back('\t'); break;
default: return {};
}
}
return {};
}
static int blockType(const std::string& value) {
// Mentor's eReuseBlockType uses 0 for the logical-physical (RULP/LP)
// reusable-block partition. Keep numeric input available for probing.
if (value == "RULP" || value == "LP" || value.empty()) return 0;
if (value == "RUL") return 1;
try { return std::stoi(value); } catch (...) { return 0; }
}
static std::wstring widen(const std::string& value) {
if (value.empty()) return {};
const int size = MultiByteToWideChar(CP_UTF8, 0, value.data(), static_cast<int>(value.size()), nullptr, 0);
if (size <= 0) return {};
std::wstring result(static_cast<size_t>(size), L'\0');
MultiByteToWideChar(CP_UTF8, 0, value.data(), static_cast<int>(value.size()), result.data(), size);
return result;
}
static std::string dllPath() {
const char* configured = std::getenv("LMCDLL70_PATH");
if (configured && *configured) return configured;
const char* sddHome = std::getenv("SDD_HOME");
if (sddHome && *sddHome) return std::string(sddHome) + "\\common\\win32\\lib\\LMCDLL70.dll";
return "LMCDLL70.dll";
}
static void printError(const std::string& message) {
std::cout << "{\"ok\":false,\"error\":\"" << jsonEscape(message) << "\"}" << std::endl;
}
static void trace(const char* message) {
const char* enabled = std::getenv("CBB_STATUS_BRIDGE_TRACE");
if (enabled && std::string(enabled) == "1") {
std::cerr << "[status-bridge] " << message << std::endl;
}
}
static bool requestIsValid(const std::string& request, std::string& lmc,
std::string& name, std::string& type,
std::string& requestId) {
const std::string op = field(request, "op");
lmc = field(request, "lmc_file");
name = field(request, "block_name");
type = field(request, "block_type");
requestId = field(request, "request_id");
return op == "is_verified" && !requestId.empty() && !lmc.empty() && !name.empty();
}
static void handleRequest(const std::string& request, IsVerifiedReuseBlock fn,
bool serverMode) {
std::string lmc;
std::string name;
std::string type;
std::string requestId;
if (!requestIsValid(request, lmc, name, type, requestId)) {
printError("请求必须包含 op=is_verified、request_id、lmc_file 和 block_name");
return;
}
try {
bool verified = false;
// Keep MFC CString instances alive through the private call. In
// server mode the DLL remains loaded until process exit.
{
const MentorString block(name.c_str());
const MentorString library(lmc.c_str());
trace("calling-status-function");
verified = fn(block, blockType(type), library);
trace("status-function-returned");
}
trace("cstring-scope-ended");
std::cout << "{\"ok\":true,\"request_id\":\""
<< jsonEscape(requestId) << "\",\"block_name\":\""
<< jsonEscape(name) << "\",\"lmc_file\":\""
<< jsonEscape(lmc) << "\",\"status\":\""
<< (verified ? "READY" : "PENDING")
<< "\",\"source\":\"IsVerifiedReuseBlock\",\"raw_status\":"
<< (verified ? "1" : "0") << "}" << std::endl;
} catch (...) {
// Do not unload LMCDLL70 after entering Mentor's private MFC code.
// The server can continue with the next isolated request; the process
// owns the module lifetime and the OS reclaims it at exit.
printError("调用 Mentor 私有状态函数时发生异常");
}
}
static int runServer(HMODULE module, FARPROC address) {
(void)module;
const auto fn = reinterpret_cast<IsVerifiedReuseBlock>(address);
std::string request;
trace("server-ready");
while (std::getline(std::cin, request)) {
if (request.empty()) {
printError("空请求");
continue;
}
handleRequest(request, fn, true);
std::cout.flush();
}
trace("server-eof");
return 0;
}
int main(int argc, char** argv) {
const bool codecTest = argc > 1 && std::string(argv[1]) == "--codec-test";
if (codecTest) {
std::string request;
if (!std::getline(std::cin, request)) return 5;
const std::string requestId = field(request, "request_id");
const std::string lmc = field(request, "lmc_file");
const std::string name = field(request, "block_name");
if (requestId.empty() || lmc.empty() || name.empty()) return 6;
std::cout << "{\"request_id\":\"" << jsonEscape(requestId)
<< "\",\"lmc_file\":\"" << jsonEscape(lmc)
<< "\",\"block_name\":\"" << jsonEscape(name)
<< "\"}" << std::endl;
return 0;
}
const bool probeOnly = argc > 1 && std::string(argv[1]) == "--probe-only";
const bool serverMode = argc > 1 && std::string(argv[1]) == "--server";
const std::string path = dllPath();
trace("starting");
HMODULE module = LoadLibraryW(widen(path).c_str());
trace(module ? "dll-loaded" : "dll-load-failed");
if (!module) {
printError("无法加载 LMCDLL70.dll: " + path);
return 2;
}
const char* decorated =
"?IsVerifiedReuseBlock@reusableBlocks@@YA_NV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@W4eReuseBlockType@1@ABV23@@Z";
auto address = GetProcAddress(module, decorated);
trace(address ? "export-found" : "export-missing");
if (!address) {
FreeLibrary(module);
printError("LMCDLL70.dll 中没有 IsVerifiedReuseBlock 导出");
return 3;
}
if (probeOnly) {
FreeLibrary(module);
std::cout << "{\"ok\":true,\"probe\":true,\"export_found\":true,\"source\":\"IsVerifiedReuseBlock\"}" << std::endl;
return 0;
}
// Calling a private MFC ABI is opt-in. The default probe is harmless;
// production integration must explicitly enable this after compiling and
// validating the helper with the target Mentor installation.
const char* allow = std::getenv("CBB_STATUS_BRIDGE_ALLOW_PRIVATE");
if (!allow || std::string(allow) != "1") {
FreeLibrary(module);
printError("私有 MFC 状态调用未启用;仅完成导出探测");
return 4;
}
if (serverMode) {
return runServer(module, address);
}
std::string request;
trace("waiting-for-request");
if (!std::getline(std::cin, request)) {
FreeLibrary(module);
printError("缺少 JSON 请求");
return 5;
}
trace("request-parsed");
const auto fn = reinterpret_cast<IsVerifiedReuseBlock>(address);
std::string lmc;
std::string name;
std::string type;
std::string requestId;
if (!requestIsValid(request, lmc, name, type, requestId)) {
FreeLibrary(module);
printError("请求必须包含 op=is_verified、request_id、lmc_file 和 block_name");
return 6;
}
handleRequest(request, fn, false);
return 0;
}
+70
View File
@@ -0,0 +1,70 @@
# CBB 状态桥接试验
这是主程序使用的隔离只读状态桥。它不修改中心库,只调用
`IsVerifiedReuseBlock` 读取权威 `READY/PENDING` 状态。
## 编译前提
- 32 位 Visual C++ 工具链;
- 与 Mentor EE 7.9 兼容的 MFC/ATL ABI;
- `LMCDLL70.dll` 的 32 位运行环境。
必须使用 32 位 MSVC/MFC 构建;64 位或 MinGW 产物不能替代经过验证的 x86 MFC 版本。
在具备 x86 MSVC 的机器上,从此目录执行类似命令:
```powershell
cmake -S . -B build-x86 -A Win32
cmake --build build-x86 --config Release
```
## 只读导出探测
默认只建议运行探测模式:
```powershell
$env:SDD_HOME = 'D:\Mentor\7.9.5EE\SDD_HOME'
.\build-x86\Release\CbbStatusBridge32.exe --probe-only
```
成功只证明导出存在,不会调用状态函数。
真正调用私有函数前必须显式设置:
```powershell
$env:CBB_STATUS_BRIDGE_ALLOW_PRIVATE = '1'
```
主程序已通过 `BatchStatusSession` 接入该桥。UI 默认读取权威状态;旧图标/文件证据
仅在显式设置 `CBB_STATUS_BRIDGE_MODE=legacy` 时使用。任何现场调用仍应保留 JSONL
检查点、原始响应和 DLL 路径。
## 已验证的真实调用
桥已用本机 `D:\Mentor\7.9.5EE\SDD_HOME\common\win32\lib\LMCDLL70.dll`
对中心库副本和生产库进行只读调用。`RULP`/`LP` 对应 `eReuseBlockType = 0`;
调用 `IsVerifiedReuseBlock` 能返回 `READY` 或 `PENDING`,结果与已知人工状态一致。
桥默认是一次性进程;也支持 `--server` 常驻 JSONL 模式。常驻模式从标准输入逐行
读取 `op=is_verified`、`request_id`、`lmc_file`、`block_name`、`block_type`,每行输出
一个 JSON 响应并立即刷新。成功响应回显 `request_id`、`block_name` 和 `lmc_file`;
Python 客户端会核对三者,拒绝错序或串项响应。DLL 只加载一次,请求串行处理;单条
坏请求会返回 `ok:false` 并继续处理后续请求。
调用 Mentor 私有 MFC 函数后不主动 `FreeLibrary`,由操作系统在进程退出时回收 DLL;
主动卸载会触发 Mentor 模块级状态的堆异常或阻塞。常驻模式尤其必须遵守这一点。
## Verify 导出只读探测
`bin\\VerifyProbe32.exe --probe-exports` 只加载 `LMCDLL70.dll` 和
`LibManagerDBPI.dll`,枚举 `IsVerifiedReuseBlock`、
`GetStatusRBInContextOfCL`、`VerifyReuseBlock`、`UnVerifyReuseBlock` 与
`GetReusableCircuitVerificationStatus` 的导出地址,并输出一行 JSON。它不会调用
任何 Verify/UnVerify 写接口,响应中的 `write_call.enabled` 始终为 `false`。
探测桥也不会主动卸载 Mentor DLL。该 DLL 的 MFC/DBPI 模块状态在卸载时可能触发堆
损坏,因此由操作系统在短进程退出时统一回收。探测结果只能证明导出存在,不能证明
`CFilename` ABI 已经可以安全构造。
经过验证的可执行文件位于 `bin\\CbbStatusBridge32.exe`。主 UI 的读取和 Verify 后复查
默认使用该桥;执行结果只有在关闭 PCB 后再次读到 `READY` 才能保留为 `PASS`。
+148
View File
@@ -0,0 +1,148 @@
// VerifyProbe32 - read-only export inventory for Mentor EE 7.9.
//
// This helper intentionally does not call VerifyReuseBlock or
// UnVerifyReuseBlock. Those exports use Mentor's private CFilename MFC ABI;
// the probe records that the symbols exist so a separate isolated ABI study
// can be performed without changing a library.
#include <windows.h>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
struct ExportSpec {
const char* key;
const char* module;
const char* decorated;
};
static const ExportSpec kExports[] = {
{"IsVerifiedReuseBlock", "LMCDLL70.dll",
"?IsVerifiedReuseBlock@reusableBlocks@@YA_NV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@W4eReuseBlockType@1@ABV23@@Z"},
{"GetStatusRBInContextOfCL", "LMCDLL70.dll",
"?GetStatusRBInContextOfCL@reusableBlocks@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4eReuseBlockType@1@ABVDatabase@ODB@@@Z"},
{"VerifyReuseBlock", "LMCDLL70.dll",
"?VerifyReuseBlock@reusableBlocks@@YA_NABV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@W4eReuseBlockType@1@ABVCFilename@@@Z"},
{"UnVerifyReuseBlock", "LMCDLL70.dll",
"?UnVerifyReuseBlock@reusableBlocks@@YA_NABV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@W4eReuseBlockType@1@ABVCFilename@@_N@Z"},
{"GetReusableCircuitVerificationStatus", "LibManagerDBPI.dll",
"?GetReusableCircuitVerificationStatus@@YAHABV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@0HAAH@Z"},
};
static std::string jsonEscape(const std::string& value) {
std::ostringstream out;
for (const char ch : value) {
switch (ch) {
case '\\': out << "\\\\"; break;
case '"': out << "\\\""; break;
case '\n': out << "\\n"; break;
case '\r': out << "\\r"; break;
default: out << ch; break;
}
}
return out.str();
}
static std::wstring widen(const std::string& value) {
if (value.empty()) return {};
const int size = MultiByteToWideChar(CP_UTF8, 0, value.data(),
static_cast<int>(value.size()), nullptr, 0);
if (size <= 0) return {};
std::wstring result(static_cast<size_t>(size), L'\0');
MultiByteToWideChar(CP_UTF8, 0, value.data(), static_cast<int>(value.size()),
result.data(), size);
return result;
}
static std::string narrow(const std::wstring& value) {
if (value.empty()) return {};
const int size = WideCharToMultiByte(CP_UTF8, 0, value.data(),
static_cast<int>(value.size()), nullptr, 0,
nullptr, nullptr);
if (size <= 0) return {};
std::string result(static_cast<size_t>(size), '\0');
WideCharToMultiByte(CP_UTF8, 0, value.data(), static_cast<int>(value.size()),
result.data(), size, nullptr, nullptr);
return result;
}
static std::string envValue(const char* name) {
const char* value = std::getenv(name);
return value && *value ? value : std::string();
}
static std::string lmPath() {
const std::string configured = envValue("LMCDLL70_PATH");
if (!configured.empty()) return configured;
const std::string sddHome = envValue("SDD_HOME");
if (!sddHome.empty()) return sddHome + "\\common\\win32\\lib\\LMCDLL70.dll";
return "LMCDLL70.dll";
}
static std::string dbPath(const std::string& lm) {
const std::string configured = envValue("LIBMANAGERDBPI_PATH");
if (!configured.empty()) return configured;
const size_t slash = lm.find_last_of("\\/");
if (slash == std::string::npos) return "LibManagerDBPI.dll";
return lm.substr(0, slash + 1) + "LibManagerDBPI.dll";
}
static std::string address(FARPROC value) {
if (!value) return {};
std::ostringstream out;
out << "0x" << std::hex << std::uppercase
<< reinterpret_cast<unsigned long>(value);
return out.str();
}
static void errorResponse(const std::string& message) {
std::cout << "{\"ok\":false,\"error\":\""
<< jsonEscape(message) << "\"}" << std::endl;
}
static int runProbe() {
const std::string lm = lmPath();
const std::string db = dbPath(lm);
HMODULE lmModule = LoadLibraryW(widen(lm).c_str());
if (!lmModule) {
errorResponse("无法加载 LMCDLL70.dll: " + lm);
return 2;
}
HMODULE dbModule = LoadLibraryW(widen(db).c_str());
std::ostringstream out;
out << "{\"ok\":true,\"probe\":\"exports\",\"dll_path\":\""
<< jsonEscape(lm) << "\",\"architecture\":\"x86\",\"modules\":{";
out << "\"LMCDLL70.dll\":{\"loaded\":true,\"path\":\""
<< jsonEscape(lm) << "\"},\"LibManagerDBPI.dll\":{\"loaded\":"
<< (dbModule ? "true" : "false") << ",\"path\":\""
<< jsonEscape(db) << "\"}},\"exports\":{";
for (size_t index = 0; index < sizeof(kExports) / sizeof(kExports[0]); ++index) {
const ExportSpec& spec = kExports[index];
HMODULE module = std::string(spec.module) == "LMCDLL70.dll" ? lmModule : dbModule;
FARPROC proc = module ? GetProcAddress(module, spec.decorated) : nullptr;
if (index) out << ',';
out << '"' << spec.key << "\":{\"module\":\"" << spec.module
<< "\",\"found\":" << (proc ? "true" : "false")
<< ",\"address\":\"" << address(proc) << "\"}";
}
out << "},\"write_call\":{\"enabled\":false,\"reason\":\"CFilename MFC ABI has not been reconstructed; this probe never calls VerifyReuseBlock or UnVerifyReuseBlock\"}}";
std::cout << out.str() << std::endl;
// Do not call FreeLibrary here. Mentor's module graph owns process-wide
// MFC/DBPI state; unloading it, even without calling a private function,
// can terminate the helper with STATUS_HEAP_CORRUPTION. The operating
// system reclaims the modules when this short-lived probe exits.
return 0;
}
int main(int argc, char** argv) {
if (argc != 2 || std::string(argv[1]) != "--probe-exports") {
errorResponse("仅支持只读参数 --probe-exports");
return 1;
}
return runProbe();
}
Binary file not shown.
Binary file not shown.