/// <summary> /// Load debug info /// </summary> /// <param name="peOrPdbPath"></param> /// <param name="symbolPath"></param> private void Init(string peOrPdbPath, string symbolPath) { try { DiaSource diaSource = new DiaSource(); Environment.SetEnvironmentVariable("_NT_SYMBOL_PATH", ""); if (symbolPath == null) { string pdbPath = Path.ChangeExtension(peOrPdbPath, ".pdb"); if (File.Exists(pdbPath)) { peOrPdbPath = pdbPath; } } // load the debug info depending on the file type if (peOrPdbPath.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) { diaSource.loadDataFromPdb(peOrPdbPath); } else { diaSource.loadDataForExe(peOrPdbPath, symbolPath, IntPtr.Zero); } diaSource.openSession(out _session); } catch (COMException ce) { throw new PdbParseException(ce); } }
private static IDiaSymbol LoadFile(string path) { IDiaSession session; IDiaSymbol global; try { IDiaDataSource source = new DiaSource(); source.loadDataFromPdb(path); source.openSession(out session); global = session.globalScope; } catch (COMException ex) { if (ex.ErrorCode == ErrorCodes.E_PDB_FORMAT) { throw new PdbFormatException(); } else { Console.WriteLine(ex.Message); Environment.Exit(1); throw new PdbNotFoundException(); } } return(global); }
/// <summary> /// Opens the module for the specified XML module description. /// </summary> /// <param name="module">The XML module description.</param> public static Module Open(XmlModule module) { IDiaDataSource dia = new DiaSource(); IDiaSession session; string moduleName = !string.IsNullOrEmpty(module.Name) ? module.Name : Path.GetFileNameWithoutExtension(module.PdbPath).ToLower(); module.Name = moduleName; dia.loadDataFromPdb(module.PdbPath); dia.openSession(out session); return(new Module(module.Name, module.Namespace, dia, session)); }
private static IDiaSymbol LoadFile(string path) { IDiaSession session; IDiaSymbol global; IDiaDataSource source = new DiaSource(); source.loadDataFromPdb(path); source.openSession(out session); global = session.globalScope; return(global); }
static ProgramDatabase() { module = GetUnityModule(); #if UNITY_EDITOR dia = new DiaSource(); dia.loadDataForExe(module.FileName, null, null); dia.openSession(out session); #else const string PipeName = "Unity.PdbService"; server = new NamedPipeServerStream(PipeName, PipeDirection.InOut); process = new Process { StartInfo = new ProcessStartInfo { FileName = Path.GetFullPath("PdbService.exe"), Arguments = PipeName, CreateNoWindow = true, UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, } }; process.Start(); server.WaitForConnection(); writer = new StreamWriter(server) { AutoFlush = true }; reader = new StreamReader(server); writer.WriteLine("InitFromExe"); writer.WriteLine(module.FileName); Application.quitting += () => { reader.Dispose(); writer.Dispose(); server.Dispose(); process.Kill(); process.Dispose(); }; #endif }
private bool ParsePdbFile() { FileInfo fi = new FileInfo(_pdbFile); if (!fi.Exists) { _errorList.Add("The PDB file doesn't exist: " + _pdbFile); return(false); } _fileLength = fi.Length; DiaSource source = new DiaSource(); source.loadDataFromPdb(_pdbFile); source.openSession(out _session); _session.globalScope.findChildren(SymTagEnum.SymTagUDT, null, 0, out _enumUTDs); _session.globalScope.findChildren(SymTagEnum.SymTagPublicSymbol, null, 0, out _enumPublicSymbols); _session.globalScope.findChildren(SymTagEnum.SymTagEnum, null, 0, out _enumEnums); return(true); }
/// <summary> /// Opens the module for the specified XML module description. /// </summary> /// <param name="module">The XML module description.</param> public static Module Open(XmlModule module) { IDiaDataSource dia = new DiaSource(); IDiaSession session; string moduleName = !string.IsNullOrEmpty(module.Name) ? module.Name : Path.GetFileNameWithoutExtension(module.PdbPath).ToLower(); module.Name = moduleName; dia.loadDataFromPdb(module.PdbPath); dia.openSession(out session); return new Module(module.Name, module.Namespace, dia, session); }
/// <summary> /// Perform full symbol walk scanning for a struct/member position and length /// /// TODO: make safe for type collisions in other pdb's /// </summary> /// <param name="PDBFile">d:\dev\symbols\ntkrnlmp.pdb\DD08DD42692B43F199A079D60E79D2171\ntkrnlmp.pdb</param> /// <param name="Struct">_EPROCESS</param> /// <param name="Member">Pcb.DirectoryTableBase</param> /// <returns>Tuple of Position & Length </returns> public Tuple<int, int> StructMemberInfo(string PDBFile, string Struct, string Member) { IDiaSession Session; IDiaSymbol Master = null; IDiaEnumSymbols EnumSymbols = null; uint compileFetched = 0; var result = from symx in StructInfo where symx.Key.EndsWith(Member) select symx; if (result.Count() > 0) return result.First().Value; var foo = new DiaSource(); foo.loadDataFromPdb(PDBFile); foo.openSession(out Session); if (Session == null) return null; Session.findChildren(Session.globalScope, SymTagEnum.SymTagNull, Struct, 0, out EnumSymbols); do { EnumSymbols.Next(1, out Master, out compileFetched); if (Master == null) continue; #if DEBUGX Console.ForegroundColor = ConsoleColor.White; WriteLine($"Dumping Type [{Master.name}] Len [{Master.length}]"); #endif if (!StructInfo.ContainsKey(Master.name)) StructInfo.Add(Master.name, Tuple.Create<int, int>(0, (int)Master.length)); DumpStructs(Master, Master.name, Struct, 0); } while (compileFetched == 1); var resultx = (from symx in StructInfo where symx.Key.EndsWith(Member) select symx).FirstOrDefault(); return resultx.Value; }
public dynamic xStructInfo(string PDBFile, string Struct, long[] memRead = null) { dynamic Info = null; IDiaSymbol Master = null; IDiaEnumSymbols EnumSymbols = null; IDiaSession Session; uint compileFetched = 0; var foo = new DiaSource(); foo.loadDataFromPdb(PDBFile); foo.openSession(out Session); if (Session == null) return null; // 10 is regex Session.globalScope.findChildren(SymTagEnum.SymTagNull, Struct, 10, out EnumSymbols); do { EnumSymbols.Next(1, out Master, out compileFetched); if (Master == null) continue; #if DEBUGX Console.ForegroundColor = ConsoleColor.White; WriteLine($"Dumping Type [{Master.name}] Len [{Master.length}]"); #endif Info = new ExpandoObject(); Info.TypeName = Master.name; Info.Length = Master.length; //StructInfo.Add(Master.name, Info); // Tuple.Create<int, int>(0, (int)Master.length)); xDumpStructs(Info, Master, Master.name, 0, memRead); } while (compileFetched == 1); return Info; }