Dnlib - 从加载的程序集中执行 IL MethodBody [英] Dnlib - Execute IL MethodBody from loaded assembly

查看:59
本文介绍了Dnlib - 从加载的程序集中执行 IL MethodBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个简单的 .Net 打包程序开发一个解包程序.

I am working on an unpacker for a simple .Net packer.

我想使用 dnlib 从加载的程序集中执行一个方法.

I would like to execute a method from a loaded assembly using dnlib.

我不能使用 System.Reflection,因为打包器打包了原始的可执行文件,然后它会在执行之前在内存中解包,所以使用反射给了我无法找到 xxx 模块的错误.

I can't use System.Reflection because the packer pack the original executable and then it will unpack in memory before executing so using reflection give me the error unable to find xxx module.

目前我扫描加载的程序集并获取我需要执行解包的方法的 MethodDef.

Currently i scan the loaded assembly and get MethodDef of methods that i need to perform unpacking.

如您所知,有一种方法可以使用 C# 从 dnlib 中加载的程序集执行 IL 代码?

As you know there is a way to execute the IL code from a loaded assembly in dnlib using C#?

这个想法是调用加壳器方法以避免在每次加壳器更新时重写解包器.

The idea is to call packers methods to avoid rewriting of the unpacker at each packer update.

这种情况可能吗?还是只是一个梦?XD

Is this scenario possible? Or it is just a dream? XD

如果不可能,我的另一个想法是编写一个 IL 模拟器.

If it is not possible the other idea that i have is to write an IL emulator.

还有其他方法可以解决这个问题吗?

There are other path to solve this?

非常感谢您抽出宝贵时间.

Thanks a lot for your time.

推荐答案

您不需要 dnlib,只需使用这些方法调用程序集即可.此示例调用一个以单个整数作为参数的方法,该方法返回一个字符串.

You don't need dnlib, just call the assembly using these methods. This example calls a method with a single integer as the argument that returns a string.

var assembly = Assembly.LoadFile(fullpathofexecutable);
BindingFlags eFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

Type classInstance = GetClass("Class196", assembly.GetTypes());

MethodInfo myMethod = classInstance.GetMethod("methodThatIWantToExecute", eFlags);

object[] arguments = {1,2,3 };
string result = (string)myMethod.Invoke(null, arguments);

这篇关于Dnlib - 从加载的程序集中执行 IL MethodBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆