// 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 #include #include #include #include #include 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(value.size()), nullptr, 0); if (size <= 0) return {}; std::wstring result(static_cast(size), L'\0'); MultiByteToWideChar(CP_UTF8, 0, value.data(), static_cast(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(value.size()), nullptr, 0, nullptr, nullptr); if (size <= 0) return {}; std::string result(static_cast(size), '\0'); WideCharToMultiByte(CP_UTF8, 0, value.data(), static_cast(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(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(); }