-
大小: 139KB文件類型: .7z金幣: 1下載: 0 次發(fā)布日期: 2021-05-14
- 語(yǔ)言: 其他
- 標(biāo)簽:
資源簡(jiǎn)介
內(nèi)存加載exe的兩種方式(支持win7)
代碼片段和文件信息
//?LoadExeWin32.cpp?:?定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//
#include?“stdafx.h“
#include?“MemoryModule.h“
#include?
#include?
#include?
#pragma?comment(lib?“shlwapi.lib“)
#pragma?warning(disable?:?4996)
using?namespace?std;
unsigned?char?bMemory[1024*1024*2]?=?{0};
DWORD?LoadDll2Memory(string?strDllPath){
FILE?*fpLoadDll;?
char?cCache[1024];????????????
if((fpLoadDll?=?fopen(strDllPath.c_str()“rb“))?==?NULL)?{?
return?0;
}?
DWORD?dwNowReadId?=?0;
while?(1)?{?
ZeroMemory(cCache?sizeof(cCache));
DWORD?dwReadSize?=?fread(cCache11024?fpLoadDll);
DWORD?dwErrorCode?=?GetLastError();
if(dwReadSize?==?0){
break;
}
for(int?i?=?1?;i?<=?dwReadSize?;i?++){
bMemory[dwNowReadId++]?=?cCache[i-1];
}
}?
fclose(fpLoadDll);?????
return?dwNowReadId;
}
VOID?SetCurrentDir(){
WCHAR?wcLocalPath[MAX_PATH*2]?=?{0};
GetModuleFileName(0?wcLocalPath?MAX_PATH);
PathRemoveFileSpec(wcLocalPath);
SetCurrentDirectory(wcLocalPath);
}
int?_tmain(int?argc?_TCHAR*?argv[])
{
//WCHAR?wcCache[MAX_PATH]?=?{0};
????//GetModuleFileName(NULL?wcCache?MAX_PATH);
//MessageBox(NULL?wcCache?L“tit“?MB_OK);
//return?0;
SetCurrentDir();
HMEMORYMODULE?handle;
DWORD?dwFileSize?=?LoadDll2Memory(“c:\\a32.exe“);
handle?=?MemoryLoadLibrary(bMemory?dwFileSize);
MemoryCallEntryPoint(handle);
//下面的位置不會(huì)被運(yùn)行,直接在上面吧a**.exe加載到內(nèi)存然后執(zhí)行之后調(diào)用了退出函數(shù),直接導(dǎo)致本進(jìn)程退出。
//在a**.exe調(diào)用獲取本地路徑得到的是當(dāng)前程序的路徑,不是a**.exe的路徑,這一點(diǎn)類似于dll如果想繼續(xù)往下執(zhí)行,
//可用通過(guò)參數(shù)控制,多次執(zhí)行同一個(gè)程序。
MessageBox(NULL?L“tit“?L“tit“?MB_OK);
MemoryFreeLibrary(handle);
return?0;
}
評(píng)論
共有 條評(píng)論