函数名获取函数地址 MmGetSystemRoutineAddress

本文展示了一个简单的Windows驱动程序卸载函数实现示例。该示例通过使用`DriverUnLoad`函数来完成驱动程序的卸载过程,并打印一条消息以确认驱动已成功卸载。此外,还展示了如何获取系统例程地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


#include<ntifs.h>


VOID DriverUnLoad(PDRIVER_OBJECT pDriverObject)
{
	DbgPrint("驱动已卸载...");
}

NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegPath)
{

	NTSTATUS Status;
	ULONG RetAddress;

	pDriverObject->DriverUnload = DriverUnLoad;
	UNICODE_STRING str1;
	RtlInitUnicodeString(&str1, L"PsSynchronizeWithThreadInsertion");
		ULONG PsSynchronizeWithThreadInsertion =(ULONG) MmGetSystemRoutineAddress(&str1);
		KdPrint(("PsSynchronizeWithThreadInsertion %x\n", PsSynchronizeWithThreadInsertion));
	
	return STATUS_SUCCESS;
}

 

#include "ntddk.h" /* 获取指定地址的数值 base:要获取地址 offset:偏移量 size:获取的大小 */ PVOID GetAddrValue(PVOID* base, INT offset, INT size) { PVOID Addr = *base; PVOID templong = 0; //复制内存,将指定位置的内存的值读取出来 RtlCopyMemory(&templong, (PUCHAR)Addr + offset, size); return templong; } VOID DriverUnload(IN PDRIVER_OBJECT DriverObject) { DbgPrint("卸载完成!\n"); } NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) { //通过MmGetSystemRoutineAddress直接获取PsTerminateSystemThread地址 UNICODE_STRING s; CHAR* string = L"PsTerminateSystemThread"; RtlInitUnicodeString(&s, string); PVOID address = MmGetSystemRoutineAddress(&s); DbgPrint("PsTerminateSystemThread Address:%p\n", address); //将PsTerminateSystemThread作为起始地址 ULONG beginAdress =(ULONG) address; //搜索范围限制为0x1000 ULONG endAdress = beginAdress + 0x1000; //刚开始匹配地址为0,表示尚未匹配到 PVOID matchAdress = 0; //开始循环比较 搜索特征码 for (ULONG i=beginAdress;i< endAdress;i+=1) { PVOID value = GetAddrValue(&i, 0, 4); PVOID value2 = GetAddrValue(&i, 0, 3); //特征码为8b ff 55 8b ec 5d e9 小端存储 if (value == 0x8b55ff8b && value2 == 0xe95dec) { //匹配特征码后 赋值,终止循环 matchAdress = i; break; } } DbgPrint("PsTerminateProcess Address:%p\n", address); DriverObject->DriverUnload = DriverUnload; return STATUS_SUCCESS; }分析代码的特征码搜索原理
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值