Monday, February 3, 2014

DayZ Me Rollin', Dey Hating - DayZ Commander without Admin Privileges

I arrived on the DayZ scene rather late; PC Gamer had been talking about the famous Arma 2 mod for months by the time I got around to playing it. In fact, it was only when the mod became a distinct title to install via Steam for owners of Arma 2: Combined Operations that I took the plunge.

Running DayZ through Steam is a cinch, however you only get access to the vanilla mod. In fairness, there's still a lot of fun to be had playing vanilla DayZ; I have clocked up 77 hours playing it according to my Steam profile. I know my friends have played for even longer and between us all we've had many amazing and terrifying experiences.

Vanilla is plenty of fun, but I have been watching YouTube videos and Twitch streams of other players, which made me aware of the many mods of the mod; Day Zero, Epoch, Namalsk, for example. Some of these mods simply fixed a few issues with the standard mod, others added whole new functionality such as base building, while others brought new maps to the experience.

Installing any of the mods isn't a trivial process, but then neither was DayZ itself originally. However, even before the vanilla mod was available through Steam, there was a tool that simplified the whole process.

DayZ Commander

I had my first experience with DayZ Commander a few months ago and I had unfortunately been put off using it for two reasons:

  • The download page itself was a mess of unrelated download links for software I didn't want and the installer itself was packaged with various third party pieces of bloatware. There was a tiny link to a version of the installer that was free of anything unnecessary, but it was a bad first impression. However, I have visited the tool's homepage again recently, and things are better; the download page is far easier to navigate, the default download link points to a clean installer and there was even a post from the developer apologising for going down that dark path (which I can't seem to find to link to any more).
  • The application required administrative rights to run. Many people that I mention this to are nonplussed by this requirement, especially the large number of people who are using an administrator account for their day to day computer use. I'm not going to go into detail here explaining why that's a bad idea, that's a topic for a whole other post, but suffice to say; this exposes yourself to additional and unnecessary risk.

The download/installer issue didn't put me off by itself, but the requirement that the tool run with admin privileges was a show stopper for me. After searching online for information why this might be necessary, I happened across a discussion on the DayZ Commander Google group from 2012. In the conversation thread, the tool's author states this requirement is a legacy hangup from when he originally wrote it, and mentions that this is something he'd like to review. Clearly, this hasn't happened yet, but I was intrigued to see a response from a user who had written a utility that would remove the administrative requirements, for which a download link was provided.

As well intentioned as that helpful user may have been, I'm not keen on downloading random executables (I'm quite a paranoid user, as you may have guessed by now). However, it did lead me to think how does somebody go about changing a binary in this fashion?

Windows SDK

It turns out that executable files tend to have a manifest containing metadata required by the OS to correctly run the program. The manifest itself is an XML document, and part of it can be used to specify the privilege level required by the application:

<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
  <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>

You can probably tell the above snippet tells Windows that the executable requires admin rights in order to run. Changing this XML requires the use of a command line tool from the Windows SDK: mt.exe.

Installing the SDK is a simple enough process; just grab the relevant installer directly from Microsoft. During the installation, you need to select the ".NET Development -> Tools" component in order to have mt.exe available to you.

Finally, the Solution

Before we start, it's worth noting the following preconditions that you will have to ensure are met before attempting the solution. The process may work if you don't, however, I have only tested the solution with given this system state:

  • To get myself started, I followed the instructions I found for working with DayZ Commander and Steam on the Steam community forums. However, I did not perform step 3c; running the Arma executables as an administrator.
  • To clarify, I only installed Arma 2 and Arma 2: Operation Arrowhead via Steam, not the Operation Arrowhead Beta or the DayZ Mod (DayZ Commander manages these for you).
  • Install DayZ Commander only for the limited user account you play games as, instead of for all users of the system. For me, this allowed the modified tool to work properly. I suspect the issue I had when I installed for all users was down to folder permissions. Maybe changing them would fix the problem, I haven't tried yet.

So, assuming the above criteria are met (or you're happy to try anyway), here's my step-by-step guide to stripping the admin requirements from the DayZ Commander binary:

  1. Install the Windows SDK, making sure you select the ".NET Development -> Tools" component when asked:


    NB: I already had the Debugging Tools for Windows installed, hence the reason it's selected (and greyed out) in the above example. It's a useful set of tools to have, especially if you want to debug BSOD crash dumps, so feel free to include it yourself.

  2. Install DayZ Commander, choosing the option to only make the program available to your own user. This will install the application into your user's home directory, at a location similar to the following (substitute "peter_000" for your own user directory):

    C:\Users\peter_000\AppData\Local\Apps\Dotjosh Studios\DayZ Commander

  3. Make a backup of the executable by copying it to another directory. The binary is called DayZCommander.exe and can be found in the Current directory from the installation path mentioned previously.

  4. Open an instance of command prompt.

  5. Navigate to the directory where the mt.exe tool is located. This depends on which version of the SDK you installed, but it should be something similar to:

    C:\Program Files (x86)\Windows Kits\8.1\bin\x86

  6. Use mt.exe to export the manifest (remember to adjust for your different installation path and output location if necessary):

    mt -inputresource:"C:\Users\peter_000\AppData\Local\Apps\Dotjosh Studios\DayZ Commander\Current\DayZCommander.exe;#1" -out:D:\tmp\extracted.manifest

  7. Open the resulting file and search for the following line:

    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

    NB: I had to find the second instance of this line, as the first was present in a comment section of the document.

  8. Change the line so it reads as follows:

    <requestedExecutionLevel level="asInvoker" uiAccess="false" />

  9. Save the updated manifest.

  10. Us the mt.exe utility to overwrite the manifest embedded in the DayZ Commander binary with the one you modified in the previous step (again, update paths as necessary):

    mt -manifest D:\tmp\extracted.manifest -outputresource:"C:\Users\peter_000\AppData\Local\Apps\Dotjosh Studios\DayZ Commander\Current\DayZCommander.exe;#1"

    When I performed this step, I instantly could tell the change had worked because the small shield icon that denotes an executable will require admin privileges disappeared from the DayZ Commander.exe.

  11. Run DayZ Commander to check it no longer prompts you for admin privileges. However, it's worth noting that when using the tool to update the Arma 2: Operation Arrowhead binary, you will need to provide them.

Hopefully this gives those of you out there that are as paranoid as myself the peace of mind to install and use the DayZ Commander tool. I'm happy to report that I've been using it for a few weeks now without any problems.