ULONG ExReleaseFastMutex_addr,ReExReleaseFastMutex_addr;
char g_ExReleaseFastMutex[8];
VOID GetExReleaseFastMutexAddr()
{
ULONG Address=0;
ULONG temp_addr;
char* temp_cr=0;
Address = (ULONG)_KeServiceDescriptorTable->NotUse1.ServiceTableBase + 269 * 4;
temp_addr = *(ULONG*)Address;
temp_addr=temp_addr+0x19A;
temp_cr=(char*)temp_addr;
ExReleaseFastMutex_addr=*((ULONG*)&temp_cr[2]);
ExReleaseFastMutex_addr=*(ULONG*)ExReleaseFastMutex_addr;
}
VOID __declspec(naked)MyExReleaseFastMutex()
{
__asm
{
cmp
ecx,DbgkpProcessDebugPortMutexaddr
jnz ONMYFAST
mov ecx,pMyDbgkpProcessDebugPortMutex
ONMYFAST:
xor eax, eax
mov al, [ecx + 0x1c]
jmp [ReExReleaseFastMutex_addr]
}
}
VOID Patch_ExReleaseFastMutex()
{
KIRQL oldIrql;
unsigned char newcode[] = { 0xE9, 0x44, 0x33, 0x22, 0x11};
GetExReleaseFastMutexAddr();
ReExReleaseFastMutex_addr=ExReleaseFastMutex_addr+5;
*( (ULONG *)(&newcode[1]) ) =(ULONG)MyExReleaseFastMutex-ExReleaseFastMutex_addr-5;
WPOFF();
oldIrql = KeRaiseIrqlToDpcLevel();
memcpy(g_ExReleaseFastMutex,(VOID*)ExReleaseFastMutex_addr,5);
memcpy((VOID*)ExReleaseFastMutex_addr,newcode,5);
KeLowerIrql(oldIrql);
WPON();
}
VOID UnPatch_ExReleaseFastMutex()
{
KIRQL oldIrql;
WPOFF();
oldIrql = KeRaiseIrqlToDpcLevel();
memcpy((VOID*)ExReleaseFastMutex_addr,g_ExReleaseFastMutex,5);
KeLowerIrql(oldIrql);
WPON();
}