本文整理汇总了C#中dnlib.DotNet.Emit.OpCode类的典型用法代码示例。如果您正苦于以下问题:C# OpCode类的具体用法?C# OpCode怎么用?C# OpCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpCode类属于dnlib.DotNet.Emit命名空间,在下文中一共展示了OpCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsFallThrough
static public bool IsFallThrough(OpCode opCode) {
switch (opCode.FlowControl) {
case FlowControl.Call:
return opCode != OpCodes.Jmp;
case FlowControl.Cond_Branch:
case FlowControl.Next:
return true;
default:
return false;
}
}
示例2: IsUnconditionalBranch
public static bool IsUnconditionalBranch(OpCode opcode)
{
if (opcode.OpCodeType == OpCodeType.Prefix)
return false;
switch (opcode.FlowControl) {
case FlowControl.Branch:
case FlowControl.Throw:
case FlowControl.Return:
return true;
default:
return false;
}
}
示例3: GetCallInfo
protected override void GetCallInfo(object context, FieldDef field, out IMethod calledMethod, out OpCode callOpcode) {
var name = field.Name.String;
callOpcode = OpCodes.Call;
if (name.EndsWith("%", StringComparison.Ordinal)) {
callOpcode = OpCodes.Callvirt;
name = name.TrimEnd(new char[] { '%' });
}
byte[] value = Convert.FromBase64String(name);
int methodIndex = BitConverter.ToInt32(value, 0); // 0-based memberRef index
var mr = module.ResolveMemberRef((uint)methodIndex + 1);
if (mr == null || !mr.IsMethodRef)
throw new ApplicationException(string.Format("Invalid MemberRef index: {0}", methodIndex));
calledMethod = mr;
}
示例4: GetCallInfo
protected override void GetCallInfo(object context, FieldDef field, out IMethod calledMethod, out OpCode callOpcode) {
var ctx = (Context)context;
switch (ctx.proxyCreatorType) {
case ProxyCreatorType.CallOrCallvirt:
callOpcode = field.IsFamilyOrAssembly ? OpCodes.Callvirt : OpCodes.Call;
break;
case ProxyCreatorType.CallCtor:
callOpcode = OpCodes.Call;
break;
case ProxyCreatorType.Newobj:
callOpcode = OpCodes.Newobj;
break;
default:
throw new ApplicationException(string.Format("Invalid proxy creator type: {0}", ctx.proxyCreatorType));
}
calledMethod = module.ResolveToken(ctx.methodToken) as IMethod;
}
示例5: GetCallInfo
protected override void GetCallInfo(object context, FieldDef field, out IMethod calledMethod, out OpCode callOpcode) {
callOpcode = OpCodes.Call;
string name = field.Name.String;
uint memberRefRid = 0;
for (int i = name.Length - 1; i >= 0; i--) {
char c = name[i];
if (c == '~') {
callOpcode = OpCodes.Callvirt;
break;
}
int val;
if (specialCharsDict.TryGetValue(c, out val))
memberRefRid = memberRefRid * (uint)specialChars.Length + (uint)val;
}
memberRefRid++;
calledMethod = module.ResolveMemberRef(memberRefRid);
if (calledMethod == null)
Logger.w("Ignoring invalid method RID: {0:X8}, field: {1:X8}", memberRefRid, field.MDToken.ToInt32());
}
示例6: GetOpCodeDocumentation
public static string GetOpCodeDocumentation(OpCode code) {
int index = (int)code.Code;
int hi = index >> 8;
if (hi == 0xFE)
index -= 0xFD00;
else if (hi != 0)
return null;
var s = cachedOpCodeDocs[index];
if (s != null)
return s;
var docProvider = XmlDocLoader.MscorlibDocumentation;
if (docProvider != null) {
string docXml = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + code.Code.ToString());
if (docXml != null) {
XmlDocRenderer renderer = new XmlDocRenderer();
renderer.AddXmlDocumentation(docXml);
return cachedOpCodeDocs[index] = renderer.ToString();
}
}
return null;
}
示例7: GetFlippedBranchOpCode
public bool GetFlippedBranchOpCode(out OpCode opcode) {
switch (OpCode.Code) {
case Code.Bge: opcode = OpCodes.Blt; return true;
case Code.Bge_S: opcode = OpCodes.Blt_S; return true;
case Code.Bge_Un: opcode = OpCodes.Blt_Un; return true;
case Code.Bge_Un_S: opcode = OpCodes.Blt_Un_S; return true;
case Code.Blt: opcode = OpCodes.Bge; return true;
case Code.Blt_S: opcode = OpCodes.Bge_S; return true;
case Code.Blt_Un: opcode = OpCodes.Bge_Un; return true;
case Code.Blt_Un_S: opcode = OpCodes.Bge_Un_S; return true;
case Code.Bgt: opcode = OpCodes.Ble; return true;
case Code.Bgt_S: opcode = OpCodes.Ble_S; return true;
case Code.Bgt_Un: opcode = OpCodes.Ble_Un; return true;
case Code.Bgt_Un_S: opcode = OpCodes.Ble_Un_S; return true;
case Code.Ble: opcode = OpCodes.Bgt; return true;
case Code.Ble_S: opcode = OpCodes.Bgt_S; return true;
case Code.Ble_Un: opcode = OpCodes.Bgt_Un; return true;
case Code.Ble_Un_S: opcode = OpCodes.Bgt_Un_S; return true;
case Code.Brfalse: opcode = OpCodes.Brtrue; return true;
case Code.Brfalse_S:opcode = OpCodes.Brtrue_S; return true;
case Code.Brtrue: opcode = OpCodes.Brfalse; return true;
case Code.Brtrue_S: opcode = OpCodes.Brfalse_S; return true;
// Can't flip beq and bne.un since it's object vs uint/float
case Code.Beq:
case Code.Beq_S:
case Code.Bne_Un:
case Code.Bne_Un_S:
default:
opcode = OpCodes.Nop; // Whatever...
return false;
}
}
示例8: FindInstruction
static int FindInstruction(IList<Instruction> instrs, int index, OpCode opcode) {
if (index < 0)
return -1;
for (int i = index; i < instrs.Count; i++) {
if (instrs[i].OpCode == opcode)
return i;
}
return -1;
}
示例9: Get
public static OpCodeInfo Get(OpCode opCode)
{
return Get(opCode.Code);
}
示例10: ConvertOpCode
ROpCode ConvertOpCode(OpCode opcode)
{
ROpCode ropcode;
if (dnlibToReflection.TryGetValue(opcode, out ropcode))
return ropcode;
return ROpCodes.Nop;
}
示例11: CreateDNLibOperand
object CreateDNLibOperand(OpCode opcode, Value op) {
if (op is Int32Value)
return ((Int32Value)op).Value;
if (op is StringValue)
return ((StringValue)op).value;
return null;
}
示例12: InverseBranch
static OpCode InverseBranch(OpCode opCode)
{
switch (opCode.Code) {
case Code.Bge:
return OpCodes.Blt;
case Code.Bge_Un:
return OpCodes.Blt_Un;
case Code.Blt:
return OpCodes.Bge;
case Code.Blt_Un:
return OpCodes.Bge_Un;
case Code.Bgt:
return OpCodes.Ble;
case Code.Bgt_Un:
return OpCodes.Ble_Un;
case Code.Ble:
return OpCodes.Bgt;
case Code.Ble_Un:
return OpCodes.Bgt_Un;
case Code.Brfalse:
return OpCodes.Brtrue;
case Code.Brtrue:
return OpCodes.Brfalse;
case Code.Beq:
return OpCodes.Bne_Un;
case Code.Bne_Un:
return OpCodes.Beq;
}
throw new NotSupportedException();
}
示例13: AddOperand
public static void AddOperand(IList<short> instrs, ModuleDefMD module, uint offset, OpCode opCode, object operand)
{
Instruction target;
IVariable variable;
switch (opCode.OperandType) {
case OperandType.InlineBrTarget:
target = operand as Instruction;
if (target == null)
instrs.AddUnknownInt32();
else
instrs.AddInt32(unchecked((int)target.Offset - (int)(offset + 4)));
break;
case OperandType.InlineField:
case OperandType.InlineMethod:
case OperandType.InlineTok:
case OperandType.InlineType:
var tok = operand as ITokenOperand;
instrs.AddToken(module, tok == null ? 0 : tok.MDToken.Raw);
break;
case OperandType.InlineSig:
var msig = operand as MethodSig;
instrs.AddToken(module, msig == null ? 0 : msig.OriginalToken);
break;
case OperandType.InlineString:
instrs.AddUnknownInt32();
break;
case OperandType.InlineI:
if (operand is int)
instrs.AddInt32((int)operand);
else
instrs.AddUnknownInt32();
break;
case OperandType.InlineI8:
if (operand is long)
instrs.AddInt64((long)operand);
else
instrs.AddUnknownInt64();
break;
case OperandType.InlineR:
if (operand is double)
instrs.AddDouble((double)operand);
else
instrs.AddUnknownInt64();
break;
case OperandType.ShortInlineR:
if (operand is float)
instrs.AddSingle((float)operand);
else
instrs.AddUnknownInt32();
break;
case OperandType.InlineSwitch:
var targets = operand as IList<Instruction>;
if (targets == null)
instrs.AddUnknownInt32();
else {
uint offsetAfter = offset + 4 + (uint)targets.Count * 4;
instrs.AddInt32(targets.Count);
foreach (var instr in targets) {
if (instr == null)
instrs.AddUnknownInt32();
else
instrs.AddInt32(unchecked((int)instr.Offset - (int)offsetAfter));
}
}
break;
case OperandType.InlineVar:
variable = operand as IVariable;
if (variable == null)
instrs.AddUnknownInt16();
else if (ushort.MinValue <= variable.Index && variable.Index <= ushort.MaxValue)
instrs.AddInt16(unchecked((short)variable.Index));
else
instrs.AddUnknownInt16();
break;
case OperandType.ShortInlineVar:
variable = operand as IVariable;
if (variable == null)
instrs.AddUnknownByte();
else if (byte.MinValue <= variable.Index && variable.Index <= byte.MaxValue)
instrs.Add((byte)variable.Index);
else
instrs.AddUnknownByte();
break;
case OperandType.ShortInlineBrTarget:
target = operand as Instruction;
if (target == null)
instrs.AddUnknownByte();
else {
int displ = unchecked((int)target.Offset - (int)(offset + 1));
//.........这里部分代码省略.........
示例14: Add
protected void Add(MethodDef oldMethod, IMethod newMethod, OpCode opCode) {
if (oldMethod == null)
return;
oldToNewMethod.Add(oldMethod, new NewMethodInfo(opCode, newMethod));
}
示例15: create
static Instruction create(OpCode opcode, object operand)
{
return new Instruction {
OpCode = opcode,
Operand = operand,
};
}