关于ReadProcessMemory出错的问题
发表于:
2010-12-31 11:09
6474
使用ReadProcessMemory总是报错 不提升权限的情况下 getlasterror是5 为拒绝访问 提升权限后发现getlasterror为0 但是程序报错 请达人指点 代码如下:
//get "Direct3DCreate9" address
DIRECT3DCREATE9 pDirect3DCreate9 = (DIRECT3DCREATE9)::GetProcAddress(::LoadLibrary("d3d9.dll"), "Direct3DCreate9");
HANDLE hCurrentProcess = GetCurrentProcess();
EnableDebugPri();
unsigned char code[5];
::ReadProcessMemory(hCurrentProcess, (const void*)pDirect3DCreate9, code, 5, 0);
if(code[0] != OPCODE_LONG_JMP)
{
DWORD dwErr = GetLastError();
char chTemp[MAX_PATH];
sprintf_s(chTemp,"操 出错了ReadProcessMemory code[0] != OPCODE_LONG_JMP ErrCode = %d",dwErr);
MessageBox(NULL,chTemp,"唉 错了",MB_OK);
return;
}
BOOL EnableDebugPri()
{
HANDLE hToken;
BOOL fOK = FALSE;
if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken))
{
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
if(!LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tp.Privileges[0].Luid))
{
MessageBox(NULL,"Can't lookup privilege value","Error",MB_OK);
}
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(!AdjustTokenPrivileges(hToken,FALSE,&tp,sizeof(tp),NULL,NULL))
{
MessageBox(NULL,"Can't adjust privilege value","Error",MB_OK);
}
fOK = (GetLastError() == ERROR_SUCCESS);
CloseHandle(hToken);
}
return fOK;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!