Skip to content

Commit c0d1d2d

Browse files
committed
Support using EXPAND.EXE as well as EXTRACT.EXE for testing
1 parent 6ccbb8d commit c0d1d2d

File tree

5 files changed

+100
-29
lines changed

5 files changed

+100
-29
lines changed

libmspack/ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
drvs/2019/11/016c7f3e-809d-4720-893b-
88
e0d74f10c39d_35e12507628e8dc8ae5fb3332835f4253d2dab23.cab)
99

10+
* cabd_compare: use EXPAND.EXE instead of EXTRACT.EXE when
11+
testing files in a directory called 'expand'. The example
12+
cab file above is extracted wrongly by EXTRACT.EXE, but
13+
correctly by EXPAND.EXE because they take different approaches
14+
to E8 transformations:
15+
16+
- EXTRACT.EXE writes "E8E8E8E8E8E8' to the last 6 bytes of
17+
frame, looks for E8 bytes up to the last 6 bytes, then restores
18+
the last 6 bytes, leaving partial transforms of 1-3 bytes if
19+
E8 byte is found near the end of the frame
20+
21+
- EXPAND.EXE looks for E8 bytes up to the last 10 bytes of a
22+
frame, therefore the last 6 bytes are never altered and all
23+
transforms are 4 bytes
24+
1025
2019-02-18 Stuart Caie <[email protected]>
1126

1227
* chmd_read_headers(): a CHM file name beginning "::" but shorter

libmspack/README

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ examples/msexpand.c - expands an SZDD or KWAJ file
9090
examples/oabextract.c - extracts an Exchange Offline Address Book (.LZX) file
9191

9292
test/cabd_c10 - tests the CAB decompressor on the C10 collection
93-
test/cabd_compare - compares libmspack with Microsoft's EXTRACT.EXE
93+
test/cabd_compare - compares libmspack with Microsoft's EXTRACT/EXPAND.EXE
9494
test/cabd_md5 - shows MD5 checksums of all files in a CAB file/set
9595
test/chmd_compare - compares libmspack with Microsoft's HH.EXE
9696
test/chmd_find.c - checks all files in a CHM file can be fast-found
9797
test/chmd_md5.c - shows MD5 checksums of all files within a CHM file
9898
test/chmd_order.c - extracts files in a CHM file in four different ways
9999
test/chminfo.c - prints verbose information about CHM file structures
100100
test/msdecompile_md5 - runs Microsoft's HH.EXE -DECOMPILE via WINE
101+
test/msexpand_md5 - runs Microsoft's EXPAND.EXE via WINE
101102
test/msextract_md5 - runs Microsoft's EXTRACT.EXE via WINE
102103

103104
Here is a simple example of usage, which will create a CAB decompressor,

libmspack/test/cabd_compare

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
#!/bin/sh
22
# Test if cabd_md5 expands cab files identically to Microsoft's EXTRACT.EXE
3+
# (or EXPAND.EXE if cab file is in a directory called 'expand')
34

45
[ -d .cache ] || mkdir .cache
56
BASEDIR=`dirname "$0"`
67

78
cnt=1
9+
orig=.$$.orig
10+
test=.$$.test
811
for cab in "$@"; do
912
name=`printf '%d/%d %s' $cnt $# $cab`
1013
cnt=`expr $cnt + 1`
1114

1215
echo "test $name"
1316
cached=`echo $cab | sed -e 's/\//-/g' -e 's/^/.cache\//'`
1417
if [ ! -s $cached ]; then
15-
$BASEDIR/msextract_md5 $cab >.orig.out 2>.orig.err
16-
if [ -s .orig.err ]; then
18+
case $cab in
19+
*/expand/*) $BASEDIR/msexpand_md5 $cab >$orig 2>$orig.err;;
20+
*) $BASEDIR/msextract_md5 $cab >$orig 2>$orig.err;;
21+
esac
22+
23+
if [ -s $orig.err ]; then
1724
echo "FAIL $name: MS errors" >&2
18-
cat .orig.err >&2
19-
else
20-
mv .orig.out $cached
25+
cat $orig.err >&2
26+
continue
2127
fi
28+
mv $orig $cached
2229
fi
2330

24-
$BASEDIR/cabd_md5 $cab >.test.out 2>.test.err
25-
perl -pi -e 'if($.>1){s{\\}{/}g;s{ /}{ }}' .test.out
31+
$BASEDIR/cabd_md5 $cab >$test 2>$test.err
32+
perl -pi -e 'if($.>1){s{\\}{/}g;s{ /}{ }}' $test
2633

2734
# suppress warning. PRECOPY2.CAB does not extend to CATALOG3.CAB, but
2835
# CATALOG3.CAB extends backwards to PRECOPY2.CAB. cabd_md5 supports this
2936
# but msextract_md5 does not, so differences appear. As a workaround, test
3037
# PRECOPYn.CAB separately and suppress the warning when testing CATALOG3.CAB
31-
sed -i "/can't find \"PRECOPY2.CAB\" to prepend/d" .test.err
38+
sed -i "/can't find \"PRECOPY2.CAB\" to prepend/d" $test.err
3239

3340
# suppress warning. One cabinet set has this structure:
3441
# * cab1: file1 FROM_PREV, file2 TO_NEXT
@@ -38,18 +45,19 @@ for cab in "$@"; do
3845
# This is wrong. file3 and file4 are in the same folder, so both should
3946
# be FROM_PREV_AND_TO_NEXT in cab3, and both should be listed in cab4.
4047
# However, the set unpacks despite the warning, so suppress it.
41-
sed -i '/rainloop.xa not listed in both cabinets/d' .test.err
48+
sed -i '/rainloop.xa not listed in both cabinets/d' $test.err
4249

43-
if [ -s .test.err ]; then
50+
if [ -s $test.err ]; then
4451
echo "FAIL $name: errors" >&2
45-
cat .test.err >&2
52+
cat $test.err >&2
53+
continue
4654
fi
4755

48-
if cmp $cached .test.out >/dev/null; then
56+
if cmp $cached $test >/dev/null; then
4957
echo "OK $name"
5058
else
5159
echo "FAIL $name: differences" >&2
52-
diff -u $cached .test.out >&2
60+
diff -u $cached $test >&2
5361
fi
5462
done
55-
rm -f .orig.out .orig.err .test.out .test.err
63+
rm -f $orig $orig.err $test $test.err

libmspack/test/chmd_compare

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,41 @@
55
BASEDIR=`dirname $0`
66

77
cnt=1
8+
orig=.$$.orig
9+
test=.$$.test
810
for chm in "$@"; do
911
name=`printf '%d/%d %s' $cnt $# $chm`; cnt=`expr $cnt + 1`
1012

1113
echo "test $name"
1214
cached=`echo $chm | sed -e 's/\//-/g' -e 's/^/.cache\//'`
1315
if [ ! -s $cached ]; then
14-
$BASEDIR/msdecompile_md5 $chm >.orig.out 2>.orig.err
15-
if [ -s .orig.err ]; then
16+
$BASEDIR/msdecompile_md5 $chm >$orig 2>$orig.err
17+
if [ -s $orig.err ]; then
1618
echo "FAIL $name: MS errors" >&2
17-
cat .orig.err >&2
18-
else
19-
LANG=C sort -k2 .orig.out >$cached
19+
cat $orig.err >&2
20+
continue
2021
fi
22+
LANG=C sort -k2 $orig >$cached
2123
fi
2224

23-
$BASEDIR/chmd_md5 $chm >.test.out 2>.test.errwarn
24-
perl -pe 'if($.>1){$_=""if/^[0-9a-f]{32} \/[#\$]/;s{ /}{ }}' .test.out | LANG=C sort -k2 >.test.sorted
25-
sed '/^WARNING; /d' .test.errwarn > .test.err
26-
if [ -s .test.err ]; then
25+
$BASEDIR/chmd_md5 $chm >$test.unsorted 2>$test.errwarn
26+
perl -pe 'if($.>1){$_=""if/^[0-9a-f]{32} \/[#\$]/;s{ /}{ }}' $test.unsorted | LANG=C sort -k2 >$test
27+
sed '/^WARNING; /d' $test.errwarn > $test.err
28+
if [ -s $test.err ]; then
2729
echo "FAIL $name: errors" >&2
28-
cat .test.errwarn >&2
30+
cat $test.errwarn >&2
31+
continue
2932
fi
3033

31-
if cmp $cached .test.sorted >/dev/null; then
34+
if cmp $cached $test >/dev/null; then
3235
echo "OK $name"
3336
else
34-
if [ `diff $cached .test.sorted | grep -c '^<'` -gt 0 ]; then
37+
if [ `diff $cached $test | grep -c '^<'` -gt 0 ]; then
3538
echo "FAIL $name: differences" >&2
36-
diff -u $cached .test.sorted >&2
39+
diff -u $cached $test >&2
3740
else
3841
echo "OK $name (better than hh.exe)"
3942
fi
4043
fi
4144
done
42-
rm -f .orig.out .orig.err .test.out .test.err .test.errwarn .test.sorted
45+
rm -f $orig $orig.err $test $test.err $test.errwarn $test.unsorted

libmspack/test/msexpand_md5

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/perl -w
2+
# put expand.exe and dpx.dll (or a link to them) into this directory
3+
# for this script to work.
4+
#
5+
# NOTE: when a cabinet only contains one file, expand.exe fails to
6+
# preserve its filename, it renames the output after the source cabinet
7+
8+
use strict;
9+
use File::Temp qw(tempdir);
10+
use Cwd qw(cwd);
11+
12+
my $expand = $0; $expand =~ s{[^/]+$}{expand.exe};
13+
my $HDR1 = 'Microsoft (R) File Expansion Utility';
14+
my $HDR2 = 'Copyright (c) Microsoft Corp';
15+
16+
my $dir = tempdir("./.tempXXXX", CLEANUP => 1) . '/extradir';
17+
mkdir $dir;
18+
$ENV{LANG} = 'C';
19+
$ENV{WINEPREFIX} = "$ENV{HOME}/.wine64";
20+
$ENV{WINEARCH} = 'win64';
21+
22+
for my $cab (@ARGV) {
23+
my @files;
24+
print "*** $cab\n";
25+
for (`wine $expand $cab -F:* $dir 2>&1`) {
26+
s/\015?\012$//s; # remove line endings
27+
next if /^(\Q$HDR1\E|\Q$HDR2\E|\s*$|Expanding Files |Progress: |\d+ files total)/;
28+
if (/^Adding \Q$dir\E\\(.+) to Extraction Queue$/) {
29+
my $file = $1;
30+
$file =~ s{\\}{/}g;
31+
$file =~ s{^/+}{};
32+
push @files, $file;
33+
}
34+
else {
35+
print STDERR "$_\n";
36+
}
37+
}
38+
39+
next unless @files;
40+
my $olddir = cwd();
41+
chdir $dir;
42+
system 'md5sum', @files;
43+
chdir $olddir;
44+
}

0 commit comments

Comments
 (0)