Loading the strings from the MUI file?

by Michael S. Kaplan, published on 2010/08/11 14:01 +00:00, original URI: http://blogs.msdn.com/b/michkap/archive/2010/08/11/10048694.aspx


It was a less than thirty four months ago that I wrote Cracking the binary (aka How to open .MUI files?).

And it was a less than 24 hours ago that reader Vinzy asked in a comment to that blog:

Is there a way to read strings from loaded MUI files, say shell32.dll.mui using C#?

I'll admit my first thought was that the answer was in the original blog, albeit buried a bit.

I mean after all, if you could open up the resources by making Visual Studio treat the files the same way they would treat other binaries like DLLs, then it kind of implies that they are in the exact same format, from a resources point of view.

But I thought about it a bit.

I mean it isn't like C# or even .Net has a bunch of built in methods to load traditional Wine32 resources built in, right?

Basically you have to P/Invoke the Win32 functions, like LoadString, for example:

            [DllImport("user32.dll", CharSet=CharSet.Unicode, EntryPoint="LoadStringW", ExactSpelling=true)]
            internal static extern int LoadString(
                IntPtr hInstance, 
                uint uID, 
                StringBuilder lpBuffer, 
                int nBufferMax);

Now Vinzy was specific about the idea that the files were already loaded, so a GetModuleHandle call will get the IntPtr that fits for that hInstance parameter, or maybe that vaslue is something already loaded.

And you can l,oad up any string you need.

Note that although it is possible to do all of this with a .MUI file directly, that is not the best way to do it.

You can instead load the original resource DLL and let Windows and its resource loader figure out which .MUI file to load and get data from.

You can reserve figuring it out yourself and loading the .MUI file directly for the times  that you are writing your own resource loader. :-)

There is also one last point to make here, since we are talking about getting strings from shell32.dll.mui and shell32.dll.

For almost everyone in the world, that is the wrong thing to do; the one real exception would be people on the Shell team who are loading the strings as part of their feature -- no one else should really be depending on strings in system files like shell2.dll or shell32.dll.mui!


comments not archived

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day