Move getLocalVar() and add getArgType()
This commit is contained in:
parent
5185dc8364
commit
cbf37e8732
|
@ -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) {
|
public static bool isConditionalBranch(Code code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case Code.Bge:
|
case Code.Bge:
|
||||||
|
@ -651,6 +678,14 @@ namespace de4dot.blocks {
|
||||||
return args;
|
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) {
|
public static int getArgsCount(MethodReference method) {
|
||||||
int count = method.Parameters.Count;
|
int count = method.Parameters.Count;
|
||||||
if (method.HasThis)
|
if (method.HasThis)
|
||||||
|
|
|
@ -45,28 +45,7 @@ namespace de4dot.blocks {
|
||||||
// Returns the variable or null if it's not a ldloc/stloc instruction. It does not return
|
// 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.
|
// a local variable if it's a ldloca/ldloca.s instruction.
|
||||||
public static VariableDefinition getLocalVar(IList<VariableDefinition> locals, Instr instr) {
|
public static VariableDefinition getLocalVar(IList<VariableDefinition> locals, Instr instr) {
|
||||||
switch (instr.OpCode.Code) {
|
return DotNetUtils.getLocalVar(locals, instr.Instruction);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public bool isFallThrough(OpCode opCode) {
|
static public bool isFallThrough(OpCode opCode) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user