Add method to return stack size and not truncate locals/args

This commit is contained in:
de4dot 2012-05-02 10:44:34 +02:00
parent c1abe2965b
commit 61bb3abdee
2 changed files with 17 additions and 1 deletions

View File

@ -26,6 +26,7 @@ using Mono.Cecil.Metadata;
namespace de4dot.blocks.cflow {
public class InstructionEmulator {
ValueStack valueStack = new ValueStack();
Dictionary<Value, bool> protectedStackValues = new Dictionary<Value, bool>();
IList<ParameterDefinition> parameterDefinitions;
IList<VariableDefinition> variableDefinitions;
List<Value> args = new List<Value>();
@ -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);
}

View File

@ -25,6 +25,10 @@ namespace de4dot.blocks.cflow {
class ValueStack {
List<Value> stack = new List<Value>();
public int Size {
get { return stack.Count; }
}
public void init() {
stack.Clear();
}