private static void Pdb_OnDbiInit(DBIReader DBI) { if (OptDumpModules) { DBI.OnModuleData += DBI_OnModuleData; } DBI.OnModuleReaderInit += DBI_OnModuleReaderInit; }
public GraphBuilder(IServiceContainer ctx) { this.Dbi = ctx.GetService <DBIReader>(); }
static void Main(string[] args) { ParseArguments(args); if (PdbFilePath == null) { Console.Error.WriteLine(@"PDBSharp.Dumper Usage: PDBSharp.Dumper <options> <file.pdb> [-dump] Save individual PDB Streams to files [-dump-modules] Verbose output for DBI Modules [-dump-leaves] Verbose output for TPI Leaves [-dump-syms] Verbose output for DBI Symbols [-print] Extract and print type definitions"); Environment.Exit(1); } #if PERF Console.WriteLine("Starting..."); Stopwatch sw = new Stopwatch(); sw.Start(); #endif PDBFile pdb = PDBFile.Open(PdbFilePath); IServiceContainer sc = pdb.Services; DBIReader dbi = sc.GetService <DBIReader>(); TPIReader tpi = sc.GetService <TPIReader>(); StreamTableReader streamTable = sc.GetService <StreamTableReader>(); if (OptPrintDecls) { var tree = new GraphBuilder(sc).Build(); CodeWriter cw = new CodeWriter(tree); #if !PERF cw.Write(Console.Out); #endif } if (OptDumpLeaves) { pdb.OnTpiInit += Pdb_OnTpiInit; } if (OptDumpModules || OptDumpSymbols) { pdb.OnDbiInit += Pdb_OnDbiInit; } if (OptDumpStreams) { DirectoryInfo dumpDir = Directory.CreateDirectory(Path.GetFileNameWithoutExtension(PdbFilePath)); for (int i = 1; i < streamTable.NumStreams; i++) { string dumpPath = Path.Combine(dumpDir.ToString(), $"stream{i}.bin"); byte[] stream = streamTable.GetStream(i); File.WriteAllBytes(dumpPath, stream); } } /* * foreach(var type in ctx.TpiReader.Types) { * //Console.WriteLine(type); * }*/ TPIHashReader tpiHash = sc.GetService <TPIHashReader>(); UdtNameTableReader udtNameTable = sc.GetService <UdtNameTableReader>(); TypeResolver resolver = sc.GetService <TypeResolver>(); if (tpiHash != null && udtNameTable != null) { foreach (var pair in tpiHash.NameIndexToTypeIndex) { string name = udtNameTable.GetString(pair.Key); ILeafContainer leaf = resolver.GetTypeByIndex(pair.Value); #if !PERF Console.WriteLine($"=> {name} [NI={pair.Key}] [TI={pair.Value}]"); Console.WriteLine(leaf.Data.GetType().Name); #endif } } foreach (var contrib in dbi.SectionContribs.SectionContribs) { #if !PERF ObjectDumper.Dump(contrib); #endif } DebugReader debug = dbi.DebugInfo; if (debug != null && debug.FPO != null) { foreach (var frame in debug.FPO.Frames) { #if !PERF ObjectDumper.Dump(frame); #endif } } foreach (var container in dbi.Modules) { #if !PERF Console.WriteLine($"[MODULE => {container.Info.ModuleName}]"); Console.WriteLine($"[OBJECT => {container.Info.ObjectFileName}]"); Console.WriteLine($"[SRC => {container.Info.SourceFileName}]"); if (container.Module != null) { Console.WriteLine($"[TYPE => {container.Module.GetType().Name}"); } Console.WriteLine(); #endif IModule mod = container.Module; if (mod != null) { foreach (var sym in mod.Symbols) { #if !PERF Console.WriteLine(sym); #endif } } } foreach (var type in tpi.Types) { #if !PERF Console.WriteLine(type); #endif } #if !PERF Console.WriteLine("Press Enter to continue..."); Console.ReadLine(); #else sw.Stop(); Console.WriteLine($"Finished in {sw.Elapsed.TotalSeconds} seconds"); #endif }