Compiling C# to Native?

后端 未结 11 1341
醉酒成梦
醉酒成梦 2020-12-12 10:26

I think I\'m somewhat confused about compiling .NET byte-code to native code, or maybe I\'m confused about the end result. So please bear with me as I try to sort through w

相关标签:
11条回答
  • 2020-12-12 11:03

    This is possible using the IL2CPU compiler. IL2CPU is developed by the same people who make COSMOS (C# Open Source Managed Operating System) and is only available by downloading cosmos. IL2CPU produces ASM files which can be compiled through Nasm (some other assemblers may work but it is best to use nasm). the only problem with IL2CPU is that it is built in to the Cosmos Project and it is quite difficult to get it to run on its own.

    0 讨论(0)
  • 2020-12-12 11:06

    That's not how ngen.exe works. It merely runs the JIT compiler up front to generate the .ni.exe or .ni.dll module. That binary file does not contain metadata, only the machine code generated from the IL for the method bodies. The CLR still must find the original assembly. Only then can it determine that there is an ngen-ed image available so that it can use the machine code from it rather than generate it from the assembly's IL.

    Ngen.exe speeds up the warm startup time of your app, that's all.

    My usual advice to anybody that might be interested in disassembling my assemblies is to point them to sourceforge.net. It has terabytes of source code, written and maintained by programmers that are usually better than me. Sometimes even with good comments. If your obfuscator doesn't work well then shop around for a better one. There are many.

    0 讨论(0)
  • 2020-12-12 11:06

    If you want to protect your code, an obfuscator is the typical approach. Dotfuscator has been in an arms race with reflector for a while and we use it on our products. In practice, however, a skilled human can easily read obfuscated code.

    Compiling to native code defeats the purpose of having a managed language. The main benefit is to allow the target runtime to JIT the IL into something that is optimally palatable for the target CPU. If you want otherwise, you would use something like the ahead-of-time option in mono.

    0 讨论(0)
  • 2020-12-12 11:11

    this is a free obfuscator, which is quiet good: eazfuscator

    0 讨论(0)
  • 2020-12-12 11:11

    This is finally possible using Microsoft's .NET Native compiler

    It automatically compiles the release version of apps that are written in managed code (C# or Visual Basic) and that target the .NET Framework and Windows 10 to native code.

    ..

    •Your apps will provide the superior performance of native code.

    •You can continue to program in C# or Visual Basic.

    •You can continue to take advantage of the resources provided by the .NET Framework, including its class library, automatic memory management and garbage collection, and exception handling.

    For users of your apps, .NET Native offers these advantages:

    •Fast execution times

    •Consistently speedy startup times

    •Low deployment and update costs

    •Optimized app memory usage

    But .NET Native involves more than a compilation to native code. It transforms the way that .NET Framework apps are built and executed. In particular:

    •During precompilation, required portions of the .NET Framework are statically linked into your app. This allows the app to run with app-local libraries of the .NET Framework, and the compiler to perform global analysis to deliver performance wins. As a result, apps launch consistently faster even after .NET Framework updates.

    •The .NET Native runtime is optimized for static precompilation and thus is able to offer superior performance. At the same time, it retains the core reflection features that developers find so productive.

    •.NET Native uses the same back end as the C++ compiler, which is optimized for static precompilation scenarios.

    https://msdn.microsoft.com/en-us/library/dn584397(v=vs.110).aspx

    This is only available with VS.NET 2015.

    0 讨论(0)
  • 2020-12-12 11:11

    I might step back and ask why you are looking for this type of protection. I'm not trying to argue that you don't need the protection, but I think it is worth understanding the motivation.

    For instance, if you want protection because you have an algorithm in your system where it would be devastating to security if someone reverse-engineered it, then you might need to consider a different approach. It means there is a flaw in the algorithm and no amount of obfuscation or native compiling will help you there.

    If is a matter of IP, then I think obfuscation is probably your best approach here. It is kind of like putting a lock on your door. Someone can break the lock and get in, but they are intentionally doing it as opposed to just walking in the door.

    0 讨论(0)
提交回复
热议问题