public ReadMemoryRH(ReadMemoryDelegate readMemory, byte[] buffer, UInt64 size, GDBSubProcess gdbProc) : base(gdbProc) { _readMemory = readMemory; _buffer = buffer; //_size = size; }
/// <summary> /// Utils ctor. /// </summary> //public Utils() { } /// <summary> /// Load a string from memory. Load bytes until a 0 encountered or max bytes reached. /// </summary> /// <param name="rm">function to use to read a byte</param> /// <param name="address">address to start reading</param> /// <param name="maxSize">max bytes to read</param> /// <returns></returns> public static string loadStringFromMemory(ReadMemoryDelegate readMemoryDelegate, uint address, uint maxSize) { StringBuilder str = new StringBuilder(); uint bytesLeft = maxSize; try { uint data; do { data = readMemoryDelegate(address++, ARMPluginInterfaces.MemorySize.Byte); if (data == 0) { break; } str.Append((char)data); } while (--bytesLeft > 0); }//try catch (Exception ex) { ARMPluginInterfaces.Utils.OutputDebugString("Error while reading string from memory:" + ex.Message); str.Length = 0; } //catch return(str.ToString()); } //loadStringFromMemory
public TargetStream(IntPtr address, int size, ReadMemoryDelegate readMemory) : base() { _address = address; _readMemory = readMemory; Length = size; Position = 0; }
public TargetStream(IntPtr address, int size, ReadMemoryDelegate readMemory) : base() { _address = address; _readMemory = readMemory; Length = size; Position = 0; }
/// <summary> /// Checks availability of debugging information for given assembly. /// </summary> /// <param name="assemblyPath"> /// File path of the assembly or null if the module is in-memory or dynamic (generated by Reflection.Emit) /// </param> /// <param name="isFileLayout">type of in-memory PE layout, if true, file based layout otherwise, loaded layout</param> /// <param name="loadedPeAddress"> /// Loaded PE image address or zero if the module is dynamic (generated by Reflection.Emit). /// Dynamic modules have their PDBs (if any) generated to an in-memory stream /// (pointed to by <paramref name="inMemoryPdbAddress"/> and <paramref name="inMemoryPdbSize"/>). /// </param> /// <param name="loadedPeSize">loaded PE image size</param> /// <param name="inMemoryPdbAddress">in memory PDB address or zero</param> /// <param name="inMemoryPdbSize">in memory PDB size</param> /// <returns>Symbol reader handle or zero if error</returns> internal static IntPtr LoadSymbolsForModule(string assemblyPath, bool isFileLayout, IntPtr loadedPeAddress, int loadedPeSize, IntPtr inMemoryPdbAddress, int inMemoryPdbSize, ReadMemoryDelegate readMemory) { try { TargetStream peStream = null; if (assemblyPath == null && loadedPeAddress != IntPtr.Zero) { peStream = new TargetStream(loadedPeAddress, loadedPeSize, readMemory); } TargetStream pdbStream = null; if (inMemoryPdbAddress != IntPtr.Zero) { pdbStream = new TargetStream(inMemoryPdbAddress, inMemoryPdbSize, readMemory); } OpenedReader openedReader = GetReader(assemblyPath, isFileLayout, peStream, pdbStream); if (openedReader != null) { GCHandle gch = GCHandle.Alloc(openedReader); return(GCHandle.ToIntPtr(gch)); } } catch { } return(IntPtr.Zero); }
/// <summary> /// Load native symbols and modules (i.e. dac, dbi). /// </summary> /// <param name="callback">called back for each symbol file loaded</param> /// <param name="parameter">callback parameter</param> /// <param name="moduleDirectory">module path</param> /// <param name="moduleFileName">module file name</param> /// <param name="address">module base address</param> /// <param name="size">module size</param> /// <param name="readMemory">read memory callback delegate</param> internal static void LoadNativeSymbols(SymbolFileCallback callback, IntPtr parameter, string tempDirectory, string moduleDirectory, string moduleFileName, ulong address, int size, ReadMemoryDelegate readMemory) { if (s_symbolStore != null) { Debug.Assert(s_tracer != null); string path = Path.Combine(moduleDirectory, moduleFileName); Stream stream = new TargetStream(address, size, readMemory); KeyTypeFlags flags = KeyTypeFlags.SymbolKey | KeyTypeFlags.ClrKeys; KeyGenerator generator = null; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var elfFile = new ELFFile(new StreamAddressSpace(stream), 0, true); generator = new ELFFileKeyGenerator(s_tracer, elfFile, path); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { var machOFile = new MachOFile(new StreamAddressSpace(stream), 0, true); generator = new MachOFileKeyGenerator(s_tracer, machOFile, path); } else { return; } try { IEnumerable <SymbolStoreKey> keys = generator.GetKeys(flags); foreach (SymbolStoreKey key in keys) { string symbolFileName = Path.GetFileName(key.FullPathName); s_tracer.Verbose("{0} {1}", key.FullPathName, key.Index); // Don't download the sos binaries that come with the runtime if (symbolFileName != "SOS.NETCore.dll" && !symbolFileName.StartsWith("libsos.")) { using (SymbolStoreFile file = GetSymbolStoreFile(key)) { if (file != null) { try { string downloadFileName = file.FileName; // If the downloaded doesn't already exists on disk in the cache, then write it to a temporary location. if (!File.Exists(downloadFileName)) { downloadFileName = Path.Combine(tempDirectory, symbolFileName); using (Stream destinationStream = File.OpenWrite(downloadFileName)) { file.Stream.CopyTo(destinationStream); } s_tracer.WriteLine("Downloaded symbol file {0}", key.FullPathName); } s_tracer.Information("{0}: {1}", symbolFileName, downloadFileName); callback(parameter, symbolFileName, downloadFileName); } catch (Exception ex) when(ex is UnauthorizedAccessException || ex is DirectoryNotFoundException) { s_tracer.Error("{0}", ex.Message); } } } } } } catch (Exception ex) when(ex is BadInputFormatException || ex is InvalidVirtualAddressException) { s_tracer.Error("Exception: {0}/{1}: {2:X16}", moduleDirectory, moduleFileName, address); } } }
/// <summary> /// Checks availability of debugging information for given assembly. /// </summary> /// <param name="assemblyPath"> /// File path of the assembly or null if the module is in-memory or dynamic (generated by Reflection.Emit) /// </param> /// <param name="isFileLayout">type of in-memory PE layout, if true, file based layout otherwise, loaded layout</param> /// <param name="loadedPeAddress"> /// Loaded PE image address or zero if the module is dynamic (generated by Reflection.Emit). /// Dynamic modules have their PDBs (if any) generated to an in-memory stream /// (pointed to by <paramref name="inMemoryPdbAddress"/> and <paramref name="inMemoryPdbSize"/>). /// </param> /// <param name="loadedPeSize">loaded PE image size</param> /// <param name="inMemoryPdbAddress">in memory PDB address or zero</param> /// <param name="inMemoryPdbSize">in memory PDB size</param> /// <returns>Symbol reader handle or zero if error</returns> internal static IntPtr LoadSymbolsForModule(string assemblyPath, bool isFileLayout, IntPtr loadedPeAddress, int loadedPeSize, IntPtr inMemoryPdbAddress, int inMemoryPdbSize, ReadMemoryDelegate readMemory) { try { TargetStream peStream = null; if (assemblyPath == null && loadedPeAddress != IntPtr.Zero) { peStream = new TargetStream(loadedPeAddress, loadedPeSize, readMemory); } TargetStream pdbStream = null; if (inMemoryPdbAddress != IntPtr.Zero) { pdbStream = new TargetStream(inMemoryPdbAddress, inMemoryPdbSize, readMemory); } OpenedReader openedReader = GetReader(assemblyPath, isFileLayout, peStream, pdbStream); if (openedReader != null) { GCHandle gch = GCHandle.Alloc(openedReader); return GCHandle.ToIntPtr(gch); } } catch { } return IntPtr.Zero; }
public MemoryCache(ReadMemoryDelegate readMemory) { _map = new Dictionary <ulong, Cluster>(); _readMemory = readMemory; }
/// <summary> /// Load native symbols and modules (i.e. dac, dbi). /// </summary> /// <param name="callback">called back for each symbol file loaded</param> /// <param name="parameter">callback parameter</param> /// <param name="tempDirectory">temp directory unique to this instance of SOS</param> /// <param name="moduleFilePath">module path</param> /// <param name="address">module base address</param> /// <param name="size">module size</param> /// <param name="readMemory">read memory callback delegate</param> public static void LoadNativeSymbols(SymbolFileCallback callback, IntPtr parameter, string tempDirectory, string moduleFilePath, ulong address, int size, ReadMemoryDelegate readMemory) { if (IsSymbolStoreEnabled()) { Debug.Assert(s_tracer != null); Stream stream = new TargetStream(address, size, readMemory); KeyTypeFlags flags = KeyTypeFlags.SymbolKey | KeyTypeFlags.ClrKeys; KeyGenerator generator = null; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var elfFile = new ELFFile(new StreamAddressSpace(stream), 0, true); generator = new ELFFileKeyGenerator(s_tracer, elfFile, moduleFilePath); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { var machOFile = new MachOFile(new StreamAddressSpace(stream), 0, true); generator = new MachOFileKeyGenerator(s_tracer, machOFile, moduleFilePath); } else { return; } try { IEnumerable <SymbolStoreKey> keys = generator.GetKeys(flags); foreach (SymbolStoreKey key in keys) { string moduleFileName = Path.GetFileName(key.FullPathName); s_tracer.Verbose("{0} {1}", key.FullPathName, key.Index); // Don't download the sos binaries that come with the runtime if (moduleFileName != "SOS.NETCore.dll" && !moduleFileName.StartsWith("libsos.")) { string downloadFilePath = GetSymbolFile(key, tempDirectory); if (downloadFilePath != null) { s_tracer.Information("{0}: {1}", moduleFileName, downloadFilePath); callback(parameter, moduleFileName, downloadFilePath); } } } } catch (Exception ex) when(ex is BadInputFormatException || ex is InvalidVirtualAddressException) { s_tracer.Error("{0}/{1:X16}: {2}", moduleFilePath, address, ex.Message); } } }