#1 25 Nov 2012 03:59

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 247
Website

[Undocumented] Expand.exe

Time ago I studied and use the Expand.exe utility.
Now I explain what are the types of compressed files that it support (using Windows 7).

The expand.exe decompress any CABINET file (it are files with the extension .cab or for example with a extension that end with underscore, example: .ex_).
This files internally begin with a header that says:

MSCF

The cabinet files can be compressed with these type of compression:

MSZIP
LZX
QUANTUM
NONE

You can expand any cabinet files with all these types of compression.
For example, currently you cannot make a cabinet file using QUANTUM or NONE compression with the utility makecab.exe or compress.exe, but you can expand or decompress it with the Expand.exe. Makecab.exe and Compress.exe lost support for it compression types, but not Expand.exe (since version 5 from windows 2000).

This is good, because in some cases you get smaller files using QUANTUM compression than MSZIP or LZX. Then if you create a cabinet files with these compression, you can expand it anyways. You not get a message like: The compression type of the file is not supported.

Now, how I can use these types of compression? All examples if you have a file called file.ext

MSZIP: makecab.exe, compress.exe

Makecab.exe file.ext file.ex_
Makecab.exe /D CompressionType=MSZIP file.ext file.ex_
Compress.exe -Z file.ext file.ex_

LZX:  makecab.exe, compress.exe (version 5.2.3790.0)
memory: 15 to 21.

Makecab.exe /D CompressionType=LZX /D CompressionMemory=15 file.ext file.ex_
Makecab.exe /D CompressionType=LZX /D CompressionMemory=16 file.ext file.ex_
Makecab.exe /D CompressionType=LZX /D CompressionMemory=17 file.ext file.ex_
Makecab.exe /D CompressionType=LZX /D CompressionMemory=18 file.ext file.ex_
Makecab.exe /D CompressionType=LZX /D CompressionMemory=19 file.ext file.ex_
Makecab.exe /D CompressionType=LZX /D CompressionMemory=20 file.ext file.ex_
Makecab.exe /D CompressionType=LZX /D CompressionMemory=21 file.ext file.ex_
Compress.exe -ZX file.ext file.ex_

QUANTUM: old compress.exe (version 5.00.2134.1), old diamond.exe (version 1.00.0530)
levels: 1 to 7.

Compress.exe -zq1 file.ext file.ex_
Compress.exe -zq2 file.ext file.ex_
Compress.exe -zq3 file.ext file.ex_
Compress.exe -zq4 file.ext file.ex_
Compress.exe -zq5 file.ext file.ex_
Compress.exe -zq6 file.ext file.ex_
Compress.exe -zq7 file.ext file.ex_
Diamond.exe /D CompressionType=QUANTUM /D CompressionLevel=1 file.ext file.ex_
Diamond.exe /D CompressionType=QUANTUM /D CompressionLevel=2 file.ext file.ex_
Diamond.exe /D CompressionType=QUANTUM /D CompressionLevel=3 file.ext file.ex_
Diamond.exe /D CompressionType=QUANTUM /D CompressionLevel=4 file.ext file.ex_
Diamond.exe /D CompressionType=QUANTUM /D CompressionLevel=5 file.ext file.ex_
Diamond.exe /D CompressionType=QUANTUM /D CompressionLevel=6 file.ext file.ex_
Diamond.exe /D CompressionType=QUANTUM /D CompressionLevel=7 file.ext file.ex_

NONE: makecab.exe, cabarc.exe (version 1.00.0601)

Makecab.exe /D Compress=Off file.ext file.ex_
Cabarc.exe -m NONE N file.ex_ file.ext

When I make a cabinet file I test all these compression and I use the better (that generate the smallest file). For example, in larger files almost always is best the LZX compression, but in small files sometimes is better MSZIP or QUANTUM. For example I have a small executable of 1186 bytes.
Using best Quantum I get 389 bytes
Using MSZIP I get 423 bytes
Using best LZX I get 471 bytes
Using NONE I get 1267 bytes

But in larger files almost always is best the LZX. The trick is test all these compression types, Expand.exe (since version 5 from windows 2000) support all. Note: Expand version 2.5 from windows nt NOT support LZX, but yes MSZIP, QUANTUM and NONE.

Last edited by carlos (13 Apr 2015 20:10)

Offline

#2 04 Jan 2013 16:44

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 247
Website

Re: [Undocumented] Expand.exe

[Continuation]

Now. I write about the option -D of Expand.exe.
This option show a list of the files that have a cabinet file. But this option have a little problem. It not show the full path of the file. Files inside a cabinet file can have a path name (not absolute path). This means that inside a cabinet file you can have a file with this type of name. For example:

creating a cabinet file with path name

Md mypath
Echo nothing>mypath\file.txt
Cabarc.exe -p -m NONE n file.tx_ mypath\file.txt

file.tx_ in a hexadecimal editor looks this:

0000	4D 53 43 46 00 00 00 00 5D 00 00 00 00 00 00 00   MSCF....].......
0010	2C 00 00 00 00 00 00 00 03 01 01 00 01 00 00 00   ,...............
0020	00 00 00 00 4C 00 00 00 01 00 00 00 09 00 00 00   ....L...........
0030	00 00 00 00 00 00 24 42 E8 63 20 00 6D 79 70 61   ......$B.c .mypa
0040	74 68 5C 66 69 6C 65 2E 74 78 74 00 04 01 1A 65   th\file.txt....e
0050	09 00 09 00 6E 6F 74 68 69 6E 67 0D 0A            ....nothing..

Then if you use the Expand.exe -D option this show:

C:\folder>Expand.exe -D file.tx_
Microsoft (R) Utilidad de expansión de archivos versión 6.1.7600.16385
Copyright (c) Microsoft Corporation. Reservados todos los derechos.

file.tx_: file.txt

The -D option hide the path of files when it have. This is not good, because if you expand the file using Expand.exe it make the folder mypath\ and the file file.txt inside it.

Last edited by carlos (04 Jan 2013 16:51)

Offline

#3 06 Nov 2013 17:18

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 430

Re: [Undocumented] Expand.exe

Now looking at MAKECAB (is this the same as cabarc.exe ?) , COMPRESS ,COMPACT , CIPHER, EXPAND and EXTRACT commands.

Makecab could store it's directives in self contained bat file :

;@echo off
;makecab /f "%~f0" /v3
;exit /b 0

.Set ChecksumWidth=8
.Set InfFileName= info.inf
.Set MaxDiskSize=1.44M
.Set Cabinet=off
.Set Compress=off
.Set GenerateInf=ON

.Set InfFileLineFormat="*disk#*,*cab#*,*file*,*date*,*size*,*csum*,*time*,*ver*,*vers*,*attr*,*file#*,*lang*"


.Set InfDateFormat=yyyy-mm-dd
.Set RptFileName=filename.rpt
;.InfWrite ";<disk#--cab#-,-file-,-date-,-size-,-csum-,-time-,-ver-,-vers-,-attr-,-file#-,-lang-
.\test.file
.\tst.exe

as the ; is a comment for the directives and is delimiter for the bat if this is saved as bat will work without problems.Where I can find all directives?
EDIT: here they are: http://mo.notono.us/2007/07/ddf-command … yntax.html
http://msdn.microsoft.com/en-us/library/bb417343.aspx

btw. compact can be used to count files and subdirectories and to get file and directory size( unlike dir it is not localized).Here are the last lines of compact {/s} output  :

compact wrote:

Of 41 files within 5 directories
0 are compressed and 41 are not compressed.
114,062,999 total bytes of data are stored in 114,062,999 bytes.
The compression ratio is 1.0 to 1.

Last edited by npocmaka (06 Nov 2013 20:50)

Offline

#4 06 Nov 2013 21:07

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 430

Re: [Undocumented] Expand.exe

here's one example (and not very refined) script with information that can be taken from a file with makecab:

;@echo off
;if "%~1" equ "" echo enter a parameter & exit /b 1
;if not exist "%~1" echo file does not exist & exit /b 2
;echo %~s1 > file.path
;REM Creating a Newline variable (the two blank lines are required!)
;set NLM=^


;set NL=^^^%NLM%%NLM%^%NLM%%NLM%
;set "file_info="

;makecab /f "%~f0"  /f file.path /v0>nul

;for /f %%f in (file.inf) do (
; set "file_info=%%f"
;)
;setlocal enableDelayedExpansion
;set !file_info:,=%nl%!

;endlocal
;del /q /f file.inf 2>nul
;del /q /f file.path 2>nul
;exit /b 0


.set RptFileName=nul
.set InfFooter=;
.set InfHeader=;
.Set ChecksumWidth=8
.Set InfDiskLineFormat=;
.Set Cabinet=off
.Set Compress=off
.Set GenerateInf=ON
.Set InfFileName=.\file.inf
.Set InfDiskHeader=;
.Set InfFileHeader=;
.set InfCabinetHeader=;
.Set InfFileLineFormat="disk#:*disk#*,cab#:*cab#*,file:*file*,date:*date*,size:*size*,csum:*csum*,time:*time*,ver:*ver*,vers:*vers*,attr:*attr*,file#:*file#*,lang:*lang*"

I've tried to deactivate as much information is possible (deactivating some of the makecab default values is easy with starting a comment before value definition).I've included all possible inffileformat (can be seen in microsoft documentation ) parameters which will be written in file.inf file generated by makecab. makecab.exe can work with more than one directive files so I generate one additional with the file that I want to get info from.

Here's an output example:

makecab tool wrote:

Environment variable disk#:1
cab#:0
file:file
date:06/22/13
size:155918
csum:b0c33e6d
time:02:11:14p
ver:
vers:
attr:A
file#:1
lang: not defined

File date and time are corresponding to "last modified" and does not depend on time settings.

Here's the info about attributes:

Parameter	Disk	Cab	File	Description
attr	 	 	Yes	File attributes (A=archive, R=read-only, H=hidden, S=system)
cab#	 	Yes	Yes	Cabinet number (0 means not in cabinet, 1 or higher is cabinet number)
cabfile	 	Yes	 	Cabinet file name
csum	 	 	Yes	Checksum
date	 	 	Yes	File date (mm/dd/yy or yyyy-mm-dd, depending upon InfDateFormat)
disk#	Yes	Yes	Yes	Disk number (1-based)
file	 	 	Yes	Destination file name in layout (in cabinet or on a disk)
file#	 	 	Yes	Destination file number in layout (first file is 1, second file is 2, ...); the order of File Copy Commands controls the file number, so in relational INF mode the order of File Reference Commands has no affect on the file number.
label	Yes	 	 	Disk user-readable label (value comes from DiskLabeln, if defined, and otherwise is constructed from DiskLabelTemplate).
lang	 	 	Yes	Language (i.e., VER.DLL info) in base 10, blank separated if multiple values
size	 	 	Yes	File size (only affects value written to INF file)
time	 	 	Yes	File time (hh:mm:ss[a|p])
ver	 	 	Yes	Binary File version (n.n.n.n base 10 format)
vers	 	 	Yes	String File version -- can be different from ver!
attr	 	 	Yes	File attributes (A=archive, R=read-only, H=hidden, S=system)

checksum , language , versions are not accessible with dir command so I suppose they are most interesting.

Offline

#5 06 Nov 2013 22:33

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 430

Re: [Undocumented] Expand.exe

more refined script:

; @echo off
;;setlocal DISABLEDELAYEDEXPANSION ENABLEEXTENSIONS
;;goto :end_help
;;;
;;;
;;; fileinf /l list of full file paths separated with ;
;;; fileinf /f text file with a list of files to be processed ( one on each line )
;;; fileinf /? prints the help
;;;
;;:end_help
 
; REM Creating a Newline variable (the two blank lines are required!)
; set NLM=^
 
 
; set NL=^^^%NLM%%NLM%^%NLM%%NLM%
; if "%~1" equ "/?" type "%~f0" | find ";;;" | find /v "find" && exit /b 0
; if "%~2" equ "" type "%~f0" | find ";;;" | find /v "find" && exit /b 0
; setlocal enableDelayedExpansion
; if "%~1" equ "/l" (
;  set "_files=%~2"
;  echo !_files:;=%NL%!>"%TEMP%\file.paths"
;  set _process_file="%TEMP%\file.paths"
;  goto :get_info
; )
 
; if "%~1" equ "/f" if exist "%~2" (
;  set _process_file="%~2"
;  goto :get_info
; )
 
; echo incorect parameters & exit /b 1
; :get_info
; set "file_info="
 
; makecab /d InfFileName=%TEMP%\file.inf /d "DiskDirectory1=%TEMP%" /f "%~f0"  /f %_process_file% /v0>nul
 
; for /f "usebackq skip=4 delims=" %%f in ("%TEMP%\file.inf") do (
;  set "file_info=%%f"
;  echo !file_info:,=%nl%!
; )
 
; endlocal
;endlocal
; del /q /f %TEMP%\file.inf 2>nul
; del /q /f %TEMP%\file.path 2>nul
; exit /b 0
 
.set DoNotCopyFiles=on
.set DestinationDir=;
.set RptFileName=nul
.set InfFooter=;
.set InfHeader=;
.Set ChecksumWidth=8
.Set InfDiskLineFormat=;
.Set Cabinet=off
.Set Compress=off
.Set GenerateInf=ON
.Set InfDiskHeader=;
.Set InfFileHeader=;
.set InfCabinetHeader=;
.Set InfFileLineFormat=",file:*file*,date:*date*,size:*size*,csum:*csum*,time:*time*,vern:*ver*,vers:*vers*,lang:*lang*"

output:

C:\test>fileinfo.bat /l C:\Windows\HelpPane.exe

file:HelpPane.exe
date:01/21/08
size:734720
csum:b2a70166
time:04:50:02a
vern:6.0.6001.18000
vers:6.0.6000.16386 (vista_rtm.061101-2205)
lang:1033

Last edited by npocmaka (07 Nov 2013 09:08)

Offline

Board footer

Powered by FluxBB