• 大小: 139KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: 其他
  • 标签:

资源简介

内存加载exe的两种方式(支持win7)

资源截图

代码片段和文件信息

// LoadExeWin32.cpp : 定义控制台应用程序的入口点。
//

#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);
//下面的位置不会被运行,直接在上面吧a**.exe加载到内存然后执行之后调用了退出函数,直接导致本进程退出。
//在a**.exe调用获取本地路径得到的是当前程序的路径,不是a**.exe的路径,这一点类似于dll如果想继续往下执行,
//可用通过参数控制,多次执行同一个程序。
MessageBox(NULL L“tit“ L“tit“ MB_OK);
MemoryFreeLibrary(handle);
return 0;
}


评论

共有 条评论

相关资源