Advertisement
Guest User

Untitled

a guest
May 29th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /// <summary>
  2. /// Violate Cecil encapsulation to get the PDB path -- a candidate
  3. /// for another method on ModuleDefinition
  4. /// </summary>
  5. /// <param name="assembly">The assembly to find the .pdb path for</param>
  6. /// <returns>The path (null if the operation fails)</returns>
  7. public static string GetPdbFromImage(AssemblyDefinition assembly)
  8. {
  9. var m = assembly.MainModule;
  10. var imageField = typeof(ModuleDefinition).GetField("Image", BindingFlags.Instance | BindingFlags.NonPublic);
  11. var image = imageField.GetValue(m);
  12. var getDebugHeaderInfo = image.GetType().GetMethod("GetDebugHeader");
  13. byte[] result = null;
  14. var args = new object[] { result };
  15.  
  16. try
  17. {
  18. getDebugHeaderInfo.Invoke(image, args);
  19. var SizeOfDebugInfo = 0x18;
  20. result = args[0] as byte[];
  21. if (null == result)
  22. {
  23. return null;
  24. }
  25.  
  26. var byteValue = result.Skip(SizeOfDebugInfo).
  27. TakeWhile(x => x != 0).ToArray();
  28.  
  29. if (byteValue.Length > 0)
  30. {
  31. // UTF-8 encoding works for an assembly named GetÞePdbLocation.
  32. return Encoding.UTF8.GetString(byteValue);
  33. }
  34. }
  35. catch (TargetInvocationException)
  36. {}
  37.  
  38. return null;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement