MemoryModule For .NET[内存DLL/EXE加载] v1.0.0.2 by wwh1004
本帖最后由 wwh1004 于 2018-9-23 22:54 编辑打算写个.net程序集打包器,但是fastlzma2/lzma2没.net版本的(LZMA SDK里面c#源码的是lzma,不是lzma2,而且似乎压缩率低很多?)。
于是去github上找peloader,发现了memorymodule,无奈它的.net版本不是太好用,还不能AnyCPU编译。
于是自己转换源码,把c代码转成了c#的,方法名,实现过程和memorymodule完全一致,并且支持AnyCPU编译!!!!!
例子:
```
#pragma warning disable IDE0001
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using MemoryModule;
using size_t = System.IntPtr;
namespace Test
{
public static class MemoryModuleTest
{
private delegate size_t FastLzma2CompressProc(byte[] dst, size_t dstCapacity, byte[] src, size_t srcSize, int compressionLevel, uint nbThreads);
private delegate size_t FastLzma2DecompressProc(byte[] dst, size_t dstCapacity, byte[] src, size_t compressedSize);
private static FastLzma2CompressProc FastLzma2Compress;
private static FastLzma2DecompressProc FastLzma2Decompress;
public static void Test()
{
MemoryModule memoryModule;
byte[] src;
byte[] deced;
using (BinaryReader binaryReader = new BinaryReader(Assembly.GetExecutingAssembly().GetManifestResourceStream($"Test.FLzma2_{(Environment.Is64BitProcess ? "64" : "32")}.dll")))
memoryModule = MemoryModule.Create(binaryReader.ReadBytes((int)binaryReader.BaseStream.Length));
FastLzma2Compress = memoryModule.GetProcDelegate<FastLzma2CompressProc>("FL2_compressMt");
FastLzma2Decompress = memoryModule.GetProcDelegate<FastLzma2DecompressProc>("FL2_decompress");
List<byte> byteList = new List<byte>();
foreach (string filePath in Directory.EnumerateFiles(Environment.CurrentDirectory))
byteList.AddRange(File.ReadAllBytes(filePath));
src = byteList.ToArray();
Compress(src);
deced = Decompress((size_t)src.Length);
Console.WriteLine(src.SequenceEqual(deced));
GC.Collect();
while (true)
Thread.Sleep(int.MaxValue);
}
private static void Compress(byte[] src)
{
byte[] tmp;
size_t size;
byte[] dest;
tmp = new byte;
size = FastLzma2Compress(tmp, (size_t)tmp.Length, src, (size_t)src.Length, 100, 0);
dest = new byte[(ulong)size];
Buffer.BlockCopy(tmp, 0, dest, 0, dest.Length);
File.WriteAllBytes("enced", dest);
}
private static byte[] Decompress(size_t length)
{
byte[] src;
byte[] dest;
src = File.ReadAllBytes("enced");
dest = new byte[(ulong)length];
FastLzma2Decompress(dest, (size_t)dest.Length, src, (size_t)src.Length);
return dest;
}
}
}
#pragma warning restore IDE0001
```
更完整的例子在Tests项目中有,压缩包里找
github:https://github.com/wwh1004/MemoryModule
给个fork给个star呗
上不去github的这里下载(可能不是最新版本,更新都是放在github上)
peter336620 发表于 2018-3-28 23:20
这是反编译看dll或者exe里的源代码吗?想问问如果exe被加密狗加密用这个MemoryModuleSX能有效看到源代码不 ...
不是。loadlibrary只能指定路径,不能加载内存中的dll。这个东西实现了loadlibrary内存中dll 这是反编译看dll或者exe里的源代码吗?想问问如果exe被加密狗加密用这个MemoryModuleSX能有效看到源代码不? 感谢共享好资源 已star,第一个 专业工具 楼主辛苦 感谢共享 这是搞什么用的 上不去github的这里下载(可能不是最新版本,更新都是放在github上)
DotNet Dumper 1.0 by CodeRipper
will show only .NET processes under list,
all dumps will be saved under dumps
页:
[1]
2