mirror of
https://github.com/Zypherion-Technologies/UnConfuserEx
synced 2026-06-23 09:25:30 +00:00
31 lines
1.0 KiB
C#
31 lines
1.0 KiB
C#
using dnlib.DotNet.Emit;
|
|
using System;
|
|
|
|
namespace MSILEmulator.Instructions.Branch
|
|
{
|
|
internal static class BranchCompare
|
|
{
|
|
public static int Emulate(Context ctx, Instruction instr, Func<int, int, bool> compareInt, Func<long, long, bool> compareLong)
|
|
{
|
|
object val2 = ctx.Stack.Pop();
|
|
object val1 = ctx.Stack.Pop();
|
|
|
|
if (val1.GetType() != val2.GetType())
|
|
{
|
|
throw new EmulatorException($"Attempted to compare different types {val1.GetType()} != {val2.GetType()}");
|
|
}
|
|
|
|
bool branch = val1 switch
|
|
{
|
|
int leftInt => compareInt(leftInt, (int)val2),
|
|
long leftLong => compareLong(leftLong, (long)val2),
|
|
_ => throw new NotImplementedException($"Comparison of {val1.GetType().Name} not handled")
|
|
};
|
|
|
|
return branch
|
|
? ctx.Offsets[((Instruction)instr.Operand).Offset]
|
|
: ctx.Offsets[instr.Offset] + 1;
|
|
}
|
|
}
|
|
}
|