chore: 初始化 ViperApps 仓库
纳入 11 个示例工程(不含 ViperOS,另行开专题)的源码:已完成新语法迁移(R1-R16 机械规则与 R1/R12 改写)。.gitignore 排除 ViperOS/、各工程编译产物(.tpv_build/.native_build/output/temp)、二进制与 ViperMNIST/data 数据集。
This commit is contained in:
commit
df8e301720
54 files changed
+12112
No files matched your search
@@ -0,0 +1,13 @@
|
||||
*.o
|
||||
*.obj
|
||||
*.exe
|
||||
*.img
|
||||
*.iso
|
||||
**/__pycache__/
|
||||
.cache/
|
||||
*.pyc
|
||||
|
||||
# 编译
|
||||
**/output/
|
||||
**/temp/
|
||||
**/.tpv_build/
|
||||
@@ -0,0 +1,46 @@
|
||||
# main.vp — ViperOpenSSLProject:版本 + 摘要演示
|
||||
#
|
||||
# 使用 includes/openssl FFI 层(import openssl):
|
||||
# 1) 打印 OpenSSL 版本号
|
||||
# 2) 计算 "hello openssl" 的 MD5 / SHA256 十六进制摘要
|
||||
#
|
||||
# 链接目标尚未定(msys2 预装 3.6.2 动态库 或 openssl_358_C 自编译),
|
||||
# 配好 project.vpj 的 -lcrypto/-lssl(或 static_libs)后才可链接运行。
|
||||
import t, c
|
||||
import stdlib
|
||||
import binascii
|
||||
import openssl
|
||||
import w32.win32console as w32cmd
|
||||
import viperlib
|
||||
|
||||
|
||||
def print_digest(name: str, buf: bytes, length: int):
|
||||
hex_str: str = binascii.hexlify(buf, length)
|
||||
print(f"{name}: {hex_str}")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
w32cmd.SetConsoleOutputCP(65001)
|
||||
w32cmd.SetConsoleCP(65001)
|
||||
|
||||
# ---- 1) 版本 ----
|
||||
ver: str = openssl.OpenSSL_version(openssl.OpenSslVersion)
|
||||
print("OpenSSL version:", ver)
|
||||
num: uint32 = openssl.OpenSSL_version_num()
|
||||
print(f"Version number : 0x{num:x}")
|
||||
|
||||
# ---- 2) 摘要 ----
|
||||
data: str = "hello openssl"
|
||||
dlen: int = len(data)
|
||||
|
||||
md5_buf: bytes = stdlib.malloc(openssl.Md5DigestLength)
|
||||
openssl.MD5(data, dlen, md5_buf)
|
||||
print_digest("MD5 ", md5_buf, openssl.Md5DigestLength)
|
||||
stdlib.free(md5_buf)
|
||||
|
||||
sha256_buf: bytes = stdlib.malloc(openssl.Sha256DigestLength)
|
||||
openssl.SHA256(data, dlen, sha256_buf)
|
||||
print_digest("SHA256", sha256_buf, openssl.Sha256DigestLength)
|
||||
stdlib.free(sha256_buf)
|
||||
|
||||
return 0
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 TermiNexus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,36 @@
|
||||
# ViperOpenSSLProject
|
||||
|
||||
基于 [ViperTemplateProject](../ViperTemplateProject) 模板创建的 **OpenSSL 3.x FFI 测试工程**,
|
||||
用来验证 `includes/openssl` FFI 层(摘要/哈希、EVP、证书 PKI、SSL/TLS)的链接与调用。
|
||||
|
||||
## 说明
|
||||
|
||||
- FFI 层源码在 `../includes/openssl/`(`import openssl` 使用)。
|
||||
- 当前 App/main.vp 为「版本 + SHA256/MD5 摘要」演示。
|
||||
- 链接目标:**已选 msys2 mingw64 预装 OpenSSL 3.6.2 动态库**(`-L D:/msys64/mingw64/lib -lssl -lcrypto`,见 project.vpj)。
|
||||
运行 `app.exe` 前需把 `D:/msys64/mingw64/bin` 加入 PATH(依赖 `libcrypto-3-x64.dll` / `libssl-3-x64.dll`)。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
ViperOpenSSLProject/
|
||||
├── .gitignore
|
||||
├── LICENSE
|
||||
├── README.md
|
||||
├── project.vpj # 编译/链接配置(msys2 3.6.2 动态库)
|
||||
└── App/
|
||||
└── main.vp # 版本 + 摘要演示
|
||||
```
|
||||
|
||||
## 备选:openssl_358_C 源码自编译静态库
|
||||
|
||||
若改用 `../includes/openssl/openssl_358_C` 自编译,先把生成的
|
||||
`libcrypto.a` / `libssl.a` 填入 `linker.static_libs`(并去掉上面的 `-lcrypto -lssl`)。
|
||||
|
||||
## 编译运行
|
||||
|
||||
```powershell
|
||||
cd D:\Users\TermiNexus\Desktop\TransPyC\ViperOpenSSLProject
|
||||
python ..\Projectrans.py --project .\project.vpj --clean-cache=false
|
||||
.\output\app.exe # 需 D:\msys64\mingw64\bin 在 PATH(依赖 libcrypto-3-x64.dll/libssl-3-x64.dll)
|
||||
```
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "ViperOpenSSLProject - OpenSSL 3.x FFI Test",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"build_dir": "./.tpv_build",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": [
|
||||
"-filetype=obj",
|
||||
"-relocation-model=pic"
|
||||
]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "D:/msys64/mingw64/bin/clang++.exe",
|
||||
"flags": [
|
||||
"-fuse-ld=lld",
|
||||
"-lws2_32",
|
||||
"-lcrypt32",
|
||||
"-ladvapi32",
|
||||
"-lmsvcrt",
|
||||
"-lmingwex",
|
||||
"-lgdi32",
|
||||
"-lpthread",
|
||||
"-lkernel32"
|
||||
],
|
||||
"static_libs": [
|
||||
"../../dlls/lib/libssl.a",
|
||||
"../../dlls/lib/libcrypto.a"
|
||||
],
|
||||
"output": "app.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user