pub struct ModuleHandle { /* private fields */ }Implementations§
Source§impl ModuleHandle
impl ModuleHandle
Sourcepub fn open(lib_name: &str) -> Result<Self>
pub fn open(lib_name: &str) -> Result<Self>
Examples found in repository?
examples/module_params.rs (line 34)
15fn main() -> dobby_rs_framework::Result<()> {
16 // EN: 1) `cast_fn` - turn a raw address into a typed function pointer.
17 // CN: 1) `cast_fn` - 把地址转换成带类型的函数指针。
18 let p = local_add as *const () as *mut c_void;
19 let f: fn(i32) -> i32 = unsafe { params::cast_fn(p) };
20 println!("cast_fn(local_add)(1) = {}", f(1));
21
22 // EN: 2) `read_ptr_value` / `write_ptr_value` - simple raw memory access.
23 // CN: 2) `read_ptr_value` / `write_ptr_value` - 简单的裸指针读写。
24 let mut buf = [0u8; 8];
25 let buf_ptr = buf.as_mut_ptr() as *mut c_void;
26 unsafe {
27 params::write_ptr_value(buf_ptr, 0x11223344u32);
28 let v: u32 = params::read_ptr_value(buf_ptr as *const c_void);
29 println!("read_ptr_value = 0x{v:08x}");
30 }
31
32 // EN: 3) `ModuleHandle` - open a module and resolve a symbol.
33 // CN: 3) `ModuleHandle` - 打开动态库并解析符号。
34 let m = ModuleHandle::open(common::DEMO_LIB)?;
35 println!("opened module: {}", m.lib_name());
36
37 // EN: Pick a tiny symbol per OS.
38 // CN: 选择一个各平台都常见的小符号。
39 #[cfg(windows)]
40 let sym = "GetCurrentThreadId";
41 #[cfg(unix)]
42 let sym = "puts";
43
44 let addr = m.wrapped_sym(sym);
45 println!("resolved {sym} = {:?}", addr);
46
47 // EN: `cast_ptr` is just a typed cast helper.
48 // CN: `cast_ptr` 只是一个带类型的转换辅助。
49 let _typed: *mut u8 = params::cast_ptr(buf_ptr);
50
51 // EN: CString is a common helper when calling `resolve` directly.
52 // CN: 如果直接用 `resolve`,通常要用 CString 来构造 CStr。
53 let _ = CString::new(sym).ok();
54 Ok(())
55}Sourcepub fn lib_name(&self) -> &str
pub fn lib_name(&self) -> &str
Examples found in repository?
examples/module_params.rs (line 35)
15fn main() -> dobby_rs_framework::Result<()> {
16 // EN: 1) `cast_fn` - turn a raw address into a typed function pointer.
17 // CN: 1) `cast_fn` - 把地址转换成带类型的函数指针。
18 let p = local_add as *const () as *mut c_void;
19 let f: fn(i32) -> i32 = unsafe { params::cast_fn(p) };
20 println!("cast_fn(local_add)(1) = {}", f(1));
21
22 // EN: 2) `read_ptr_value` / `write_ptr_value` - simple raw memory access.
23 // CN: 2) `read_ptr_value` / `write_ptr_value` - 简单的裸指针读写。
24 let mut buf = [0u8; 8];
25 let buf_ptr = buf.as_mut_ptr() as *mut c_void;
26 unsafe {
27 params::write_ptr_value(buf_ptr, 0x11223344u32);
28 let v: u32 = params::read_ptr_value(buf_ptr as *const c_void);
29 println!("read_ptr_value = 0x{v:08x}");
30 }
31
32 // EN: 3) `ModuleHandle` - open a module and resolve a symbol.
33 // CN: 3) `ModuleHandle` - 打开动态库并解析符号。
34 let m = ModuleHandle::open(common::DEMO_LIB)?;
35 println!("opened module: {}", m.lib_name());
36
37 // EN: Pick a tiny symbol per OS.
38 // CN: 选择一个各平台都常见的小符号。
39 #[cfg(windows)]
40 let sym = "GetCurrentThreadId";
41 #[cfg(unix)]
42 let sym = "puts";
43
44 let addr = m.wrapped_sym(sym);
45 println!("resolved {sym} = {:?}", addr);
46
47 // EN: `cast_ptr` is just a typed cast helper.
48 // CN: `cast_ptr` 只是一个带类型的转换辅助。
49 let _typed: *mut u8 = params::cast_ptr(buf_ptr);
50
51 // EN: CString is a common helper when calling `resolve` directly.
52 // CN: 如果直接用 `resolve`,通常要用 CString 来构造 CStr。
53 let _ = CString::new(sym).ok();
54 Ok(())
55}pub fn lib_name_cstr(&self) -> &CStr
pub fn raw(&self) -> *mut c_void
Sourcepub fn wrapped_sym(&self, symbol: &str) -> Option<*mut c_void>
pub fn wrapped_sym(&self, symbol: &str) -> Option<*mut c_void>
Examples found in repository?
examples/module_params.rs (line 44)
15fn main() -> dobby_rs_framework::Result<()> {
16 // EN: 1) `cast_fn` - turn a raw address into a typed function pointer.
17 // CN: 1) `cast_fn` - 把地址转换成带类型的函数指针。
18 let p = local_add as *const () as *mut c_void;
19 let f: fn(i32) -> i32 = unsafe { params::cast_fn(p) };
20 println!("cast_fn(local_add)(1) = {}", f(1));
21
22 // EN: 2) `read_ptr_value` / `write_ptr_value` - simple raw memory access.
23 // CN: 2) `read_ptr_value` / `write_ptr_value` - 简单的裸指针读写。
24 let mut buf = [0u8; 8];
25 let buf_ptr = buf.as_mut_ptr() as *mut c_void;
26 unsafe {
27 params::write_ptr_value(buf_ptr, 0x11223344u32);
28 let v: u32 = params::read_ptr_value(buf_ptr as *const c_void);
29 println!("read_ptr_value = 0x{v:08x}");
30 }
31
32 // EN: 3) `ModuleHandle` - open a module and resolve a symbol.
33 // CN: 3) `ModuleHandle` - 打开动态库并解析符号。
34 let m = ModuleHandle::open(common::DEMO_LIB)?;
35 println!("opened module: {}", m.lib_name());
36
37 // EN: Pick a tiny symbol per OS.
38 // CN: 选择一个各平台都常见的小符号。
39 #[cfg(windows)]
40 let sym = "GetCurrentThreadId";
41 #[cfg(unix)]
42 let sym = "puts";
43
44 let addr = m.wrapped_sym(sym);
45 println!("resolved {sym} = {:?}", addr);
46
47 // EN: `cast_ptr` is just a typed cast helper.
48 // CN: `cast_ptr` 只是一个带类型的转换辅助。
49 let _typed: *mut u8 = params::cast_ptr(buf_ptr);
50
51 // EN: CString is a common helper when calling `resolve` directly.
52 // CN: 如果直接用 `resolve`,通常要用 CString 来构造 CStr。
53 let _ = CString::new(sym).ok();
54 Ok(())
55}Auto Trait Implementations§
impl Freeze for ModuleHandle
impl RefUnwindSafe for ModuleHandle
impl !Send for ModuleHandle
impl !Sync for ModuleHandle
impl Unpin for ModuleHandle
impl UnsafeUnpin for ModuleHandle
impl UnwindSafe for ModuleHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more