Created
June 19, 2020 08:03
-
-
Save chrisnas/1990e68fdaab47cc4b074caf16b686f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private string GetNativeMethodName(ulong address) | |
| { | |
| var symbol = new NativeDbgHelp.SYMBOL_INFO(); | |
| symbol.MaxNameLen = 1024; | |
| symbol.SizeOfStruct = (uint)Marshal.SizeOf(symbol) - 1024; // char buffer is not counted | |
| // the ANSI version of SymFromAddr is called so each character is 1 byte long | |
| if (NativeDbgHelp.SymFromAddr(_hProcess, address, out var displacement, ref symbol)) | |
| { | |
| var buffer = new StringBuilder(symbol.Name.Length); | |
| // remove weird "$##" at the end of some symbols | |
| var pos = symbol.Name.LastIndexOf("$##"); | |
| if (pos == -1) | |
| buffer.Append(symbol.Name); | |
| else | |
| buffer.Append(symbol.Name, 0, pos); | |
| // add offset if any | |
| if (displacement != 0) | |
| buffer.Append($"+0x{displacement}"); | |
| return buffer.ToString(); | |
| } | |
| // default value is the just the address in HEX | |
| return $"0x{address:x}"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment