Exemplo n.º 1
0
 public void UnloadModule(ulong base_address)
 {
     if (0 == DbgHelpNative.SymUnloadModule64(m_Handle, base_address))
     {
         Debug.WriteLine("Failed to load " + base_address);
     }
 }
Exemplo n.º 2
0
        public ulong LoadModule(string name, ulong base_address, ulong size)
        {
            ulong baseDll = DbgHelpNative.SymLoadModule64(m_Handle, IntPtr.Zero, name, null, base_address, (uint)size);

            if (baseDll == 0)
            {
                Debug.WriteLine("Failed to load " + name);
            }
            return(baseDll);
        }
Exemplo n.º 3
0
        private void Dispose(bool disposing)
        {
            if (m_Handle.ToInt64() == 0)
            {
                return;
            }

            DbgHelpNative.SymCleanup(m_Handle);

            m_Handle = IntPtr.Zero;
        }
Exemplo n.º 4
0
        public bool LookupSymbol(ulong address, out SymbolInfo sym)
        {
            sym.FileName   = "";
            sym.LineNumber = 0;
            sym.Symbol     = "";
            sym.Address    = address;

            DbgHelpNative.SYMBOL_INFO data = new DbgHelpNative.SYMBOL_INFO();
            data.SizeOfStruct = (uint)Marshal.SizeOf(data) - 1024;
            data.MaxNameLen   = 1024;

            ulong displacement;

            if (DbgHelpNative.SymFromAddr(m_Handle, address, out displacement, ref data))
            {
                sym.Symbol = data.Name;
            }
            else
            {
                return(false);
            }

            DbgHelpNative.IMAGEHLP_LINE64 line = new DbgHelpNative.IMAGEHLP_LINE64();
            line.SizeOfStruct = (uint)Marshal.SizeOf(line);

            uint disp32;

            if (DbgHelpNative.SymGetLineFromAddr64(m_Handle, address, out disp32, ref line))
            {
                StringBuilder fn = new StringBuilder(128);
                for (int i = 0; ; ++i)
                {
                    byte b = Marshal.ReadByte(IntPtr.Add(line.FileName, i));
                    if (0 == b)
                    {
                        break;
                    }
                    fn.Append((char)b);
                }

                sym.FileName   = fn.ToString();
                sym.LineNumber = (int)line.LineNumber;
            }
            else
            {
                sym.FileName = "(no source)";
            }

            return(true);
        }
Exemplo n.º 5
0
        public List <SymbolInfo> GetSymbols(string name, ulong base_address)
        {
            List <SymbolInfo> symbols = new List <SymbolInfo>();

            DbgHelpNative.SymEnumSymbols(m_Handle, base_address, null, (symbol, symbolSize, userContext) =>
            {
                symbols.Add(new SymbolInfo()
                {
                    Address = symbol.Address + base_address,
                    Symbol  = symbol.Name,
                });
                return(true);
            }, IntPtr.Zero);
            return(symbols);
        }
Exemplo n.º 6
0
        public DbgHelp(ICollection <string> symbol_search_paths)
        {
            IntPtr handle = IntPtr.Add(IntPtr.Zero, 0x7ffffffe);

            DbgHelpNative.SetErrorMode(DbgHelpNative.SetErrorFlags.SEM_FAILCRITICALERRORS | DbgHelpNative.SetErrorFlags.SEM_NOOPENFILEERRORBOX);

            DbgHelpNative.SymSetOptions(DbgHelpNative.Options.SYMOPT_DEFERRED_LOADS | DbgHelpNative.Options.SYMOPT_DEBUG);

            string search_paths = null;

            if (symbol_search_paths != null && symbol_search_paths.Count > 0)
            {
                var path = new StringBuilder(1024);
                foreach (var sym in symbol_search_paths)
                {
                    if (path.Length > 0)
                    {
                        path.Append(";");
                    }
                    path.Append(sym);
                }
                search_paths = path.ToString();
            }


            if (!DbgHelpNative.SymInitialize(handle, search_paths, false))
            {
                throw new ApplicationException("Failed to initialize DbgHelp library");
            }

            m_CallbackGc = new DbgHelpNative.SymRegisterCallbackProc64(OnCallback);

            DbgHelpNative.SymRegisterCallback64(handle, m_CallbackGc, 0);

            m_Handle = handle;
        }