public static void Convert(string pdb, string windowsRootFolder, string linuxRootFolder) { string filenameWithoutExtension = Path.GetFileNameWithoutExtension(pdb); string filename = Path.Combine(Path.GetDirectoryName(pdb), $"{filenameWithoutExtension}.dll"); if (!File.Exists(filename)) { filename = Path.Combine(Path.GetDirectoryName(pdb), $"{filenameWithoutExtension}.exe"); } if (!File.Exists(filename)) { throw new FileNotFoundException("Assembly file doesn't exist: " + pdb); } using (var asm = AssemblyDefinition.ReadAssembly(filename)) { using (var stream = File.OpenRead(pdb)) { if (IsPortablePdb(stream)) { throw new PortablePdbNotSupportedException(); } var funcs = PdbFile.LoadFunctions(stream, true); Converter.Convert(asm, funcs, new MonoSymbolWriter(filename), windowsRootFolder, linuxRootFolder); } } }
/* * uint Magic = 0x53445352; * Guid Signature; * uint Age; * string FileName; */ public bool ProcessDebugHeader(ImageDebugHeader header) { if (!header.HasEntries) { return(false); } using (pdb_file) { var info = PdbFile.LoadFunctions(pdb_file.value); foreach (var entry in header.Entries) { if (!IsMatchingEntry(info, entry)) { continue; } foreach (var function in info.Functions) { functions.Add(function.token, function); } return(true); } } return(false); }
public void Initialize(string assemblyFilePath) { using (var pdbFileStream = File.OpenRead(Path.ChangeExtension(assemblyFilePath, "pdb"))) { _pdbFunctions = PdbFile.LoadFunctions(pdbFileStream, true).ToDictionary(func => func.token, func => func); } }
void PopulateFunctions(string file) { using (Stream pdb = File.OpenRead(file)) { int age; Guid guid; PdbFunction [] funcs = PdbFile.LoadFunctions(pdb, true, out age, out guid); if (this.age != 0) { if (this.age != age) { throw new InvalidOperationException(); } if (this.guid != guid) { throw new InvalidOperationException(); } } foreach (PdbFunction function in funcs) { functions.Add(function.token, function); } } }
internal void RunTest(string name, out PdbFunction original, out PdbFunction rewritten) { int originalAge; Guid originalGuid; PdbFunction[] originalFunctions; using (var file = File.OpenRead(pdbFileName)) originalFunctions = PdbFile.LoadFunctions(file, true, out originalAge, out originalGuid); var method = GetMethod(name); original = originalFunctions.Single(f => f.token == method.MetadataToken.ToUInt32()); var pdb = ProgramDatabase.Read(pdbFileName); pdb.Write(pdbFileName, new CecilMetadataProvider(module)); int rewrittenAge; Guid rewrittenGuid; PdbFunction[] rewrittenFunctions; using (var file = File.OpenRead(pdbFileName)) rewrittenFunctions = PdbFile.LoadFunctions(file, true, out rewrittenAge, out rewrittenGuid); rewritten = rewrittenFunctions.Single(f => f.token == method.MetadataToken.ToUInt32()); Assert.AreEqual(originalAge, rewrittenAge); Assert.AreEqual(originalGuid, rewrittenGuid); }
bool PopulateFunctions() { using (pdb_file) { int age; Guid guid; var funcs = PdbFile.LoadFunctions(pdb_file, true, out age, out guid); if (this.age != 0 && this.guid != guid) { return(false); } { // foreach(var function in funcs) var __enumerator1 = (funcs).GetEnumerator(); while (__enumerator1.MoveNext()) { var function = (PdbFunction)__enumerator1.Current; functions.Add(function.token, function); } } } return(true); }
bool PopulateFunctions() { using (pdb_file) { int age; Guid guid; var funcs = PdbFile.LoadFunctions(pdb_file, true, out age, out guid); if (this.age != 0) { if (this.age != age) { return(false); } if (this.guid != guid) { return(false); } } foreach (PdbFunction function in funcs) { functions.Add(function.token, function); } } return(true); }
/// <summary> /// Allocates an object that can map some kinds of ILocation objects to IPrimarySourceLocation objects. /// For example, a PDB reader that maps offsets in an IL stream to source locations. /// </summary> public PdbReader(Stream pdbStream, IMetadataHost host) { this.host = host; foreach (PdbFunction pdbFunction in PdbFile.LoadFunctions(pdbStream, true)) { this.pdbFunctionMap[pdbFunction.token] = pdbFunction; } }
static void Convert(AssemblyDefinition assembly, Stream pdb, MonoSymbolWriter mdb) { try { Converter.Convert(assembly, PdbFile.LoadFunctions(pdb, true), mdb); } catch (Exception e) { Error(e); } }
/// <summary> /// Allocates an object that can map some kinds of ILocation objects to IPrimarySourceLocation objects. /// For example, a PDB reader that maps offsets in an IL stream to source locations. /// </summary> public PdbReader(Stream pdbStream, IMetadataHost host) { Contract.Requires(pdbStream != null); Contract.Requires(host != null); this.pdbStream = pdbStream; this.host = host; foreach (PdbFunction pdbFunction in PdbFile.LoadFunctions(pdbStream, out this.tokenToSourceMapping, out this.sourceServerData)) { this.pdbFunctionMap[pdbFunction.token] = pdbFunction; } }
public static void Convert(string filename) { var asm = AssemblyDefinition.ReadAssembly(filename); var pdb = asm.Name.Name + ".pdb"; pdb = Path.Combine(Path.GetDirectoryName(filename), pdb); using (var stream = File.OpenRead(pdb)) { var funcs = PdbFile.LoadFunctions(stream, true); Converter.Convert(asm, funcs, new MonoSymbolWriter(filename)); } }
/// <summary> /// Allocates an object that can map some kinds of ILocation objects to IPrimarySourceLocation objects. /// For example, a PDB reader that maps offsets in an IL stream to source locations. /// Uses the default host /// </summary> public PdbReader(string modulePath) { host = new PeReader.DefaultHost(); module = host.LoadUnitFrom(modulePath) as IModule; string pdbFile = Path.ChangeExtension(modulePath, "pdb"); using (Stream pdbStream = File.OpenRead(pdbFile)) { foreach (PdbFunction pdbFunction in PdbFile.LoadFunctions(pdbStream, out this.tokenToSourceMapping)) { this.pdbFunctionMap[pdbFunction.token] = pdbFunction; } } }
bool PopulateFunctions() { using (pdb_file) { Dictionary <uint, PdbTokenLine> tokenToSourceMapping; string sourceServerData; var funcs = PdbFile.LoadFunctions(pdb_file, out tokenToSourceMapping, out sourceServerData); foreach (PdbFunction function in funcs) { functions.Add(function.token, function); } } return(true); }
/// <summary> /// Read a pdb from a stream. /// </summary> /// <param name="stream">The stream containing the pdb.</param> /// <returns>A representation of the pdb.</returns> public static ProgramDatabase Read(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanRead) { throw new ArgumentException("Can not read from stream", "stream"); } int age; Guid guid; return(new ProgramDatabase(PdbFile.LoadFunctions(stream, true, out age, out guid), age, guid)); }
public IList <string> ReadSources(Stream peStream, Stream pdbStream) { var result = new List <string>(); foreach (var obj1 in PdbFile.LoadFunctions(pdbStream, false)) { if (obj1.lines != null) { foreach (var obj2 in obj1.lines) { result.Add(obj2.file.name); } } } return(result.Where(IsValidSourceFileName).Distinct().ToArray()); }
public IList <string> ReadSources(Stream pdbStream) { var result = new List <string>(); Dictionary <uint, PdbTokenLine> mapping; foreach (var obj1 in PdbFile.LoadFunctions(pdbStream, out mapping)) { if (obj1.lines != null) { foreach (var obj2 in obj1.lines) { result.Add(obj2.file.name); } } } return(result.Where(c => !string.IsNullOrEmpty(c)).Distinct().ToArray()); }
bool PopulateFunctions() { using (pdb_file) { var info = PdbFile.LoadFunctions(pdb_file.value); if (this.guid != info.Guid) { return(false); } foreach (PdbFunction function in info.Functions) { functions.Add(function.token, function); } } return(true); }
public static ISymbolLoader Create(Stream stream) { try { Dictionary <uint, PdbTokenLine> tokenToSourceMapping; string sourceServerData; int age; Guid guid; var funcs = PdbFile.LoadFunctions(stream, out tokenToSourceMapping, out sourceServerData, out age, out guid); return(new PdbSymbolLoader(funcs.ToDictionary(x => x.token, x => x))); } catch (Exception e) { Debug.WriteLine(e.ToString()); } return(null); }
public IList <string> ReadSources(Stream peStream, Stream pdbStream) { var result = new List <string>(); var tokenToSourceMapping = new Dictionary <uint, PdbTokenLine>(); foreach (var obj1 in PdbFile.LoadFunctions(pdbStream, out tokenToSourceMapping)) { if (obj1.lines != null) { foreach (var obj2 in obj1.lines) { result.Add(obj2.file.name); } } } return(result.Where(IsValidSourceFileName).Distinct().ToArray()); }
bool PopulateFunctions() { using (pdb_file) { int age; Guid guid; var funcs = PdbFile.LoadFunctions(pdb_file, true, out age, out guid); // 11111111111111111111111 这里做了点修改 //if (this.age != 0 && this.guid != guid) // return false; foreach (PdbFunction function in funcs) { functions.Add(function.token, function); } } return(true); }
public static void Convert(string assembly) { var pdb = Path.ChangeExtension(assembly, "pdb"); // No need to warn about a missing pdb, just skip conversion. if (File.Exists(pdb)) { var assemblyDefinition = AssemblyDefinition.ReadAssembly(assembly); try { using (var stream = File.OpenRead(pdb)) Pdb2Mdb.Converter.Convert(assemblyDefinition, PdbFile.LoadFunctions(stream, true), new MonoSymbolWriter(assembly)); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { //Console.LogException(ex); } } }
public static void Convert(string filename) { using (var asm = AssemblyDefinition.ReadAssembly(filename)) { var pdb = asm.Name.Name + ".pdb"; pdb = Path.Combine(Path.GetDirectoryName(filename), pdb); if (!File.Exists(pdb)) { throw new FileNotFoundException("PDB file doesn't exist: " + pdb); } using (var stream = File.OpenRead(pdb)) { if (IsPortablePdb(stream)) { throw new PortablePdbNotSupportedException(); } var funcs = PdbFile.LoadFunctions(stream, true); Converter.Convert(asm, funcs, new MonoSymbolWriter(filename)); } } }
bool PopulateFunctions() { using (pdb_file) { Dictionary <uint, PdbTokenLine> tokenToSourceMapping; string sourceServerData; int age; Guid guid; var funcs = PdbFile.LoadFunctions(pdb_file.value, out tokenToSourceMapping, out sourceServerData, out age, out guid); if (this.guid != guid) { return(false); } foreach (PdbFunction function in funcs) { functions.Add(function.token, function); } } return(true); }
public static void Convert(string assembly) { var pdb = Path.ChangeExtension(assembly, "pdb"); // No need to warn about a missing pdb, just skip conversion. if (File.Exists(pdb)) { var assemblyDefinition = AssemblyDefinition.ReadAssembly(assembly); try { using (var stream = File.OpenRead(pdb)) Pdb2Mdb.Converter.Convert(assemblyDefinition, PdbFile.LoadFunctions(stream, true), new MonoSymbolWriter(assembly)); } catch (System.Exception ex) { Console.LogException(ex); } assemblyDefinition = null; } pdb = null; }
static int Main(string[] args) { bool good = false; bool quiet = false; if (args.Length == 0) { Usage(); return(1); } for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg.Length >= 2 && (arg[0] == '-' || arg[0] == '/')) { string name = null; string value = null; int n = arg.IndexOf(':'); if (n > -1) { name = arg.Substring(1, n - 1).ToLower(); if (n < arg.Length + 1) { value = arg.Substring(n + 1); } } else { name = arg.Substring(1).ToLower(); } bool badArg = false; switch (name) { case "q": case "quiet": quiet = true; break; default: badArg = true; break; } if (badArg) { Console.WriteLine("Malformed argument: \"{0}\"", arg); Usage(); return(1); } } else { try { string path = Path.GetDirectoryName(arg); string match = Path.GetFileName(arg); if (path == null || path == String.Empty) { path = "."; } Console.WriteLine("[{0}] [{1}]", path, match); String[] files = Directory.GetFiles(path, match); if (files == null) { Console.WriteLine("Could not find: {0}", arg); return(2); } if (files != null) { foreach (string file in files) { try { FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read); Console.WriteLine("{0}:", file); GC.Collect(); GC.Collect(); GC.Collect(); GC.Collect(); GC.Collect(); long gcBefore = GC.GetTotalMemory(true); PdbFunction[] funcs = PdbFile.LoadFunctions(stream, true); long gcAfter = GC.GetTotalMemory(false); #if false bits = null; head = null; reader = null; dir = null; // 50KB -- pages for streams. modules = null; // 40KB -- names = null; // 50KB -- lots of names. funcList = null; // 40KB -- lots of functions. #endif long gcClean = GC.GetTotalMemory(false); long gcFinal = GC.GetTotalMemory(true); Console.WriteLine(" gcBefore = {0,12}", gcBefore); Console.WriteLine(" gcAfter = {0,12}", gcAfter); Console.WriteLine(" gcClean = {0,12}", gcClean); Console.WriteLine(" gcFinal = {0,12} => used={1,12} temp=[{2,13}]", gcFinal, gcFinal - gcBefore, gcClean - gcFinal); Console.WriteLine(" {0} functions", funcs.Length); #if true for (int f = 0; f < funcs.Length; f++) { if (quiet) { Console.WriteLine(" {0:x4}:{1:x8} token={2:X8} [{3}::{4}]", funcs[f].segment, funcs[f].address, funcs[f].token, StripNamespace(funcs[f].module), funcs[f].name); } else { Dump(funcs[f], 0); } } #endif GC.Collect(); good = true; } catch (IOException e) { Console.Error.WriteLine("{0}: I/O Failure: {1}", file, e.Message); good = false; } } } } catch (IOException e) { Console.Error.WriteLine("{0}: I/O Failure: {1}", arg, e.Message); good = false; } } } if (!good) { return(1); } return(0); }