Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Platform:Windows Runtime

From ReverseEngineering.wiki
Platform
On this wiki Facts · Code · Notes · Topics

The Windows Runtime (WinRT): COM-based object model with IInspectable, HSTRING class names and activation factories; how its activation path (RoGetActivationFactory, DllGetActivationFactory) and string type look in a binary.

Model

WinRT objects are COM objects whose interfaces derive from IInspectable (IID af86e2e0-b12d-4c6a-9c5a-d7aa65101e90), which adds three slots after IUnknown: GetIids (slot 3), GetRuntimeClassName (slot 4, returns an HSTRING) and GetTrustLevel (slot 5, TrustLevel BaseTrust 0, PartialTrust 1, FullTrust 2). Sources: wine include/inspectable.idl; windows-rs crates/libs/core/src/inspectable.rs (IInspectable_Vtbl). The vtable of a WinRT interface therefore has its own methods from slot 6 (x64 offset 0x30). Types are described in Format:WinRT metadata (WinMD).

HSTRING

An HSTRING is a pointer to an immutable, reference-counted UTF-16 string, created by WindowsCreateString (and friends from combase.dll) and freed by WindowsDeleteString; the null pointer is the empty string. windows-rs's mirror of the header (crates/libs/strings/src/hstring_header.rs) is: u32 flags (bit 0 HSTRING_REFERENCE_FLAG, set for stack-based references made by WindowsCreateStringReference), u32 len (UTF-16 code units), two reserved u32, a data pointer to the characters, a reference count, then the inline characters with a NUL. Code seldom touches the fields; it calls WindowsGetStringRawBuffer. A class name is typically built from a wide string literal in .rdata, e.g. L"Windows.Foundation.Uri".

Activation

WinRT classes are created through their activation factory (IActivationFactory, IID 00000035-0000-0000-c000-000000000046, ActivateInstance at slot 6; wine include/activation.idl). The common path in C++/WinRT (strings/base_activation.h) and windows-rs (crates/libs/core/src/imp/factory_cache.rs):

  1. RoGetActivationFactory(HSTRING className, REFIID iid, void** factory).
  2. If it returns CO_E_NOTINITIALIZED, both libraries start an MTA (CoIncrementMTAUsage found with GetProcAddress in combase.dll, or windows-rs init_mta) and retry.
  3. If the class is not registered (windows-rs does this only for REGDB_E_CLASSNOTREG), try registration-free activation: strip the last .Component of the class name, append .dll, load that library and call its exported DllGetActivationFactory(HSTRING, IActivationFactory**); for A.B.Type the order is A.B.dll, then A.dll.

So a WinRT component DLL exports DllGetActivationFactory (and normally DllCanUnloadNow, Unverified), and an app binary shows RoGetActivationFactory, WindowsCreateString, WindowsDeleteString and RoInitialize imports. Classes in the Windows platform are registered under HKLM\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId (Unverified, not read in a source). Static methods are called on a factory interface obtained from the same call with the IID of that statics interface; constructors with arguments use another factory interface; new-style default construction uses ActivateInstance.

Related

Technique:Reading COM and WinRT code, Format:WinRT metadata (WinMD).

Code & repositories

  • https://github.com/microsoft/windows-rs @ 20f6de7473ebb2761a19a73dcc2c25ac9499db6e · license: MIT OR Apache-2.0 (declared by the contributor for the files used; GitHub reports Apache-2.0 for the repository)
    Rust bindings for Windows: crates/libs/metadata (winmd reader, WindowsRuntime flags), strings (HSTRING header), core (IInspectable, activation factory cache).
    Tested on: source read, not run: source read, not run · checked 2026-10-18; last activity 2026-10-18
  • https://github.com/microsoft/cppwinrt @ 856eaff70a48d6b053c2ad3dffec15b81ca34b10 · license: MIT
    C++/WinRT: strings/base_abi.h (IInspectable ABI), base_activation.h (activation with DllGetActivationFactory fallback), base_implements.h.
    Tested on: source read, not run: source read, not run · checked 2026-10-18; last activity 2026-10-17