private bool AnalyzePointerFromImages(out PointerInfo info, ulong address) { info = default; Image image = GetImage(address, out int imageIndex); if (image == null) { // Value isn't a pointer to a known image... return(false); } info.Offset = address - image.BaseAddress; // Try to find what this pointer is referring to if (TryGetSubName(image, address, out ElfSymbol symbol)) { info.SubName = symbol.Name; // Demangle string if possible if (info.SubName.StartsWith("_Z")) { info.SubName = Demangler.Parse(info.SubName); } info.SubOffset = info.Offset - symbol.Value; } else { info.SubName = ""; } info.ImageName = GetGuessedNsoNameFromIndex(imageIndex); return(true); }
public void PrintGuestStackTrace(CpuThreadState threadState) { EnsureLoaded(); StringBuilder trace = new StringBuilder(); trace.AppendLine("Guest stack trace:"); void AppendTrace(long address) { Image image = GetImage(address, out int imageIndex); if (image == null || !TryGetSubName(image, address, out string subName)) { subName = $"Sub{address:x16}"; } else if (subName.StartsWith("_Z")) { subName = Demangler.Parse(subName); } if (image != null) { long offset = address - image.BaseAddress; string imageName = GetGuessedNsoNameFromIndex(imageIndex); string imageNameAndOffset = $"[{_owner.Name}] {imageName}:0x{offset:x8}"; trace.AppendLine($" {imageNameAndOffset} {subName}"); } else { trace.AppendLine($" [{_owner.Name}] ??? {subName}"); } } //TODO: ARM32. long framePointer = (long)threadState.X29; while (framePointer != 0) { if ((framePointer & 7) != 0 || !_owner.CpuMemory.IsMapped(framePointer) || !_owner.CpuMemory.IsMapped(framePointer + 8)) { break; } //Note: This is the return address, we need to subtract one instruction //worth of bytes to get the branch instruction address. AppendTrace(_owner.CpuMemory.ReadInt64(framePointer + 8) - 4); framePointer = _owner.CpuMemory.ReadInt64(framePointer); } Logger.PrintInfo(LogClass.Cpu, trace.ToString()); }
public void PrintGuestStackTrace(CpuThreadState ThreadState) { EnsureLoaded(); StringBuilder Trace = new StringBuilder(); Trace.AppendLine("Guest stack trace:"); void AppendTrace(long Address) { Image Image = GetImage(Address, out int ImageIndex); if (Image == null || !TryGetSubName(Image, Address, out string SubName)) { SubName = $"Sub{Address:x16}"; } else if (SubName.StartsWith("_Z")) { SubName = Demangler.Parse(SubName); } if (Image != null) { long Offset = Address - Image.BaseAddress; string ImageName = GetGuessedNsoNameFromIndex(ImageIndex); string ImageNameAndOffset = $"[{Owner.Name}] {ImageName}:0x{Offset:x8}"; Trace.AppendLine($" {ImageNameAndOffset} {SubName}"); } else { Trace.AppendLine($" [{Owner.Name}] ??? {SubName}"); } } long FramePointer = (long)ThreadState.X29; while (FramePointer != 0) { if ((FramePointer & 7) != 0 || !Owner.CpuMemory.IsMapped(FramePointer) || !Owner.CpuMemory.IsMapped(FramePointer + 8)) { break; } //Note: This is the return address, we need to subtract one instruction //worth of bytes to get the branch instruction address. AppendTrace(Owner.CpuMemory.ReadInt64(FramePointer + 8) - 4); FramePointer = Owner.CpuMemory.ReadInt64(FramePointer); } Logger.PrintInfo(LogClass.Cpu, Trace.ToString()); }
public string GetGuestStackTrace(ARMeilleure.State.ExecutionContext context) { EnsureLoaded(); StringBuilder trace = new StringBuilder(); void AppendTrace(long address) { Image image = GetImage(address, out int imageIndex); if (image == null || !TryGetSubName(image, address, out string subName)) { subName = $"Sub{address:x16}"; } else if (subName.StartsWith("_Z")) { subName = Demangler.Parse(subName); } if (image != null) { long offset = address - image.BaseAddress; string imageName = GetGuessedNsoNameFromIndex(imageIndex); trace.AppendLine($" {imageName}:0x{offset:x8} {subName}"); } else { trace.AppendLine($" ??? {subName}"); } } // TODO: ARM32. long framePointer = (long)context.GetX(29); trace.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}"); while (framePointer != 0) { if ((framePointer & 7) != 0 || !_owner.CpuMemory.IsMapped(framePointer) || !_owner.CpuMemory.IsMapped(framePointer + 8)) { break; } // Note: This is the return address, we need to subtract one instruction // worth of bytes to get the branch instruction address. AppendTrace(_owner.CpuMemory.ReadInt64(framePointer + 8) - 4); framePointer = _owner.CpuMemory.ReadInt64(framePointer); } return(trace.ToString()); }
public void PrintStackTrace(AThreadState ThreadState) { StringBuilder Trace = new StringBuilder(); Trace.AppendLine("Guest stack trace:"); void AppendTrace(long Position) { Executable Exe = GetExecutable(Position); if (Exe == null) { return; } if (!TryGetSubName(Exe, Position, out string SubName)) { SubName = $"Sub{Position:x16}"; } else if (SubName.StartsWith("_Z")) { SubName = Demangler.Parse(SubName); } long Offset = Position - Exe.ImageBase; string ExeNameWithAddr = $"{Exe.Name}:0x{Offset:x8}"; Trace.AppendLine(" " + ExeNameWithAddr + " " + SubName); } long FramePointer = (long)ThreadState.X29; while (FramePointer != 0) { AppendTrace(Memory.ReadInt64(FramePointer + 8)); FramePointer = Memory.ReadInt64(FramePointer); } Logger.PrintInfo(LogClass.Cpu, Trace.ToString()); }
public void PrintStackTrace(AThreadState ThreadState) { long[] Positions = ThreadState.GetCallStack(); StringBuilder Trace = new StringBuilder(); Trace.AppendLine("Guest stack trace:"); foreach (long Position in Positions) { if (!SymbolTable.TryGetValue(Position, out string SubName)) { SubName = $"Sub{Position:x16}"; } else if (SubName.StartsWith("_Z")) { SubName = Demangler.Parse(SubName); } Trace.AppendLine(" " + SubName + " (" + GetNsoNameAndAddress(Position) + ")"); } Device.Log.PrintInfo(LogClass.Cpu, Trace.ToString()); }
public string GetGuestStackTrace(ARMeilleure.State.ExecutionContext context) { EnsureLoaded(); StringBuilder trace = new StringBuilder(); void AppendTrace(ulong address) { Image image = GetImage(address, out int imageIndex); if (image == null || !TryGetSubName(image, address, out string subName)) { subName = $"Sub{address:x16}"; } else if (subName.StartsWith("_Z")) { subName = Demangler.Parse(subName); } if (image != null) { ulong offset = address - image.BaseAddress; string imageName = GetGuessedNsoNameFromIndex(imageIndex); trace.AppendLine($" {imageName}:0x{offset:x8} {subName}"); } else { trace.AppendLine($" ??? {subName}"); } } trace.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}"); if (context.IsAarch32) { ulong framePointer = context.GetX(11); while (framePointer != 0) { if ((framePointer & 3) != 0 || !_owner.CpuMemory.IsMapped(framePointer) || !_owner.CpuMemory.IsMapped(framePointer + 4)) { break; } AppendTrace(_owner.CpuMemory.Read <uint>(framePointer + 4)); framePointer = _owner.CpuMemory.Read <uint>(framePointer); } } else { ulong framePointer = context.GetX(29); while (framePointer != 0) { if ((framePointer & 7) != 0 || !_owner.CpuMemory.IsMapped(framePointer) || !_owner.CpuMemory.IsMapped(framePointer + 8)) { break; } AppendTrace(_owner.CpuMemory.Read <ulong>(framePointer + 8)); framePointer = _owner.CpuMemory.Read <ulong>(framePointer); } } return(trace.ToString()); }