WinCE 下进程可访问的代码页的地址获取

来源:互联网 发布:淘宝客推广效果如何 编辑:程序博客网 时间:2024/06/05 22:52

此功能是在看 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;#else4096;#endifif(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_PLATFORMRETAILMSG(1,(L"[CodeAddr]min = 0x%X; max = 0x%X\r\n",pucMin,pucMax));#elseprintf("[CodeAddr]min = 0x%X; max = 0x%X\r\n",pucMin,pucMax);#endif}运行结果:[CodeAddr]min = 0x11000; max = 0x195000


0 0
原创粉丝点击