|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics.Contracts; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using ReClassNET.Memory; |
| 8 | +using ReClassNET.UI; |
| 9 | +using ReClassNET.Util; |
| 10 | + |
| 11 | +namespace ReClassNET.Nodes |
| 12 | +{ |
| 13 | + public class FunctionNode : BaseNode |
| 14 | + { |
| 15 | + private int memorySize = IntPtr.Size; |
| 16 | + |
| 17 | + private IntPtr address = IntPtr.Zero; |
| 18 | + private readonly List<string> disassembledCode = new List<string>(); |
| 19 | + |
| 20 | + /// <summary>Size of the node in bytes.</summary> |
| 21 | + public override int MemorySize => memorySize; |
| 22 | + |
| 23 | + public override string GetToolTipText(HotSpot spot, MemoryBuffer memory) |
| 24 | + { |
| 25 | + DisassembleRemoteCode(memory, spot.Address); |
| 26 | + |
| 27 | + return string.Join("\n", disassembledCode); |
| 28 | + } |
| 29 | + |
| 30 | + public override int Draw(ViewInfo view, int x, int y) |
| 31 | + { |
| 32 | + Contract.Requires(view != null); |
| 33 | + |
| 34 | + if (IsHidden) |
| 35 | + { |
| 36 | + return DrawHidden(view, x, y); |
| 37 | + } |
| 38 | + |
| 39 | + AddSelection(view, x, y, view.Font.Height); |
| 40 | + AddDelete(view, x, y); |
| 41 | + AddTypeDrop(view, x, y); |
| 42 | + |
| 43 | + x += TextPadding; |
| 44 | + |
| 45 | + x = AddIcon(view, x, y, Icons.Function, -1, HotSpotType.None); |
| 46 | + x = AddAddressOffset(view, x, y); |
| 47 | + |
| 48 | + var tx = x; |
| 49 | + |
| 50 | + x = AddText(view, x, y, Program.Settings.TypeColor, HotSpot.NoneId, "Function") + view.Font.Width; |
| 51 | + x = AddText(view, x, y, Program.Settings.NameColor, HotSpot.NameId, Name) + view.Font.Width; |
| 52 | + |
| 53 | + x = AddOpenClose(view, x, y) + view.Font.Width; |
| 54 | + |
| 55 | + x = AddComment(view, x, y); |
| 56 | + |
| 57 | + var ptr = view.Address.Add(Offset); |
| 58 | + |
| 59 | + DisassembleRemoteCode(view.Memory, ptr); |
| 60 | + |
| 61 | + if (levelsOpen[view.Level]) |
| 62 | + { |
| 63 | + foreach (var line in disassembledCode) |
| 64 | + { |
| 65 | + y += view.Font.Height; |
| 66 | + |
| 67 | + AddText(view, tx, y, Program.Settings.NameColor, HotSpot.ReadOnlyId, line); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + return y + view.Font.Height; |
| 72 | + } |
| 73 | + |
| 74 | + public override int CalculateHeight(ViewInfo view) |
| 75 | + { |
| 76 | + if (IsHidden) |
| 77 | + { |
| 78 | + return HiddenHeight; |
| 79 | + } |
| 80 | + |
| 81 | + var h = view.Font.Height; |
| 82 | + if (levelsOpen[view.Level]) |
| 83 | + { |
| 84 | + h += disassembledCode.Count() * view.Font.Height; |
| 85 | + } |
| 86 | + return h; |
| 87 | + } |
| 88 | + |
| 89 | + private void DisassembleRemoteCode(MemoryBuffer memory, IntPtr address) |
| 90 | + { |
| 91 | + Contract.Requires(memory != null); |
| 92 | + |
| 93 | + if (this.address != address) |
| 94 | + { |
| 95 | + disassembledCode.Clear(); |
| 96 | + |
| 97 | + this.address = address; |
| 98 | + |
| 99 | + if (!address.IsNull() && memory.Process.IsValid) |
| 100 | + { |
| 101 | + memorySize = 0; |
| 102 | + |
| 103 | + memory.Process.NativeHelper.DisassembleRemoteCode( |
| 104 | + memory.Process.Process.Handle, |
| 105 | + address, |
| 106 | + 4096, |
| 107 | + (a, l, i) => |
| 108 | + { |
| 109 | + memorySize += l; |
| 110 | +#if WIN64 |
| 111 | + disassembledCode.Add($"{a.ToString("X08")} {i}"); |
| 112 | +#else |
| 113 | + disassembledCode.Add($"{a.ToString("X04")} {i}"); |
| 114 | +#endif |
| 115 | + } |
| 116 | + ); |
| 117 | + |
| 118 | + ParentNode?.ChildHasChanged(this); |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments