From 49b2976965a372bcac112c210dfcfc3cd16d5be5 Mon Sep 17 00:00:00 2001 From: de4dot Date: Fri, 4 Nov 2011 07:43:24 +0100 Subject: [PATCH] Handle call instrs with invalid metadata tokens --- de4dot.code/deobfuscators/TypesRestorer.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/de4dot.code/deobfuscators/TypesRestorer.cs b/de4dot.code/deobfuscators/TypesRestorer.cs index 1116ef07..5bbce1ca 100644 --- a/de4dot.code/deobfuscators/TypesRestorer.cs +++ b/de4dot.code/deobfuscators/TypesRestorer.cs @@ -470,11 +470,16 @@ namespace de4dot.deobfuscators { // May not return all args. The args are returned in reverse order. PushedArgs getPushedArgInstructions(IList instructions, int index) { - int pushes, pops; - DotNetUtils.calculateStackUsage(instructions[index], false, out pushes, out pops); - if (pops == -1) - return new PushedArgs(0); - return getPushedArgInstructions(instructions, index, pops); + try { + int pushes, pops; + DotNetUtils.calculateStackUsage(instructions[index], false, out pushes, out pops); + if (pops != -1) + return getPushedArgInstructions(instructions, index, pops); + } + catch (System.NullReferenceException) { + // Here if eg. invalid metadata token in a call instruction (operand is null) + } + return new PushedArgs(0); } // May not return all args. The args are returned in reverse order.