cfun 0.2.11

Tidy up common functions
Documentation
#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
use std::{arch::global_asm, ffi::c_void};

#[allow(dead_code)]
type GetKernelAddrType = extern "C" fn() -> i64;

#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
extern "C" {
    #[allow(dead_code)]
    pub fn get_kernel_addr() -> i64;
}

#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
global_asm! {
    "get_kernel_addr:",
    "xor rax, rax",
    "mov rax, gs:[60h]",
    "mov rax, [rax + 18h]",
    "mov rax, [rax + 10h]",
    "mov rax, [rax]",
    "ret",
}

#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
#[repr(C, packed)]
#[allow(dead_code)]
struct InjectParam {
    get_kernel_addr_fun: GetKernelAddrType,
    kernel: *const u16,
    get_proc_address: *const u16,
}

#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
#[repr(C, packed)]
#[allow(non_snake_case)]
struct UnicodeString {
    Length: u16,
    MaximumLength: u16,
    Buffer: *const u16,
}

#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
#[repr(C, packed)]
#[allow(non_snake_case)]
struct ListEntry {
    Flink: *mut ListEntry,
    Blink: *mut ListEntry,
}

#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
#[repr(C, packed)]
#[allow(non_snake_case)]
struct LdrModule {
    InLoadOrderModuleList: ListEntry,
    InMemoryOrderModuleList: ListEntry,
    InInitializationOrderModuleList: ListEntry,
    BaseAddress: *mut c_void,
    EntryPoint: *mut c_void,
    SizeOfImage: u32,
    FullDllName: UnicodeString,
    BaseDllName: UnicodeString,
    Flags: u32,
    LoadCount: i16,
    TlsIndex: i16,
}
#[allow(dead_code)]
#[cfg(all(target_arch = "x86_64", target_os = "windows", feature = "inject"))]
extern "C" fn inject_fun() {
    let param = 0xFEFEFEFEFEFEFEFE as *const InjectParam;
    let get_kernel_addr_fun = unsafe { (*param).get_kernel_addr_fun };
    let kernel_addr = get_kernel_addr_fun();
    let lib = kernel_addr as *const LdrModule;
    unsafe {
        let lib = lib.as_ref().unwrap();
        while !lib.BaseDllName.Buffer.is_null() {}
    };
}