ildasm 和动态 exe 文件

发布于 2024-08-27 16:20:34 字数 475 浏览 10 评论 0原文

我正在尝试创建一个可以修改 IL 中的属性以创建略有不同的可执行文件的应用程序。例如,客户端 A 运行应用程序,WinForm 标签上的标签为“客户端 A:”。客户端 B 运行应用程序,标签显示“客户端 B”。很简单,我知道使用配置文件或资源文件,但这不是这个项目的选项。主程序需要能够根据用户输入的某些表单字段动态生成 .exe 文件。

我的解决方案是创建一个独立的可执行文件,其中包含动态化所需的所有元素。然后,我使用 ildasm 生成 IL,并认为我可以使用此 IL 并替换我想要动态化的元素的标签。然后,我可以在用户使用正则表达式等填写表单后在运行时替换这些标签。 问题是,如果我将 ILDASM 生成的 IL 文件重新保存为 exe 并尝试运行它。我只是启动控制台,什么也不做。

我是否以错误的方式处理这个问题?我不想深入研究 Reflection,因为动态 .exe 非常简单,我认为使用 ildasm 进行逆向工程 IL 将是最快的方法。

非常感谢您的想法和指点。 托尼

I am trying to create an application can modify properties in IL to create a slightly different executable. E.g Client A runs app and a label on the WinForm label Reads "Client A:". Client B runs the app and Label Says "Client B". Easy I know using config files or resource files but thats not an option for this project. The Main program needs to be able to generate .exe file dynamically based on some form fields entered by user.

My solution was to create a standalone executable that contained all the elements which I needed to make dynamic. I then used ildasm to generate the IL and thought that I could use this IL and substitute tags for the elements i wanted to make dynamic. I could then replace those tags at runtime after user filled the form using regex etc.
The problem is, the if i re save the IL file generated by ILDASM as an exe and try to run it. I just launches console and does nothing.

Am I going about this the wrong way? I didnt want to delve into Reflection as the dynamic .exe is a really simple one and I thought reverse engineering IL with ildasm would be the quickest way.

You thoughts and pointers are much appreciated.
Tony

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦屿孤独相伴 2024-09-03 16:20:34

可执行文件是现场生成的吗?或者您是否为客户生成可执行文件,然后发送结果?

如果您是生成可执行文件的人,则可以将客户特定的数据/代码放入单独的 DLL 中,并将其作为资源嵌入到可执行文件中,并在 AppDomain.CurrentDomain.AssemblyResolve 事件发生时加载它。

这样您就可以对客户特定的数据进行版本控制。

Is the executable generated on-site? Or do you generate the executable for a customer and then ship the result?

If you are the one generating the executable, you could put the customer-specific data/code in a separate DLL and embed it in your executable as a resource, and load it when the AppDomain.CurrentDomain.AssemblyResolve event occurs.

That way you can have version control over the customer-specific data.

感情洁癖 2024-09-03 16:20:34

当您说“重新保存”由 ildasm 创建的文件并运行它时,您是否意味着您正在通过 ilasm (提供的 Microsoft IL 编译器)?如果没有,您可能想尝试一下。执行替换时一定要非常小心,因为 IL 有一些非常具体的要求,并且 ilasm 不像 csc 和 vbc 等更高级别的编译器那么宽容。

您还可以使用 Mono.Cecil 来修改程序集文件,这样您就不必将 IL 运送给您的客户。

如果您打算继续传送源代码并编译它,则可以通过传送 C# 源代码并在现场编译来完成相同的操作,而无需涉及 IL,因为 csc 包含在框架中。

When you say "re-save" the file created by ildasm and run it do you mean you are running all of the IL files through ilasm (the provided Microsoft IL compiler)? If not, you may want to try that. Do be very careful when performing your substitution as IL has some quite specific requirements and ilasm is not as forgiving as the higher level compilers like csc and vbc.

You can also use Mono.Cecil to modify assembly files, that way you don't have to ship IL to your customers.

If you are going to continue on the route of shipping the source and compiling it you can accomplish the same thing without involving IL by shipping the C# source and compiling it onsite since csc is included in the framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文