DEV Community

Wesley
Wesley

Posted on • Updated on • Originally published at gist.github.com

(Feb'19) Get Unicode Character Name in C# (DllImport) (charmap mechanism)

Found this using IDA 6.8 Pro
Charmap loads a DLL named GetUName.dll which has a selfnamed function and pulls the name of a unicode character using an int and loads the name into a string
In C++, it is used like GetUName(int, LPWSTR *)
In C#, it can be imported this way:

[DllImport("GetUName.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int GetUName(int x, [MarshalAs(UnmanagedType.LPWStr)]string lpBuffer);
Enter fullscreen mode Exit fullscreen mode

Then, create a string buffer to load name in (255 in case of large names, can be changed)
public static string charactername = new string('*', 255);
And use in the program like so:

GetUName('A', charactername);
// asteriks are still left in (* because names don't include
// any), simply cut the length so they aren't included
charactername = charactername.Substring(0, charactername.IndexOf('*') - 1);
Console.Write(charactername);
Enter fullscreen mode Exit fullscreen mode

Included this in a program I wrote that inserts a character in the previously active window: https://github.com/donnaken15/quickcharmap/
Also shared this on the pinvoke wiki:
https://www.pinvoke.net/default.aspx/getuname.GetUName

Top comments (0)