本帖最后由 wushaominkk 于 2018-5-7 11:05 编辑
学了很长世间内核,由于基础差 一开始 看的脑袋大 在内核级 混了一年依然啥也不会 但明白了该怎么写 但是由于基础差C语言都忘得差不多了 写出来的代码总是有错误,
下面贴一个 自己写的 inline 代码 有问题 我也找不出是哪里错了 MDL inline hook 和一般的那种 设置CR0 的有点区别
[C++] 纯文本查看 复制代码 #include<ntddk.h>
PULONG VA = { 0 };
ULONG VB;
typedef struct ServiceDescriptorEntry {
unsigned int *ServiceTableBase;
unsigned int *ServiceCounterTableBase;
unsigned int NumberOfServices;
unsigned char *ParamTableBase;
}SSDT;
_declspec(dllimport) SSDT KeServiceDescriptorTable;
VOID Unload(PDRIVER_OBJECT driver)
{
}
VOID MY_CODE()
{
KdPrint(("%s",(CHAR*) PsGetCurrentProcess() + 0x16c));
}
__declspec(naked)
VOID MY_JMP_fuction()
{
_asm {
pushad
call MY_CODE
popad
mov ecx, dword ptr[ebp + 14]
mov edx, dword ptr[ebp + 10]
jmp VB
}
}
NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING STRING)
{
#if DBG
_asm int 3;
#endif
CHAR source_copy[6];
PULONG Table_Base = { 0 };
CHAR MY_jmp[6];
PMDL P_mdl;
ULONG length = 1024;
ULONG jmp_length;
PULONG VA_address;
ULONG VC;
Table_Base =(PULONG) KeServiceDescriptorTable.ServiceTableBase[190];
P_mdl =IoAllocateMdl((PVOID)Table_Base, length, FALSE, FALSE, NULL);
MmBuildMdlForNonPagedPool(P_mdl);
MmMapLockedPagesSpecifyCache(P_mdl, KernelMode, MmCached, NULL, FALSE, HighPagePriority);
P_mdl->MdlFlags |= MDL_MAPPED_TO_SYSTEM_VA;
VA_address=MmGetSystemAddressForMdlSafe(P_mdl, HighPagePriority);
//VA = (PULONG)(((ULONG)VA_address) + 0x13);
VA = (PULONG)((ULONG)VA_address + 0x13);
VB = (ULONG)(((ULONG)VA )+ 0x6);
VC = VB;
jmp_length = (ULONG)MY_JMP_fuction - ((ULONG)VA) - 0x6;
MY_jmp[0] = 0x90;
MY_jmp[1] = 0xE9;
*(PULONG)&MY_jmp[2] = (ULONG)jmp_length;
RtlCopyMemory((VOID*)(source_copy), (VOID*)VA, 6); //拷贝源 地址处的代码
RtlCopyMemory((VOID*)VA, MY_jmp, 6);//写入跳转代码
driver->DriverUnload = Unload;
return STATUS_SUCCESS; |