AsmResolver.Net.Msil.MsilDisassembler.Disassemble C# (CSharp) Method

Disassemble() public method

public Disassemble ( ) : IList
return IList
        public IList<MsilInstruction> Disassemble()
        {
            var instructions = new List<MsilInstruction>();
            while (_reader.Position < _reader.StartPosition + _reader.Length)
                instructions.Add(ReadNextInstruction());

            foreach (var instruction in instructions)
                ResolveOperand(instructions, instruction);

            return instructions;
        }

Usage Example

        public void SetCurrentFrame(IFrame currentFrame)
        {
            if (currentFrame == null || currentFrame.Function != _lastFunction)
            {
                instructionsListView.Items.Clear();
                _lastFunction = null;
            }

            if (currentFrame != null)
            {
                if (currentFrame.Function == _lastFunction)
                {
                    foreach (var item in instructionsListView.Items.Cast<MsilInstructionListViewItem>()) 
                        item.UpdateItem(currentFrame);
                }
                else
                {
                    _lastFunction = currentFrame.Function;
                    var bytes = ((RuntimeFunction)currentFrame.Function).IlCode.GetBytes();
                    var disassembler = new MsilDisassembler(new MemoryStreamReader(bytes), new DefaultOperandResolver());
                    foreach (var instruction in disassembler.Disassemble())
                    {
                        var instructionBytes = new byte[instruction.Size];
                        Buffer.BlockCopy(bytes, instruction.Offset, instructionBytes, 0, instruction.Size);
                        var item = new MsilInstructionListViewItem(instruction, instructionBytes);
                        item.UpdateItem(currentFrame);
                        instructionsListView.Items.Add(item);
                    }
                }
            }
        }