obfuz/Editor/Virtualization/DataNodes/ConstDataNode.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2025-04-22 10:42:58 +08:00
using dnlib.DotNet.Emit;
using System;
2025-04-21 08:58:25 +08:00
namespace Obfuz.Virtualization
{
[NodeOutput(DataNodeType.Int32)]
[NodeOutput(DataNodeType.Int64)]
public class ConstDataNode : DataNodeAny
{
public override void Compile(CompileContext ctx)
{
// only Int32 - Null,
// to avoid GC,
// the leaf node that can create string or bytes is ConstFieldDataNode.
// float and double can only come from RawCastAs int32 and int64.
// so we only need to deal int32 and int64
switch (Type)
{
case DataNodeType.Int32:
{
// create ldloc.i4
2025-04-22 10:42:58 +08:00
ctx.output.Add(Instruction.CreateLdcI4(IntValue));
2025-04-21 08:58:25 +08:00
break;
}
case DataNodeType.Int64:
{
// create ldloc.i8
2025-04-22 10:42:58 +08:00
ctx.output.Add(Instruction.Create(OpCodes.Ldc_I8, LongValue));
2025-04-21 08:58:25 +08:00
break;
}
default:
{
throw new NotImplementedException($"Type:{Type} not implemented");
}
}
}
}
}