Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Violate Cecil encapsulation to get the PDB path -- a candidate
- /// for another method on ModuleDefinition
- /// </summary>
- /// <param name="assembly">The assembly to find the .pdb path for</param>
- /// <returns>The path (null if the operation fails)</returns>
- public static string GetPdbFromImage(AssemblyDefinition assembly)
- {
- var m = assembly.MainModule;
- var imageField = typeof(ModuleDefinition).GetField("Image", BindingFlags.Instance | BindingFlags.NonPublic);
- var image = imageField.GetValue(m);
- var getDebugHeaderInfo = image.GetType().GetMethod("GetDebugHeader");
- byte[] result = null;
- var args = new object[] { result };
- try
- {
- getDebugHeaderInfo.Invoke(image, args);
- var SizeOfDebugInfo = 0x18;
- result = args[0] as byte[];
- if (null == result)
- {
- return null;
- }
- var byteValue = result.Skip(SizeOfDebugInfo).
- TakeWhile(x => x != 0).ToArray();
- if (byteValue.Length > 0)
- {
- // UTF-8 encoding works for an assembly named GetÞePdbLocation.
- return Encoding.UTF8.GetString(byteValue);
- }
- }
- catch (TargetInvocationException)
- {}
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement