WinCE 下进程可访问的代码页的地址获取
时间:2018-11-26 09:46:01
手机看文章
扫描二维码
随时随地手机看文章
[导读]此功能是在看 TCPMP 代码时发现的,感觉以后的工作中可能用到此部分功能,所以记录下来。#include "windef.h"
#include "windows.h"
/*
* 功能: 进程可访
此功能是在看 TCPMP 代码时发现的,感觉以后的工作中可能用到此部分功能,所以记录下来。
#include "windef.h" #include "windows.h" /* * 功能: 进程可访问的代码页 * 参数: pPtr(in) 进程中一函数的指针 ppucMin,ppucMax(out) 输出进程可访问地址的最小/最大值 puiPageSize(in/out) 页面大小设置与输出 */ void CodeAddrFindPages(void *pPtr,unsigned char **ppucMin,unsigned char **ppucMax,unsigned int *puiPageSize) { unsigned char *pucMin = NULL; unsigned char *pucMax = NULL; unsigned int uiPageSize = #if defined(MIPS) 1024; #else 4096; #endif if(puiPageSize) *puiPageSize = uiPageSize; pucMin = pucMax = (unsigned char *)((unsigned int)pPtr & (~(uiPageSize - 1))); // ~ 的优先级高于位操作符 & // Leo: IsBadCodePtr - Determines whether the calling process has read access to the memory at the specified address. while(!IsBadCodePtr((FARPROC)(pucMin - uiPageSize))) pucMin -= uiPageSize; while(!IsBadCodePtr((FARPROC)pucMax)) pucMax += uiPageSize; *ppucMin = pucMin; *ppucMax = pucMax; #ifdef _USE_WINDOWS_CE_PLATFORM RETAILMSG(1,(L"[CodeAddr]min = 0x%X; max = 0x%Xrn",pucMin,pucMax)); #else printf("[CodeAddr]min = 0x%X; max = 0x%Xrn",pucMin,pucMax); #endif } 运行结果: [CodeAddr]min = 0x11000; max = 0x195000