前记
JIT\AOT
JIT编译器(Just-in-Time Complier),AOT编译器(Ahead-of-Time Complier)。

AOT测试
首先编译一段普通代码
using System;
using System.Runtime.InteropServices;
namespace coleak
{
class winfun
{
[DllImport("User32.dll")]
public static extern int MessageBox(IntPtr h, string m, string c, uint type);
[DllImport("kernel32.dll", EntryPoint = "Beep")]
public static extern bool mymethod(uint frequency, uint duration);
}
class Program
{
static void Main(string[] args)
{
winfun winfun = new winfun();
winfun.MessageBox((IntPtr)0, "yueyy", "coleak",(uint) 0);
Random random = new Random();
for (int i = 0; i < 10000; i++)
{
winfun.mymethod((uint)random.Next(10000), 100);
}
Console.ReadLine();
}
}
}
和csc直接编译相比,AOT发布确实可以防止dnspy出源码,但不能解决反汇编,该加壳还是得加壳
优点
不依赖.net框架环境也可以运行
不会被直接反编译而导致代码泄露
缺点
不能Assembly.Load进行动态加载
不支持32位程序
示例如下
using System;
using System.Reflection;
namespace LoadExe
{
class Program
{
static void Main(string[] args)
{
string base64string = @"";
byte[] Buffer = Convert.FromBase64String(base64string);
Assembly assembly = Assembly.Load(Buffer);
Type type = assembly.GetType("DemoExe.Test");
MethodInfo method = type.GetMethod("TestMethod");

本文讨论了AOT编译器在C#中的使用,比较了它与JIT的区别,强调了AOT的优点如无需.NET框架环境、防止源码泄露,以及缺点如不支持动态加载和部分反射API的限制。同时,文章还涉及了JSON反序列化和Emit用于动态创建程序集的过程及其局限性。
最低0.47元/天 解锁文章
1634

被折叠的 条评论
为什么被折叠?



