#include "stdafx.h"
#include "Context.h"
#include <windows.h>
#include <strsafe.h>
#include <process.h>
#define MAX_LOADSTRING 100
DWORD WINAPI thread(PVOID pvParam){
for(int i=0; i<9000000;i++){
1+1+1+1;
}
return 0;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
int x =0;
DWORD ID;
CONTEXT co;
TCHAR buf[100];
HANDLE hThread = (HANDLE)_beginthreadex(NULL,0,(unsigned int (__stdcall *)(void *))thread,(PVOID)&x,0,(unsigned int *)&ID);
GetThreadContext(hThread,&co);
SuspendThread(hThread);
StringCchPrintf(buf,_countof(buf),TEXT("0x%8x"),co.Eip);
MessageBox(NULL,buf,TEXT("爷爷,你要的EIP来了"),MB_OK);
co.ContextFlags = CONTEXT_CONTROL;
co.Eip = 0x10000000;
SetThreadContext(hThread,&co);
GetThreadContext(hThread,&co);
StringCchPrintf(buf,_countof(buf),TEXT("0x%8x"),co.Eip);
MessageBox(NULL,buf,TEXT("爷爷,你要的EIP来了"),MB_OK);
ResumeThread(hThread);
return 0;
}

这篇博客通过一个示例程序详细介绍了如何在Windows环境下进行线程上下文的操作,包括创建线程、获取与设置线程上下文、挂起和恢复线程等关键步骤。通过实际代码演示了如何修改EIP寄存器值,展示了Windows核心编程中的线程控制技巧。
9094

被折叠的 条评论
为什么被折叠?



