| Crates.io | lua-assembler |
| lib.rs | lua-assembler |
| version | 0.0.0 |
| created_at | 2025-10-16 05:49:15.599348+00 |
| updated_at | 2025-10-16 05:49:15.599348+00 |
| description | 解析以及写入 `.pyc` bytecode files |
| homepage | |
| repository | https://github.com/oovm/wasm.exe |
| max_upload_size | |
| id | 1885469 |
| size | 38,226 |
用于读取/写入 Python .pyc 字节码文件的 Rust 实现。
.pyc 文件:解析 16 字节头(PEP 552)并保留主体.pyc 文件:按原样写回头与主体,实现无损回写pyc-assembler <in.pyc> <out.pyc> 进行回写验证cargo build -p pyc-assembler
python - <<'PY'
import py_compile, pathlib
p = pathlib.Path('tests/pyc_src')
p.mkdir(parents=True, exist_ok=True)
(p/'hello.py').write_text('print("hello from pyc")\n')
py_compile.compile(str(p/'hello.py'), cfile=str(p/'hello.pyc'))
print('OK')
PY
cargo run -p pyc-assembler -- tests/pyc_src/hello.pyc tests/pyc_src/out.pyc
python tests/pyc_src/out.pyc
# 预期输出:hello from pyc
use std::path::Path;
use pyc_assembler::formats::pyc::{read_pyc_file, write_pyc_file};
let pyc = read_pyc_file(Path::new("tests/pyc_src/hello.pyc")).unwrap();
write_pyc_file(Path::new("tests/pyc_src/out.pyc"), &pyc).unwrap();
.pyc 主体为 Python 的 marshal 序列化的 code object,本库当前不解析主体,仅做无损读写;这足以用于执行验证与后续扩展。