Move methods to DotNetUtils.cs

This commit is contained in:
de4dot 2011-12-21 06:38:01 +01:00
parent 74b8299ef2
commit 534aba0dfe
2 changed files with 32 additions and 29 deletions

View File

@ -174,6 +174,36 @@ namespace de4dot.blocks {
} }
} }
// Return true if it's one of the stloc instructions
public static bool isStloc(Instruction instr) {
switch (instr.OpCode.Code) {
case Code.Stloc:
case Code.Stloc_0:
case Code.Stloc_1:
case Code.Stloc_2:
case Code.Stloc_3:
case Code.Stloc_S:
return true;
default:
return false;
}
}
// Returns true if it's one of the ldloc instructions
public static bool isLdloc(Instruction instr) {
switch (instr.OpCode.Code) {
case Code.Ldloc:
case Code.Ldloc_0:
case Code.Ldloc_1:
case Code.Ldloc_2:
case Code.Ldloc_3:
case Code.Ldloc_S:
return true;
default:
return false;
}
}
// 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, Instruction instr) { public static VariableDefinition getLocalVar(IList<VariableDefinition> locals, Instruction instr) {

View File

@ -103,7 +103,6 @@ namespace de4dot.blocks {
} }
} }
// Returns true if it's one of the ldc.i4 instructions
public bool isLdcI4() { public bool isLdcI4() {
return DotNetUtils.isLdcI4(OpCode.Code); return DotNetUtils.isLdcI4(OpCode.Code);
} }
@ -112,34 +111,12 @@ namespace de4dot.blocks {
return DotNetUtils.getLdcI4Value(instruction); return DotNetUtils.getLdcI4Value(instruction);
} }
// Return true if it's one of the stloc instructions
public bool isStloc() { public bool isStloc() {
switch (OpCode.Code) { return DotNetUtils.isStloc(instruction);
case Code.Stloc:
case Code.Stloc_0:
case Code.Stloc_1:
case Code.Stloc_2:
case Code.Stloc_3:
case Code.Stloc_S:
return true;
default:
return false;
}
} }
// Returns true if it's one of the ldloc instructions
public bool isLdloc() { public bool isLdloc() {
switch (OpCode.Code) { return DotNetUtils.isLdloc(instruction);
case Code.Ldloc:
case Code.Ldloc_0:
case Code.Ldloc_1:
case Code.Ldloc_2:
case Code.Ldloc_3:
case Code.Ldloc_S:
return true;
default:
return false;
}
} }
public bool isNop() { public bool isNop() {
@ -150,22 +127,18 @@ namespace de4dot.blocks {
return OpCode == OpCodes.Pop; return OpCode == OpCodes.Pop;
} }
// Returns true if it's a leave/leave.s
public bool isLeave() { public bool isLeave() {
return OpCode == OpCodes.Leave || OpCode == OpCodes.Leave_S; return OpCode == OpCodes.Leave || OpCode == OpCodes.Leave_S;
} }
// Returns true if it's a br or br.s instruction
public bool isBr() { public bool isBr() {
return OpCode == OpCodes.Br || OpCode == OpCodes.Br_S; return OpCode == OpCodes.Br || OpCode == OpCodes.Br_S;
} }
// Returns true if it's a brfalse/brfalse.s instr
public bool isBrfalse() { public bool isBrfalse() {
return OpCode == OpCodes.Brfalse || OpCode == OpCodes.Brfalse_S; return OpCode == OpCodes.Brfalse || OpCode == OpCodes.Brfalse_S;
} }
// Returns true if it's a brtrue/brtrue.s instr
public bool isBrtrue() { public bool isBrtrue() {
return OpCode == OpCodes.Brtrue || OpCode == OpCodes.Brtrue_S; return OpCode == OpCodes.Brtrue || OpCode == OpCodes.Brtrue_S;
} }