资源简介
纯C# 实现的 从内存加载动态链接库,支持加壳的DLL,使用方便
class Program
{
public delegate Int32 CompressHandle(ref Byte dest,ref Int32 len, Byte [] source,Int32 sourcelen);
static void Main(string[] args)
{
Byte[] source = new byte[10000];
Byte[] dest = new byte[10000];
Int32 len = source.Length;
Byte[] dllBin = File.ReadAllBytes("zlib1.dll");
using (var dll = new DllLoader())
{
if (dll.LoadLibrary(dllBin))
{
var Compress = dll.GetProcDelegate("compress");
if (Compress != null)
{
var result = Compress.Invoke(ref dest[0], ref len, source, len);
Console.WriteLine(result);
}
}
}
}
}

代码片段和文件信息
using System;
using System.IO;
using System.Runtime.InteropServices;
using InvokeDll.Win32;
namespace InvokeDll
{
///
/// DllMain函数委托
///
///
///
///
///
public delegate Boolean DllMainHandle(IntPtr hModule UInt32 ul_reason_for_call IntPtr lpReserved);
///
/// 动态链接库内存加载器
///
public class DllLoader : IDisposable
{
///
/// 从Byte数组加载Dll
///
///
///
public Boolean LoadLibrary(Byte[] data)
{
IntPtr buffer = IntPtr.Zero;
try
{
buffer = Marshal.AllocHGlobal(data.Length);
Marshal.Copy(data 0 buffer data.Length);
return LoadDll(buffer data.Length);
}
catch (Exception ex)
{
if (hModule != IntPtr.Zero)
{
API.VirtualFreeEx(-1 hModule hModuleSize API.MEM_RELEASE);
hModule = IntPtr.Zero;
}
throw ex;
}
finally
{
Marshal.FreeHGlobal(buffer);
}
}
///
/// 加载dLL
///
///
///
///
private unsafe Boolean LoadDll(IntPtr localPtr Int32 DataLength)
{
IMAGE_DOS_HEADER* dosHeader = (IMAGE_DOS_HEADER*)localPtr;
IMAGE_NT_HEADERS* peHeader = (IMAGE_NT_HEADERS*)(localPtr + dosHeader->e_lfanew);
IMAGE_SECTION_HEADER* sectionHeader = (IMAGE_SECTION_HEADER*)(localPtr + dosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS));
if (dosHeader->e_magic != 0x5A4D)
{
throw new Exception(“DOS file format error“);
}
if (DataLength < dosHeader->e_lfanew + sizeof(IMAGE_DOS_HEADER))
{
throw new Exception(“DOS file header data error“);
}
if (peHeader->Signature != API.IMAGE_NT_SIGNATURE)
{
throw new Exception(“windows file Signature error“);
}
if ((peHeader->FileHeader.Characteristics & API.IMAGE_FILE_DLL) != API.IMAGE_FILE_DLL)
{
throw new Exception(“Dll Not dynamic library“);
}
for (int i = 0; i < peHeader->FileHeader.NumberOfSections; i++)
{
if (sectionHeader->PointerToRawData + sectionHeader->SizeOfRawData > DataLength)
{
throw new Exception(“Section data error“);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-09-08 08:53 InvokeDll\
目录 0 2018-09-08 08:53 InvokeDll\.vs\
目录 0 2018-09-08 16:11 InvokeDll\.vs\InvokeDll\
目录 0 2018-09-08 16:11 InvokeDll\.vs\InvokeDll\DesignTimeBuild\
文件 226 2018-09-08 16:11 InvokeDll\.vs\InvokeDll\DesignTimeBuild\.dtbcache
目录 0 2018-09-08 08:53 InvokeDll\.vs\InvokeDll\v15\
文件 52224 2018-09-08 16:11 InvokeDll\.vs\InvokeDll\v15\.suo
目录 0 2018-09-08 08:53 InvokeDll\.vs\InvokeDll\v15\Server\
目录 0 2018-09-08 08:53 InvokeDll\.vs\InvokeDll\v15\Server\sqlite3\
文件 0 2018-09-08 08:53 InvokeDll\.vs\InvokeDll\v15\Server\sqlite3\db.lock
文件 483328 2018-09-08 15:57 InvokeDll\.vs\InvokeDll\v15\Server\sqlite3\storage.ide
文件 32768 2018-09-08 11:22 InvokeDll\.vs\InvokeDll\v15\Server\sqlite3\storage.ide-shm
文件 4152992 2018-09-08 16:11 InvokeDll\.vs\InvokeDll\v15\Server\sqlite3\storage.ide-wal
目录 0 2018-09-08 16:09 InvokeDll\InvokeDll\
文件 184 2018-09-08 16:02 InvokeDll\InvokeDll\App.config
目录 0 2018-09-08 16:02 InvokeDll\InvokeDll\bin\
目录 0 2018-09-08 16:07 InvokeDll\InvokeDll\bin\Debug\
文件 28672 2018-09-08 16:09 InvokeDll\InvokeDll\bin\Debug\InvokeDll.exe
文件 184 2018-09-08 16:02 InvokeDll\InvokeDll\bin\Debug\InvokeDll.exe.config
文件 69120 2018-09-08 16:09 InvokeDll\InvokeDll\bin\Debug\InvokeDll.pdb
文件 1426944 2016-08-12 07:58 InvokeDll\InvokeDll\bin\Debug\Msvbvm60.dll
文件 180832 2012-07-10 12:07 InvokeDll\InvokeDll\bin\Debug\System.Net.Http.dll
文件 72192 2012-05-11 16:39 InvokeDll\InvokeDll\bin\Debug\zlib.dll
文件 42496 2015-01-10 20:53 InvokeDll\InvokeDll\bin\Debug\zlib1.dll
目录 0 2018-09-08 10:46 InvokeDll\InvokeDll\bin\Release\
目录 0 2018-09-08 16:02 InvokeDll\InvokeDll\bin\x86\
目录 0 2018-09-08 16:02 InvokeDll\InvokeDll\bin\x86\Debug\
文件 14641 2018-09-08 15:57 InvokeDll\InvokeDll\DllLoader.cs
文件 3598 2018-09-08 16:02 InvokeDll\InvokeDll\InvokeDll.csproj
目录 0 2018-09-08 16:02 InvokeDll\InvokeDll\obj\
目录 0 2018-09-08 16:01 InvokeDll\InvokeDll\obj\Debug\
............此处省略28个文件信息
相关资源
- C# IP地址输入控件
- C#在一个窗口刷新更改另一个窗口控件
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
评论
共有 条评论