From 1302608470ec4c359ffffdf0509fbe828318aacf Mon Sep 17 00:00:00 2001 From: de4dot Date: Wed, 9 Nov 2011 11:28:09 +0100 Subject: [PATCH] Move getInstruction() to DotNetUtils.cs --- blocks/DotNetUtils.cs | 17 +++++++++++++++++ blocks/cflow/MethodCallInliner.cs | 25 ++++--------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/blocks/DotNetUtils.cs b/blocks/DotNetUtils.cs index a495f6fb..cc2b9174 100644 --- a/blocks/DotNetUtils.cs +++ b/blocks/DotNetUtils.cs @@ -807,5 +807,22 @@ namespace de4dot.blocks { return type; } + + public static Instruction getInstruction(IList instructions, ref int index) { + for (int i = 0; i < 10; i++) { + if (index < 0 || index >= instructions.Count) + return null; + var instr = instructions[index++]; + if (instr.OpCode.Code == Code.Nop) + continue; + if (instr == null || (instr.OpCode.Code != Code.Br && instr.OpCode.Code != Code.Br_S)) + return instr; + instr = instr.Operand as Instruction; + if (instr == null) + return null; + index = instructions.IndexOf(instr); + } + return null; + } } } diff --git a/blocks/cflow/MethodCallInliner.cs b/blocks/cflow/MethodCallInliner.cs index fa9e95dc..5d6e3879 100644 --- a/blocks/cflow/MethodCallInliner.cs +++ b/blocks/cflow/MethodCallInliner.cs @@ -66,7 +66,7 @@ namespace de4dot.blocks.cflow { return false; int index = 0; - var instr = getInstruction(body.Instructions, ref index); + var instr = DotNetUtils.getInstruction(body.Instructions, ref index); if (instr == null) return false; @@ -109,7 +109,7 @@ namespace de4dot.blocks.cflow { } bool inlineLoadMethod(int patchIndex, MethodDefinition method, Instruction loadInstr, int instrIndex) { - var instr = getInstruction(method.Body.Instructions, ref instrIndex); + var instr = DotNetUtils.getInstruction(method.Body.Instructions, ref instrIndex); if (instr == null || instr.OpCode.Code != Code.Ret) return false; @@ -135,7 +135,7 @@ namespace de4dot.blocks.cflow { if (DotNetUtils.getArgIndex(method, instr) != loadIndex) return false; loadIndex++; - instr = getInstruction(method.Body.Instructions, ref instrIndex); + instr = DotNetUtils.getInstruction(method.Body.Instructions, ref instrIndex); continue; } break; @@ -161,7 +161,7 @@ namespace de4dot.blocks.cflow { return false; } - instr = getInstruction(method.Body.Instructions, ref instrIndex); + instr = DotNetUtils.getInstruction(method.Body.Instructions, ref instrIndex); if (instr == null || instr.OpCode.Code != Code.Ret) return false; @@ -176,22 +176,5 @@ namespace de4dot.blocks.cflow { return false; return newType.FullName == "System.Object"; } - - static Instruction getInstruction(IList instructions, ref int index) { - for (int i = 0; i < 10; i++) { - if (index < 0 || index >= instructions.Count) - return null; - var instr = instructions[index++]; - if (instr.OpCode.Code == Code.Nop) - continue; - if (instr == null || (instr.OpCode.Code != Code.Br && instr.OpCode.Code != Code.Br_S)) - return instr; - instr = instr.Operand as Instruction; - if (instr == null) - return null; - index = instructions.IndexOf(instr); - } - return null; - } } }