DEV Community

Wesley
Wesley

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

1

(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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay