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> /// 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); } }
/// <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); }
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); }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Expected: <pdb file name> <output json name>"); } string pdbFileName = args[0]; string jsonFileName = args[1]; IDiaDataSource dia = new DiaSource(); dia.loadDataFromPdb(pdbFileName); dia.openSession(out IDiaSession session); session.globalScope.findChildren(SymTagEnum.SymTagUDT, null, 0, out var symbols); List <InterfaceInfo> interfaceInfos = new List <InterfaceInfo>(); foreach (IDiaSymbol type in symbols) { if (!type.name.StartsWith('I')) { continue; } System.Diagnostics.Debug.WriteLine(type.name); List <string> functions = new List <string>(); type.findChildren(SymTagEnum.SymTagNull, null, 0, out IDiaEnumSymbols members); foreach (IDiaSymbol member in members) { var memberTag = (SymTagEnum)member.symTag; if (memberTag == SymTagEnum.SymTagFunction && member.@virtual == 1) { StringBuilder methodText = new StringBuilder(); IDiaSymbol funcType = member.type; IDiaSymbol returnType = funcType.type; AppendType(returnType, methodText); methodText.Append($" {member.name}("); funcType.findChildren(SymTagEnum.SymTagNull, null, 0, out IDiaEnumSymbols parameters); bool first = true; foreach (IDiaSymbol p in parameters) { if (first) { first = false; } else { methodText.Append(", "); } AppendType(p.type, methodText); } methodText.Append(')'); functions.Add(methodText.ToString()); } } if (functions.Count != 0) { InterfaceInfo info = new InterfaceInfo() { Name = type.name, Methods = functions.ToArray() }; interfaceInfos.Add(info); } } var interfacesText = Newtonsoft.Json.JsonConvert.SerializeObject(interfaceInfos, formatting: Newtonsoft.Json.Formatting.Indented); File.WriteAllText(jsonFileName, interfacesText); }
/// <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; }