Wednesday, August 3, 2011

How to replace a file in MSI

Use msi2xml. For example, the file you want to replace is Test.dll and your MSI is TestMSI.MSI.

  1. This command extracts the MSI files:

    • msi2xml -c OutputDir TestMSI.MSI
  2. Open OutputDir and modify the file.

    • The extracted file names are some random numbers with no file extension, e.g. _132667984196873216. To identify the file you want to replace, open the TestMSI.xml generated by above command, then search for Test.dll and find the matching random number file name.

    • You may replace the file using the same random number file name. Modify the file size in TestMSI.xml too.

  3. To pack the files back to MSI:

    • xml2msi.exe -m TestMSI.xml

You need the -m to ignore the 'MD5 checksum test' that fails when an MSIs file(s) are modified.

From my observation, the file size of MSI reduces after running xml2msi, but all the contents are correct.