VirtualProtectEx 失败并显示 ERROR_NOACCESS(错误代码 998) [英] VirtualProtectEx fails with ERROR_NOACCESS (error code 998)

查看:50
本文介绍了VirtualProtectEx 失败并显示 ERROR_NOACCESS(错误代码 998)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CreateProcess("something.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, 
    NULL, NULL, &sInfo, &pInfo);

ReadProcessMemory(pInfo.hProcess, (LPCVOID) (contx.Ebx + 8),
  (LPVOID) &baseAddress, sizeof(baseAddress), NULL);

hProcess=OpenProcess(PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION,
  FALSE, pInfo.dwProcessId);

VirtualProtectEx(hProcess, (LPVOID) baseAddress, sizeof(IMAGE_DOS_HEADER),
    PAGE_EXECUTE_READWRITE, NULL);

WriteProcessMemory(hProcess, (LPVOID) baseAddress, (LPCVOID) pidh,
    sizeof(IMAGE_DOS_HEADER), NULL);

为什么 VirtualProctecEx 给我 ERROR_NOACCESS ?

Why VirtualProctecEx gives me ERROR_NOACCESS ?

推荐答案

VirtualProtectEx 文档说

lpflOldProtect [out] 指向接收指定区域第一页的先前访问保护页数.如果此参数为 NULL 或未指向有效变量,函数失败.

lpflOldProtect [out] A pointer to a variable that receives the previous access protection of the first page in the specified region of pages. If this parameter is NULL or does not point to a valid variable, the function fails.

关于最后一个论点.您正在传递 NULL,因此应该期望它会失败.

about the last argument. You're passing NULL so should expect it to fail.

可能还有其他问题.例如你不检查 ReadProcessMemory 所以 baseAddress 可能无效.

Its possible there are also other problems. e.g. you don't check the return value from ReadProcessMemory so baseAddress may be invalid.

这篇关于VirtualProtectEx 失败并显示 ERROR_NOACCESS(错误代码 998)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆