readprocessmemory error 299[通俗易懂]

readprocessmemory error 299[通俗易懂]Itrytoreadallcommitedpagesofaprocess(Win7-64).Onmostpagesitworksbutitfailsforafewpages.Icannotexplainwhy.Hereismytestprogramme(compiledx32,testedinWin7-64):#inclu

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

I try to read all commited pages of a process (Win7-64). On most pages it works but it fails for a few pages. I cannot explain why. Here is my test programme (compiled x32, tested in Win7-64):

#include <windows.h> void main() { 
    HANDLE hProc = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,FALSE,GetCurrentProcessId()); SYSTEM_INFO si; ZeroMemory(&si,sizeof(SYSTEM_INFO)); GetSystemInfo(&si); char* buf = new char[si.dwPageSize]; for (unsigned i = 0; i < 0x7fff0; i++) { 
    void* baseOffs = (void*) (i * si.dwPageSize); MEMORY_BASIC_INFORMATION mbi; ZeroMemory(&mbi,sizeof(MEMORY_BASIC_INFORMATION)); if (VirtualQueryEx(hProc, baseOffs, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0) { 
    MessageBox(NULL, TEXT("VirtualQueryEx failed"),TEXT(""),MB_OK); } if (mbi.State == MEM_COMMIT) { 
    SIZE_T numByteWritten = 0; if(ReadProcessMemory(hProc, baseOffs,buf,si.dwPageSize,&numByteWritten) == FALSE) OutputDebugString(TEXT("bad\n")); //GetLastError()==ERROR_PARTIALLY_READ; numByteWritten == 0; else OutputDebugString(TEXT("good\n")); } } delete[] buf; }

I tired to look into the MEMORY_BASIC_INFORMATION for the failing pages but I didn’t find anything strange there. Also the number of failing pages varies from run to run (in average about 5). WHat prevents me from reading these pages? Do I need to adjust some privilges in the process token?

A little bit of debugging and somethings interesting is identified: all pages that fail have protection bit PAGE_GUARD set (see MSDN doc). As I interpret the docs, it is by design that you cannot read these pages with ReadProcessMemory.

if(ReadProcessMemory(hProc, baseOffs,buf,si.dwPageSize,&numByteWritten) == FALSE) { 
     assert(mbi.Protect & 0x100); OutputDebugString(TEXT("bad\n")); //GetLastError()==ERROR_PARTIALLY_READ; numByteWritten == 0;  } else { 
     assert(!(mbi.Protect & 0x100)); OutputDebugString(TEXT("good\n")); }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/185978.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • eclipse Maven配置[通俗易懂]

    eclipse Maven配置[通俗易懂]简述:现需要在Eclipse中配置Maven插件,同时安装maven应用,配置Maven环境变量,建立Maven管理的工程,并用Maven导入Gson包,编写简易Json输出程序步骤:1.首先到EclipseMarketplace中下载MavenIntegrationforEclipseWTP,如下,之后查看是否成功下载,Win

    2022年5月17日
    35
  • HDU 变形课[通俗易懂]

    HDU 变形课[通俗易懂]HDU 变形课

    2022年4月21日
    36
  • python中sqrt的用法_Python中sqrt函数怎么用「建议收藏」

    python中sqrt的用法_Python中sqrt函数怎么用「建议收藏」Python中sqrt函数怎么用?下面给大家带来sqrt函数的相关介绍:Python数字sqrt()函数返回x的平方根(x>0)。语法以下是sqrt()方法的语法-importmathmath.sqrt(x)注意-此函数不可直接访问,需要导入math模块,然后需要使用math静态对象调用此函数。参数x-这是一个数字表达式。返回值该方法返回x的平方根(x>0)。sqrt()…

    2022年6月5日
    69
  • conda 删除源_conda删除包

    conda 删除源_conda删除包记录自己新建一个py3.5的conda环境,遇到镜像连接超级慢,清华的镜像也不太行的亚子,发现之前安装的anaconda中有一个源速度还可以。一、查看自己conda的链接进入cmdcondainfo调出conda的信息二、添加源condaconfig–addchannelshttps://repo.continuum.io/pkgs/main/condaconf…

    2022年9月27日
    0
  • docker 安装rabbitmq 3.8.9

    docker 安装rabbitmq 3.8.9docker配置加速镜像https://www.runoob.com/docker/docker-mirror-acceleration.htmldockerhub仓库查找官方镜像https://registry.hub.docker.com/_/rabbitmq/获取镜像:dockerpullrabbitmq:3.8.9-management查看镜像dockerimages启动镜像dockerrun-d-it–namerabbit…

    2022年5月23日
    59
  • 最常用英语单词2000个[通俗易懂]

    最常用英语单词2000个[通俗易懂]最常用英语单词2000个1 a[ei,ə]art.一(个);任何一(个);每一(个)2 I[ai]pron.我3 ability[əbiliti]n.能力,本领;才能,才智4 able[eibəl]a.能够…的,得以…

    2022年6月23日
    32

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号