Decompiled .winmd file contains nothing but external calls

六眼飞鱼酱① 提交于 2019-12-04 11:56:22

问题


I am trying to decompile the ComboBox control for my Windows Store app into C#, but there's no code. Instead, all the properties are calls to a separate assembly, it seems. How do I find where the real code exists, and how do I read the method bodies in C#? I cannot read assembly, so that would do me no good


回答1:


Some notes on how to reverse-engineer the WinRT internals.
Under the hood, WinRT is pure COM. First place you want to look on your machine is

C:\Program Files (x86)\Windows Kits\8.0\Include\WinRT

This directory contains IDL files, or Interface Description Language. IDL is the starting point for describing COM types. A quick search for ComboBox will let you find Windows.UI.Xaml.Controls.IDL and the declaration for the ComboBox type:

    [marshaling_behavior(agile)]
    [threading(both)]
    [static(Windows.UI.Xaml.Controls.IComboBoxStatics, 0x06020000)]
    [version(0x06020000)]
    [composable(Windows.UI.Xaml.Controls.IComboBoxFactory, public, 0x06020000)]
    runtimeclass ComboBox : Windows.UI.Xaml.Controls.Primitives.Selector
    {
        [default] interface Windows.UI.Xaml.Controls.IComboBox;
        [overridable] interface Windows.UI.Xaml.Controls.IComboBoxOverrides;
    }

It is kinda readable as-is, resembling an interface declaration in C#. If you've tinkered with COM before then you'll see new attributes from the original IDL syntax. Extra stuff to aid the language projection built into your runtime support library to create the illusion that WinRT supports implementation inheritance, generics and static class members, features that pure COM doesn't have.

These IDL files are compiled by midlrt.exe into a machine-readable format that is usable by tools like compilers. You already know that format, the output of midlrt.exe is a .winmd file. Similar to the type libraries of old but much enhanced, the underlying format was adopted from .NET's assembly manifest format. So decompiling the .winmd file isn't useful, you already have the source on your machine ;)

As is common in COM, the registry is used to find the executable that contains the code for a COM server. Start regedit.exe and navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId. You'll find a list of all WinRT types that an app can create. The Windows.UI.Xaml.Controls.ComboBox key is the one you are interested in. Note the DllPath value, that points to the DLL that contains the code: C:\Windows\System32\Windows.UI.Xaml.dll on my machine. The CLSID value is the familiar COM class guid, used to ask the class factory to create the instance.

That's about where you hit the wall; the DLL contains native code like the majority of COM servers do. Written in C++ and compiled to machine code. Quite impervious to decompilation, it is an 18 megabyte monster.




回答2:


So I found the assembly. You just have to search for the .dll file on the system (eg. Windows.XAML.UI.Controls.dll in my case), but it's not possible to disassemble it to C#. Turns out there are no C# disassemblers for the WinRT assemblies (at least, when I looked last)



来源:https://stackoverflow.com/questions/12843830/decompiled-winmd-file-contains-nothing-but-external-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!