Location>code7788 >text

Modify the PE file to implement administrator privileges

Popularity:270 ℃/2024-07-26 17:14:30

The common method we use in Windows is to add a manifest file to the application and then the resulting Exe will have administrator privileges.
Recently, when I used Wix to create Exe installer, I found that this method does not work, I searched on github and * for a long time did not find a good way, the only feasible way is to use the App application to wrap a layer so that the installer will have administrator privileges at startup, but I do not think it is very good, so I decided to modify the PE file directly after a day of effort, has been successfully implemented in C# code (of course, you can use C# code to do it), and I have been able to use C# code to do it. After a day's effort, I've successfully realized it with C# code (of course, you can also use theCFF Explorertool interface words operation to achieve), the next section describes the use of the tool to modify to achieve the effect.

1. After installing the CFF Explorer tool, open the tool

2. Check for administrator privileges


As shown above, we want to realize that the location becomes requireAdministrator

3. Finding the address of the inventory document


Copy the address as shown above

4. Modify the size of the contents of the manifest file by adding 0x0B to the current value.


5. Find the address of the manifest file and change the hexadecimal value so that asInvoker becomes requireAdministrator.

6. Save and repeat step 2 to check that the switchover has taken place

7. code implementation is basically in accordance with this step, if necessary, you can realize, or in the following message exchange