首次提交

This commit is contained in:
2026-01-17 00:44:30 +08:00
commit 7f56f47f13
7 changed files with 2084 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/target
.idea

1936
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "DNF"
version = "0.1.0"
edition = "2024"
[dependencies]
libloading = "0.9.0"
tracing = "0.1.44"
log_collection = { git = "https://gitea.lingapi.top/Rust/log_service.git", rev = "7086053f" }
tokio = "1.49.0"
once_cell = "1.21.3"

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# WindowsMemoryDemo
Windows Miss.dll以及Usb.dll库的封装

26
src/log.rs Normal file
View File

@@ -0,0 +1,26 @@
// 版权所有 (c) ling 保留所有权利。
// 除非另行说明否则仅允许在DNF中使用此文件中的代码。
//
// 由 ling 创建于 2026/1/16.
#![allow(non_snake_case)]
use std::{env, fs};
use std::path::PathBuf;
/// 获取可执行文件所在目录
pub fn get_current_dir() -> PathBuf {
PathBuf::from(
env::current_exe()
.expect("获取可执行文件路径失败!")
.parent()
.expect("获取可执行文件所在目录失败!"),
)
}
pub fn get_log_path() -> PathBuf {
let exe_path = get_current_dir().join("log");
if !exe_path.exists() {
fs::create_dir_all(&exe_path).expect("创建日志目录失败!");
}
exe_path
}

12
src/main.rs Normal file
View File

@@ -0,0 +1,12 @@
use crate::log::get_log_path;
mod log;
pub mod memory;
#[tokio::main]
async fn main() {
log_collection::init_logging("DNF", env!("CARGO_PKG_NAME"), get_log_path(), None).await;
// 先初始化dll库
memory::init();
}

94
src/memory.rs Normal file
View File

@@ -0,0 +1,94 @@
// 版权所有 (c) ling 保留所有权利。
// 除非另行说明否则仅允许在DNF中使用此文件中的代码。
//
// 由 ling 创建于 2026/1/16.
#![allow(non_snake_case)]
use libloading::{Library, Symbol};
use std::ffi::{CString, c_char, c_void};
use std::sync::OnceLock;
use tracing::{debug, error};
static LIB: OnceLock<Library> = OnceLock::new();
// dll导出符号的函数定义
type FunLoadX = unsafe extern "stdcall" fn(c_key: *const c_char) -> i32;
type FunReadMemory =
unsafe extern "stdcall" fn(pid: i32, address: i64, value: *mut c_void, len: i32) -> bool;
type FunWriteMemory =
unsafe extern "stdcall" fn(pid: i32, address: i64, value: *mut c_void, len: i32) -> bool;
type FunTestCall =
unsafe extern "stdcall" fn(pid: i32, shellcode: *const c_void, len: i32, add: i64);
type FunGetModule = unsafe extern "stdcall" fn(pid: i32, c_name: *mut c_char) -> *mut c_void;
type FunAllocMemory = unsafe extern "stdcall" fn(pid: i32, len: i32) -> *mut c_void;
type FunFreeMemoryNew = unsafe extern "stdcall" fn(pid: i32, address: *mut c_void) -> bool;
type FunProtectPid = unsafe extern "stdcall" fn(pid: i32) -> *mut c_void;
static FUN_LOAD_X: OnceLock<Symbol<FunLoadX>> = OnceLock::new();
static FUN_READ_MEMORY: OnceLock<Symbol<FunReadMemory>> = OnceLock::new();
static FUN_WRITE_MEMORY: OnceLock<Symbol<FunWriteMemory>> = OnceLock::new();
static FUN_TEST_CALL: OnceLock<Symbol<FunTestCall>> = OnceLock::new();
static FUN_GET_MODULE: OnceLock<Symbol<FunGetModule>> = OnceLock::new();
static FUN_ALLOC_MEMORY: OnceLock<Symbol<FunAllocMemory>> = OnceLock::new();
static FUN_FREE_MEMORY_NEW: OnceLock<Symbol<FunFreeMemoryNew>> = OnceLock::new();
static FUN_PROTECT_PID: OnceLock<Symbol<FunProtectPid>> = OnceLock::new();
pub fn init() {
unsafe {
debug!("初始化Miss.dll");
let lib = Library::new("Miss.dll").expect("Miss.dll加载失败");
LIB.set(lib).expect("重复加载!");
debug!("Miss.dll加载成功");
let lib = LIB.get().unwrap();
let fun: Symbol<FunLoadX> = lib.get(b"loadx").expect("查找fun_load_x失败");
FUN_LOAD_X.set(fun).unwrap();
let fun: Symbol<FunReadMemory> = lib.get(b"ReadMemory").expect("查找ReadMemory失败");
FUN_READ_MEMORY.set(fun).unwrap();
let fun: Symbol<FunWriteMemory> = lib.get(b"WriteMemory").expect("查找WriteMemory失败");
FUN_WRITE_MEMORY.set(fun).unwrap();
let fun: Symbol<FunTestCall> = lib.get(b"TestCall").expect("查找TestCall失败");
FUN_TEST_CALL.set(fun).unwrap();
let fun: Symbol<FunGetModule> = lib.get(b"GetModule").expect("查找GetModule失败");
FUN_GET_MODULE.set(fun).unwrap();
let fun: Symbol<FunAllocMemory> = lib.get(b"AllocMemory").expect("查找AllocMemory失败");
FUN_ALLOC_MEMORY.set(fun).unwrap();
let fun: Symbol<FunFreeMemoryNew> = lib.get(b"FreeMemory").expect("查找FreeMemory失败");
FUN_FREE_MEMORY_NEW.set(fun).unwrap();
let fun: Symbol<FunProtectPid> = lib.get(b"ProtectPid").expect("查找ProtectPid失败");
FUN_PROTECT_PID.set(fun).unwrap();
debug!("Miss.dll全部符号加载成功");
if load("CCCCI168DH2s9WJvIDdbg4D6WVIpTy5G") != 0 {
error!("加载key失败");
} else {
debug!("Key加载成功");
}
}
}
fn load<S>(key: S) -> i32
where
S: Into<String>,
{
let c_string = CString::new(key.into()).expect("转CString失败");
let c_ptr = c_string.as_ptr();
let fun = FUN_LOAD_X.get().expect("还没有初始化dll");
unsafe { fun(c_ptr) }
}
pub struct MemoryTools {
/// 目标进程的pid
pid: i32,
}
impl MemoryTools {
pub fn new(pid: i32) -> Self {
todo!()
}
}