Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed manifest file to require administrator execution level with mingw32

I'm cross compiling an application with i586-mingw32msvc under ubuntu.

I'm having difficulties understanding how to embed a manifest file to require administrator execution level with mingw32.

For my example I used this hello.c:

int main() {
    return 0;
}

this resource file hello.rc:

1 Manifest "hello.exe.manifest"

this manifest file hello.exe.manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="hello" type="win32"/> 
    <description>Hello World</description> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

I compile my resource file with:

i586-mingw32msvc-windres hello.rc hello.o

I compile my final application with:

i586-mingw32msvc-gcc -O3 -Os -s -o hello.exe hello.c hello.o

SigCheck does not show the manifest file running sigcheck -m hello.exe.

Now when I run my application under Windows it does not trigger the UAC (=does not run as administrator) while when I attach the hello.exe.manifest file in the same folder it does trigger the UAC (as expected).

What did I miss?

EDIT1: Playing with Resource Hacker I've opened a Setup.exe file I've created with NSIS, the only sensible difference is that Manifest is written MANIFEST in my hello.exe and Manifest in Setup.exe though in hello.rc it's written Manifest. O_o

NSIS Installer vs hello.exe

EDIT2: I've changed the Manifest group manually with Resource Hacker:

Modified with Resource Hacker

Now hello.exe is acting normally triggering the UAC alert and running as an administrator. Seems like a "bug" with i586-mingw32msvc-windres. :-)

like image 539
pr.nizar Avatar asked Oct 07 '15 18:10

pr.nizar


People also ask

How is the execution level defined in the Windows application manifest?

The execution level is defined in the manifest as follows: Other valid values for the level attribute are highestAvailable and requireAdministrator. If the Setup Launcher setting is set to No for a Basic MSI project, InstallShield does not embed the Windows application manifest in the Setup.exe launcher.

Does InstallShield embed a Windows application manifest in the launcher?

For Advanced UI, InstallScript, InstallScript MSI, and Suite/Advanced UI projects, and for Basic MSI projects if the Setup Launcher setting is set to Yes, InstallShield embeds a Windows application manifest in the Setup.exe launcher as a resource. This manifest specifies the selected execution level.

How to inspect the embedded manifest in Visual C++ 2010?

To confirm that the settings have been processed by the build process and included in the embedded manifest file, the binary image can be opened inside Visual C++ 2010, and the manifest resource can be inspected as shown in Figure 4. Figure 4. Inspecting the embedded manifest file

What is the location of the manifest file?

File Location. Application manifests should be included as a resource in the application's EXE file or DLL. For more information, see Installing Side-by-side Assemblies. File Name Syntax. The name of an application manifest file is the name of the application's executable followed by .manifest.


Video Answer


2 Answers

With regard to the magic voodoo numbers 1 and 24:

1 24 "hello.exe.manifest"

That line translates to somthing like this:

ID_MANIFEST RT_MANIFEST "hello.exe.manifest"

where those defines are as defined as follows:

#define ID_MANIFEST 1
#ifndef RT_MANIFEST
#define RT_MANIFEST MAKEINTRESOURCE(24)
#endif

As shown above by the conditional wrappers, the RT_MANIFEST might already be defined and if you do a Google search for that RT_MANIFEST term you will find lots of hits with more details on what is going on.

like image 125
jussij Avatar answered Oct 13 '22 01:10

jussij


With some intense voodoo I got it to work with this on my hello.rc file:

1 24 "hello.exe.manifest"

Won't even search to know what the 24 is for (resource type manifest?!).. :-)

like image 29
pr.nizar Avatar answered Oct 13 '22 01:10

pr.nizar