转换.NET应用程序,以原生的x86 code [英] Converting .NET App to x86 native code

查看:173
本文介绍了转换.NET应用程序,以原生的x86 code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有完全用C#编写一个程序,面向.NET Framework 2.0的。 有没有一种方法,我可以以某种方式编译(翻译)管理的EXE到本机之一,所以它可能是.NET无关?我知道有可能是商业产品为目的...但他们是有点贵。

的问题是,我们要部署运行Windows XP没有安装.NET框架的计算机上的程序。还有一个要求,即该程序的大小必须不超过500KB(1Mb的最大值),直到它从网络服务器下载的(即现在的大小是255KB)。这就是为什么没有办法,我们可以附加一个完全成熟的.NET FX(或者甚至是降低的)来下载程序的文件。

显然,这是应被检测,并避免了前面,所以我们可以使用本机的技术,如C ++一个可怕的软件工程的错误信息。

我们已经尝试过,现在的Novell的Mono - 一个开源实现.NET框架为Linux,Mac和Windows。单由C#编译器,IDE,运行时(CLR)和类库组件(如System.dll中和mscorlib.dll中 - 就像安装到GAC .NET的类库组件)。 我们试图做的是要找到CLR文件,并把那些伴随着我们的程序的文件和一些组件。通过这种方式,程序可以通过运行单PROGRAM.EXE(命令提示)在用户的计算机上被调用。 除了对最终用户的CLR文件(mono.exe和mono.dll)这样的使用上的不便竟然是约2.5 MB的总比所需500 KB或甚1Mb的大得多。

所以,我们留下没有其他选择,只能由编译器把我们的.NET应用程序到本机之一,然而问题依然存在 - 我们应该用什么样的编译器,我们在这里可以找到一个...

现在我已经偶然发现了一个奇异OS项目由微软研究院。这是(至少部分)写在管理code一个开放源代码的研究操作系统。奇点的操作系统包括操作系统使用,以托管的程序转换为一个本地一(86的32位)一个巴托克的编译器。应该指出的是,巴托克无法翻译的.NET 2.0的所有方面,以天然code,但其中的大多数。不过,我还没有学会如何使用奇异...

我会很感激你,如果你能为我提供了关于这个问题的一些有用的提示和建议,你自己的经验与奇异操作系统和巴托克的编译器或其他方法的问题,我忽略了,解决它的方法。

非常感谢你提前!

最后,使用Mono的全部AOT功能(在卡勒姆·罗杰斯的意见)我已经成功地生产出program.exe.dll缺乏一个CLI头。 因此,在我看来像一个本地的dll。不过,我无法弄清楚如何在DLL转换为EXE或使其运作。 另外这个DLL似乎并没有暴露任何感兴趣的功能,如主要功能。

从Mono项目
解决方案

查看AOT(提前)编译。这将编译您管理的项目到本地EXE或ELF可执行文件(取决于系统你的目标),其 不需要JIT。这是用来获取单应用程序到iPhone(其中JIT /框架是不允许的)的技术,还具有更快的启动时间的增加的好处,更低的内存使用,这使得它很难为人们反编译你的code 。你说你已经在使用单声道,所以它应该是兼容的。

读了一下在mono-project.com网站和的在米格尔·伊卡萨的博客(和的 iPhone信息)。

请注意,您不能使用动态code或通用的接口,如

 接口IFoo的< T> {
...
    无效的someMethod();
}
 

和你将不得不编译所有你使用的库的DLL文件。

PS:一定要使用全AOT您的问题

There's a program written entirely in C# that targets .NET Framework 2.0. Is there a way I could somehow compile (translate) managed EXE to a native one so it could be .NET-agnostic? I know there are probably commercial products for that purpose... but they are a bit expensive.

The problem is that we are to deploy the program on computers running Windows XP with no .NET Framework installed. There's also a requirement that the program's size must not exceed 500Kb (1Mb maximum) for it is downloaded from the web server (now the size is 255Kb). That is why there's no way we could attach a full-fledged .NET FX (or even a reduced one) to the downloaded program's file.

Obviously it is a terrible software engineering error that should have been detected and avoided earlier so we could use native technologies like C++ instead.

We have tried for now Novell's Mono - an open-source implementation of .NET Framework for Linux, MAC and Windows. Mono consists of C# Compiler, IDE, runtime (CLR) and Class Library assemblies (like System.dll and mscorlib.dll - much like .NET's class library assemblies installed to GAC). What we tried to do is to locate CLR files and ship those along with our program's file and a few assemblies. This way the program can be invoked by running "mono program.exe" (command prompt) on a user's computer. In addition to the inconvenience of such a use for the end user CLR files (mono.exe and mono.dll) turned out to be about 2.5 Mb in total that is much greater than the desired 500 Kb or even 1 Mb.

So, we have left with no other option but to translate our .NET App to a native one by a compiler, however the question remains - what compiler should we use and where could we find one...

For now I have stumbled upon a Singularity OS Project by Microsoft Research. It is an open-source research OS that is written in managed code (in part at least). The Singularity OS includes a Bartok compiler that the OS uses in order to translate a managed program to a native one (x86 32 bit). It should be noted that Bartok can't translate all the aspects of .NET 2.0 to a native code, but most of them. However I haven't yet learnt how to use the Singularity...

I would be really grateful to you if you could provide me with some useful tips and advice regarding the problem, your own experience with Singularity OS and Bartok Compiler or another approaches to the problem that I have overlooked and ways of solving it.

Thank you very much in advance!

Finally, using Mono's Full AOT feature (on Callum Rogers' advice) I've managed to produce a program.exe.dll that lacks a CLI header. So it looks to me like a native dll. However I can't figure out how to convert that dll into exe or make it operational. Also this dll doesn't seem to expose any functions of interest such as main function.

解决方案

Check out AOT (Ahead Of Time) Compilation from the Mono project. This compiles your managed project into a native exe or an elf executable (depending on which system you target) that does not need the JIT. This is the technique used to get mono apps onto the iPhone (where the JIT/Framework are not allowed) and also has the added benefits of faster startup times, lower memory usage and it makes it harder for people to decompile your code. You said you were already using Mono, so it should be compatible.

Read up about it at the mono-project.com website and at Miguel de Icaza's blog (and iPhone info).

Note that you cannot use dynamic code or generic interfaces like

interface IFoo<T> {
...
    void SomeMethod ();
}

And you will have to compile the DLLs of all the libraries you use.

PS: Make sure to use "Full" AOT for your problem.

这篇关于转换.NET应用程序,以原生的x86 code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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