forked from Whitecat18/Rust-for-Malware-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallfunc_dll.rs
55 lines (45 loc) · 1.63 KB
/
callfunc_dll.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::ffi::CString;
use winapi::um::libloaderapi::{FreeLibrary, GetProcAddress, LoadLibraryA};
const PLU: &str = "[+]";
// Some shit i tried . dont laugh at me @_@
// fn calling(handle:*mut HINSTANCE__ ,name: &str) -> *mut __some_function{
// let name_cstr = Cstring::new(name).unwrap();
// let name_cstr_ptr = unsafe {
// GetProcAddress(handle, name_cstr.as_ptr());
// };
// return name_cstr_ptr
// }
fn main(){
let dll_path = "hook.dll";
unsafe{
let dll_path_cstr = CString::new(dll_path).expect("Failed CString");
let dll_path_ptr = dll_path_cstr.as_ptr();
let handle = LoadLibraryA(dll_path_ptr);
if handle.is_null(){
println!("Failed to load DLL");
return;
}
let name = CString::new("msg_frm_vx").unwrap();
let name_ptr = GetProcAddress(handle, name.as_ptr());
let name1 = CString::new("msg_frm_smukx").unwrap();
let name_ptr1 = GetProcAddress(handle, name1.as_ptr());
if name_ptr.is_null(){
println!("{} Failed to get function Address for vx",PLU);
FreeLibrary(handle);
return;
}
if name_ptr1.is_null(){
println!("{} Failed to get function Address for smukx",PLU);
FreeLibrary(handle);
return;
}
//unsafe
type MyFunction = extern "stdcall" fn();
let my_func: MyFunction = std::mem::transmute(name_ptr);
let my_func1: MyFunction = std::mem::transmute(name_ptr1);
//exec the func
my_func();
my_func1();
FreeLibrary(handle);
}
}