views:

3647

answers:

5

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?

+3  A: 

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

jeffm
+6  A: 

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
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
+4  A: 

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
bk1e
+1  A: 

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
+1  A: 

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