pub struct WinElfLoader { /* private fields */ }Expand description
elf loader
Implementations§
Source§impl WinElfLoader
impl WinElfLoader
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/load.rs (line 15)
5fn main() {
6 extern "sysv64" fn print(s: *const i8) {
7 let s = unsafe { CStr::from_ptr(s).to_str().unwrap() };
8 println!("{}", s);
9 }
10 // Symbols required by dynamic library liba.so
11 let host = SyntheticModule::new(
12 "__host",
13 [SyntheticSymbol::function("print", print as *const ())],
14 );
15 let mut loader: WinElfLoader = WinElfLoader::new();
16 // Load and relocate dynamic library liba.so
17 let liba = loader
18 .load_file(r".\crates\windows-elf-loader\example_dylib\liba.so")
19 .unwrap()
20 .relocator()
21 .scope([host])
22 .relocate()
23 .unwrap();
24 // Call function a in liba.so
25 let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
26 println!("{}", f());
27}More examples
examples/from_memory.rs (line 16)
6fn main() {
7 extern "sysv64" fn print(s: *const i8) {
8 let s = unsafe { CStr::from_ptr(s).to_str().unwrap() };
9 println!("{}", s);
10 }
11
12 let host = ModuleHandle::from(SyntheticModule::new(
13 "__host",
14 [SyntheticSymbol::function("print", print as *const ())],
15 ));
16 let mut loader = WinElfLoader::new();
17 let liba = loader
18 .load_dylib("liba", include_bytes!("../example_dylib/liba.so"))
19 .unwrap()
20 .relocator()
21 .scope([host.clone()])
22 .relocate()
23 .unwrap();
24 let libb = loader
25 .load_dylib("libb", include_bytes!("../example_dylib/libb.so"))
26 .unwrap()
27 .relocator()
28 .scope([host.clone(), ModuleHandle::from(&liba)])
29 .relocate()
30 .unwrap();
31 let libc = loader
32 .load_dylib("libc", include_bytes!("../example_dylib/libc.so"))
33 .unwrap()
34 .relocator()
35 .scope([host.clone(), ModuleHandle::from(&libb)])
36 .relocate()
37 .unwrap();
38 let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
39 assert!(f() == 1);
40 let f = unsafe { libb.get::<extern "sysv64" fn() -> i32>("b").unwrap() };
41 assert!(f() == 2);
42 let f = unsafe { libc.get::<extern "sysv64" fn() -> i32>("c").unwrap() };
43 assert!(f() == 3);
44}examples/relocate.rs (line 16)
6fn main() {
7 extern "sysv64" fn print(s: *const i8) {
8 let s = unsafe { CStr::from_ptr(s).to_str().unwrap() };
9 println!("{}", s);
10 }
11
12 let host = ModuleHandle::from(SyntheticModule::new(
13 "__host",
14 [SyntheticSymbol::function("print", print as *const ())],
15 ));
16 let mut loader = WinElfLoader::new();
17 let liba = loader
18 .load_file(r".\crates\windows-elf-loader\example_dylib\liba.so")
19 .unwrap()
20 .relocator()
21 .scope([host.clone()])
22 .relocate()
23 .unwrap();
24 let libb = loader
25 .load_file(r".\crates\windows-elf-loader\example_dylib\libb.so")
26 .unwrap()
27 .relocator()
28 .scope([host.clone(), ModuleHandle::from(&liba)])
29 .relocate()
30 .unwrap();
31 let libc = loader
32 .load_file(r".\crates\windows-elf-loader\example_dylib\libc.so")
33 .unwrap()
34 .relocator()
35 .scope([host.clone(), ModuleHandle::from(&libb)])
36 .relocate()
37 .unwrap();
38 let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
39 assert!(f() == 1);
40 let f = unsafe { libb.get::<extern "sysv64" fn() -> i32>("b").unwrap() };
41 assert!(f() == 2);
42 let f = unsafe { libc.get::<extern "sysv64" fn() -> i32>("c").unwrap() };
43 assert!(f() == 3);
44}Sourcepub fn load_dylib(
&mut self,
name: &str,
bytes: impl AsRef<[u8]>,
) -> Result<ElfDylib<()>, Error>
pub fn load_dylib( &mut self, name: &str, bytes: impl AsRef<[u8]>, ) -> Result<ElfDylib<()>, Error>
Examples found in repository?
examples/from_memory.rs (line 18)
6fn main() {
7 extern "sysv64" fn print(s: *const i8) {
8 let s = unsafe { CStr::from_ptr(s).to_str().unwrap() };
9 println!("{}", s);
10 }
11
12 let host = ModuleHandle::from(SyntheticModule::new(
13 "__host",
14 [SyntheticSymbol::function("print", print as *const ())],
15 ));
16 let mut loader = WinElfLoader::new();
17 let liba = loader
18 .load_dylib("liba", include_bytes!("../example_dylib/liba.so"))
19 .unwrap()
20 .relocator()
21 .scope([host.clone()])
22 .relocate()
23 .unwrap();
24 let libb = loader
25 .load_dylib("libb", include_bytes!("../example_dylib/libb.so"))
26 .unwrap()
27 .relocator()
28 .scope([host.clone(), ModuleHandle::from(&liba)])
29 .relocate()
30 .unwrap();
31 let libc = loader
32 .load_dylib("libc", include_bytes!("../example_dylib/libc.so"))
33 .unwrap()
34 .relocator()
35 .scope([host.clone(), ModuleHandle::from(&libb)])
36 .relocate()
37 .unwrap();
38 let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
39 assert!(f() == 1);
40 let f = unsafe { libb.get::<extern "sysv64" fn() -> i32>("b").unwrap() };
41 assert!(f() == 2);
42 let f = unsafe { libc.get::<extern "sysv64" fn() -> i32>("c").unwrap() };
43 assert!(f() == 3);
44}Sourcepub fn load_file(&mut self, name: &str) -> Result<ElfDylib<()>, Error>
pub fn load_file(&mut self, name: &str) -> Result<ElfDylib<()>, Error>
Examples found in repository?
examples/load.rs (line 18)
5fn main() {
6 extern "sysv64" fn print(s: *const i8) {
7 let s = unsafe { CStr::from_ptr(s).to_str().unwrap() };
8 println!("{}", s);
9 }
10 // Symbols required by dynamic library liba.so
11 let host = SyntheticModule::new(
12 "__host",
13 [SyntheticSymbol::function("print", print as *const ())],
14 );
15 let mut loader: WinElfLoader = WinElfLoader::new();
16 // Load and relocate dynamic library liba.so
17 let liba = loader
18 .load_file(r".\crates\windows-elf-loader\example_dylib\liba.so")
19 .unwrap()
20 .relocator()
21 .scope([host])
22 .relocate()
23 .unwrap();
24 // Call function a in liba.so
25 let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
26 println!("{}", f());
27}More examples
examples/relocate.rs (line 18)
6fn main() {
7 extern "sysv64" fn print(s: *const i8) {
8 let s = unsafe { CStr::from_ptr(s).to_str().unwrap() };
9 println!("{}", s);
10 }
11
12 let host = ModuleHandle::from(SyntheticModule::new(
13 "__host",
14 [SyntheticSymbol::function("print", print as *const ())],
15 ));
16 let mut loader = WinElfLoader::new();
17 let liba = loader
18 .load_file(r".\crates\windows-elf-loader\example_dylib\liba.so")
19 .unwrap()
20 .relocator()
21 .scope([host.clone()])
22 .relocate()
23 .unwrap();
24 let libb = loader
25 .load_file(r".\crates\windows-elf-loader\example_dylib\libb.so")
26 .unwrap()
27 .relocator()
28 .scope([host.clone(), ModuleHandle::from(&liba)])
29 .relocate()
30 .unwrap();
31 let libc = loader
32 .load_file(r".\crates\windows-elf-loader\example_dylib\libc.so")
33 .unwrap()
34 .relocator()
35 .scope([host.clone(), ModuleHandle::from(&libb)])
36 .relocate()
37 .unwrap();
38 let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
39 assert!(f() == 1);
40 let f = unsafe { libb.get::<extern "sysv64" fn() -> i32>("b").unwrap() };
41 assert!(f() == 2);
42 let f = unsafe { libc.get::<extern "sysv64" fn() -> i32>("c").unwrap() };
43 assert!(f() == 3);
44}Auto Trait Implementations§
impl Freeze for WinElfLoader
impl !RefUnwindSafe for WinElfLoader
impl !Send for WinElfLoader
impl !Sync for WinElfLoader
impl Unpin for WinElfLoader
impl UnsafeUnpin for WinElfLoader
impl !UnwindSafe for WinElfLoader
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