Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / UWP

Reverse Engineering UWP/HoloLens application

3.67/5 (3 votes)
26 Jun 2017CPOL5 min read 13.8K  
This article will show you how to start reverse engineer existing UWP/HoloLens applications using official Microsoft tools.

Introduction

Appx and Appxbundle are the application package formats supported by the Universal Windows Platform (UWP). All the HoloLens applications should be bundled as appx or appxbundle since HoloLens is based on UWP. I assume that you already know how to develop application for HoloLens.

In this article you are going to learn the following:

  1. How to unpack UWP application
  2. Modifying the manifest file entries
  3. Repackaging the application and install it on HoloLens

Background

HoloLens application is just like any UWP application with specific mixed reality features enabled. It is possible to unpack UWP application (appxbundle and appx) files. You can assume these application files as simple zip files. We can extract it using software like 7zip. But if we extract the application and modify the content of the files, for example updating AppxManifest.xml file, compress it again to .appx file extension, it will not be considered as a valid package. The following error will be thrown when you try to install the modified package on the device using device portal or power shell.

Failure reason: Failed to start deployment. Failure text: Package could not be opened.
(0x80073cf0)

App Packager Tool

HoloLens application is just like any UWP application with specific mixed reality features enabled. It is possible to unpack UWP application (appxbundle and appx) files. You can assume these application files as simple zip files. We can extract it using software like 7zip. But if we extract the application and modify the content of the files, for example updating AppxManifest.xml file, compress it again to .appx file extension, it will not be considered as a valid package. The following error will be thrown when you try to install the modified package on the device using device portal or power shell.

Failure reason: Failed to start deployment. Failure text: Package could not be opened.
(0x80073cf0)

To avoid this error, you should use Microsoft’s official tool App packager (MakeAppx.exe) for Unpacking and Repacking existing UWP application.

App Packager:

App packager (MakeAppx.exe) creates an app package from files on disk or extracts the files from an app package to disk. Starting with Windows 8.1, App packager also creates an app package bundle from app packages on disk or extracts the app packages from an app package bundle to disk. It is included in Microsoft Visual Studio and the Windows Software Development Kit (SDK) for Windows 8 or Windows Software Development Kit (SDK) for Windows 8.1. Visit Downloads for developers to get them.

You can find MakeAppx.exe tool at the following locations:

On 32 bit machine (x86)

C:\Program Files (x86)\Windows Kits\8.0\bin\x86\makeappx.exe 
or 
C:\Program Files (x86)\Windows Kits\8.1\bin\x86\makeappx.exe

On 64 bit machine (x64), in two locations

C:\Program Files (x86)\Windows Kits\8.0\bin\x86\makeappx.exe 
or 
C:\Program Files (x86)\Windows Kits\8.1\bin\x86\makeappx.exe

and

C:\Program Files (x86)\Windows Kits\8.0\bin\x64\makeappx.exe 
or 
C:\Program Files (x86)\Windows Kits\8.1\bin\x64\makeappx.exe

Unpacking and Re-Packaging appx and appxbundle

For this article, I have created a store build of a sample UWP application. In that application, I have not included HoloLens support in the manifest file and with Microsoft.NET.Native.Runtime.1.3. But my HoloLens device supports Microsoft.NET.Native.Runtime.1.4 an hence this application cannot be installed on my device.

To test this out, I have tried sideloading the Sample app (Sample.com.Sample_2017.815.1000.0_neutral_-_343d40qqvtj1t.AppxBundle) using the Device Portal and encountered the below error.

Failure reason: Failed to start deployment. Failure text: Package failed updates, dependency or conflict validation. (0x80073cf3)

After that, I have tried unzipping the application and opened the manifest file in a text editor.

Image 1

You can notice that the application is dependent on Microsoft .NET Runtime version 1.3. I have modified the dependency version value to 1.4 and then repackaged the folder to .zip file using Windows zip utility and renamed the zip file to appx and appxbundle extensions as required.

Deployment was not successful since the HoloLens app installer was not able to identify the integrity of the app package. This is because the installer is checking the hash value stored in AppxBlockMap.xml and the current package hash value. Since the content is modified, the calculated hash value is different than the original value. Sample application is having x86 architecture app package, but the dependencies specified in the manifest is different than the HoloLens device is using (i.e. Microsoft.NET.Native.Runtime.1.4 is expected but Microsoft.NET.Native.Runtime.1.3 is available). It is necessary that all the dependencies declared in AppxManifest.xml file is required. Any conflict in the dependency or mismatch in the processor architecture will lead to unsuccessful deployment.

Steps followed to make store sample app installable on HoloLens

  1. Type the following command in command line to unpack / unzip application bundle using App Packager tool. You should make sure that MakeAppx.exe exists in the path.
    MakeAppx unbundle /p Sample.appxbundle /d samplebundle
  2. Since this application is a bundle, you will see multiple .appx files, one for each selected architecture, inside the “samplebundle” folder. The following three appx files need to be updated for dependency.

    WindowsUWPShoppingApp_2016.815.1000.0_ARM.appx
    WindowsUWPShoppingApp_2016.815.1000.0_x64.appx
    WindowsUWPShoppingApp_2016.815.1000.0_x86.appx

    MakeAppx unpack /v /l /p WindowsUWPShoppingApp_2016.815.1000.0_x86.appx /d WindowsUWPShoppingApp_2016.815.1000.0_x86
  3. Existing dependencies list is shown below. Highlighted information needs to be updated to the following.
    Name="Microsoft.NET.Native.Runtime.1.4" MinVersion="1.4.24201.0"

    Image 2

  4. Repackage each extracted folder individually. 3 folders in this case,
    WindowsUWPShoppingApp_2016.815.1000.0_x86
    WindowsUWPShoppingApp_2016.815.1000.0_x64
    WindowsUWPShoppingApp_2016.815.1000.0_ARM
    MakeAppx pack /l /d WindowsUWPShoppingApp_2016.815.1000.0_x86 /p WindowsUWPShoppingApp_2016.815.1000.0_x86.appx
  5. Existing appx files will be replaced. After repackaging all the three folders, delete those folders.
  6. Create signing certificate. Note that the publisher name should be same as the existing Sample app’s publisher name (E.g. CN=3250E920-A812-4A12-AF74-9E12AC355EDF), specify the future date as expiry date.
    MakeCert /n CN=3250E920-A812-4A12-AF74-9E12AC355EDF /r /h 0 /eku "1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13" /e 08/30/2027 /sv MyKey.pvk MyKey.cer
    Pvk2Pfx /pvk MyKey.pvk /pi testpass /spc MyKey.cer /pfx MyKey.pfx /po testpass
  7. Sign the packages using SignTool.exe
    SignTool sign /a /v /fd SHA256 /f MyKey.pfx /p testpass WindowsUWPSampleApp_2016.815.1000.0_x86.appx
  8. Create application bundle
    MakeAppx bundle /v /l /d samplebundle /p samplebundlenew.appxbundle
  9. Sign the bundle with the same certificate
    SignTool sign /a /v /fd SHA256 /f MyKey.pfx /p testpass samplebundlenew.appxbundle
  10. Newly created bundle “samplebundlenew.appxbundle” can now be installed on HoloLens device or emulator.

    Install the bundle using the Device Portal. It is necessary to add all required dependencies explicitly.

    Image 3

In this case, the following dependencies are required.

  1. Microsoft.NET.Native.Framework.1.3.appx
  2. Microsoft.NET.Native.Runtime.1.4.appx
  3. Microsoft.VCLibs.x86.14.00.appx

These dependency files can be found at Windows SDK installation folder. Typical location for these files is listed below.

Microsoft.NET.Native.Framework.1.3.appx can be found at

C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.NET.Native.Framework.1.3\1.3\x86\ret\Native

Microsoft.NET.Native.Runtime.1.4.appx can be found at

C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.NET.Native.Runtime.1.4\1.4\AppX\x86

Microsoft.VCLibs.x86.14.00.appx can be found at

C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.VCLibs\14.0\Appx\Retail\x8

Sample app will be listed in Device Portal -> App Manager page as shown in the below screenshot.

Image 4

The application is successfully installed on the emulator as shown in the below screenshot.

Image 5

Conclusion

We have successfully unpacked an existing UWP application and updated the manifest file and repacked it to be installed on HoloLens device/emulator. Similarly, you can update the static image assets and other editable files.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)