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.

3 comments:

  1. Did not work for me. After "xml2msi.exe -m TestMSI.xml" at

    Populating table '_Streams'

    i'll get the error:

    The table contains non-unique primary keys
    Location: table "_Streams", row 1

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete