static Instruction ldelem_read(BinaryReader reader, IInstructionOperandResolver resolver) { Instruction instr = null; bool first = reader.ReadBoolean(); bool second = reader.ReadBoolean(); int value = reader.ReadInt32(); foreach (var info in instructionInfos2) { if (info.First != first || info.Second != second) { continue; } if (second && value != info.Value) { continue; } if (second) { instr = new Instruction(info.OpCode); } else { instr = new Instruction(info.OpCode, resolver.ResolveToken((uint)value)); } break; } if (instr == null) { throw new ApplicationException("Invalid opcode"); } return(instr); }
static Instruction ldftn_read(BinaryReader reader, IInstructionOperandResolver resolver) { byte code = reader.ReadByte(); uint token = reader.ReadUInt32(); switch (code) { case 0: return(new Instruction(OpCodes.Ldftn, resolver.ResolveToken(token))); case 1: reader.ReadInt32(); // token of newobj .ctor return(new Instruction(OpCodes.Ldvirtftn, resolver.ResolveToken(token))); default: throw new ApplicationException("Invalid opcode"); } }
/// <summary> /// Reads the locals /// </summary> /// <returns>All locals or <c>null</c> if there are none</returns> IList <TypeSig> ReadLocals() { if (opResolver.ResolveToken(localVarSigTok, gpContext) is not StandAloneSig standAloneSig) { return(null); } var localSig = standAloneSig.LocalSig; if (localSig is null) { return(null); } return(localSig.Locals); }
/// <summary> /// Reads the locals /// </summary> /// <returns>All locals or <c>null</c> if there are none</returns> IList <TypeSig> ReadLocals() { var standAloneSig = opResolver.ResolveToken(localVarSigTok, gpContext) as StandAloneSig; if (standAloneSig == null) { return(null); } var localSig = standAloneSig.LocalSig; if (localSig == null) { return(null); } return(localSig.Locals); }
static Instruction cast_read(BinaryReader reader, IInstructionOperandResolver resolver) { var instr = new Instruction(); switch (reader.ReadByte()) { case 0: instr.OpCode = OpCodes.Castclass; break; case 1: instr.OpCode = OpCodes.Isinst; break; default: throw new ApplicationException("Invalid opcode"); } instr.Operand = resolver.ResolveToken(reader.ReadUInt32()); return(instr); }
static Instruction box_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) { var instr = new Instruction(); switch (reader.ReadByte()) { case 0: instr.OpCode = OpCodes.Box; break; case 1: instr.OpCode = OpCodes.Unbox_Any; break; default: throw new ApplicationException("Invalid opcode"); } instr.Operand = resolver.ResolveToken(reader.ReadUInt32(), gpContext); return(instr); }
static Instruction ldfld_read(BinaryReader reader, IInstructionOperandResolver resolver) { byte b = reader.ReadByte(); var field = resolver.ResolveToken(reader.ReadUInt32()) as IField; switch (b) { case 0: return(new Instruction(null, new FieldInstructionOperand(OpCodes.Ldsfld, OpCodes.Ldfld, field))); case 1: return(new Instruction(null, new FieldInstructionOperand(OpCodes.Ldsflda, OpCodes.Ldflda, field))); case 2: return(new Instruction(null, new FieldInstructionOperand(OpCodes.Stsfld, OpCodes.Stfld, field))); default: throw new ApplicationException("Invalid opcode"); } }
static Instruction ldftn_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) { byte code = reader.ReadByte(); uint token = reader.ReadUInt32(); switch (code) { case 0: return new Instruction(OpCodes.Ldftn, resolver.ResolveToken(token, gpContext)); case 1: reader.ReadInt32(); // token of newobj .ctor return new Instruction(OpCodes.Ldvirtftn, resolver.ResolveToken(token, gpContext)); default: throw new ApplicationException("Invalid opcode"); } }
static Instruction ldfld_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) { byte b = reader.ReadByte(); var field = resolver.ResolveToken(reader.ReadUInt32(), gpContext) as IField; switch (b) { case 0: return new Instruction(null, new FieldInstructionOperand(OpCodes.Ldsfld, OpCodes.Ldfld, field)); case 1: return new Instruction(null, new FieldInstructionOperand(OpCodes.Ldsflda, OpCodes.Ldflda, field)); case 2: return new Instruction(null, new FieldInstructionOperand(OpCodes.Stsfld, OpCodes.Stfld, field)); default: throw new ApplicationException("Invalid opcode"); } }
static Instruction ldelem_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) { Instruction instr = null; bool first = reader.ReadBoolean(); bool second = reader.ReadBoolean(); int value = reader.ReadInt32(); foreach (var info in instructionInfos2) { if (info.First != first || info.Second != second) continue; if (second && value != info.Value) continue; if (second) instr = new Instruction(info.OpCode); else instr = new Instruction(info.OpCode, resolver.ResolveToken((uint)value, gpContext)); break; } if (instr == null) throw new ApplicationException("Invalid opcode"); return instr; }
static Instruction initobj_read(BinaryReader reader, IInstructionOperandResolver resolver) { return new Instruction(OpCodes.Initobj, resolver.ResolveToken(reader.ReadUInt32())); }
Instruction Handler_Box(BinaryReader reader) { var type = resolver.ResolveToken(reader.ReadUInt32()) as ITypeDefOrRef; return(OpCodes.Box.ToInstruction(type)); }
static Instruction ldtoken_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) => new Instruction(OpCodes.Ldtoken, resolver.ResolveToken(reader.ReadUInt32(), gpContext));
static Instruction initobj_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) { return(new Instruction(OpCodes.Initobj, resolver.ResolveToken(reader.ReadUInt32(), gpContext))); }
static Instruction newarr_read(BinaryReader reader, IInstructionOperandResolver resolver) { return new Instruction(OpCodes.Newarr, resolver.ResolveToken(reader.ReadUInt32())); }
static Instruction newarr_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) { return new Instruction(OpCodes.Newarr, resolver.ResolveToken(reader.ReadUInt32(), gpContext)); }
static Instruction box_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) { var instr = new Instruction(); switch (reader.ReadByte()) { case 0: instr.OpCode = OpCodes.Box; break; case 1: instr.OpCode = OpCodes.Unbox_Any; break; default: throw new ApplicationException("Invalid opcode"); } instr.Operand = resolver.ResolveToken(reader.ReadUInt32(), gpContext); return instr; }
static Instruction initobj_read(BinaryReader reader, IInstructionOperandResolver resolver) { return(new Instruction(OpCodes.Initobj, resolver.ResolveToken(reader.ReadUInt32()))); }
/// <summary> /// Resolves a token /// </summary> /// <param name="self">An <see cref="IInstructionOperandResolver"/> object</param> /// <param name="token">The metadata token</param> /// <returns>A <see cref="IMDTokenProvider"/> or <c>null</c> if <paramref name="token"/> is invalid</returns> public static IMDTokenProvider ResolveToken(this IInstructionOperandResolver self, uint token) { return(self.ResolveToken(token, new GenericParamContext())); }
static Instruction ldtoken_read(BinaryReader reader, IInstructionOperandResolver resolver) { return(new Instruction(OpCodes.Ldtoken, resolver.ResolveToken(reader.ReadUInt32()))); }
Instruction Handler_Box(BinaryReader reader) => OpCodes.Box.ToInstruction(resolver.ResolveToken(reader.ReadUInt32(), gpContext) as ITypeDefOrRef);
static Instruction cast_read(BinaryReader reader, IInstructionOperandResolver resolver) { var instr = new Instruction(); switch (reader.ReadByte()) { case 0: instr.OpCode = OpCodes.Castclass; break; case 1: instr.OpCode = OpCodes.Isinst; break; default: throw new ApplicationException("Invalid opcode"); } instr.Operand = resolver.ResolveToken(reader.ReadUInt32()); return instr; }