Add method to return stack size and not truncate locals/args
This commit is contained in:
parent
c1abe2965b
commit
61bb3abdee
|
@ -26,6 +26,7 @@ using Mono.Cecil.Metadata;
|
||||||
namespace de4dot.blocks.cflow {
|
namespace de4dot.blocks.cflow {
|
||||||
public class InstructionEmulator {
|
public class InstructionEmulator {
|
||||||
ValueStack valueStack = new ValueStack();
|
ValueStack valueStack = new ValueStack();
|
||||||
|
Dictionary<Value, bool> protectedStackValues = new Dictionary<Value, bool>();
|
||||||
IList<ParameterDefinition> parameterDefinitions;
|
IList<ParameterDefinition> parameterDefinitions;
|
||||||
IList<VariableDefinition> variableDefinitions;
|
IList<VariableDefinition> variableDefinitions;
|
||||||
List<Value> args = new List<Value>();
|
List<Value> args = new List<Value>();
|
||||||
|
@ -52,6 +53,7 @@ namespace de4dot.blocks.cflow {
|
||||||
this.parameterDefinitions = method.Parameters;
|
this.parameterDefinitions = method.Parameters;
|
||||||
this.variableDefinitions = method.Body.Variables;
|
this.variableDefinitions = method.Body.Variables;
|
||||||
valueStack.init();
|
valueStack.init();
|
||||||
|
protectedStackValues.Clear();
|
||||||
|
|
||||||
if (method != prev_method) {
|
if (method != prev_method) {
|
||||||
prev_method = method;
|
prev_method = method;
|
||||||
|
@ -77,6 +79,10 @@ namespace de4dot.blocks.cflow {
|
||||||
locals.AddRange(cached_locals);
|
locals.AddRange(cached_locals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProtected(Value value) {
|
||||||
|
protectedStackValues[value] = true;
|
||||||
|
}
|
||||||
|
|
||||||
static Value getUnknownValue(TypeReference typeReference) {
|
static Value getUnknownValue(TypeReference typeReference) {
|
||||||
if (typeReference == null)
|
if (typeReference == null)
|
||||||
return new UnknownValue();
|
return new UnknownValue();
|
||||||
|
@ -94,9 +100,11 @@ namespace de4dot.blocks.cflow {
|
||||||
return new UnknownValue();
|
return new UnknownValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Value truncateValue(Value value, TypeReference typeReference) {
|
Value truncateValue(Value value, TypeReference typeReference) {
|
||||||
if (typeReference == null)
|
if (typeReference == null)
|
||||||
return value;
|
return value;
|
||||||
|
if (protectedStackValues.ContainsKey(value))
|
||||||
|
return value;
|
||||||
|
|
||||||
switch (typeReference.EType) {
|
switch (typeReference.EType) {
|
||||||
case ElementType.Boolean:
|
case ElementType.Boolean:
|
||||||
|
@ -208,6 +216,10 @@ namespace de4dot.blocks.cflow {
|
||||||
return new UnknownValue();
|
return new UnknownValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int stackSize() {
|
||||||
|
return valueStack.Size;
|
||||||
|
}
|
||||||
|
|
||||||
public void push(Value value) {
|
public void push(Value value) {
|
||||||
valueStack.push(value);
|
valueStack.push(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@ namespace de4dot.blocks.cflow {
|
||||||
class ValueStack {
|
class ValueStack {
|
||||||
List<Value> stack = new List<Value>();
|
List<Value> stack = new List<Value>();
|
||||||
|
|
||||||
|
public int Size {
|
||||||
|
get { return stack.Count; }
|
||||||
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
stack.Clear();
|
stack.Clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user