How to get ordered list of items in cab archive? - windows

I have 182Mb uncompressed .cab file with ~350 files. I'd like to apply compression to it using command line tools. This seems to be straightforward task - use expand.exe to extract contents of the file into temporary folder, build ddf file from files in the folder and feed it to makecab.exe.
However things don't work as expected. If I build list of files for makecab.exe from temporary folder listing and create no compression .cab it appears to be larger than original .cab by 2Mb. This is an unpleasant surprise for me as I expected uncompressed .cab files produced from the same set of files to be equal.
Inspecting contents of two .cab files with 7Z GUI Archive Viewer uncovered that items in two .cab files are in different order. Also the first one contains 82 blocks and the second one 88 blocks.
This observation makes me believe ordering of items in ddf file affects output of makecab.exe.
I tried using expand.exe -d with hope that the tool will output list of entries in .cab file in the order they actually appear in the archive. However the tool outputs alphabetically sorted list of entries.
Questions:
Is it possible to get list of entries in .cab file right in the order they appear in the archive with standard command line tools?
Is it possible to instruct makecab.exe reorder files listed in ddf file for best layout?
My ddf file fragment:
.OPTION EXPLICIT
.Set Cabinet=ON
.Set GenerateInf=OFF
.Set CabinetFileCountThreshold=0
.Set FolderFileCountThreshold=0
.Set FolderSizeThreshold=0
.Set MaxCabinetSize=0
.Set MaxDiskFileCount=0
.Set MaxDiskSize=0
.Set ReservePerCabinetSize=0
.Set ReservePerDataBlockSize=0
.Set ReservePerFolderSize=0
.Set DiskDirectoryTemplate=
.Set ClusterSize=100000
.Set CabinetNameTemplate=C:\cygwin\tmp\radE7C61.cab
.Set Compress=OFF
"C:\cygwin\tmp\radCF764_core.cab.contents\File_003760a98ae0a9890833a40c14abcf3a" "File_003760a98ae0a9890833a40c14abcf3a" /INF=NO
"C:\cygwin\tmp\radCF764_core.cab.contents\File_00632a927382f2d81133ca36816174b7" "File_00632a927382f2d81133ca36816174b7" /INF=NO
"C:\cygwin\tmp\radCF764_core.cab.contents\File_008544959270414d85c069b9e9cdd1d6" "File_008544959270414d85c069b9e9cdd1d6" /INF=NO
"C:\cygwin\tmp\radCF764_core.cab.contents\File_0296ad9da2e43352229fd713f496db61" "File_0296ad9da2e43352229fd713f496db61" /INF=NO
SOLVED
My source .cab file was created with WiX and included a number of binary equal files. For such files WiX stores only one of them and other are just referenced. makecab.exe can't do this. makecab.exe can reorder input items for better performance, but it can't replace duplicated files with references.
So, different ordering of items in ddf file for makecab.exe doesn't make much sense, the tool will still produce larger files compared to what WiX can do if some items are duplicates.

Related

put together .text, .rdata, .data, .code to a exe(cutable) file

I get zip.exe from http://stahlworks.com/dev/index.php?tool=zipunzip
I have unpacked the files to:
.text
.rdata
.data
How to connect together through a command line using an external program or without?
copy /B .text+.rdata+.data zip.exe
The above code does not work.
You can't just glue together sections of a PE or ELF file and expect to get a working executable because there's more information needed, namely a number of headers that describe those sections and other important things.
At any rate, I'm not sure why you're dealing with this in first place. zip.exe downloads just fine from that page. I see no reason to break it only to be unable to later repair it.
the unzipping feature of winrar is something rather for fun its kinda easter egg i think, that ilustrates the fact that exe has some internal format that contains section, but you shouldnt unzip it really as an user (only someone could do this for some reverse engeenering attempt, like hex viewing a contents of an exe)... so simply dont unzip exe you wouldnt need to pack it together then.. exe is exe dont unzip it

Merge PDF files from multiple folders with same filename

I am looking to merge PDF files from two separate folders into a third folder, based on file name.
Directory structure:
FOLDER_1 = File set #1.
FOLDER_2 = File set #2.
MERGED_PDFS = Output of merged files.
FOLDER_1 contains a set of PDF files which could be named with any combination of letters, numbers and allowed symbols.
FOLDER_2 contains a set of PDFs with the exact same names as FOLDER_1. The data on these sheets is different. The files from FOLDER_2 need to be inserted into the files from FOLDER_1, at the end of the file.
The output of this merged file will be placed in the MERGED_PDFs folder, retaining the name used to match the files in FOLDER_1 and FOLDER_2.
Example:
FOLDER_1: R000135322.PDF
FOLDER_2: R000135322.PDF
MERGED_PDFS: R000135322.PDF
(MERGED_PDFS contains a merged PDF from FOLDER_1 & FOLDER_2, with the PDF from FOLDER_2 being placed at the end of the PDF in FOLDER_1.
I saw some similar examples of this being done with PDFtk, but unsure how to edit to get my expected output.
Thanks
Here's what you need to do:
Install FolderMill
Specify the Incoming folder and the Output folder for FolderMill on your PC
Since you mention that files in FOLDER_1 and files in FOLDER_2 have the same filenames, just add "Convert to PDF" action and select Multipage: "Append pages to existing document" in the options.
Click Apply changes
Start FolderMill by pressing the Play button.
Grab the files from FOLDER_1 and put them into the Incoming folder
Grab the files from FOLDER_2 and do the same.
Receive the merged PDFs from the Output folder
If the you are not sure if all the corresponding files have the same filenames, you may also need to use the "Rename" action.
FYI, we have a detailed step-by-step guide how to do it (with screenshots).
You are welcome :)

Compress file to one cab file

I am currently trying to modify one file in a .cab file and then rebuild .cab file using 'makecab.exe' with all the files including the changed one. Following is the .ddf file, I am using.
.Set CabinetNameTemplate=Documents.CAB
.Set Cabinet=on
.Set Compress=on
"00000000.000"
"10000000.000"
"20000000.000"
"30000000.000"
"40000000.000"
"manifest.xml"
The problem is that three files are generated stored in disk1,disk2 and disk3 folders. The files are trimmed to <1424kb. I want a single cab file. I have tried setting the threshold and size variables.
I encountered same problem today and luckily I found solution in Microsoft page.
(http://msdn.microsoft.com/en-us/library/bb417343.aspx#microsoftmakecabusersguide)
You can add maxdisksize option in .ddf file and it will work!
.Set MaxDiskSize=CDROM

Using MakeCab.exe & .ddf file (i.e. using directive file) how to specify destination cab filename?

I have decided to use makecab.exe for my requirement to create cab files in my application.
http://msdn.microsoft.com/en-us/library/bb417343.aspx#microsoftmakecabusersguide
And I need to store files as per given path whether relative or absolute inside cab and extract files with original path preserved. So I will be using directive file for this and give that input to makecab command.
windows command promt zip/compress directory
But the cab output is stored in folder Disk1\1.cab.
Please help me to know how can I specify a desired cab filename as destination (I will take cab file name from user input)?
Also, is it possible to append more files to existing cab file in second run of makecab command?
Finally found the solution.
You can set following two variables in the directive file which will identify destination path and name of cab file:
DiskDirectoryTemplate=template [Output directory name template; * is replaced by disk number]
CabinetNameTemplate=template [Cabinet file name template; * is replaced by Cabinet number]
Description from Microsoft MakeCAB User's Guide
DiskDirectoryTemplate=template
Set the output directory name template. One directory is created for
each disk of the layout.
Default: .Set DiskDirectoryTemplate=DISK* ; Default is DISK1, DISK2,
etc.
As MakeCAB processes a directive file, it will create one or more
disk "images". Rather than using some specific disk format, however,
MakeCAB simply creates one subdirectory for each disk and places the
files for each disk in the appropriate directory. If a * exists in
this variable, then it is replaced with the disk number. If no * is
specified, then all files are placed in the single directory specified
by this variable.
This variable is used only if no variable DiskDirectoryn exists for
disk n.
Examples:
.Set DiskDirectoryTemplate=C:\EXCEL6\DISK* ; Put files in separate dirs
.Set DiskDirectoryTemplate=C:\EXCEL6 ; Put all files in C:\EXCEL6
.Set DiskDirectoryTemplate= ; Put all files in current dir
CabinetNameTemplate=template
Sets the cabinet file name template.
Default: .Set CabinetNameTemplate=*.CAB ; 1.CAB, 2.CAB, ...
This template is used to construct the file name of each cabinet. The *
in this template is replaced by the cabinet number (1, 2, etc.). This
variable is used only if no variable CabinetNamen exists for cabinet
n.
NOTE: Be sure that the expanded cabinet name does not exceed the
limits for your file system! For example, if you used "CABINET*.CAB",
and MakeCAB had to create 10 or more cabinets, then you would have
cabinet names like CABINET10.CAB, which is 9.3, which is an invalid
name in the FAT file system. Unfortunately, MakeCAB would not detect
this until it had already created 9 cabinets!
Examples:
.Set CabinetNameTemplate=EXCEL*.DIA ; EXCEL1.DIA, EXCEL2.DIA, etc.
.Set CabinetNameTemplate=*. ; 1, 2, 3, etc.
In addition, when files are split across cab (in case if cabinet size exceeds its limit size) then you can set subsequent cabinet filenames also using variable CabinetNamen:
CabinetNamen=filename [Cabinet file name for cabinet number n]
CabinetNamen=filename
The cabinet file name for the specified cabinet.
Default: ; By default none of these variables are defined
If this
variable is not defined for a particular disk, then MakeCAB uses the
CabinetNameTemplate to construct the cabinet name.
Example:
.Set CabinetName2=test2.cab
If you know exactly where your source files exist, you can generate a file list from the directory:
dir C:\FolderName /s /b /a-d > c:\temp\files.txt
Then use the files.txt file to create the cab file.
makecab /d CabinetName1=test.cab /D DiskDirectoryTemplate=C:\temp /f c:\temp\files.txt
The above command will generate a test.cab file in your C:\Temp folder using the file list generated earlier.
Additional helpful reference:
Microsoft Cabinet Reference. and
makecab.exe details.

Listing the contents of a LZMA compressed file?

Is it possible to list the contents of a LZMA file (.7zip) without uncompressing the whole file? Also, can I extract a single file from the LZMA file?
My problem: I have a 30GB .7z file that uncompresses to >5TB. I would like to manipulate the original .7z file without needing to do a full uncompress.
Yes. Start with XZ Utils. There are Perl and Python APIs.
You can find the file you want from the headers. Each file is compressed separately, so you can extract just the one you want.
Download lzma922.tar.bz2 from the LZMA SDK files page on Sourceforge, then extract the files and open up C/Util/7z/7zMain.c. There, you will find routines to extract a specific archive file from a .7z archive. You don't need to extract all the data from all the entries, the example code shows how to extract just the one you are interested in. This same code has logic to list the entries without extracting all the compressed data.
I solved this problem by installing 7zip (https://www.7-zip.org/) and using the parameter l. For example:
7z l file.7z
The output has some descriptive information and the list of files in the compressed files. Then, I call this inside python using the subprocess library:
import subprocess
output = subprocess.Popen(["7z","l", "file.7z"], stdout=subprocess.PIPE)
output = output.stdout.read().decode("utf-8")
Don't forget to make sure the program 7z is accessible in your PATH variable. I had to do this manually in Windows.

Resources