research: verify headless replacement and native parts query CLI
This commit is contained in:
1 parent
4a5c5df0f5
commit
cf0ba739c6
5 files changed
+679
-3
No files matched your search
@@ -0,0 +1,358 @@
|
||||
{
|
||||
"research_only": true,
|
||||
"production_backend_changed": false,
|
||||
"native_query": {
|
||||
"dll": "PartsDB40.dll",
|
||||
"sha256": "f24d44eaa13f28550317711df6a6241e227ae56805baa73c8f3020bde513ad0d",
|
||||
"bitness": 32,
|
||||
"factory_calling_convention": "cdecl, HRESULT(void**)",
|
||||
"member_calling_convention": "stdcall, explicit interface pointer first",
|
||||
"loader_mode": 0,
|
||||
"queries": [
|
||||
{
|
||||
"part": "4100-CA0000-T0",
|
||||
"exit_code": 0,
|
||||
"seconds": 0.29699999999138527,
|
||||
"copy_database_unchanged": true,
|
||||
"result": {
|
||||
"requested": "4100-CA0000-T0",
|
||||
"matches": [
|
||||
{
|
||||
"index": 1783,
|
||||
"number": "4100-CA0000-T0",
|
||||
"name": "RESC1608N",
|
||||
"label": "0R",
|
||||
"symbols_hr": 0,
|
||||
"symbols": [
|
||||
"skyworth:res01"
|
||||
]
|
||||
}
|
||||
],
|
||||
"enumerated": 1021,
|
||||
"last_hr": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"part": "DX_RESEARCH_PART_DOES_NOT_EXIST",
|
||||
"exit_code": 0,
|
||||
"seconds": 0.32800000000861473,
|
||||
"copy_database_unchanged": true,
|
||||
"result": {
|
||||
"requested": "DX_RESEARCH_PART_DOES_NOT_EXIST",
|
||||
"matches": [],
|
||||
"enumerated": 1021,
|
||||
"last_hr": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"part": "4300-CC1040-7100",
|
||||
"exit_code": 0,
|
||||
"seconds": 0.3129999999946449,
|
||||
"copy_database_unchanged": true,
|
||||
"result": {
|
||||
"requested": "4300-CC1040-7100",
|
||||
"matches": [
|
||||
{
|
||||
"index": 1336,
|
||||
"number": "4300-CC1040-7100",
|
||||
"name": "CAPC0603X30N",
|
||||
"label": "C/100NF/16V +/-10% X5R",
|
||||
"symbols_hr": 0,
|
||||
"symbols": [
|
||||
"skyworth:cap01"
|
||||
]
|
||||
}
|
||||
],
|
||||
"enumerated": 885,
|
||||
"last_hr": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"part": "中文料号测试",
|
||||
"exit_code": 0,
|
||||
"seconds": 0.375,
|
||||
"copy_database_unchanged": true,
|
||||
"result": {
|
||||
"requested": "中文料号测试",
|
||||
"matches": [],
|
||||
"enumerated": 1021,
|
||||
"last_hr": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"initial_query_samples": [
|
||||
{
|
||||
"part": "4100-CA0000-T0",
|
||||
"exit_code": 0,
|
||||
"seconds": 0.3129999999946449,
|
||||
"copy_database_unchanged": true,
|
||||
"result": {
|
||||
"matches": [
|
||||
{
|
||||
"index": 1783,
|
||||
"number": "4100-CA0000-T0",
|
||||
"name": "RESC1608N",
|
||||
"label": "0R",
|
||||
"symbols_hr": 0,
|
||||
"symbols": [
|
||||
"skyworth:res01"
|
||||
]
|
||||
}
|
||||
],
|
||||
"enumerated": 1021,
|
||||
"last_hr": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"part": "DX_RESEARCH_PART_DOES_NOT_EXIST",
|
||||
"exit_code": 0,
|
||||
"seconds": 0.35899999999674037,
|
||||
"copy_database_unchanged": true,
|
||||
"result": {
|
||||
"matches": [],
|
||||
"enumerated": 1021,
|
||||
"last_hr": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"part": "4300-CC1040-7100",
|
||||
"exit_code": 0,
|
||||
"seconds": 0.39100000000325963,
|
||||
"copy_database_unchanged": true,
|
||||
"result": {
|
||||
"matches": [
|
||||
{
|
||||
"index": 1336,
|
||||
"number": "4300-CC1040-7100",
|
||||
"name": "CAPC0603X30N",
|
||||
"label": "C/100NF/16V +/-10% X5R",
|
||||
"symbols_hr": 0,
|
||||
"symbols": [
|
||||
"skyworth:cap01"
|
||||
]
|
||||
}
|
||||
],
|
||||
"enumerated": 885,
|
||||
"last_hr": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"negative_module_test": {
|
||||
"exit_code": 2,
|
||||
"rejected_missing_module": true,
|
||||
"result": {
|
||||
"load_error": 126
|
||||
}
|
||||
},
|
||||
"source": "tools/research/native_parts_query.cpp",
|
||||
"source_sha256": "01da76c3101461687e514dc30694cace634e81487b56b571fe9ea7ca4e163caf",
|
||||
"reviewed_fixes": [
|
||||
"Propagate metadata HRESULT failures and validate symbol pointer/count.",
|
||||
"Encode native ANSI metadata to UTF-8, releasing enum/database/module through RAII.",
|
||||
"Assert runner exit status, PDB copy hashes, parsed JSON and expected query data."
|
||||
],
|
||||
"encoding_scope": "Chinese requested-name roundtrip passed; actual non-ASCII PDB metadata code-page assumption is not independently certified."
|
||||
},
|
||||
"installed_list_cli": {
|
||||
"exe": "ListWGLib.exe",
|
||||
"arguments": "<library-copy.lmc> PDB <output.txt>",
|
||||
"exit_code": 0,
|
||||
"catalog_rows": 9436,
|
||||
"partitions": 20,
|
||||
"source_hashes_unchanged": true
|
||||
},
|
||||
"replacement": {
|
||||
"scope": "Audio test copy; same skyworth:res01 symbol; one gate; matching per-label pin-number map",
|
||||
"verified": true,
|
||||
"source_hashes_unchanged": true,
|
||||
"changed_refdes": [
|
||||
"RV05",
|
||||
"RV14",
|
||||
"RV02"
|
||||
],
|
||||
"readback": {
|
||||
"RV02": {
|
||||
"uid": "$2I1428",
|
||||
"part": "4100-CA0000-T0",
|
||||
"value": "2.2K"
|
||||
},
|
||||
"RV14": {
|
||||
"uid": "$2I1766",
|
||||
"part": "4100-CA0000-T0",
|
||||
"value": "0R/NC"
|
||||
},
|
||||
"RV19": {
|
||||
"uid": "$2I1885",
|
||||
"part": "4100-CA1030-T7",
|
||||
"value": "10K/NC"
|
||||
},
|
||||
"RV05": {
|
||||
"uid": "$2I2014",
|
||||
"part": "4100-CA0000-T0",
|
||||
"value": "0R"
|
||||
},
|
||||
"RV11": {
|
||||
"uid": "$2I2022",
|
||||
"part": "4100-CA0000-T7",
|
||||
"value": "0R"
|
||||
},
|
||||
"RV08": {
|
||||
"uid": "$2I820",
|
||||
"part": "4100-CA1030-T7",
|
||||
"value": "10K/NC"
|
||||
}
|
||||
},
|
||||
"geometry_before": {
|
||||
"RV02": {
|
||||
"location": [
|
||||
1090,
|
||||
1490
|
||||
],
|
||||
"orientation": 3,
|
||||
"scale": 1.0
|
||||
},
|
||||
"RV14": {
|
||||
"location": [
|
||||
1540,
|
||||
1000
|
||||
],
|
||||
"orientation": 1,
|
||||
"scale": 1.0
|
||||
},
|
||||
"RV05": {
|
||||
"location": [
|
||||
1230,
|
||||
1320
|
||||
],
|
||||
"orientation": 0,
|
||||
"scale": 1.0
|
||||
}
|
||||
},
|
||||
"attribute_styles_saved_and_reopened_verified": true,
|
||||
"target_pin_connections_saved_and_reopened_verified": true,
|
||||
"graph_comparison": {
|
||||
"hier": {
|
||||
"verified": true,
|
||||
"components": 57,
|
||||
"pins": 103,
|
||||
"nets": 22,
|
||||
"unchanged_components": 54,
|
||||
"rv05_exactly_matches_native_gui": true,
|
||||
"other_targets_change_only_expected_material_value_and_base_pin_fields": true,
|
||||
"all_connections_match_native_baseline": true
|
||||
},
|
||||
"flat": {
|
||||
"verified": true,
|
||||
"components": 57,
|
||||
"pins": 103,
|
||||
"nets": 22,
|
||||
"unchanged_components": 54,
|
||||
"rv05_exactly_matches_native_gui": true,
|
||||
"other_targets_change_only_expected_material_value_and_base_pin_fields": true,
|
||||
"all_connections_match_native_baseline": true
|
||||
}
|
||||
},
|
||||
"worker_phase_seconds": [
|
||||
{
|
||||
"phase": "open",
|
||||
"seconds": 44.187
|
||||
},
|
||||
{
|
||||
"phase": "validate_native_library_metadata",
|
||||
"seconds": 0.11
|
||||
},
|
||||
{
|
||||
"phase": "create_target_template",
|
||||
"seconds": 16.797
|
||||
},
|
||||
{
|
||||
"phase": "replace_selected_in_place",
|
||||
"seconds": 14.625
|
||||
},
|
||||
{
|
||||
"phase": "synchronize_pin_properties",
|
||||
"seconds": 10.172
|
||||
},
|
||||
{
|
||||
"phase": "delete_template_and_verify",
|
||||
"seconds": 11.031
|
||||
},
|
||||
{
|
||||
"phase": "save_close",
|
||||
"seconds": 3.875
|
||||
},
|
||||
{
|
||||
"phase": "reopen_and_verify",
|
||||
"seconds": 38.922
|
||||
}
|
||||
],
|
||||
"cad_startup_seconds": 66.89100000000326,
|
||||
"cad_exit_code": 0,
|
||||
"quit_helper_exit_code": 0,
|
||||
"cleanup": {
|
||||
"desktop": "dx-f1e65335ec1a4b369275b1a4d73d1db0",
|
||||
"processes": [
|
||||
{
|
||||
"pid": 48148,
|
||||
"job_active_processes": 0,
|
||||
"exit_code": 0,
|
||||
"descendant_pids": [],
|
||||
"unconfirmed_descendant_handles": 0,
|
||||
"process_handle_closed": true,
|
||||
"job_handle_closed": true,
|
||||
"errors": []
|
||||
},
|
||||
{
|
||||
"pid": 32732,
|
||||
"job_active_processes": 0,
|
||||
"exit_code": 0,
|
||||
"descendant_pids": [],
|
||||
"unconfirmed_descendant_handles": 0,
|
||||
"process_handle_closed": true,
|
||||
"job_handle_closed": true,
|
||||
"errors": []
|
||||
},
|
||||
{
|
||||
"pid": 50964,
|
||||
"job_active_processes": 0,
|
||||
"exit_code": 0,
|
||||
"descendant_pids": [],
|
||||
"unconfirmed_descendant_handles": 0,
|
||||
"process_handle_closed": true,
|
||||
"job_handle_closed": true,
|
||||
"errors": []
|
||||
},
|
||||
{
|
||||
"pid": 50144,
|
||||
"job_active_processes": 0,
|
||||
"exit_code": 0,
|
||||
"descendant_pids": [
|
||||
42508
|
||||
],
|
||||
"unconfirmed_descendant_handles": 0,
|
||||
"process_handle_closed": true,
|
||||
"job_handle_closed": true,
|
||||
"errors": []
|
||||
}
|
||||
],
|
||||
"desktop_handle_closed": true,
|
||||
"desktop_confirmation": {
|
||||
"desktop": "dx-f1e65335ec1a4b369275b1a4d73d1db0",
|
||||
"released": true,
|
||||
"elapsed_seconds": 0.014999999999417923,
|
||||
"budget_seconds": 5.0,
|
||||
"caller_pid": 50324,
|
||||
"caller_thread_id": 46800
|
||||
},
|
||||
"errors": []
|
||||
},
|
||||
"clean": true,
|
||||
"cleanup_errors": []
|
||||
},
|
||||
"limitations": [
|
||||
"RV05 has an exact GUI baseline; RV14/RV02 have expected-field and topology checks, not separate full GUI baselines.",
|
||||
"Packager/PCB synchronization was not executed.",
|
||||
"No arbitrary-symbol, multi-gate, hierarchy-occurrence, multi-project, cancellation or production throughput claim.",
|
||||
"The existing hierarchical inventory misses some instance overrides; this must be handled before promoting the new backend."
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"source_hashes_unchanged": true,
|
||||
"cases": [
|
||||
{
|
||||
"case": "add-part-invalid",
|
||||
"error": null,
|
||||
"returned": null,
|
||||
"changed_count": 1,
|
||||
"dialogs": [],
|
||||
"call_seconds": 1.110000000000582,
|
||||
"changed_count_certified": true
|
||||
},
|
||||
{
|
||||
"case": "ccomp-colon",
|
||||
"error": null,
|
||||
"returned": false,
|
||||
"changed_count": 0,
|
||||
"dialogs": [
|
||||
{
|
||||
"title": "Change Component",
|
||||
"text": [
|
||||
"自定义 2",
|
||||
"确定(&O)",
|
||||
"取消(&C)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"call_seconds": 0.3600000000005821,
|
||||
"changed_count_certified": true
|
||||
},
|
||||
{
|
||||
"case": "ccomp-colon-preserve",
|
||||
"error": "AttributeError(\"'NoneType' object has no attribute 'Query'\")",
|
||||
"returned": true,
|
||||
"changed_count": null,
|
||||
"dialogs": [
|
||||
{
|
||||
"title": "DxDesigner",
|
||||
"text": [
|
||||
"确定",
|
||||
"提交数据库事务被拒。\n正在重新导入项目。"
|
||||
]
|
||||
}
|
||||
],
|
||||
"call_seconds": 0.6879999999946449,
|
||||
"changed_count_certified": false,
|
||||
"note": "Active view disappeared after transaction-rejected dialog. Final component state of the disposable copy is not certified."
|
||||
}
|
||||
],
|
||||
"invalid_part_creation": {
|
||||
"$2I2277": {
|
||||
"uid": "$2I2277",
|
||||
"refdes": "R?",
|
||||
"part": "DX_RESEARCH_PART_DOES_NOT_EXIST",
|
||||
"label": "",
|
||||
"value": "",
|
||||
"cell": "",
|
||||
"symbol": "res01",
|
||||
"location": [
|
||||
5000,
|
||||
5000
|
||||
],
|
||||
"orientation": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# 替换 CLI 替代:核心调用与无弹窗实验
|
||||
|
||||
这份记录继续验证本机 Mentor 7.9.5EE 的实际替换路径。原生清单 CLI 已接入;这里研究的是写入替换,不把查询成功视为替换成功。正式替换后端未切换,没有打包或发布。
|
||||
这份记录继续验证本机 Mentor 7.9.5EE 的实际替换路径。**同符号、单 gate、相同引脚映射的无弹窗替换已有真实验证路径**:原生 DLL 查询物料 → COM 在原 UID 上应用库属性和引脚号 → 保存重开 → 原生 CLI 独立读回。它需要 CAD 进程,并非独立编辑数据库的替换 EXE。正式替换后端未切换,没有打包或发布。
|
||||
|
||||
## 已确认的原生提交链
|
||||
|
||||
@@ -38,6 +38,62 @@ PlaceDevice.dll 有 `NotifySelectionObservers`、`SelectLibrarySymbol`、`Create
|
||||
|
||||
该原型与原生替换的 flat 输出已逐器件、逐引脚比较:57 个器件、103 个引脚、22 个网络一致。比较保留引脚对应的连接,仅忽略同层属性顺序。分层输出仍有差别,因此尚未将它认定为等价的正式后端。
|
||||
|
||||
只改 `Value` 的对照实验在 Part Name 的有效值断言处失败,说明已有实例值会覆盖基础值。正在继续验证同时同步基础与实例属性,并补查无效料号和命令边界。实验脚本与工程副本保存在忽略目录 build 中,均为研究原型。
|
||||
只改 `Value` 的对照实验在 Part Name 的有效值断言处失败,说明已有实例值会覆盖基础值。同时写基础与实例属性后,料号独立读回通过;再把目标引脚的 `Pin Number` 基础值和实例值一起同步,才补齐原生替换在分层输出中的引脚号。
|
||||
|
||||
核心调用证据见 [JSON](2026-10-17-replacement-core-trace-evidence.json)。所有内部地址都需要匹配模块哈希,不能写成跨版本正式接口。
|
||||
最终批量实验只修改三个目标,使用同一个真实库模板,覆盖旋转及 Value/NC 选项:
|
||||
|
||||
| 位号 | 原方向枚举 | 新料号 | 最终 Value | 核验 |
|
||||
| --- | ---: | --- | --- | --- |
|
||||
| RV05 | 0 | 4100-CA0000-T0 | 0R | 与原生 GUI 基准完整比较 |
|
||||
| RV14 | 1 | 4100-CA0000-T0 | 0R/NC | 保留旧 NC、检查预期字段变化 |
|
||||
| RV02 | 3 | 4100-CA0000-T0 | 2.2K | 保留旧 Value、检查预期字段变化 |
|
||||
|
||||
保存重开后,三个 UID、位置、方向、比例、属性显示样式与引脚网络均通过核验,独立清单返回上述结果,RV11、RV08、RV19 等未选中同料号器件不变。分层和展开的完整输出均核验 57 个器件、103 个引脚、22 个网络:54 个未选中器件不变,所有连接保持一致;RV05 与原生 GUI 基准相同。RV14/RV02 没有各自再跑一轮 GUI 对照,不能宣称所有选项均已证明与 GUI 等价。
|
||||
|
||||
实际研究命令为 `python build/probe_headless_batch.py build/<新的输出目录>`,会复制固定 Audio 测试工程,在自有私有桌面打开新副本;不是面向任意生产工程的正式命令。来源测试工程的 `.prj` 与 `icdb.dat` 哈希核验通过,CAD 正常退出,桌面释放。
|
||||
|
||||
## 料号有效性与真实库接口
|
||||
|
||||
负例证实:`AddPartInstance` 接受不存在的 `DX_RESEARCH_PART_DOES_NOT_EXIST`,生成空 Part Name/Part Label 的器件。因此必须先查真实库,不能靠设置 PartNumber 后回读、HasPins、GetSlotsCount 或创建模板成功判断料号有效。
|
||||
|
||||
已验证安装自带命令:
|
||||
|
||||
```text
|
||||
ListWGLib.exe <中央库副本.lmc> PDB <输出.txt>
|
||||
```
|
||||
|
||||
本次在只含中央库文件及 PartsDBLibs 的副本上执行,退出码 0,列出 20 个分区、9,436 条料号,来源库哈希未变。它返回 `分区:料号`,可以精确匹配料号,不能单独证明料号关联哪个符号。
|
||||
|
||||
进一步将 **PartsDB40.dll 实际导出**封装成 32 位研究 CLI,已成功读取关联符号。可复用查询源码保留在 [native_parts_query.cpp](../../tools/research/native_parts_query.cpp),编译说明见 [README](../../tools/research/README.md):
|
||||
|
||||
```text
|
||||
native_parts_query.exe <原生DLL目录> <分区副本.pdb> <料号>
|
||||
```
|
||||
|
||||
调用 `GetPartsDBPtr` 创建对象,再调用导出的 Loader、GetPartEnum、GetPartNumber、GetPartName、GetPartLabel、GetSymDfnList、GetSymDfnName;枚举与数据库对象均 Release。使用简单指针和整数参数,没有构造厂商 STL/MFC 对象,也没有调用未导出的进程地址。
|
||||
|
||||
| 查询 | 真实返回 | 单次子进程调用耗时 |
|
||||
| --- | --- | ---: |
|
||||
| 4100-CA0000-T0 | RESC1608N / 0R / skyworth:res01 | 0.313 秒 |
|
||||
| 不存在料号 | matches 为空 | 0.359 秒 |
|
||||
| 4300-CC1040-7100 | CAPC0603X30N / C/100NF/16V +/-10% X5R / skyworth:cap01 | 0.391 秒 |
|
||||
|
||||
这三个进程退出码为 0,PDB 副本字节不变。`matches=[]` 是未找到料号,调用方必须处理,退出码 0 只表示查询完成。以上是库查询耗时,不能当作替换或全流程耗时。接口 ABI 只在本机 x86 DLL 上验证,不是厂商承诺的公开接口。
|
||||
|
||||
复核后补齐属性读取失败返回、符号指针/数量校验、UTF-8 输出及对象/模块释放。最终源码重新编译,前三种实际查询及中文请求名回传均通过,耗时 0.297~0.375 秒;缺少 DLL 的负例返回非零退出码 2。中文回传验证的是参数与序列化,不等于已验证所有中文 PDB 元数据的实际代码页。
|
||||
|
||||
## 命令边界与后续接入条件
|
||||
|
||||
带前导冒号的 `ccomp :skyworth:cap01.1` 仍弹出 Change Component。附加 `1` 的实验返回 True,却触发“提交数据库事务被拒,正在重新导入项目”,当前视图丢失。因此 ExecuteCommand 的 True 也不是替换成功证据;这两种写法均排除。该实验未主动保存,视图丢失后不能认证副本的最终器件状态;来源测试工程哈希未变。见 [边界证据](2026-10-17-replacement-boundaries-evidence.json)。
|
||||
|
||||
适合接入的受限路线是:精确验证料号存在及关联符号 → 冻结工程/图页/UID → 拒绝多 gate 或符号、引脚映射不一致 → 在原 UID 上应用模板属性,同时同步基础值和实例值、引脚号 → 按现有策略处理 Value/NC、显示样式 → 删除未连接模板 → 验证范围、连接、保存重开和独立读回。可按目标料号复用一个模板。
|
||||
|
||||
正式切换前仍需要补齐:
|
||||
|
||||
- 当前分层采集对实例覆盖值的处理。实验已证明只读基础层会返回旧料号,需要正确合并有效值或退回 CAD 核验。
|
||||
- 不同符号、多 gate、不同引脚映射、重复层级实例及任意库的属性策略。这些不能直接使用此次受限路径。
|
||||
- 打包/PCB 同步、Undo/取消恢复、连续多工程和重复执行的正式回归。完整原生图数据一致并不代替 PCB 打包实测。
|
||||
|
||||
对不同符号等范围,当前可用路径仍是已有原生替换窗口;没有确认可安全直调的通用替换 CLI。内部核心已定位,但其对象生命周期与完整 ABI 尚不具备正式封装条件。替换实验脚本、工程副本与原始报告保存在忽略目录 build 中,均为研究原型。保留的查询源码不参与应用构建或发布。
|
||||
|
||||
核心调用证据见 [JSON](2026-10-17-replacement-core-trace-evidence.json),批量与库查询结果见 [JSON](2026-10-17-headless-replacement-evidence.json)。所有内部地址都需要匹配模块哈希,不能写成跨版本正式接口。
|
||||
@@ -0,0 +1,23 @@
|
||||
# 原生接口研究探针
|
||||
|
||||
此目录不参与应用构建或发布。当前只保留可复现的物料查询客户端;替换实验仍在本机 build 中的可丢弃工程副本运行。
|
||||
|
||||
`native_parts_query.cpp` 使用本机 EE7.9.5 的 PartsDB40.dll 导出查询物料属性与关联符号。它不是替换命令,不启动 CAD,不调用未导出的内存地址。
|
||||
|
||||
在 Visual Studio **x86** 开发者命令提示符中,从仓库根目录编译:
|
||||
|
||||
```bat
|
||||
cl /std:c++17 /nologo /W4 /EHsc /O2 tools\research\native_parts_query.cpp /Febuild\native_parts_query.exe /Fobuild\native_parts_query.obj
|
||||
```
|
||||
|
||||
准备一个分区 PDB 副本,再查询:
|
||||
|
||||
```bat
|
||||
build\native_parts_query.exe "D:\Mentor\7.9.5EE\SDD_HOME\common\win32\lib" "<分区副本.pdb>" "4100-CA0000-T0"
|
||||
```
|
||||
|
||||
成功结果是 UTF-8 JSON,含 `requested`、`matches`、`enumerated`。料号不存在时 `matches=[]`;退出码 0 表示查询完成。退出码非 0 表示加载、枚举、属性读取或编码失败,调用方必须丢弃标准输出,不能使用可能已输出的部分 JSON。
|
||||
|
||||
程序检查 x86 位数,使用该安装版实测的 `__cdecl` 工厂与 `__stdcall` 导出方法;对象先于模块释放。ABI、Loader 模式 0、原生 ANSI 编码转换只在本机安装验证。不要把接口视为跨版本合同,也不要直接用用户库做首次测试。路径使用本机 ANSI 代码页,任意 Unicode 路径和长路径未验证。
|
||||
|
||||
本轮验证记录与 DLL 哈希见 [研究记录](../../docs/research/2026-10-17-replacement-cli-alternative.md)及 [证据](../../docs/research/2026-10-17-headless-replacement-evidence.json)。
|
||||
@@ -0,0 +1,173 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
// Disposable research client for the locally verified EE7.9.5 x86 PartsDB40 ABI.
|
||||
// Query a copied PDB. No CAD process or private replacement address is invoked.
|
||||
static_assert(sizeof(void *) == 4, "This research ABI requires an x86 build.");
|
||||
struct ObjectGuard {
|
||||
void *value;
|
||||
ULONG(__stdcall *release)(void *);
|
||||
~ObjectGuard() {
|
||||
if (value)
|
||||
release(value);
|
||||
}
|
||||
};
|
||||
struct ModuleGuard {
|
||||
HMODULE value;
|
||||
~ModuleGuard() {
|
||||
if (value)
|
||||
FreeLibrary(value);
|
||||
}
|
||||
};
|
||||
static void str(const char *p) {
|
||||
std::string utf8;
|
||||
if (p && *p) {
|
||||
int count =
|
||||
MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, p, -1, nullptr, 0);
|
||||
if (!count)
|
||||
throw std::runtime_error(
|
||||
"Metadata encoding is invalid for the native ANSI code page");
|
||||
std::vector<wchar_t> wide(count);
|
||||
if (!MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, p, -1, wide.data(),
|
||||
count))
|
||||
throw std::runtime_error("ANSI decoding failed");
|
||||
int size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wide.data(),
|
||||
count - 1, nullptr, 0, nullptr, nullptr);
|
||||
if (!size)
|
||||
throw std::runtime_error("UTF-8 conversion failed");
|
||||
utf8.resize(size);
|
||||
if (!WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wide.data(),
|
||||
count - 1, utf8.data(), size, nullptr, nullptr))
|
||||
throw std::runtime_error("UTF-8 conversion failed");
|
||||
}
|
||||
putchar('"');
|
||||
for (unsigned char c : utf8) {
|
||||
if (c == '"' || c == '\\')
|
||||
printf("\\%c", c);
|
||||
else if (c < 32)
|
||||
printf("\\u%04x", c);
|
||||
else
|
||||
putchar(c);
|
||||
}
|
||||
putchar('"');
|
||||
}
|
||||
template <class T> T proc(HMODULE h, const char *name) {
|
||||
auto p = GetProcAddress(h, name);
|
||||
if (!p)
|
||||
throw std::runtime_error(name);
|
||||
return reinterpret_cast<T>(p);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 4) {
|
||||
std::fputs("Usage: native_parts_query <DLL directory> <copied partition.pdb> "
|
||||
"<part number>\n", stderr);
|
||||
return 64;
|
||||
}
|
||||
SetDllDirectoryA(argv[1]);
|
||||
char path[32768];
|
||||
sprintf_s(path, "%s\\PartsDB40.dll", argv[1]);
|
||||
HMODULE h = LoadLibraryA(path);
|
||||
ModuleGuard module{h};
|
||||
if (!h) {
|
||||
printf("{\"load_error\":%lu}\n", GetLastError());
|
||||
return 2;
|
||||
}
|
||||
using Factory = HRESULT(__cdecl *)(void **);
|
||||
using Loader = HRESULT(__stdcall *)(void *, const char *, int);
|
||||
using GetEnum = HRESULT(__stdcall *)(void *, void **);
|
||||
using Next = HRESULT(__stdcall *)(void *, ULONG, int *, ULONG *);
|
||||
using Release = ULONG(__stdcall *)(void *);
|
||||
using GetStr = HRESULT(__stdcall *)(void *, int, const char **);
|
||||
using GetList = HRESULT(__stdcall *)(void *, int, const int **, int *);
|
||||
try {
|
||||
auto create = proc<Factory>(h, "GetPartsDBPtr");
|
||||
auto load = proc<Loader>(h, "?Loader@PartsDB@@UAGJPBDH@Z");
|
||||
auto enumerate =
|
||||
proc<GetEnum>(h, "?GetPartEnum@PartsDB@@UAGJPAPAUIEnumInt@@@Z");
|
||||
auto next = proc<Next>(h, "?Next@EnumPartsDBPart@@UAGJKPAHPAK@Z");
|
||||
auto release_enum = proc<Release>(h, "?Release@EnumPartsDBPart@@UAGKXZ");
|
||||
auto release = proc<Release>(h, "?Release@PartsDB@@UAGKXZ");
|
||||
auto number = proc<GetStr>(h, "?GetPartNumber@PartsDB@@UAGJHPAPBD@Z");
|
||||
auto pname = proc<GetStr>(h, "?GetPartName@PartsDB@@UAGJHPAPBD@Z");
|
||||
auto label = proc<GetStr>(h, "?GetPartLabel@PartsDB@@UAGJHPAPBD@Z");
|
||||
auto syms = proc<GetList>(h, "?GetSymDfnList@PartsDB@@UAGJHPAPBHPAH@Z");
|
||||
auto symname = proc<GetStr>(h, "?GetSymDfnName@PartsDB@@UAGJHPAPBD@Z");
|
||||
void *db = nullptr;
|
||||
HRESULT hr = create(&db);
|
||||
ObjectGuard db_guard{db, release};
|
||||
if (FAILED(hr) || !db) {
|
||||
printf("{\"create_hr\":%ld}", hr);
|
||||
return 3;
|
||||
}
|
||||
hr = load(db, argv[2], 0);
|
||||
if (FAILED(hr)) {
|
||||
printf("{\"load_hr\":%ld}", hr);
|
||||
return 4;
|
||||
}
|
||||
void *e = nullptr;
|
||||
hr = enumerate(db, &e);
|
||||
ObjectGuard enum_guard{e, release_enum};
|
||||
if (FAILED(hr) || !e) {
|
||||
printf("{\"enum_hr\":%ld}", hr);
|
||||
return 5;
|
||||
}
|
||||
unsigned count = 0, matches = 0;
|
||||
printf("{\"requested\":");
|
||||
str(argv[3]);
|
||||
printf(",\"matches\":[");
|
||||
for (;;) {
|
||||
int id = -1;
|
||||
ULONG fetched = 0;
|
||||
hr = next(e, 1, &id, &fetched);
|
||||
if (FAILED(hr) || !fetched)
|
||||
break;
|
||||
if (++count > 100000) {
|
||||
return 6;
|
||||
}
|
||||
const char *pn = nullptr;
|
||||
if (FAILED(number(db, id, &pn)) || !pn) {
|
||||
return 7;
|
||||
}
|
||||
if (strcmp(pn, argv[3]))
|
||||
continue;
|
||||
if (matches++)
|
||||
putchar(',');
|
||||
printf("{\"index\":%d,\"number\":", id);
|
||||
str(pn);
|
||||
const char *n = nullptr, *l = nullptr;
|
||||
if (FAILED(pname(db, id, &n)))
|
||||
throw std::runtime_error("GetPartName failed");
|
||||
if (FAILED(label(db, id, &l)))
|
||||
throw std::runtime_error("GetPartLabel failed");
|
||||
printf(",\"name\":");
|
||||
str(n);
|
||||
printf(",\"label\":");
|
||||
str(l);
|
||||
const int *defs = nullptr;
|
||||
int len = 0;
|
||||
hr = syms(db, id, &defs, &len);
|
||||
printf(",\"symbols_hr\":%ld,\"symbols\":[", hr);
|
||||
if (FAILED(hr) || len < 0 || len >= 1000 || (len > 0 && !defs))
|
||||
throw std::runtime_error("GetSymDfnList returned invalid metadata");
|
||||
for (int j = 0; j < len; ++j) {
|
||||
const char *s = nullptr;
|
||||
if (FAILED(symname(db, defs[j], &s)) || !s)
|
||||
throw std::runtime_error("GetSymDfnName failed");
|
||||
if (j)
|
||||
putchar(',');
|
||||
str(s);
|
||||
}
|
||||
printf("]}");
|
||||
}
|
||||
printf("],\"enumerated\":%u,\"last_hr\":%ld}\n", count, hr);
|
||||
return FAILED(hr) ? 8 : 0;
|
||||
} catch (const std::exception &e) {
|
||||
printf("{\"query_error\":");
|
||||
str(e.what());
|
||||
printf("}\n");
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user