标签:mon 调用 demo 包含 struct 处理机 ges not 设计者


typedef struct _CONTEXT {
//
// The flags values within this flag control the contents of
// a CONTEXT record.
//
// If the context record is used as an input parameter, then
// for each portion of the context record controlled by a flag
// whose value is set, it is assumed that that portion of the
// context record contains valid context. If the context record
// is being used to modify a threads context, then only that
// portion of the threads context will be modified.
//
// If the context record is used as an IN OUT parameter to capture
// the context of a thread, then only those portions of the thread‘s
// context corresponding to set flags will be returned.
//
// The context record is never used as an OUT only parameter.
//
DWORD ContextFlags;
//
// This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
// set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
// included in CONTEXT_FULL.
//
DWORD Dr0;
DWORD Dr1;
DWORD Dr2;
DWORD Dr3;
DWORD Dr6;
DWORD Dr7;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
//
FLOATING_SAVE_AREA FloatSave;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_SEGMENTS.
//
DWORD SegGs;
DWORD SegFs;
DWORD SegEs;
DWORD SegDs;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_INTEGER.
//
DWORD Edi;
DWORD Esi;
DWORD Ebx;
DWORD Edx;
DWORD Ecx;
DWORD Eax;
//
// This section is specified/returned if the
// ContextFlags word contians the flag CONTEXT_CONTROL.
//
DWORD Ebp;
DWORD Eip;
DWORD SegCs; // MUST BE SANITIZED
DWORD EFlags; // MUST BE SANITIZED
DWORD Esp;
DWORD SegSs;
//
// This section is specified/returned if the ContextFlags word
// contains the flag CONTEXT_EXTENDED_REGISTERS.
// The format and contexts are processor specific
//
BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
} CONTEXT;
// ContextDemo.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <process.h>
BOOL bUseing = FALSE;
unsigned int __stdcall ThreadRun(void* lParam)
{
int nNum = 0;
while (true)
{
if (!bUseing)
{
bUseing = TRUE;
_tprintf(TEXT("ThreadRun:%d\r\n"), nNum++);
bUseing = FALSE;
}
}
}
unsigned int __stdcall ThreadMonitor(void* lParam)
{
HANDLE hThread = (HANDLE)(lParam);
while (true)
{
CONTEXT context;
context.ContextFlags = CONTEXT_ALL;
SuspendThread(hThread);
GetThreadContext(hThread, &context);
if (!bUseing)
{
bUseing = TRUE;
_tprintf(TEXT("EAX:0x%x ESP:0x%x EIP:0x%x\r\n"), context.Eax, context.Esp, context.Eip);
bUseing = FALSE;
}
ResumeThread(hThread);
}
}
int main()
{
HANDLE hThreads[2];
hThreads[0] = (HANDLE)_beginthreadex(nullptr, 0, ThreadRun,nullptr, 0, nullptr);
hThreads[1] = (HANDLE)_beginthreadex(nullptr, 0, ThreadMonitor,hThreads[0], 0, nullptr);
WaitForMultipleObjects(sizeof(hThreads)/sizeof(HANDLE),hThreads,true,INFINITE);
for (int i = 0; i<sizeof(hThreads)/sizeof(HANDLE);++i)
{
CloseHandle(hThreads[i]);
}
return 0;
}
PoEdu - Windows阶段班 【Po学校】Lesson006_线程_线程的启动到消亡 &线程状态 & 线程安全 & CONTEXT结构体 & 令牌锁
标签:mon 调用 demo 包含 struct 处理机 ges not 设计者
原文地址:http://www.cnblogs.com/bing-z/p/7067108.html