Files
sheet-rat/Server/MindLated/Protection/CtrlFlow/BlockParser.cs
T

55 lines
2.0 KiB
C#
Raw Normal View History

2026-08-27 11:23:25 -06:00
// Decompiled with JetBrains decompiler
// Type: MindLated.Protection.CtrlFlow.BlockParser
// Assembly: Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 33673F0A-7F43-4A2B-BC08-8E59A15CB7DA
// Assembly location: C:\Users\Admin\Desktop\Sheet RAT 2.5\Server.exe
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using System.Collections.Generic;
//#nullable disable
namespace MindLated.Protection.CtrlFlow {
public class BlockParser
{
public static List<Block> ParseMethod(MethodDef method)
{
List<Block> method1 = new List<Block>();
Block block1 = new Block();
int num1 = 0;
int num2 = 0;
block1.Number = num1;
block1.Instructions.Add(Instruction.Create(OpCodes.Nop));
method1.Add(block1);
Block block2 = new Block();
Stack<ExceptionHandler> exceptionHandlerStack = new Stack<ExceptionHandler>();
foreach (Instruction instruction in (IEnumerable<Instruction>) method.Body.Instructions)
{
foreach (ExceptionHandler exceptionHandler in (IEnumerable<ExceptionHandler>) method.Body.ExceptionHandlers)
{
if (exceptionHandler.HandlerStart == instruction || exceptionHandler.TryStart == instruction || exceptionHandler.FilterStart == instruction)
exceptionHandlerStack.Push(exceptionHandler);
}
foreach (ExceptionHandler exceptionHandler in (IEnumerable<ExceptionHandler>) method.Body.ExceptionHandlers)
{
if (exceptionHandler.HandlerEnd == instruction || exceptionHandler.TryEnd == instruction)
exceptionHandlerStack.Pop();
}
int pushes;
int pops;
instruction.CalculateStackUsage(out pushes, out pops);
block2.Instructions.Add(instruction);
num2 += pushes - pops;
if (pushes == 0 && instruction.OpCode != OpCodes.Nop && (num2 == 0 || instruction.OpCode == OpCodes.Ret) && exceptionHandlerStack.Count == 0)
{
block2.Number = ++num1;
method1.Add(block2);
block2 = new Block();
}
}
return method1;
}
}
}