obfuz/Editor/Virtualization/Functions/IntXor.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2025-04-23 10:28:27 +08:00
using dnlib.DotNet.Emit;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static UnityEngine.Networking.UnityWebRequest;
namespace Obfuz.Virtualization.Functions
{
public class IntXor : FunctionBase
{
public override void CreateArguments(DataNodeType type, object v, CreateExpressionOptions options, List<ConstValue> args)
{
switch (type)
{
case DataNodeType.Int32:
{
int value = (int)v;
int op1 = options.random.NextInt();
int op2 = value ^ op1;
args.Add(new ConstValue(DataNodeType.Int32, op1));
args.Add(new ConstValue(DataNodeType.Int32, op2));
break;
}
case DataNodeType.Int64:
{
long value = (long)v;
long op1 = options.random.NextLong();
long op2 = value ^ op1;
args.Add(new ConstValue(DataNodeType.Int64, op1));
args.Add(new ConstValue(DataNodeType.Int64, op2));
break;
}
default: throw new NotSupportedException($"Unsupported type {type} for Int32FunctionXor");
}
}
public override void CompileSelf(CompileContext ctx, List<Instruction> output)
{
output.Add(Instruction.Create(OpCodes.Xor));
}
}
}