本文整理汇总了C#中Mono.Cecil.Cil.OpCode类的典型用法代码示例。如果您正苦于以下问题:C# OpCode类的具体用法?C# OpCode怎么用?C# OpCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpCode类属于Mono.Cecil.Cil命名空间,在下文中一共展示了OpCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadSigKey
public static bool ReadSigKey(MethodDefinition DecryptMethod, OpCode[] KeySig, ref object val)
{
int score = 0;
for (int i = 0; i < DecryptMethod.Body.Instructions.Count; i++)
{
if (DecryptMethod.Body.Instructions[i].OpCode == KeySig[score])
{
score++;
if (score == KeySig.Length)
{
if (DecryptMethod.Body.Instructions[i].Next != null)
{
if (DecryptMethod.Body.Instructions[i].Next.Operand != null)
{
val = DecryptMethod.Body.Instructions[i].Next.Operand;
return true;
}
}
}
}
else
{
score = 0;
}
}
return false;
}
示例2: Create
public Instruction Create (OpCode opcode)
{
if (opcode.OperandType != OperandType.InlineNone)
throw new ArgumentException ("opcode");
return FinalCreate (opcode);
}
示例3: TryGetInstruction
private bool TryGetInstruction(List<ILRange> ilRanges, OpCode opCode, out Instruction instruction) {
int fromOffset = 0;
int toOffset = 0;
if (ilRanges == null || ilRanges.Count == 0) {
instruction = null;
return false;
}
fromOffset = ilRanges[0].From;
toOffset = ilRanges[0].To;
instruction = InstructionAt(fromOffset);
do {
if (instruction.OpCode == opCode) {
return true;
}
instruction = instruction.Next;
fromOffset = instruction.Offset;
}
while (fromOffset != toOffset);
return instruction.OpCode == opCode;
}
示例4: SimplifyOpCode
/// <summary>
///
/// </summary>
/// <param name="toSimplify"></param>
/// <returns></returns>
private static OpCode SimplifyOpCode(OpCode toSimplify)
{
switch (toSimplify.Code) {
case Code.Br_S:
return OpCodes.Br;
case Code.Brfalse_S:
return OpCodes.Brfalse;
case Code.Brtrue_S:
return OpCodes.Brtrue;
case Code.Beq_S:
return OpCodes.Beq;
case Code.Bge_S:
return OpCodes.Bge;
case Code.Bgt_S:
return OpCodes.Bgt;
case Code.Ble_S:
return OpCodes.Ble;
case Code.Blt_S:
return OpCodes.Blt;
case Code.Bne_Un_S:
return OpCodes.Bne_Un;
case Code.Bge_Un_S:
return OpCodes.Bge_Un;
case Code.Bgt_Un_S:
return OpCodes.Bgt_Un;
case Code.Ble_Un_S:
return OpCodes.Ble_Un;
case Code.Blt_Un_S:
return OpCodes.Blt_Un;
case Code.Leave_S:
return OpCodes.Leave;
default:
return toSimplify;
}
}
示例5: FindInstruction
public static Instruction FindInstruction(AssemblyDefinition assembly, string typeName, string testMethodName, OpCode testInstruction)
{
MethodDefinition testMethod = FindMethod(assembly, typeName, testMethodName);
Assert.IsNotNull(testMethod);
return FindInstruction(testMethod, testInstruction);
}
示例6: AssertInstruction
internal static void AssertInstruction(Instruction actual, OpCode opCode, MemberReference expectedCtor)
{
Assert.AreEqual(opCode, actual.OpCode);
MethodReference actualCtor = (MethodReference)actual.Operand;
Assert.AreEqual(expectedCtor.DeclaringType.Name, actualCtor.DeclaringType.Name, opCode.ToString());
Assert.AreEqual(expectedCtor, actualCtor.Resolve(), opCode.ToString());
}
示例7: GetNegativeModifier
private static int GetNegativeModifier(OpCode opCode)
{
switch (opCode.StackBehaviourPop)
{
case StackBehaviour.Pop0:
return 0;
case StackBehaviour.Pop1:
case StackBehaviour.Popi:
case StackBehaviour.Popref:
case StackBehaviour.Varpop:
return 1;
case StackBehaviour.Pop1_pop1:
case StackBehaviour.Popi_pop1:
case StackBehaviour.Popi_popi:
case StackBehaviour.Popi_popi8:
case StackBehaviour.Popi_popr4:
case StackBehaviour.Popi_popr8:
case StackBehaviour.Popref_pop1:
case StackBehaviour.Popref_popi:
return 2;
case StackBehaviour.Popi_popi_popi:
case StackBehaviour.Popref_popi_popi:
case StackBehaviour.Popref_popi_popi8:
case StackBehaviour.Popref_popi_popr4:
case StackBehaviour.Popref_popi_popr8:
case StackBehaviour.Popref_popi_popref:
return 3;
case StackBehaviour.PopAll:
return 1000;
}
return 0;
}
示例8: CreateTestAssembly
private static AssemblyDefinition CreateTestAssembly(OpCode arithmeticOperator)
{
var name = new AssemblyNameDefinition("TestBitwiseOperatorTurtleOr", new Version(1, 0));
var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
var type = new TypeDefinition("TestBitwiseOperatorTurtleOr", "TestClass",
TypeAttributes.Class | TypeAttributes.Public);
var intType = assembly.MainModule.Import(typeof(int));
var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
var leftParam = new ParameterDefinition("left", ParameterAttributes.In, intType);
var rightParam = new ParameterDefinition("right", ParameterAttributes.In, intType);
method.Parameters.Add(leftParam);
method.Parameters.Add(rightParam);
var resultVariable = new VariableDefinition(intType);
method.Body.Variables.Add(resultVariable);
var processor = method.Body.GetILProcessor();
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, leftParam));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, rightParam));
method.Body.Instructions.Add(processor.Create(arithmeticOperator));
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldloc, resultVariable));
method.Body.Instructions.Add(processor.Create(OpCodes.Ret));
type.Methods.Add(method);
assembly.MainModule.Types.Add(type);
return assembly;
}
示例9: CreateTestAssembly
private static AssemblyDefinition CreateTestAssembly(OpCode opCode, bool invert)
{
var name = new AssemblyNameDefinition("TestConditionalsBoundaryTurtle", new Version(1, 0));
var assembly = AssemblyDefinition.CreateAssembly(name, "TestClass", ModuleKind.Dll);
var type = new TypeDefinition("TestConditionalsBoundaryTurtle", "TestClass",
TypeAttributes.Class | TypeAttributes.Public);
var intType = assembly.MainModule.Import(typeof(int));
var boolType = assembly.MainModule.Import(typeof(bool));
var method = new MethodDefinition("TestMethod", MethodAttributes.Public, intType);
var param = new ParameterDefinition("input", ParameterAttributes.In, intType);
method.Parameters.Add(param);
var resultVariable = new VariableDefinition(boolType);
method.Body.Variables.Add(resultVariable);
var processor = method.Body.GetILProcessor();
Instruction loadReturnValueInstruction = processor.Create(OpCodes.Ldloc, resultVariable);
method.Body.Instructions.Add(processor.Create(OpCodes.Ldarg, param));
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(opCode));
if (invert)
{
method.Body.Instructions.Add(processor.Create(OpCodes.Ldc_I4, 0));
method.Body.Instructions.Add(processor.Create(OpCodes.Ceq));
}
method.Body.Instructions.Add(processor.Create(OpCodes.Stloc, resultVariable));
method.Body.Instructions.Add(loadReturnValueInstruction);
method.Body.Instructions.Add(processor.Create(OpCodes.Ret));
type.Methods.Add(method);
assembly.MainModule.Types.Add(type);
return assembly;
}
示例10: Create
public static Instruction Create(OpCode opcode)
{
if (opcode.OperandType != OperandType.InlineNone)
throw new ArgumentException ("opcode");
return new Instruction (opcode, null);
}
示例11: AssertOpCodeSequence
static void AssertOpCodeSequence (OpCode [] expected, MethodBody body)
{
var opcodes = body.Instructions.Select (i => i.OpCode).ToArray ();
Assert.AreEqual (expected.Length, opcodes.Length);
for (int i = 0; i < opcodes.Length; i++)
Assert.AreEqual (expected [i], opcodes [i]);
}
示例12: Create
public Instruction Create (OpCode opcode, FieldReference field)
{
if (opcode.OperandType != OperandType.InlineField &&
opcode.OperandType != OperandType.InlineTok)
throw new ArgumentException ("opcode");
return FinalCreate (opcode, field);
}
示例13: PatternInstruction
public PatternInstruction(OpCode[] eligibleOpCodes, Terminal terminal = null, Predicate predicate = null) {
if (eligibleOpCodes == null)
throw new ArgumentNullException(Name.Of(eligibleOpCodes));
if (eligibleOpCodes.Length == 0)
throw new ArgumentException("Array length must be greater than zero", Name.Of(eligibleOpCodes));
EligibleOpCodes = eligibleOpCodes;
Terminal = terminal;
this.predicate = predicate ?? PredicateDummy;
}
示例14: isAnotherPath
private bool isAnotherPath(OpCode opCode)
{
if (opCode.FlowControl == FlowControl.Branch)
return true;
if (opCode.Code == Code.Jmp)
return true;
return false;
}
示例15: Create
public Instruction Create (OpCode opcode, byte value)
{
if (opcode.OperandType == OperandType.ShortInlineVar)
return Instruction.Create (opcode, body.Variables [value]);
if (opcode.OperandType == OperandType.ShortInlineArg)
return Instruction.Create (opcode, body.GetParameter (value));
return Instruction.Create (opcode, value);
}