Move getLocalVar() and add getArgType()

This commit is contained in:
de4dot 2011-10-31 19:37:26 +01:00
parent 5185dc8364
commit cbf37e8732
2 changed files with 36 additions and 22 deletions

View File

@ -121,6 +121,33 @@ namespace de4dot.blocks {
}
}
// Returns the variable or null if it's not a ldloc/stloc instruction. It does not return
// a local variable if it's a ldloca/ldloca.s instruction.
public static VariableDefinition getLocalVar(IList<VariableDefinition> locals, Instruction instr) {
switch (instr.OpCode.Code) {
case Code.Ldloc:
case Code.Ldloc_S:
case Code.Stloc:
case Code.Stloc_S:
return (VariableDefinition)instr.Operand;
case Code.Ldloc_0:
case Code.Ldloc_1:
case Code.Ldloc_2:
case Code.Ldloc_3:
return locals[instr.OpCode.Code - Code.Ldloc_0];
case Code.Stloc_0:
case Code.Stloc_1:
case Code.Stloc_2:
case Code.Stloc_3:
return locals[instr.OpCode.Code - Code.Stloc_0];
default:
return null;
}
}
public static bool isConditionalBranch(Code code) {
switch (code) {
case Code.Bge:
@ -651,6 +678,14 @@ namespace de4dot.blocks {
return args;
}
public static TypeReference getArgType(MethodReference method, Instruction instr) {
var args = getArgs(method);
int index = getArgIndex(method, instr);
if (0 <= index && index < args.Count)
return args[index];
return null;
}
public static int getArgsCount(MethodReference method) {
int count = method.Parameters.Count;
if (method.HasThis)

View File

@ -45,28 +45,7 @@ namespace de4dot.blocks {
// Returns the variable or null if it's not a ldloc/stloc instruction. It does not return
// a local variable if it's a ldloca/ldloca.s instruction.
public static VariableDefinition getLocalVar(IList<VariableDefinition> locals, Instr instr) {
switch (instr.OpCode.Code) {
case Code.Ldloc:
case Code.Ldloc_S:
case Code.Stloc:
case Code.Stloc_S:
return (VariableDefinition)instr.Operand;
case Code.Ldloc_0:
case Code.Ldloc_1:
case Code.Ldloc_2:
case Code.Ldloc_3:
return locals[instr.OpCode.Code - Code.Ldloc_0];
case Code.Stloc_0:
case Code.Stloc_1:
case Code.Stloc_2:
case Code.Stloc_3:
return locals[instr.OpCode.Code - Code.Stloc_0];
default:
return null;
}
return DotNetUtils.getLocalVar(locals, instr.Instruction);
}
static public bool isFallThrough(OpCode opCode) {