JumpTable BuildJumpTable(Method method) { var jumpTable = new JumpTable(); int gotoCounter = 0; int ifCounter = 0; int switchCounter = 0; foreach (var opcode in method.GetInstructions()) { switch (opcode.Instruction) { case Instructions.Goto: case Instructions.Goto16: case Instructions.Goto32: var gotoOpCode = (dynamic)opcode; jumpTable.AddTarget(gotoOpCode.OpCodeOffset, gotoOpCode.GetTargetAddress(), "goto_", ref gotoCounter); break; case Instructions.PackedSwitch: case Instructions.SparseSwitch: dynamic switchOpCode = opcode; foreach (var switchTarget in switchOpCode.GetTargetAddresses()) { jumpTable.AddTarget(switchOpCode.OpCodeOffset, switchTarget, "switch_", ref switchCounter); } break; case Instructions.IfEq: case Instructions.IfNe: case Instructions.IfLt: case Instructions.IfGe: case Instructions.IfGt: case Instructions.IfLe: case Instructions.IfEqz: case Instructions.IfNez: case Instructions.IfLtz: case Instructions.IfGez: case Instructions.IfGtz: case Instructions.IfLez: dynamic ifOpCode = opcode; jumpTable.AddTarget(ifOpCode.OpCodeOffset, ifOpCode.GetTargetAddress(), "if_", ref ifCounter); break; } } var catchCounter = 0; if (method.TryCatchBlocks != null) { foreach (var tryBlock in method.TryCatchBlocks) { foreach (var catchBlock in tryBlock.Handlers) { jumpTable.AddHandler(catchBlock, "catch_", ref catchCounter); } } } return(jumpTable); }