vools-dll32 0.7.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vools/dll32/README.md +444 -0
- vools/dll32/__init__.py +86 -0
- vools/dll32/_core/__init__.py +14 -0
- vools/dll32/_core/_pipe_comm.py +18 -0
- vools/dll32/_core/_spawn32.py +342 -0
- vools/dll32/_dlls/__init__.py +63 -0
- vools/dll32/_lib/__init__.py +9 -0
- vools/dll32/_lib/clr/__init__.py +8 -0
- vools/dll32/_lib/clr/_base.py +89 -0
- vools/dll32/_lib/com/__init__.py +9 -0
- vools/dll32/_lib/com/_base.py +103 -0
- vools/dll32/_lib/com/directcom.py +115 -0
- vools/dll32/_lib/com/rc6.py +228 -0
- vools/dll32/_lib/com/rc6plus.py +344 -0
- vools/dll32/_python32/__init__.py +1 -0
- vools/dll32/_python32/python32_launcher.py +63 -0
- vools/dll32/_python32/python36._pth +5 -0
- vools/dll32/_python32/python36.zip +0 -0
- vools/dll32/_signatures/__init__.py +13 -0
- vools/dll32/_signatures/_registry.py +50 -0
- vools/dll32/_signatures/mqtt.py +46 -0
- vools/dll32/_signatures/openssl.py +35 -0
- vools/dll32/_signatures/vb6plus.py +299 -0
- vools/dll32/dll.py +77 -0
- vools/dll32/examples/basic_usage.py +74 -0
- vools/dll32/get-pip.py +27079 -0
- vools/dll32/mqtt.py +83 -0
- vools/dll32/openssl.py +54 -0
- vools/dll32/vb6plus.py +495 -0
- vools_dll32-0.7.3.dist-info/METADATA +657 -0
- vools_dll32-0.7.3.dist-info/RECORD +34 -0
- vools_dll32-0.7.3.dist-info/WHEEL +5 -0
- vools_dll32-0.7.3.dist-info/licenses/LICENSE +201 -0
- vools_dll32-0.7.3.dist-info/top_level.txt +1 -0
vools/dll32/README.md
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# vools.dll32 - 32 位 DLL 专用桥接包
|
|
2
|
+
|
|
3
|
+
通过嵌入式 Python 3.6 32 位进程,在 64 位 Python 环境中无缝调用 32 位 DLL、COM 组件和 .NET 程序集。
|
|
4
|
+
|
|
5
|
+
## 功能特点
|
|
6
|
+
|
|
7
|
+
- **跨位数调用**: 64 位 Python 调用 32 位 DLL/COM/.NET
|
|
8
|
+
- **统一装饰器接口**: 与 `vools.sys.dll` 风格一致的 `@dll32` 装饰器
|
|
9
|
+
- **内置 DLL 集合**: 预置常用 32 位 DLL,开箱即用
|
|
10
|
+
- **COM 组件支持**: 支持 RC6 (VBRichClient5) 等 COM 组件免注册调用
|
|
11
|
+
- **.NET 互操作**: 通过 pythonnet 调用 .NET 程序集
|
|
12
|
+
- **函数签名注册表**: 集中管理 DLL 函数签名,支持动态适配
|
|
13
|
+
- **跨进程通信**: 通过临时文件 + 子进程方式实现稳定通信
|
|
14
|
+
|
|
15
|
+
## 架构设计
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
vools/dll32/
|
|
19
|
+
├── __init__.py # 主入口,导出核心 API
|
|
20
|
+
├── dll.py # @dll32 装饰器
|
|
21
|
+
├── vb6plus.py # VB6Plus.dll 包装类
|
|
22
|
+
├── openssl.py # VB6OpenSSL.dll 包装类
|
|
23
|
+
├── mqtt.py # VB6MQTT.dll 包装类
|
|
24
|
+
├── _core/ # 核心通信层
|
|
25
|
+
│ ├── _spawn32.py # 32 位 Python 进程管理
|
|
26
|
+
│ └── _pipe_comm.py # 跨进程通信封装
|
|
27
|
+
├── _dlls/ # 预置 32 位 DLL 文件
|
|
28
|
+
│ ├── VB6Plus.dll
|
|
29
|
+
│ ├── VB6OpenSSL.dll
|
|
30
|
+
│ ├── VB6MQTT.dll
|
|
31
|
+
│ ├── DirectCOM.dll
|
|
32
|
+
│ ├── RC6.dll
|
|
33
|
+
│ ├── RC6Widgets.dll
|
|
34
|
+
│ ├── vbRichClient5.dll
|
|
35
|
+
│ ├── cairo_sqlite.dll
|
|
36
|
+
│ └── WebView2Loader.dll
|
|
37
|
+
├── _lib/ # 高层包装库
|
|
38
|
+
│ ├── com/ # COM 组件支持
|
|
39
|
+
│ │ ├── _base.py # COMObject 基类
|
|
40
|
+
│ │ ├── directcom.py # DirectCOM 免注册加载
|
|
41
|
+
│ │ ├── rc6.py # RC6 基础包装
|
|
42
|
+
│ │ └── rc6plus.py # RC6Plus 增强包装
|
|
43
|
+
│ └── clr/ # .NET 互操作支持
|
|
44
|
+
│ └── _base.py # CLRAssembly / DotNetObject
|
|
45
|
+
├── _signatures/ # 函数签名注册表
|
|
46
|
+
│ ├── _registry.py # 统一注册中心
|
|
47
|
+
│ ├── vb6plus.py # VB6Plus.dll 签名
|
|
48
|
+
│ ├── openssl.py # VB6OpenSSL.dll 签名
|
|
49
|
+
│ └── mqtt.py # VB6MQTT.dll 签名
|
|
50
|
+
└── _python32/ # 嵌入式 Python 3.6 32 位
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 架构层次
|
|
54
|
+
|
|
55
|
+
| 层次 | 模块 | 职责 |
|
|
56
|
+
|------|------|------|
|
|
57
|
+
| 用户接口层 | `__init__.py`, `dll.py` | 提供装饰器和便捷 API |
|
|
58
|
+
| 包装层 | `vb6plus.py`, `openssl.py`, `mqtt.py`, `_lib/` | 高层封装,简化调用 |
|
|
59
|
+
| 签名层 | `_signatures/` | 函数元数据管理 |
|
|
60
|
+
| 通信层 | `_core/` | 32 位进程管理与通信 |
|
|
61
|
+
| 资源层 | `_dlls/`, `_python32/` | DLL 文件和 Python 运行时 |
|
|
62
|
+
|
|
63
|
+
## 支持的组件
|
|
64
|
+
|
|
65
|
+
### 标准 DLL
|
|
66
|
+
|
|
67
|
+
| DLL 文件 | 功能类别 | 函数数量 |
|
|
68
|
+
|----------|----------|----------|
|
|
69
|
+
| **VB6Plus.dll** | 编解码、加密、文件、网络、GUI | 57+ |
|
|
70
|
+
| **VB6OpenSSL.dll** | HTTPS GET/POST 请求 | 2 |
|
|
71
|
+
| **VB6MQTT.dll** | MQTT 客户端 | 4 |
|
|
72
|
+
|
|
73
|
+
### COM 组件
|
|
74
|
+
|
|
75
|
+
| 组件 | 说明 |
|
|
76
|
+
|------|------|
|
|
77
|
+
| **RC6 (VBRichClient5)** | 加密、文件、集合、网络、数据库、JSON 等 |
|
|
78
|
+
| **DirectCOM** | 免注册 COM 加载器 |
|
|
79
|
+
|
|
80
|
+
### .NET 程序集
|
|
81
|
+
|
|
82
|
+
通过 pythonnet 支持任意 .NET 程序集加载和调用。
|
|
83
|
+
|
|
84
|
+
## 安装
|
|
85
|
+
|
|
86
|
+
无需额外安装,Python 3.6 32 位嵌入式环境已内置在包中。
|
|
87
|
+
|
|
88
|
+
**要求**:
|
|
89
|
+
- Windows 平台
|
|
90
|
+
- Python 3.6+ (64 位)
|
|
91
|
+
|
|
92
|
+
## 使用方法
|
|
93
|
+
|
|
94
|
+
### 1. 使用 @dll32 装饰器调用标准 DLL
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from vools.dll32 import dll32
|
|
98
|
+
|
|
99
|
+
# 装饰器模式
|
|
100
|
+
@dll32('VB6Plus.dll::Base64Encode_UTF8')
|
|
101
|
+
def base64_encode(input_str: str) -> str:
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
result = base64_encode('Hello, World!')
|
|
105
|
+
print(result) # SGVsbG8sIFdvcmxkIQ==
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. 使用内置包装类
|
|
109
|
+
|
|
110
|
+
#### VB6Plus - 多功能工具库
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from vools.dll32 import vb6plus
|
|
114
|
+
|
|
115
|
+
# Base64 编解码
|
|
116
|
+
encoded = vb6plus.base64_encode_utf8('Hello')
|
|
117
|
+
decoded = vb6plus.base64_decode_utf8(encoded)
|
|
118
|
+
|
|
119
|
+
# MD5 哈希
|
|
120
|
+
md5_32 = vb6plus.md5_32_utf8('test')
|
|
121
|
+
md5_16 = vb6plus.md5_16_utf8('test')
|
|
122
|
+
|
|
123
|
+
# HTML 编解码
|
|
124
|
+
html_encoded = vb6plus.html_encode('<div>test</div>')
|
|
125
|
+
html_decoded = vb6plus.html_decode(html_encoded)
|
|
126
|
+
|
|
127
|
+
# URL 编解码
|
|
128
|
+
url_encoded = vb6plus.url_encode_utf8('hello world')
|
|
129
|
+
url_decoded = vb6plus.url_decode_utf8(url_encoded)
|
|
130
|
+
|
|
131
|
+
# 字符串相似度
|
|
132
|
+
similarity = vb6plus.str_compare('hello', 'hallo')
|
|
133
|
+
|
|
134
|
+
# INI 文件操作
|
|
135
|
+
value = vb6plus.read_ini_value('Section', 'Key', 'default', 'config.ini')
|
|
136
|
+
vb6plus.write_ini_value('Section', 'Key', 'value', 'config.ini')
|
|
137
|
+
|
|
138
|
+
# AES 加解密
|
|
139
|
+
encrypted = vb6plus.aes_encrypt_utf8('data', 'password')
|
|
140
|
+
decrypted = vb6plus.aes_decrypt_utf8(encrypted, 'password')
|
|
141
|
+
|
|
142
|
+
# 二维码生成
|
|
143
|
+
vb6plus.make_qrcode('https://example.com', 'qrcode.jpg', size=5)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### OpenSSL - HTTPS 请求
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from vools.dll32 import openssl
|
|
150
|
+
|
|
151
|
+
# GET 请求
|
|
152
|
+
response = openssl.get('https://api.example.com/data')
|
|
153
|
+
|
|
154
|
+
# POST 请求
|
|
155
|
+
response = openssl.post(
|
|
156
|
+
'https://api.example.com/submit',
|
|
157
|
+
data='{"key": "value"}',
|
|
158
|
+
content_type='application/json'
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### MQTT - 消息队列
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from vools.dll32 import mqtt
|
|
166
|
+
|
|
167
|
+
# 连接 MQTT 服务器
|
|
168
|
+
mqtt.open('broker.example.com', 1883, 'client_id', 'user', 'password')
|
|
169
|
+
|
|
170
|
+
# 订阅主题
|
|
171
|
+
mqtt.subscribe('test/topic', qos=1)
|
|
172
|
+
|
|
173
|
+
# 发布消息
|
|
174
|
+
mqtt.publish('test/topic', 'Hello MQTT!', qos=1)
|
|
175
|
+
|
|
176
|
+
# 断开连接
|
|
177
|
+
mqtt.close()
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 3. 使用 RC6 (VBRichClient5) COM 组件
|
|
181
|
+
|
|
182
|
+
#### 方式一:全局实例
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from vools.dll32 import get_rc6
|
|
186
|
+
|
|
187
|
+
rc6 = get_rc6()
|
|
188
|
+
|
|
189
|
+
# 加密解密
|
|
190
|
+
encoded = rc6.base64_encode('Hello')
|
|
191
|
+
decoded = rc6.base64_decode(encoded)
|
|
192
|
+
|
|
193
|
+
md5 = rc6.md5('test')
|
|
194
|
+
sha256 = rc6.sha256('test')
|
|
195
|
+
|
|
196
|
+
encrypted = rc6.aes_encrypt('data', 'password')
|
|
197
|
+
decrypted = rc6.aes_decrypt(encrypted, 'password')
|
|
198
|
+
|
|
199
|
+
# 文件操作
|
|
200
|
+
content = rc6.read_text('test.txt')
|
|
201
|
+
rc6.write_text('output.txt', 'Hello World')
|
|
202
|
+
|
|
203
|
+
# 使用子对象
|
|
204
|
+
crypt = rc6.crypt # cCrypt - 加密解密
|
|
205
|
+
fso = rc6.fso # cFSO - 文件系统
|
|
206
|
+
collection = rc6.collection # cCollection - 集合
|
|
207
|
+
json = rc6.json # cJSON - JSON 处理
|
|
208
|
+
timer = rc6.timer # cTimer - 定时器
|
|
209
|
+
memdb = rc6.memdb # cMemDB - 内存数据库
|
|
210
|
+
tcp_client = rc6.tcp_client # cTCPClient - TCP 客户端
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### 方式二:直接使用 RC6Plus 类
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
from vools.dll32._lib.com import RC6Plus
|
|
217
|
+
|
|
218
|
+
rc6 = RC6Plus(dll_dir=r'path/to/dlls')
|
|
219
|
+
result = rc6.base64_encode('Hello')
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 4. 使用 .NET 程序集
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from vools.dll32._lib.clr import CLRAssembly
|
|
226
|
+
|
|
227
|
+
# 加载 .NET 程序集
|
|
228
|
+
clr = CLRAssembly.load_assembly('System.Data')
|
|
229
|
+
|
|
230
|
+
# 使用 .NET 类型
|
|
231
|
+
import System
|
|
232
|
+
table = System.Data.DataTable()
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### 5. 函数签名注册表
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from vools.dll32 import list_dlls, list_functions, get_signature
|
|
239
|
+
|
|
240
|
+
# 列出所有已注册的 DLL
|
|
241
|
+
dlls = list_dlls()
|
|
242
|
+
# ['VB6Plus.dll', 'VB6OpenSSL.dll', 'VB6MQTT.dll']
|
|
243
|
+
|
|
244
|
+
# 列出指定 DLL 的所有函数
|
|
245
|
+
funcs = list_functions('VB6Plus.dll')
|
|
246
|
+
|
|
247
|
+
# 获取函数签名
|
|
248
|
+
sig = get_signature('VB6Plus.dll', 'Base64Encode_UTF8')
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### 6. 内置 DLL 管理
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from vools.dll32._dlls import get_dll_path, list_builtin_dlls, dll_exists
|
|
255
|
+
|
|
256
|
+
# 获取内置 DLL 路径
|
|
257
|
+
path = get_dll_path('VB6Plus.dll')
|
|
258
|
+
|
|
259
|
+
# 列出所有内置 DLL
|
|
260
|
+
dlls = list_builtin_dlls()
|
|
261
|
+
|
|
262
|
+
# 检查 DLL 是否存在
|
|
263
|
+
exists = dll_exists('VB6Plus.dll')
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## API 参考
|
|
267
|
+
|
|
268
|
+
### @dll32 装饰器
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
@dll32(dll_spec, *, async_mode=False, fallback=None)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
| 参数 | 类型 | 说明 |
|
|
275
|
+
|------|------|------|
|
|
276
|
+
| `dll_spec` | `str` | DLL 规格,格式: `"path/to/dll::func_name"` |
|
|
277
|
+
| `async_mode` | `bool` | 是否启用异步模式 (默认 False) |
|
|
278
|
+
| `fallback` | `Callable` | 调用失败时的回退函数 |
|
|
279
|
+
|
|
280
|
+
**说明**:
|
|
281
|
+
- 如果 `dll_spec` 是相对路径,会自动在 `_dlls/` 目录中查找
|
|
282
|
+
- 函数参数类型会自动适配(str、int、float、bytes 等)
|
|
283
|
+
- 支持可选参数和默认值
|
|
284
|
+
|
|
285
|
+
### VB6Plus 类
|
|
286
|
+
|
|
287
|
+
#### 编解码
|
|
288
|
+
|
|
289
|
+
| 方法 | 说明 |
|
|
290
|
+
|------|------|
|
|
291
|
+
| `base64_encode_gb(input_str)` | Base64 编码 (GB) |
|
|
292
|
+
| `base64_decode_gb(input_str)` | Base64 解码 (GB) |
|
|
293
|
+
| `base64_encode_utf8(input_str)` | Base64 编码 (UTF-8) |
|
|
294
|
+
| `base64_decode_utf8(input_str)` | Base64 解码 (UTF-8) |
|
|
295
|
+
| `html_encode(input_str)` | HTML 编码 |
|
|
296
|
+
| `html_decode(input_str)` | HTML 解码 |
|
|
297
|
+
| `url_encode_gb(input_str)` | URL 编码 (GB) |
|
|
298
|
+
| `url_decode_gb(input_str)` | URL 解码 (GB) |
|
|
299
|
+
| `url_encode_utf8(input_str)` | URL 编码 (UTF-8) |
|
|
300
|
+
| `url_decode_utf8(input_str)` | URL 解码 (UTF-8) |
|
|
301
|
+
| `unicode_encode(input_str)` | Unicode 编码 (\uXXXX) |
|
|
302
|
+
| `unicode_decode(input_str)` | Unicode 解码 |
|
|
303
|
+
| `str_to_hex_gb(input_str, is_upper=1)` | 字符串转十六进制 (GB) |
|
|
304
|
+
| `str_to_hex_utf8(input_str, is_upper=1)` | 字符串转十六进制 (UTF-8) |
|
|
305
|
+
| `hex_to_str_gb(input_str)` | 十六进制转字符串 (GB) |
|
|
306
|
+
| `hex_to_str_utf8(input_str)` | 十六进制转字符串 (UTF-8) |
|
|
307
|
+
|
|
308
|
+
#### 哈希
|
|
309
|
+
|
|
310
|
+
| 方法 | 说明 |
|
|
311
|
+
|------|------|
|
|
312
|
+
| `md5_16_gb(input_str)` | MD5 16 位 (GB) |
|
|
313
|
+
| `md5_32_gb(input_str)` | MD5 32 位 (GB) |
|
|
314
|
+
| `md5_16_utf8(input_str)` | MD5 16 位 (UTF-8) |
|
|
315
|
+
| `md5_32_utf8(input_str)` | MD5 32 位 (UTF-8) |
|
|
316
|
+
|
|
317
|
+
#### 加密
|
|
318
|
+
|
|
319
|
+
| 方法 | 说明 |
|
|
320
|
+
|------|------|
|
|
321
|
+
| `aes_encrypt_gb(input_str, password, iv, mode, padding, out_type)` | AES 加密 (GB) |
|
|
322
|
+
| `aes_decrypt_gb(input_str, password, iv, mode, padding, in_type)` | AES 解密 (GB) |
|
|
323
|
+
| `aes_encrypt_utf8(input_str, password, iv, mode, padding, out_type)` | AES 加密 (UTF-8) |
|
|
324
|
+
| `aes_decrypt_utf8(input_str, password, iv, mode, padding, in_type)` | AES 解密 (UTF-8) |
|
|
325
|
+
|
|
326
|
+
#### 字符串
|
|
327
|
+
|
|
328
|
+
| 方法 | 说明 |
|
|
329
|
+
|------|------|
|
|
330
|
+
| `no_html(input_str, no_html_more=0)` | 去除 HTML 标签 |
|
|
331
|
+
| `str_compare(str_a, str_b)` | 字符串相似度比较 (0-1) |
|
|
332
|
+
| `permutation(input_str, separator=',', result_total=0)` | 字符串全排列 |
|
|
333
|
+
| `combination(input_str, separator=',', result_total=0)` | 字符串组合 |
|
|
334
|
+
| `explode_data(input_str, start_str, end_str)` | 提取中间文本 |
|
|
335
|
+
| `regex_replace(input_str, pattern, replacement)` | 正则替换 |
|
|
336
|
+
|
|
337
|
+
#### 文件操作
|
|
338
|
+
|
|
339
|
+
| 方法 | 说明 |
|
|
340
|
+
|------|------|
|
|
341
|
+
| `read_ini_value(section, key, default='', ini_file='Config.ini')` | 读取 INI 值 |
|
|
342
|
+
| `write_ini_value(section, key, value, ini_file='Config.ini')` | 写入 INI 值 |
|
|
343
|
+
|
|
344
|
+
#### 网络
|
|
345
|
+
|
|
346
|
+
| 方法 | 说明 |
|
|
347
|
+
|------|------|
|
|
348
|
+
| `xmlhttp_get(url, headers='', ...)` | XMLHTTP GET 请求 |
|
|
349
|
+
| `xmlhttp_post(url, data, headers='', ...)` | XMLHTTP POST 请求 |
|
|
350
|
+
|
|
351
|
+
#### 图片处理
|
|
352
|
+
|
|
353
|
+
| 方法 | 说明 |
|
|
354
|
+
|------|------|
|
|
355
|
+
| `image_to_jpg(src, dst, quality=95)` | 图片转 JPG |
|
|
356
|
+
| `image_to_bmp(src, dst)` | 图片转 BMP |
|
|
357
|
+
| `make_qrcode(text, path, size=0, ...)` | 生成二维码 |
|
|
358
|
+
| `scan_qr_image(path, ...)` | 扫描二维码 |
|
|
359
|
+
|
|
360
|
+
#### 对话框
|
|
361
|
+
|
|
362
|
+
| 方法 | 说明 |
|
|
363
|
+
|------|------|
|
|
364
|
+
| `show_open_file(hwnd=0, filter='', ...)` | 打开文件对话框 |
|
|
365
|
+
| `show_save_file(hwnd=0, filter='', ...)` | 保存文件对话框 |
|
|
366
|
+
| `show_browser_folder(hwnd=0, ...)` | 浏览文件夹对话框 |
|
|
367
|
+
|
|
368
|
+
#### 数据库
|
|
369
|
+
|
|
370
|
+
| 方法 | 说明 |
|
|
371
|
+
|------|------|
|
|
372
|
+
| `sqlite_open(db_file='DB.DB')` | 打开 SQLite 数据库 |
|
|
373
|
+
| `sqlite_close(db_handle)` | 关闭 SQLite 数据库 |
|
|
374
|
+
| `sqlite_execute(db_handle, sql)` | 执行 SQL 语句 |
|
|
375
|
+
|
|
376
|
+
#### 系统工具
|
|
377
|
+
|
|
378
|
+
| 方法 | 说明 |
|
|
379
|
+
|------|------|
|
|
380
|
+
| `win_copy_file_to_clipboard(file_or_dir)` | 复制文件到剪贴板 |
|
|
381
|
+
| `run_vbscript(vbscript, error_msg)` | 执行 VBScript |
|
|
382
|
+
|
|
383
|
+
### RC6Plus 类
|
|
384
|
+
|
|
385
|
+
#### 便捷方法
|
|
386
|
+
|
|
387
|
+
| 方法 | 说明 |
|
|
388
|
+
|------|------|
|
|
389
|
+
| `base64_encode(text)` | Base64 编码 |
|
|
390
|
+
| `base64_decode(text)` | Base64 解码 |
|
|
391
|
+
| `md5(text)` | MD5 哈希 |
|
|
392
|
+
| `sha256(text)` | SHA256 哈希 |
|
|
393
|
+
| `aes_encrypt(data, password, mode=0, padding=0)` | AES 加密 |
|
|
394
|
+
| `aes_decrypt(encrypted, password, mode=0, padding=0)` | AES 解密 |
|
|
395
|
+
| `read_text(file_path, encoding='utf-8')` | 读取文本文件 |
|
|
396
|
+
| `write_text(file_path, content, encoding='utf-8')` | 写入文本文件 |
|
|
397
|
+
|
|
398
|
+
#### 子对象
|
|
399
|
+
|
|
400
|
+
| 属性 | 类型 | 说明 |
|
|
401
|
+
|------|------|------|
|
|
402
|
+
| `constructor` | cConstructor | RC6 构造器 |
|
|
403
|
+
| `crypt` | cCrypt | 加密解密 |
|
|
404
|
+
| `fso` | cFSO | 文件系统 |
|
|
405
|
+
| `collection` | cCollection | 集合 |
|
|
406
|
+
| `sorted_dict` | cSortedDictionary | 有序字典 |
|
|
407
|
+
| `json` | cJSON | JSON 处理 |
|
|
408
|
+
| `stream` | cStream | 数据流 |
|
|
409
|
+
| `timer` | cTimer | 定时器 |
|
|
410
|
+
| `tcp_client` | cTCPClient | TCP 客户端 |
|
|
411
|
+
| `tcp_server` | cTCPServer | TCP 服务器 |
|
|
412
|
+
| `memdb` | cMemDB | 内存数据库 |
|
|
413
|
+
| `simple_dom` | cSimpleDOM | XML/HTML 解析 |
|
|
414
|
+
| `formula` | cFormula | 公式计算 |
|
|
415
|
+
|
|
416
|
+
## 注意事项
|
|
417
|
+
|
|
418
|
+
1. **仅支持 Windows 平台**:32 位 DLL 是 Windows 特有技术
|
|
419
|
+
2. **进程间通信开销**:每次调用都会启动 32 位 Python 进程,频繁调用建议批量处理
|
|
420
|
+
3. **数据类型限制**:跨进程传输仅支持 JSON 可序列化类型(str、int、float、bool、list、dict、None)
|
|
421
|
+
4. **COM 组件注册**:部分 COM 组件可能需要先注册才能使用
|
|
422
|
+
5. **线程安全**:当前实现不是线程安全的,多线程环境需自行加锁
|
|
423
|
+
|
|
424
|
+
## 常见问题
|
|
425
|
+
|
|
426
|
+
### Q: 调用 DLL 时提示找不到文件?
|
|
427
|
+
|
|
428
|
+
A: 请确保 DLL 文件存在。如果使用相对路径,会在 `_dlls/` 目录中查找。可以使用绝对路径。
|
|
429
|
+
|
|
430
|
+
### Q: 如何添加新的 DLL 支持?
|
|
431
|
+
|
|
432
|
+
A:
|
|
433
|
+
1. 将 DLL 文件放入 `_dlls/` 目录
|
|
434
|
+
2. 在 `_signatures/` 中创建对应的签名文件
|
|
435
|
+
3. 在 `_signatures/_registry.py` 中注册
|
|
436
|
+
4. 可选:创建包装类提供便捷 API
|
|
437
|
+
|
|
438
|
+
### Q: 性能如何?
|
|
439
|
+
|
|
440
|
+
A: 由于每次调用都需要启动 32 位 Python 进程,单次调用约有 50-100ms 的开销。适合调用频率不高但需要 32 位 DLL 功能的场景。
|
|
441
|
+
|
|
442
|
+
### Q: 可以调用自定义的 32 位 DLL 吗?
|
|
443
|
+
|
|
444
|
+
A: 可以。使用 `@dll32('path/to/your.dll::FunctionName')` 装饰器即可,不需要修改框架代码。
|
vools/dll32/__init__.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
vools.dll32 - 32位 DLL 专用桥接包
|
|
3
|
+
|
|
4
|
+
提供通过嵌入式 Python 3.6 32位进程调用 32 位 DLL 的功能。
|
|
5
|
+
|
|
6
|
+
主要功能:
|
|
7
|
+
1. @dll32 装饰器 - 通过 ctypes 调用标准 DLL
|
|
8
|
+
2. COM 支持 - 通过 win32com 调用 COM 组件 (包括 RC6)
|
|
9
|
+
3. .NET 支持 - 通过 pythonnet 调用 .NET 程序集
|
|
10
|
+
4. 函数签名注册表 - 统一管理 DLL 函数签名
|
|
11
|
+
|
|
12
|
+
用法:
|
|
13
|
+
# 1. 使用 dll32 装饰器调用标准 DLL (VB6Plus.dll, VB6OpenSSL.dll, VB6MQTT.dll)
|
|
14
|
+
from vools.dll32 import dll32
|
|
15
|
+
|
|
16
|
+
@dll32('VB6Plus.dll::Base64Encode_UTF8')
|
|
17
|
+
def base64_encode(input_str: str) -> str:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
result = base64_encode('Hello')
|
|
21
|
+
|
|
22
|
+
# 2. 使用 VB6Plus 包装类
|
|
23
|
+
from vools.dll32 import vb6plus
|
|
24
|
+
|
|
25
|
+
result = vb6plus.base64_encode_utf8('Hello')
|
|
26
|
+
result = vb6plus.md5_32_utf8('test')
|
|
27
|
+
|
|
28
|
+
# 3. 使用 RC6Plus (VBRichClient5) - 通过 COM
|
|
29
|
+
from vools.dll32 import get_rc6
|
|
30
|
+
|
|
31
|
+
rc6 = get_rc6()
|
|
32
|
+
result = rc6.crypt.base64_encode('Hello')
|
|
33
|
+
result = rc6.md5('test')
|
|
34
|
+
result = rc6.fso.read_text('test.txt')
|
|
35
|
+
|
|
36
|
+
# 4. 使用 .NET 程序集
|
|
37
|
+
from vools.dll32._lib.clr import CLRAssembly
|
|
38
|
+
|
|
39
|
+
CLRAssembly.load_assembly('System.Data')
|
|
40
|
+
|
|
41
|
+
支持的标准 DLL:
|
|
42
|
+
- VB6Plus.dll: Base64, MD5, URL, HTML, AES, INI, SQLite 等
|
|
43
|
+
- VB6OpenSSL.dll: HTTPS GET/POST 请求
|
|
44
|
+
- VB6MQTT.dll: MQTT 客户端
|
|
45
|
+
|
|
46
|
+
支持的 COM 组件:
|
|
47
|
+
- RC6 (VBRichClient5): 加密、文件、集合、网络、数据库等
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
from .dll import dll32
|
|
51
|
+
|
|
52
|
+
# 导出包装模块
|
|
53
|
+
from .vb6plus import VB6Plus, vb6plus
|
|
54
|
+
from .openssl import OpenSSL, openssl
|
|
55
|
+
from .mqtt import MQTT, mqtt
|
|
56
|
+
|
|
57
|
+
# 导出 COM/CLR 相关
|
|
58
|
+
from ._lib import COMObject, create_com_object
|
|
59
|
+
from ._lib.com import RC6Plus, get_rc6, DirectCOM
|
|
60
|
+
|
|
61
|
+
# 导出签名注册表
|
|
62
|
+
from ._signatures import SIGNATURES, get_signature, list_dlls, list_functions
|
|
63
|
+
|
|
64
|
+
__all__ = [
|
|
65
|
+
# 核心装饰器
|
|
66
|
+
'dll32',
|
|
67
|
+
# 包装类 (标准 DLL)
|
|
68
|
+
'VB6Plus',
|
|
69
|
+
'OpenSSL',
|
|
70
|
+
'MQTT',
|
|
71
|
+
# 全局实例 (标准 DLL)
|
|
72
|
+
'vb6plus',
|
|
73
|
+
'openssl',
|
|
74
|
+
'mqtt',
|
|
75
|
+
# COM/CLR
|
|
76
|
+
'COMObject',
|
|
77
|
+
'create_com_object',
|
|
78
|
+
'RC6Plus',
|
|
79
|
+
'get_rc6',
|
|
80
|
+
'DirectCOM',
|
|
81
|
+
# 签名注册表
|
|
82
|
+
'SIGNATURES',
|
|
83
|
+
'get_signature',
|
|
84
|
+
'list_dlls',
|
|
85
|
+
'list_functions',
|
|
86
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
管道通信模块
|
|
3
|
+
|
|
4
|
+
提供与 32 位 Python 进程的 JSON-RPC 通信。
|
|
5
|
+
"""
|
|
6
|
+
from ._spawn32 import get_process
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def call_dll(dll_path, func_name, args):
|
|
10
|
+
"""调用 32 位 DLL 函数"""
|
|
11
|
+
proc = get_process()
|
|
12
|
+
return proc.call('call_dll', [dll_path, func_name, args])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def ping():
|
|
16
|
+
"""Ping 检查"""
|
|
17
|
+
proc = get_process()
|
|
18
|
+
return proc.call('ping')
|