1个不稳定版本
0.1.0 | 2022年1月9日 |
---|
#59 in #dll
23KB
442 行
loserland_exec
从内存中加载DLL
将不安全的C代码翻译为Rust的一个简洁示例。
引用 fancycode
The default windows API functions to load external libraries into a program
(LoadLibrary, LoadLibraryEx) only work with files on the filesystem.
这使得在给定不在Windows文件系统上的字节流执行代码变得困难。
extern crate loserland_exec;
use std::fs::File;
// helloworld.dll exports a function named callme
let mut dll_file = File::open("helloworld.dll").unwrap();
let mut dll_data = Vec::new();
// Read the dll file into a vector of bytes so we can pretend we got them from anywhere
dll_file.read_to_end(&mut dll_data).unwrap();
// Find the function exported by our dll in memory
let callme = loserland_exec::get_proc("callme", &dll_data) as *const ();
// Execute the code
(callme)(); // Hello from plugin!
状态
正在寻找帮助编写详细文档,展示内存布局和代码执行方式。还希望增加Linux和Darwin的兼容性。
贡献
对问题、评论、关注和贡献的反馈将充满同情。
参考文献
依赖项
~480–750KB
~12K SLoC