Crates.io | lazy_link |
lib.rs | lazy_link |
version | 0.1.1 |
source | src |
created_at | 2024-09-27 15:32:10.456935 |
updated_at | 2024-09-27 15:41:14.3481 |
description | lazy_link is a Rust proc macro for dynamic runtime lookup of external functions, supporting custom resolvers, caching and no_std environments. |
homepage | |
repository | https://github.com/WolverinDEV/lazy-link |
max_upload_size | |
id | 1388735 |
size | 50,837 |
lazy_link
is a Rust procedural macro crate that allows you to dynamically look up external functions at runtime without any additional boilerplate code.
This crate is designed to simplify the process of dynamically linking to external functions as runtime, inclusing support for function name obfuscation and no_std
environments.
lazy_link
attribute to dynamically link external functions at runtime.obfstr
crate, enhancing security by making the function identifiers less readable in binary form.no_std
Compatible: Full support for no_std
environments.To use lazy_link
, simply add the attribute to your external block declarations:
use lazy_link::lazy_link;
#[lazy_link(resolver = "resolve_externals")]
extern "C" {
fn external_add(v1: u8, v2: u8) -> u8;
}
Additionally, you have to implement the resolve function, which dynamically resolves the function at runtime. This function takes the function's name (and an optional module) and returns a non-null pointer to the function:
fn resolve_externals(module: Option<&str>, name: &str) -> NonNull<()> {
// Your resolution logic here, typically using some form of dynamic lookup.
unimplemented!("Function lookup logic for {}", name)
}
Examples can be found within the examples directory of this repository. These examples demonstrate how to use lazy_link in various contexts, including platform-specific scenarios.
To run the examples, clone the repository and use the following command:
cargo run --bin <example_name>