分析ReadProcessMemory如何进入R0【中】

分析ReadProcessMemory如何进入R0【中】

(系统环境:在Windows7 32位操作系统 / 调试器:olldbg 编译器:VS2008)

一.R3进入R0分为两种方式

1.中断门

76ff70c0 8d542408 lea edx,[esp+8]
76ff70c4 cd2e int 2Eh
76ff70c6 c3 ret

中断门进入R0,需要(CS,EIP,SS,ESP)

CS,EIP在IDT表中

SS,ESP由TSS提供

2.快速调用

ntdll!KiFastSystemCall:
76ff70b0 8bd4 mov edx,esp
76ff70b2 0f34 sysenter
76ff70b4 c3 ret

快速调用进入R0,需要(CS,EIP,SS,ESP)

CS,EIP,SS,ESP在MSR寄存器中

3.快速调用与中断门进入R0区别在哪里?

本质是一样!都需要(CS,EIP,SS,ESP)

中断门需要查找[内存]

快速调用需要查找[寄存器]

寄存器比内存速度快,区别就在于这里.

二.重写ReadProcessMemory函数

#include "stdafx.h"
#include <windows.h>

int age = 0x64;
int outBuff = NULL;


BOOL MyReadProcessMemory(HANDLE hProcess,             // handle to the process
	LPCVOID lpBaseAddress,       // base of memory area
	LPVOID lpBuffer,             // data buffer
	DWORD nSize,                 // number of bytes to read
	LPDWORD lpNumberOfBytesRead  // number of bytes read
	)
{


	//快速调用
	//__asm
	//{
	//	//最外层
	//	lea eax,[ebp+0x14];
	//	push eax;
	//	push [ebp+0x14];
	//	push [ebp+0x10];
	//	push    dword ptr [ebp+0Ch] ;
	//	push    dword ptr [ebp+8] ;

	//	sub esp, 4 //模拟返回地址

	//	//内层
	//	mov     eax, 0x115;
	//	mov     edx, 0x7FFE0300;
	//	call    dword ptr[edx];
	//	add esp, 0x18;
	//}

	//中断门
	__asm
	{
		lea eax,[ebp+0x14];
		push eax;
		push [ebp+0x14];
		push [ebp+0x10];
		push    dword ptr [ebp+0Ch] ;
		push    dword ptr [ebp+8] ;
		mov	eax, 0x115;
		mov edx,esp;
		int 0x2E;  //中断门进入R0,所以不需要模拟返回地址
		add esp, 0x14;
	}

	return TRUE;
}


int _tmain(int argc, _TCHAR* argv[])
{
	MyReadProcessMemory(INVALID_HANDLE_VALUE,
		&age, &outBuff, sizeof(outBuff), NULL);
	printf("%d
", outBuff);	
	system("pause");

	return 0;
}
原文地址:https://www.cnblogs.com/Besttwuya/p/14077253.html