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 <X86InstructionListViewItem>()) { item.UpdateItem(currentFrame); } } else { _lastFunction = currentFrame.Function; var code = ((RuntimeFunction)currentFrame.Function).NativeCode; var mapping = code.GetILToNativeMapping().ToArray(); var bytes = code.GetBytes(); var reader = new MemoryStreamReader(bytes); var disassembler = new X86Disassembler(reader, (long)code.Address); while (reader.Position < reader.StartPosition + reader.Length) { try { int start = (int)reader.Position; var instruction = disassembler.ReadNextInstruction(); int end = (int)reader.Position; var instructionBytes = new byte[end - start]; Buffer.BlockCopy(bytes, start, instructionBytes, 0, end - start); var item = new X86InstructionListViewItem(instruction, instructionBytes); item.RelativeOffset = start; item.Mapping = mapping.FirstOrDefault( x => item.RelativeOffset >= x.NativeStartOffset && item.RelativeOffset < x.NativeEndOffset); item.UpdateItem(currentFrame); instructionsListView.Items.Add(item); } catch (IndexOutOfRangeException) { // HACK: ignore mnemonic choosing errors in disassembler } } } } }
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<X86InstructionListViewItem>()) item.UpdateItem(currentFrame); } else { _lastFunction = currentFrame.Function; var code = ((RuntimeFunction) currentFrame.Function).NativeCode; var mapping = code.GetILToNativeMapping().ToArray(); var bytes = code.GetBytes(); var reader = new MemoryStreamReader(bytes); var disassembler = new X86Disassembler(reader, (long) code.Address); while (reader.Position < reader.StartPosition + reader.Length) { try { int start = (int) reader.Position; var instruction = disassembler.ReadNextInstruction(); int end = (int) reader.Position; var instructionBytes = new byte[end - start]; Buffer.BlockCopy(bytes, start, instructionBytes, 0, end - start); var item = new X86InstructionListViewItem(instruction, instructionBytes); item.RelativeOffset = start; item.Mapping = mapping.FirstOrDefault( x => item.RelativeOffset >= x.NativeStartOffset && item.RelativeOffset < x.NativeEndOffset); item.UpdateItem(currentFrame); instructionsListView.Items.Add(item); } catch (IndexOutOfRangeException) { // HACK: ignore mnemonic choosing errors in disassembler } } } } }