2025-04-23 13:01:13 +08:00
|
|
|
|
using dnlib.DotNet;
|
|
|
|
|
using dnlib.DotNet.Emit;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
2025-04-22 22:53:51 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2025-04-20 14:23:40 +08:00
|
|
|
|
|
|
|
|
|
namespace Obfuz.Virtualization
|
|
|
|
|
{
|
|
|
|
|
public class ConstFieldDataNode : DataNodeAny
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public override void Compile(CompileContext ctx)
|
|
|
|
|
{
|
2025-04-23 13:01:13 +08:00
|
|
|
|
ModuleDef mod = ctx.method.Module;
|
|
|
|
|
var output = ctx.output;
|
|
|
|
|
FieldDef field;
|
2025-04-20 14:23:40 +08:00
|
|
|
|
switch (Type)
|
|
|
|
|
{
|
|
|
|
|
case DataNodeType.Int32:
|
|
|
|
|
{
|
2025-04-23 13:01:13 +08:00
|
|
|
|
field = ctx.constFieldAllocator.Allocate(mod, IntValue);
|
2025-04-20 14:23:40 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DataNodeType.Int64:
|
|
|
|
|
{
|
2025-04-23 13:01:13 +08:00
|
|
|
|
field = ctx.constFieldAllocator.Allocate(mod, LongValue);
|
2025-04-20 14:23:40 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DataNodeType.Float32:
|
|
|
|
|
{
|
2025-04-23 13:01:13 +08:00
|
|
|
|
field = ctx.constFieldAllocator.Allocate(mod, FloatValue);
|
2025-04-20 14:23:40 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DataNodeType.Float64:
|
|
|
|
|
{
|
2025-04-23 13:01:13 +08:00
|
|
|
|
field = ctx.constFieldAllocator.Allocate(mod, DoubleValue);
|
2025-04-20 14:23:40 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2025-04-20 15:20:13 +08:00
|
|
|
|
case DataNodeType.String:
|
|
|
|
|
{
|
2025-04-23 13:01:13 +08:00
|
|
|
|
field = ctx.constFieldAllocator.Allocate(mod, StringValue);
|
2025-04-20 15:20:13 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DataNodeType.Bytes:
|
|
|
|
|
{
|
2025-04-22 22:53:51 +08:00
|
|
|
|
// ldsfld
|
|
|
|
|
// ldtoken
|
2025-04-20 15:20:13 +08:00
|
|
|
|
// RuntimeHelpers.InitializeArray(array, fieldHandle);
|
2025-04-23 13:01:13 +08:00
|
|
|
|
//break;
|
|
|
|
|
throw new NotSupportedException("Bytes not supported");
|
2025-04-20 15:20:13 +08:00
|
|
|
|
}
|
2025-04-20 14:23:40 +08:00
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException($"Type:{Type} not implemented");
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-23 13:01:13 +08:00
|
|
|
|
output.Add(Instruction.Create(OpCodes.Ldsfld, field));
|
2025-04-20 14:23:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|