45

Is there an easy way to read an application's already embedded manifest file?

I was thinking along the lines of an alternate data stream?

Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636

10 Answers10

51

Windows manifest files are Win32 resources. In other words, they're embedded towards the end of the EXE or DLL. You can use LoadLibraryEx, FindResource, LoadResource and LockResource to load the embedded resource.

Here's a simple example that extracts its own manifest...

BOOL CALLBACK EnumResourceNameCallback(HMODULE hModule, LPCTSTR lpType,
    LPWSTR lpName, LONG_PTR lParam)
{
    HRSRC hResInfo = FindResource(hModule, lpName, lpType);
    DWORD cbResource = SizeofResource(hModule, hResInfo);

    HGLOBAL hResData = LoadResource(hModule, hResInfo);
    const BYTE *pResource = (const BYTE *)LockResource(hResData);

    TCHAR filename[MAX_PATH];
    if (IS_INTRESOURCE(lpName))
        _stprintf_s(filename, _T("#%d.manifest"), lpName);
    else
        _stprintf_s(filename, _T("%s.manifest"), lpName);

    FILE *f = _tfopen(filename, _T("wb"));
    fwrite(pResource, cbResource, 1, f);
    fclose(f);

    UnlockResource(hResData);
    FreeResource(hResData);

    return TRUE;   // Keep going
}

int _tmain(int argc, _TCHAR* argv[])
{
    const TCHAR *pszFileName = argv[0];

    HMODULE hModule = LoadLibraryEx(pszFileName, NULL, LOAD_LIBRARY_AS_DATAFILE);
    EnumResourceNames(hModule, RT_MANIFEST, EnumResourceNameCallback, NULL);
    FreeLibrary(hModule);
    return 0;
}

Alternatively, you can use MT.EXE from the Windows SDK:

>mt -inputresource:dll_with_manifest.dll;#1 -out:extracted.manifest
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • 10
    This is somewhat incorrect (the help is misleading). Typically .exes have an embedded manifest in resource #1, while .dlls have the manifest in resource #2. In any event, if you don't find a manifest resource in #1, check #2 rather than assuming it doesn't exist. – Wedge Aug 29 '09 at 17:05
  • Actually I was deliberately reading the manifest from the current application: "simple example that extracts its own manifest". Your way would work, too ;-) – Roger Lipscombe Feb 13 '13 at 15:09
  • Both `UnlockResource` and `FreeResource` [are obsolete](https://msdn.microsoft.com/en-us/library/windows/desktop/ms648044%28v=vs.85%29.aspx). – ghord Jan 20 '16 at 12:59
  • I've been programming Windows since 3.0; old habits die hard :) – Roger Lipscombe Jan 20 '16 at 13:59
36

You can extract/replace/merge/validate manifests using the command line manifest tool, mt.exe, which is part of the Windows SDK:

C:\Program Files\Microsoft SDKs\Windows\v6.1>mt /?
Microsoft (R) Manifest Tool version 5.2.3790.2075
...
> To extract manifest out of a dll:
mt.exe -inputresource:dll_with_manifest.dll;#1 -out:extracted.manifest

Different locations:

  • C:\Program Files\Microsoft SDKs\Windows\v6.1\bin
  • C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x86
Rand Random
  • 7,300
  • 10
  • 40
  • 88
bk1e
  • 23,871
  • 6
  • 54
  • 65
  • 4
    `-out:con` to output to console :) – Martin Connell May 25 '17 at 11:04
  • This results in an error for me with Microsoft Visual Studion 2019:mt.exe : command line error c10100a9: Some operation on the input manifests must be specified (even if it is just to pipe the input to the output) – mzabaluev Feb 15 '20 at 20:00
  • 3
    Responding to self: I ran this command line in PowerShell and it requires some escaping for the syntax used in the `inputresource` parameter, like so: `mt.exe "-inputresource:dll_with_manifest.dll;#1" -out:extracted.manifest` – mzabaluev Feb 16 '20 at 04:53
33

Open the file in Notepad. The thing's in plain text.

Screen grab

Daedalus
  • 7,586
  • 5
  • 36
  • 61
guest
  • 331
  • 3
  • 2
12

There's a manifest viewer tool available here -- I don't know if the author will make source code available.

jeffm
  • 3,120
  • 1
  • 34
  • 57
4

Resource Tuner would be nice if it supported x64 code, but as of today it's still only for 32-bit apps. Resource Hacker (the newest public beta) does support both x86 and x64 which is available from here: http://angusj.com/resourcehacker/

Mike
  • 1
  • 1
2

The easiest way to view/edit manifests in compiled apps is using Resource Tuner: http://www.restuner.com/tour-manifest.htm

In some cases, it's more robust than mt.exe from MS, and it's a visual tool.

Wylder
  • 287
  • 2
  • 3
1

Working a bit from Roger's code, here's the code that I use. It assume that the Manifest is at id #1. I guess this is the default for .exe. See the comment by Wedge, you may have to also check id #2 if you're working with DLL.

    HMODULE module = ::LoadLibraryEx(pathname, NULL, LOAD_LIBRARY_AS_DATAFILE);
    if (module == NULL)
        return false;
    HRSRC resInfo = ::FindResource(module, MAKEINTRESOURCE(1), RT_MANIFEST); // resource id #1 should be the manifest
    if (resInfo) {
        HGLOBAL resData = ::LoadResource(module, resInfo);
        DWORD resSize = ::SizeofResource(module, resInfo);
        if (resData && resSize) {
            const char *res = (const char *)::LockResource(resData); // the manifest
            if (res) {
                // got the manifest
            }
            ::UnlockResource(resData);
        }
        ::FreeResource(resData);
    }
    ::FreeLibrary(module);
Samphan
  • 123
  • 7
0

As a side reminder: remember that manifests can also be standalone files with the same name as the app (extended by ".manifest").

So if you want to check out which manifest is really used at runtime, this must be taken into account.

chksr
  • 192
  • 3
  • 13
0

Sysinterals "sigcheck -m" dumps the manifest of an exe. (You can wget from live.sysinternals.com).

Sigcheck - Windows Sysinternals _ Microsoft Docs

js2010
  • 23,033
  • 6
  • 64
  • 66
-1

Fix this problem by deleting the developers license (*_TemporaryKey.pfx) from the project or change Name of .pfx .

Ivan Ferić
  • 4,725
  • 11
  • 37
  • 47
Rahul Tripathi
  • 187
  • 1
  • 4