动态加载dll

功能:

     把一个处于内存里的dll直接加载并且使用。

用途:

     免杀(静态文件查杀),外挂(防止游戏自己hook了loadlibrary等函数),以及其他。

原理: 

    假设目前处于内存里的dll是A,然后开辟一个新的内存空间B,根据A的文件头等相关信息,把B看做是加载内存。

然后把数据拷贝到B里,并且对齐相关节,然后修正iat等相关。然后在手动调用一次dllmain函数,这样dll就被从内存A

加载到内存B里了。之后再调用函数的时候,直接根据函数名,在INT或者其他位置找到函数地址,这个过程就是模拟了

GetProcAddress函数的功能。

整理了一个内存加载dll相关的类以及测试项目代码:(http://download.csdn.net/detail/u013761036/9686863)

下面是相关测试代码:

#include "stdafx.h"
#include <string>
#include <windows.h>
#include <shlwapi.h>
#include "MemLoadDll.h"
#pragma comment(lib, "shlwapi.lib")
using namespace std;
#pragma warning(disable : 4996) unsigned char bMemory[1024*1024*5] = {0}; DWORD dwLoadDll2Memory(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(cCache,1,1024 ,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[])
{
//mark : After loading a function related to the memory will be released, that is, only one function can be loaded to perform SetCurrentDir(); DWORD dwFileLength = dwLoadDll2Memory("TestDll.dll");
CMemLoadDll *clLoadClass = new CMemLoadDll();
BOOL bLoadDllResult = clLoadClass->MemLoadLibrary(bMemory ,dwFileLength); if(bLoadDllResult){
typedef VOID (*TYPEPRINTFMSE)(const string &strMessage);
TYPEPRINTFMSE _PrintfMse = (TYPEPRINTFMSE)clLoadClass->MemGetProcAddress("PrintfMse");
if(_PrintfMse){
_PrintfMse("Memory load function executed successfully!");
}else{
// getprocaddress error
}
}else{
//loadlibrary error
} delete clLoadClass;
return 0;
}

最新文章

  1. HTML 获取屏幕、浏览器、页面的高度宽度
  2. 简单生成svg文件
  3. Oracle表空间,用户,用户授权
  4. linux的多媒体 播放 软件版权问题
  5. Practical JAVA(二)关于对象的类型和equals函数
  6. 设置让ASP.NET管道接收所有类型的请求
  7. 【转载】两军问题与Paxos算法 &amp; 动画讲解Paxos算法
  8. class 类(3) 继承
  9. 您在基于 Windows 7 的或基于 Windows Server 2008 R2 的计算机上读取器中插入智能卡时出现错误消息:&quot;设备驱动程序软件未能成功安装&quot;
  10. poj 3767 I Wanna Go Home
  11. Windows下Oracle不显示中文[已解决]
  12. JavaScript学习笔记(十二)——箭头函数(Arrow Function)
  13. windows c++ 错误汇总
  14. cookie跟session自我介绍
  15. 【LOJ6074】【2017 山东一轮集训 Day6】子序列 DP
  16. 转:Excel—“撤销工作表保护密码”的破解并获取原始密码
  17. python_Tkinter
  18. win10 python27pyhton36共存
  19. vs2017添加引用出错:对COM组件的调用返回了错误HRESULT E_FAIL
  20. C#与Excel的交互示例

热门文章

  1. 2020年12月-第02阶段-前端基础-CSS初识
  2. js 数组的浅拷贝和深拷贝
  3. DRF(django rest-framework)
  4. WPF 应用 - 通过 js 缩放 System.Windows.Controls.WebBrowser 的内容
  5. SpringBoot源码修炼—系统初始化器
  6. [源码分析] 消息队列 Kombu 之 Producer
  7. HDU_5414 CRB and String 【字符串】
  8. 详解 ZooKeeper 数据持久化
  9. java例题_10小球 自由落体
  10. Redis主从&amp;哨兵集群搭建