obfuz/Editor/Virtualization/DataNodes/ConstFieldDataNode.cs

61 lines
1.9 KiB
C#
Raw Normal View History

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)
{
ModuleDef mod = ctx.method.Module;
var output = ctx.output;
FieldDef field;
2025-04-20 14:23:40 +08:00
switch (Type)
{
case DataNodeType.Int32:
{
field = ctx.constFieldAllocator.Allocate(mod, IntValue);
2025-04-20 14:23:40 +08:00
break;
}
case DataNodeType.Int64:
{
field = ctx.constFieldAllocator.Allocate(mod, LongValue);
2025-04-20 14:23:40 +08:00
break;
}
case DataNodeType.Float32:
{
field = ctx.constFieldAllocator.Allocate(mod, FloatValue);
2025-04-20 14:23:40 +08:00
break;
}
case DataNodeType.Float64:
{
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:
{
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);
//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");
}
}
output.Add(Instruction.Create(OpCodes.Ldsfld, field));
2025-04-20 14:23:40 +08:00
}
}
}