protected override List<Instruction> ReadInstructions(MethodDef cilMethod, CsvmMethodData csvmMethod) {
			var reader = new BinaryReader(new MemoryStream(csvmMethod.Instructions));
			var instrs = new List<Instruction>();
			var handlerInfoReader = new OpCodeHandlerInfoReader(module);

			int numVmInstrs = reader.ReadInt32();
			var vmInstrs = new ushort[numVmInstrs];
			for (int i = 0; i < numVmInstrs; i++)
				vmInstrs[i] = reader.ReadUInt16();

			uint offset = 0;
			for (int vmInstrIndex = 0; vmInstrIndex < numVmInstrs; vmInstrIndex++) {
				var composite = opCodeDetector.Handlers[vmInstrs[vmInstrIndex]];
				var handlerInfos = composite.OpCodeHandlerInfos;
				if (handlerInfos.Count == 0)
					handlerInfos = new List<OpCodeHandlerInfo>() { new OpCodeHandlerInfo(HandlerTypeCode.Nop, null) };
				for (int hi = 0; hi < handlerInfos.Count; hi++) {
					var instr = handlerInfoReader.Read(handlerInfos[hi].TypeCode, reader);
					instr.Offset = offset;
					offset += (uint)GetInstructionSize(instr);
					SetCilToVmIndex(instr, vmInstrIndex);
					if (hi == 0)
						SetVmIndexToCil(instr, vmInstrIndex);
					instrs.Add(instr);
				}
			}
			return instrs;
		}
Exemplo n.º 2
0
        protected override List <Instruction> ReadInstructions(MethodDef cilMethod, CsvmMethodData csvmMethod)
        {
            var reader            = new BinaryReader(new MemoryStream(csvmMethod.Instructions));
            var instrs            = new List <Instruction>();
            var handlerInfoReader = new OpCodeHandlerInfoReader(module);

            int numVmInstrs = reader.ReadInt32();
            var vmInstrs    = new ushort[numVmInstrs];

            for (int i = 0; i < numVmInstrs; i++)
            {
                vmInstrs[i] = reader.ReadUInt16();
            }

            uint offset = 0;

            for (int vmInstrIndex = 0; vmInstrIndex < numVmInstrs; vmInstrIndex++)
            {
                var composite    = opCodeDetector.Handlers[vmInstrs[vmInstrIndex]];
                var handlerInfos = composite.OpCodeHandlerInfos;
                if (handlerInfos.Count == 0)
                {
                    handlerInfos = new List <OpCodeHandlerInfo>()
                    {
                        new OpCodeHandlerInfo(HandlerTypeCode.Nop, null)
                    }
                }
                ;
                for (int hi = 0; hi < handlerInfos.Count; hi++)
                {
                    var instr = handlerInfoReader.Read(handlerInfos[hi].TypeCode, reader);
                    instr.Offset = offset;
                    offset      += (uint)GetInstructionSize(instr);
                    SetCilToVmIndex(instr, vmInstrIndex);
                    if (hi == 0)
                    {
                        SetVmIndexToCil(instr, vmInstrIndex);
                    }
                    instrs.Add(instr);
                }
            }
            return(instrs);
        }
    }