3

I have an old "Win32 Cabinet Self-Extractor" file (*.exe extension) that I would like to make a small alteration to.

I do not know where the original file came from or who made it but it is possible to open the file in 7-Zip and at least view it's contents.

The purpose of this self extracting installer is to install a piece of firmware on a PCIe device.

One file inside the archive needs to be altered slightly to have a short sequence of binary (a serial number, 8 bytes long) inserted at the very beginning, increasing the file's length by 8 bytes. Then I want to save the changes and exit the archive so that the new file is in place of the old. I'm not changing any filenames in the archive.

I'm using Windows 7 and 7-Zip refuses to let me alter the file in-place (perhaps unsurprisingly) saying it's "read-only" (the exe isn't read only according to explorer).

Is there any way at all to accomplish this?

Unfortunately, I'm not able to upload the file because it contains proprietary company information.

3 Answers 3

3

You need to first extract all the files from the CAB into some folder. This can be done via 7-Zip or other utility, or by the Windows utility expand :

Expand mycab.cab -F:* C:\myfolder

You may then modify your file inside the folder C:\myfolder, and re-compress it again by using the Windows utility makecab :

makecab /f filename.ddf

The Directive file (.ddf) looks like this :

.Set CabinetNameTemplate=mycab.cab
.Set SourceDir=C:\myfolder
.Set Cabinet=on
.Set Compress=on

"file1name.txt"
"file2name.txt"

More information about DDF files can be found in the article MAKECAB Directive File syntax.

The entire Microsoft user guide can be found in Microsoft MakeCAB User's Guide.

1

You cannot do that. The files inside are compressed and can't be modified. If you did, the archive would be corrupted. The ability to decompress the files is unique to the contents of the archive as a whole. You need to extract the files, make any modifications, then recreate the archive.

I haven't used any CAB creation tools in many years. They might let you do this. However, they are simply doing the steps above.

1

There is an approach similar to harrymc's excellent answer that I think is a faster, easier way IF, IF, you have at least rudimentary Visual Studio and C# skills. Also, harrymc's answer did not cover the part at the end where you need to place an EXE header file at the front of your CAB to make it self extracting. I've included that here.

PART 1: Create your CAB file with your modified binary file substituted in for the original one. See my answer to this question: https://stackoverflow.com/questions/1939639/c-net-creating-a-cab-and-adding-files-to-it-without-an-external-library Roughly, the steps are: * Extract your current CAB file into a folder, say, C:\MyOriginal\CabfileExtractDir\, using 7Zip or the Expand command. * Replace the original binary file in this folder with your modified binary file with proper serial number. * Run the CabMaker program (FREE, on GitHub) as detailed in my answer, to get a resulting CAB file with your changed file. CabMaker uses the "MakeCab" program internally. Note that CabMaker handles the DDF file creation task for you. * In CabMaker, you'd supply C:\MyOriginal\CabfileExtractDir as the Source folder, and C:\MyEditedCabFile as the Target folder, and something like "MyModifiedFirmwareInstaller.cab" as the Target file name, and then click "Make CAB".

PART 2: Make your CAB file a self-extracting executable. * Review the docs here. https://docs.microsoft.com/en-us/previous-versions/bb417343(v=msdn.10)?redirectedfrom=MSDN#microsoftmakecabusersguide The relevant part, adapted to your situation would be...

C:\> copy /b "%windir%\system32\extrac32.exe"+"C:\MyEditedCabFile\MyModifiedFirmwareInstaller.cab" "C:\MyEditedCabFile\MyModifiedFirmwareInstaller.exe"
C:\> del /q /f "MyModifiedFirmwareInstaller.cab"

ADDENDUM - Towards a more fully automated process After seeing the process and getting the DDF file, you could probably automate the whole process to NOT need to use CabMaker, use the underlying MakeCab command line and DDF, and adapt it all into a batch file script, where you parameterize the serial number and the editing of the binary file. That's beyond the scope here, but quite possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.