Skip to content

Commit 9e92db9

Browse files
committed
basic of dll
1 parent fe23a2d commit 9e92db9

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

dll_injection/callfunc_dll.rs

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

dll_injection/hook.dll.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::{ffi::CString, ptr::null_mut};
2+
use winapi::um::winuser::{MessageBoxA, MB_OK};
3+
4+
/*
5+
#[no_mangle] Short Explain
6+
- no_mangle is used to interoperate with C code meaning we can call
7+
these functions directly from C without any naming conflicts.
8+
- It can also used to keep its original name during the compile time.
9+
*/
10+
#[no_mangle]
11+
pub extern "stdcall" fn msg_frm_vx(){
12+
let msg = CString::new("DLL's are awesome ! Especially Exec in Rust").expect("Failed");
13+
let cap = CString::new("Message From Vx-Underground").expect("Error cap");
14+
unsafe{
15+
MessageBoxA(null_mut(), msg.as_ptr(), cap.as_ptr(), MB_OK);
16+
}
17+
}
18+
19+
// stdcall in C
20+
#[no_mangle]
21+
pub extern "system" fn msg_frm_smukx(){
22+
let msg = CString::new("Custom DLL's are always Cool. Bye").expect("Failed");
23+
let cap = CString::new("Message From SMukx").expect("Error cap");
24+
unsafe{
25+
MessageBoxA(null_mut(), msg.as_ptr(), cap.as_ptr(), MB_OK);
26+
}
27+
}

0 commit comments

Comments
 (0)