1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | DWORD dwOK;
DWORD dwESP;
DWORD dwCS;
__declspec(naked) func(){
dwOK = 1 ;
__asm {
mov eax, esp
mov dwESP, eax
mov ax, cs
mov word ptr [dwCS], ax
iretd
}
}
int main( int argc, char * argv[])
{
DWORD CR3;
printf( "Input CR3:" );
scanf( "%x" , &CR3);
char bu[ 0x1000 ] = { 0 };
DWORD iTss[ 0x68 ] = {
0x00000000 , / / link
(DWORD)bu, / / esp0
0x00000010 , / / ss0
0x00000000 , / / esp1
0x00000000 , / / ss1
0x00000000 , / / esp2
0x00000000 , / / ss2
(DWORD)CR3,
(DWORD)func, / / eip
0x00000000 , / / eflags
0x00000000 , / / eax
0x00000000 , / / ecx
0x00000000 , / / edx
0x00000000 , / / ebx
(DWORD)bu, / / esp
0x00000000 , / / ebp
0x00000000 , / / esi
0x00000000 , / / edi
0x00000023 , / / es
0x00000008 , / / cs
0x00000010 , / / ss
0x00000023 , / / ds
0x00000030 , / / fs
0x00000000 , / / gs
0x00000000 , / / ldt
0x20ac0000
};
printf( "cr3:%x\n" , CR3);
printf( "func addr:%p\n" , (DWORD)func);
printf( "tss addr:%p\n" , (DWORD)iTss);
int pause;
printf( "input pause:\n" );
scanf( "%x" , &pause);
char buff[ 6 ];
* (DWORD * )&buff[ 0 ] = 0x12345678 ;
* (WORD * )&buff[ 4 ] = 0x48 ;
__asm {
call fword ptr[buff]
}
printf( "ok=%d ESP=%x cs=%x \n" , dwOK, dwESP, dwCS);
getchar();
return 0 ;
}
|