diff --git a/blocks/cflow/InstructionEmulator.cs b/blocks/cflow/InstructionEmulator.cs index 786f5b09..18ce2bae 100644 --- a/blocks/cflow/InstructionEmulator.cs +++ b/blocks/cflow/InstructionEmulator.cs @@ -26,6 +26,7 @@ using Mono.Cecil.Metadata; namespace de4dot.blocks.cflow { public class InstructionEmulator { ValueStack valueStack = new ValueStack(); + Dictionary protectedStackValues = new Dictionary(); IList parameterDefinitions; IList variableDefinitions; List args = new List(); @@ -52,6 +53,7 @@ namespace de4dot.blocks.cflow { this.parameterDefinitions = method.Parameters; this.variableDefinitions = method.Body.Variables; valueStack.init(); + protectedStackValues.Clear(); if (method != prev_method) { prev_method = method; @@ -77,6 +79,10 @@ namespace de4dot.blocks.cflow { locals.AddRange(cached_locals); } + public void setProtected(Value value) { + protectedStackValues[value] = true; + } + static Value getUnknownValue(TypeReference typeReference) { if (typeReference == null) return new UnknownValue(); @@ -94,9 +100,11 @@ namespace de4dot.blocks.cflow { return new UnknownValue(); } - static Value truncateValue(Value value, TypeReference typeReference) { + Value truncateValue(Value value, TypeReference typeReference) { if (typeReference == null) return value; + if (protectedStackValues.ContainsKey(value)) + return value; switch (typeReference.EType) { case ElementType.Boolean: @@ -208,6 +216,10 @@ namespace de4dot.blocks.cflow { return new UnknownValue(); } + public int stackSize() { + return valueStack.Size; + } + public void push(Value value) { valueStack.push(value); } diff --git a/blocks/cflow/ValueStack.cs b/blocks/cflow/ValueStack.cs index e9528fd5..7d26d67e 100644 --- a/blocks/cflow/ValueStack.cs +++ b/blocks/cflow/ValueStack.cs @@ -25,6 +25,10 @@ namespace de4dot.blocks.cflow { class ValueStack { List stack = new List(); + public int Size { + get { return stack.Count; } + } + public void init() { stack.Clear(); }