-
-
[讨论]关于MapAndLoad的使用问题
-
发表于: 2007-6-28 16:18 7281
-
为什么将MapAndLoad()最后一个参数设为FALSE,就出错??? 查MSDN如下:
ERROR:20 ERROR_BAD_UNIT The system cannot find the device specified.
为什么在第一种情况下不会出现'系统找不到指定设备',而后者就出现呢,可是我对于要处理的文件可是固定的,另外测试环境为: WIN2K PRO SP4 */
这是刚在XP SP2 中测试的结果:
今天干脆装了个XP,不是代码的问题,是系统的问题,在XP中一切正常;而在2K下总是出现莫名其妙的错误,真是见鬼了???
ERROR:20 ERROR_BAD_UNIT The system cannot find the device specified.
为什么在第一种情况下不会出现'系统找不到指定设备',而后者就出现呢,可是我对于要处理的文件可是固定的,另外测试环境为: WIN2K PRO SP4 */
#include <stdio.h> #include <windows.h> #include <imagehlp.h> #pragma comment(lib, "imagehlp.lib") LPDWORD GetExeEntryPoint(PSTR); //简单的测试一下子程序 int main(void) { DWORD dwEntryPoint; dwEntryPoint = (DWORD)GetExeEntryPoint("D:\\FTP.EXE"); //固定文件,方便测试 return 0; } ////////////////////////////////////////////////////////////////////////// //************************************************************************ //模块名字:GetExeEntryPoint(LPCTSTR) //模块功能:找到目标进程的入口,并将可执行节追加可写属性 //返回数值:成功返回找到的入口地址,失败返回FALSE //注意事项:无 //************************************************************************ //参数说明:参数名 | 输入/输出 | 参数说明 // lpApplicationName | IN | 要处理的可执行文件名 //************************************************************************ /////////////////////////////////////////////////////////////////////////// LPDWORD GetExeEntryPoint(PSTR lpApplicationName) { PIMAGE_NT_HEADERS pNTHeader; PIMAGE_SECTION_HEADER pSectionHeader; DWORD pEntryPoint,dwSectionNum; LOADED_IMAGE Image; PLOADED_IMAGE pImage=&Image; if(!MapAndLoad(lpApplicationName, NULL,pImage,FALSE,TRUE)) //if(!MapAndLoad(lpApplicationName, NULL,pImage,FALSE,FALSE)) /*为什么将最后一个参数设为FALSE,就出错??? 查MSDN如下: ERROR:20 ERROR_BAD_UNIT The system cannot find the device specified. 为什么在第一种情况下不会出现'系统找不到指定设备',而后者就出现呢,可是我 对于要处理的文件可是固定的,另外测试环境为: WIN2K PRO SP4 */ { printf("MapAndLoad ERROR:%X\n",GetLastError()); return 0; } pNTHeader = pImage->FileHeader; dwSectionNum = pImage->NumberOfSections; pSectionHeader = pImage->LastRvaSection; printf("NumberOfSections=%X\n",dwSectionNum); for(DWORD j,i=0;i<dwSectionNum;i++) { j=pSectionHeader->Characteristics; __asm { mov eax,j rol eax,4 cmp al,6 jne _notexec add al,8 _notexec: ror eax,4 mov j,eax } pSectionHeader->Characteristics=j; printf("IMAGE_SECTION_HEADER[%d].Characteristics=%X %X\n", i+1,(pSectionHeader++)->Characteristics,pSectionHeader); } pEntryPoint = pNTHeader->OptionalHeader.AddressOfEntryPoint + pNTHeader->OptionalHeader.ImageBase; UnMapAndLoad(pImage); return (LPDWORD)pEntryPoint; } /////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////// /* 附:MapAndLoad 使用说明 The MapAndLoad function maps an image and preloads data from the mapped file. BOOL MapAndLoad( IN LPSTR ImageName, IN LPSTR DllPath, OUT PLOADED_IMAGE LoadedImage, IN BOOL DotDll, IN BOOL ReadOnly ); Parameters ImageName The name of the image that is loaded. DllPath The path used to locate the image if the name provided cannot be found. If NULL is used, then the search path rules set forth in the SearchPath function will apply. LoadedImage A pointer to a LOADED_IMAGE structure. This structure receives information about the image after it is loaded. DotDll If the image needs to be located and the image name does not contain a file extension, this parameter controls the default extension used for the search process. If the value is TRUE, a .dll extension is used. If the value is FALSE, then a .exe extension is used. ReadOnly If this value is TRUE, the file is mapped for read-access only. If the value is FALSE, the file is mapped for read and write access. Return Values If the function succeeds, the return value is TRUE. If the function fails, then the return value is FALSE. To retrieve extended error information, call GetLastError. Remarks The MapAndLoad function maps an image and preloads data from the mapped file. The corresponding function, UnMapAndLoad , must be used to deallocate all resources that are allocated by the MapAndLoad function. */
这是刚在XP SP2 中测试的结果:
今天干脆装了个XP,不是代码的问题,是系统的问题,在XP中一切正常;而在2K下总是出现莫名其妙的错误,真是见鬼了???
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
赞赏
谁下载
freecat
娃娃[CCG]
zzsx
Tee8088
dwing
szysslszy
lhjjx
执着我一生
dragonyjd
Binny
pentacleNC
Aker
kylix
rufus
HSQ
lwykj
rick
sadnui
NIU
heretic
lsrh
yusjoel
eesoul
dezone
网络游侠
prophet
misterliwe
luogeng
JuncoJet
Netangle
better
draglog
foxxp
小子贼野
nop
AChinese
irp
poop
朱晓东
lrenzhax
海涯苦舟
pazar
still
beehgf
qqzhang
softdiy
红风
sangrant
youye
小灰狼
fengjl
zhouqian
khongninh
有一个人
zgdelphi
哈哈在世
无言无悔
killwolf
huzhao
刘觐肇
PEBOSS
skykrnl
ydfivy
renminbi
内伤
柳州小林
迷茫之中
raygod
slilo
evascz
mszjk
vienna
自由职业
eidolonlon
overwind
luckyzjx
sunnywwc
maxzism
◆华佗◆
CNNY
nineB
山村野人
thisIs
凭凡
Gooleer
wllenyj
ylrainbow
榨sui悲伤
看原图
赞赏
雪币:
留言: