-
Notifications
You must be signed in to change notification settings - Fork 10
/
archrar.pas
384 lines (367 loc) · 12.7 KB
/
archrar.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Open Source 1.51.08
// Based on Dos Navigator (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on Dos Navigator by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
{$I STDEFINE.INC}
unit archRAR; {RAR}
interface
uses
Archiver, Advance, Advance1, Defines, Objects2, Streams, Dos
;
type
PRARArchive = ^TRARArchive;
TRARArchive = object(TARJArchive)
VersionToExtr: Byte;
constructor Init;
procedure GetFile; virtual;
function GetID: Byte; virtual;
function GetSign: TStr4; virtual;
end;
type
MainRARHdr = record
Id: LongInt;
HeadLen: AWord;
HeadFlags: Byte;
end;
MainRAR2Hdr = record
HeadCRC: AWord;
HeadType: Byte;
HeadFlags: AWord;
HeadLen: AWord;
Reserved1: AWord;
Reserved2: LongInt;
end;
// HeadFags:
// $01 - €âਡãâ ⮬ (⮬ ¬®£®â®¬®£® à娢 )
// $02 - à¨áãâáâ¢ã¥â àå¨¢ë© ª®¬¬¥â ਩
// $04 - €âਡãâ ¡«®ª¨à®¢ª¨ à娢
// $08 - €âਡãâ ¥¯à¥à뢮£® (solid) à娢
// $10 - ®¢ ï á奬 ¨¬¥®¢ ¨ï ⮬®¢ ('volname.partN.rar')
// $20 - à¨áãâáâ¢ã¥â ¨ä®à¬ æ¨ï ®¡ ¢â®à¥ ¨«¨ í«¥ªâà® ï ¯®¤¯¨áì (AV)
// $40 - à¨áãâáâ¢ã¥â ¨ä®à¬ æ¨ï ¤«ï ¢®ááâ ®¢«¥¨ï
// $80 - ‡ £®«®¢ª¨ ¡«®ª®¢ § è¨ä஢ ë
var
RAR2: Boolean;
Encrypted: Boolean;
implementation
uses
Messages, Commands
;
{ ----------------------------- RAR ------------------------------------}
constructor TRARArchive.Init;
var
Sign: TStr5;
q: String;
begin
Sign := GetSign;
SetLength(Sign, Length(Sign)-1);
Sign := Sign+#0;
FreeStr := SourceDir+DNARC;
TObject.Init;
{$IFNDEF OS2}
Packer := NewStr(GetVal(@Sign[1], @FreeStr[1], PPacker, 'RAR'));
UnPacker := NewStr(GetVal(@Sign[1], @FreeStr[1], PUnPacker, 'RAR'));
{$ELSE}
Packer := NewStr(GetVal(@Sign[1], @FreeStr[1], PPacker, 'RAR32'));
UnPacker := NewStr(GetVal(@Sign[1], @FreeStr[1], PUnPacker, 'RAR32'));
{$ENDIF}
Extract := NewStr(GetVal(@Sign[1], @FreeStr[1], PExtract, 'e'));
ExtractWP := NewStr(GetVal(@Sign[1], @FreeStr[1], PExtractWP, 'x'));
Add := NewStr(GetVal(@Sign[1], @FreeStr[1], PAdd, 'a'));
Move := NewStr(GetVal(@Sign[1], @FreeStr[1], PMove, 'm'));
Delete := NewStr(GetVal(@Sign[1], @FreeStr[1], PDelete, 'd'));
Garble := NewStr(GetVal(@Sign[1], @FreeStr[1], PGarble, '-p'));
Test := NewStr(GetVal(@Sign[1], @FreeStr[1], PTest, 't'));
IncludePaths := NewStr(GetVal(@Sign[1], @FreeStr[1], PIncludePaths, ''));
ExcludePaths := NewStr(GetVal(@Sign[1], @FreeStr[1], PExcludePaths,
'-ep'));
ForceMode := NewStr(GetVal(@Sign[1], @FreeStr[1], PForceMode, '-y'));
RecoveryRec := NewStr(GetVal(@Sign[1], @FreeStr[1], PRecoveryRec,
'-rr'));
SelfExtract := NewStr(GetVal(@Sign[1], @FreeStr[1], PSelfExtract,
'-sfx'));
Solid := NewStr(GetVal(@Sign[1], @FreeStr[1], PSolid, '-s'));
RecurseSubDirs := NewStr(GetVal(@Sign[1], @FreeStr[1],
PRecurseSubDirs, '-r0'));
SetPathInside := NewStr(GetVal(@Sign[1], @FreeStr[1], PSetPathInside,
'-ap'));
StoreCompression := NewStr(GetVal(@Sign[1], @FreeStr[1],
PStoreCompression, '-m0'));
FastestCompression := NewStr(GetVal(@Sign[1], @FreeStr[1],
PFastestCompression, '-m1'));
FastCompression := NewStr(GetVal(@Sign[1], @FreeStr[1],
PFastCompression, '-m2'));
NormalCompression := NewStr(GetVal(@Sign[1], @FreeStr[1],
PNormalCompression, '-m3'));
GoodCompression := NewStr(GetVal(@Sign[1], @FreeStr[1],
PGoodCompression, '-m4'));
UltraCompression := NewStr(GetVal(@Sign[1], @FreeStr[1],
PUltraCompression, '-m5'));
ComprListChar := NewStr(GetVal(@Sign[1], @FreeStr[1], PComprListChar,
'@'));
ExtrListChar := NewStr(GetVal(@Sign[1], @FreeStr[1], PExtrListChar,
'@'));
q := GetVal(@Sign[1], @FreeStr[1], PAllVersion, '0');
AllVersion := q <> '0';
q := GetVal(@Sign[1], @FreeStr[1], PPutDirs, '0');
PutDirs := q <> '0';
{$IFNDEF DPMI32}
q := GetVal(@Sign[1], @FreeStr[1], PShortCmdLine, '0');
ShortCmdLine := q <> '0';
{$ELSE}
q := GetVal(@Sign[1], @FreeStr[1], PSwapWhenExec, '1');
SwapWhenExec := q <> '0';
{$ENDIF}
{$IFNDEF OS2}
q := GetVal(@Sign[1], @FreeStr[1], PUseLFN, '1');
UseLFN := q <> '0';
{$ENDIF}
VersionToExtr := 0;
end { TRARArchive.Init };
function TRARArchive.GetID;
begin
GetID := arcRAR;
end;
function TRARArchive.GetSign;
begin
GetSign := sigRAR;
end;
type
LocRarHdr = record
PSize: LongInt;
USize: LongInt;
CRC: AWord;
HdrLen: AWord;
Date: LongInt;
Attr: Byte;
Flags: Byte;
Ver: Byte;
NameLen: Byte;
Method: Byte;
CommLen: AWord;
end;
LocRar2Hdr = record
HeadCRC: AWord;
HeadType: Byte;
HeadFlags: AWord;
HeadSize: AWord;
PSize: LongInt;
USize: LongInt;
OSVer: Byte;
CRC: LongInt;
Date: LongInt;
Ver: Byte;
Method: Byte;
NameLen: AWord;
Attr: LongInt;
end;
// HeadFlags:
// $01 - ä ©« ¯à®¤®«¦ ¥âáï ¨§ ¯à¥¤ë¤ã饣® ⮬
// $02 - ä ©« ¯à®¤®«¦ ¥âáï ¢ á«¥¤ãî饬 ⮬¥
// $04 - ä ©« § è¨ä஢ ¯ ஫¥¬
// $08 - ¯à¨áãâáâ¢ã¥â ª®¬¬¥â ਩ ä ©«
// $10 - ¨á¯®«ì§ã¥âáï ¨ä®à¬ æ¨ï ¨§ ¯à¥¤ë¤ãé¨å ä ©«®¢
// (ä« £ ¥¯à¥à뢮áâ¨) (¤«ï RAR 2.0 ¨ áâ àè¥)
//
// ¡¨âë 7 6 5 (¤«ï RAR 2.0 ¨ ¢ëè¥):
// 0 0 0 - à §¬¥à á«®¢ àï 64 Š¡
// $20 0 0 1 - à §¬¥à á«®¢ àï 128 Š¡
// $40 0 1 0 - à §¬¥à á«®¢ àï 256 Š¡
// $60 0 1 1 - à §¬¥à á«®¢ àï 512 Š¡
// $80 1 0 0 - à §¬¥à á«®¢ àï 1024 Š¡
// $A0 1 0 1 - à §¬¥à á«®¢ àï 2048 KB
// $C0 1 1 0 - à §¬¥à á«®¢ àï 4096 KB
// $E0 1 1 1 - ä ©« ï¥âáï ª â «®£®¬
//
// $100 - ¯à¨áãâáâ¢ãîâ ¯®«ï HIGH_PACK_SIZE ¨ HIGH_UNP_SIZE.
// ⨠¯®«ï ¨á¯®«ì§ãîâáï ⮫쪮 ¤«ï à娢¨à®¢ ¨ï ®ç¥ì ¡®«ìè¨å ä ©«®¢
// (¡®«ìè¥ 2 ƒ¡), ¤«ï ä ©«®¢ ¬¥ì襣® ®¡ê¥¬ í⨠¯®«ï ®âáãâáâ¢ãîâ
// $200 - FILE_NAME ᮤ¥à¦¨â ¨¬¥ ¢ ®¡ë箬 ä®à¬ ⥠¨ ¢ Unicode,
// à §¤¥«ñë¥ ã«ñ¬. ‚ í⮬ á«ãç ¥ ¯®«¥ NAME_SIZE à ¢® ¤«¨¥
// ®¡ë箣® ¨¬¥¨ ¯«îá ¤«¨ ¨¬¥¨ ¢ ä®à¬ ⥠Unicode ¯«îá 1
// $400 - ¯®á«¥ ¨¬¥¨ ä ©« ¢ § £®«®¢ª¥ 室¨âáï 8 ¤®¯®«¨â¥«ìëå ¡ ©â,
// ª®â®àë¥ ¥®¡å®¤¨¬ë ¤«ï 㢥«¨ç¥¨ï ¤ñ¦®á⨠è¨ä஢ ¨ï ("᮫ì")
// $800 - ä« £ ¢¥àᨨ. â® áâ à ï ¢¥àá¨ï ä ©« , ®¬¥à
// ¢¥àᨨ ¤®¡ ¢«¥ ª ¨¬¥¨ ä ©« ª ª ';n'
// $8000 - íâ®â ¡¨â ¢á¥£¤ ãáâ ®¢«¥, â ª ª ª ®¡é¨© à §¬¥à
// ¡«®ª HEAD_SIZE + PACK_SIZE (¨ ¯«îá HIGH_PACK_SIZE,
// ¥á«¨ ãáâ ®¢«¥ ¡¨â 0x100)
procedure TRARArchive.GetFile;
var
FP: TFileSize;
Ps: Integer;
P: LocRarHdr;
P2: LocRar2Hdr;
DirMask: LongInt;
label 1;
begin
1:
if (ArcFile^.GetPos = ArcFile^.GetSize) then
begin
if Encrypted then
Msg(dlArcEncrypted, nil, mfOKButton);
FileInfo.Last := 1;
Exit;
end;
if (ArcFile^.Status <> stOK) then
begin
FileInfo.Last := 2;
Exit;
end;
if RAR2 then
begin
FP := ArcFile^.GetPos;
ArcFile^.Read(P2, 7);
if (ArcFile^.Status <> stOK) then
begin
FileInfo.Last := 2;
Exit;
end;
{piwamoto}
{we must skip garbage (digital sign as example) at the end of archive}
{check for valid HeadType: $72 can't be valid here, $7c..7f reserved for future RAR versions}
if not (P2.HeadType in [$73..$7a, $7c..$7f]) then
begin
FileInfo.Last := 1;
Exit;
end;
{/piwamoto}
if P2.HeadType = $74 then
begin
ArcFile^.Read(P2.PSize, SizeOf(P2)-7);
if (ArcFile^.Status <> stOK) then
begin
FileInfo.Last := 2;
Exit;
end;
FileInfo.Last := 0;
FileInfo.Date := P2.Date;
FileInfo.PSize := P2.PSize;
FileInfo.USize := P2.USize;
FileInfo.Attr := Byte(P2.HeadFlags and $04 <> 0)*Hidden;
if P2.OSVer = 3 then
DirMask := $4000 {Unix}
else
DirMask := Directory {DOS compatible};
if P2.Attr and DirMask <> 0
then
FileInfo.Attr := FileInfo.Attr or Directory;
if P2.NameLen > 255 then
P2.NameLen := 255;
if P2.HeadFlags and $100 <> 0 then
begin { HIGH_PACK_SIZE and HIGH_UNP_SIZE presents}
ArcFile^.Read(CompRec(FileInfo.PSize).Hi, 4);
ArcFile^.Read(CompRec(FileInfo.USize).Hi, 4);
end;
ArcFile^.Read(FileInfo.FName[1], P2.NameLen);
SetLength(FileInfo.FName, P2.NameLen);
if P2.HeadFlags and $200 <> 0 then
SetLength(FileInfo.FName, (PosChar(#0, FileInfo.FName)-1));
{piwamoto: skip unicode names from winrar2.80beta1+ archives}
repeat
Ps := System.Pos('./', FileInfo.FName); // slash change by unxed
if Ps = 0 then
Break;
System.Delete(FileInfo.FName, Ps, 1);
until False;
if (ArcFile^.Status <> stOK) then
begin
FileInfo.Last := 2;
Exit;
end;
ArcFile^.Seek(CompToFSize(FP+P2.HeadSize+FileInfo.PSize));
if P2.Ver > VersionToExtr then
VersionToExtr := P2.Ver;
Exit;
end;
if P2.HeadSize = 0 then
P2.HeadSize := 7;
if P2.HeadFlags and $8000 <> 0
then
begin
ArcFile^.Read(FP, 4);
ArcFile^.Seek(ArcFile^.GetPos-4);
end
else
FP := 0;
ArcFile^.Seek(ArcFile^.GetPos+FP+P2.HeadSize-7);
goto 1;
end
else
begin
ArcFile^.Read(P, SizeOf(P)-2);
if (ArcFile^.Status <> stOK) or (P.NameLen = 0) then
begin
FileInfo.Last := 2;
Exit;
end;
FileInfo.Last := 0;
FileInfo.Date := P.Date;
FileInfo.PSize := P.PSize;
FileInfo.USize := P.USize;
FileInfo.Attr := Byte(P.Flags and $04 <> 0)*Hidden;
if P.Flags and $08 <> 0 then
begin
{ArcFile^.Read(P, P.CommLen);}
ArcFile^.Seek(ArcFile^.GetPos+P.CommLen);
if (ArcFile^.Status <> stOK) then
begin
FileInfo.Last := 2;
Exit;
end;
end;
SetLength(FileInfo.FName, P.NameLen);
ArcFile^.Read(FileInfo.FName[1], P.NameLen);
if (ArcFile^.Status <> stOK) then
begin
FileInfo.Last := 2;
Exit;
end;
ArcFile^.Seek(ArcFile^.GetPos+P.PSize);
if P.Ver > VersionToExtr then
VersionToExtr := P.Ver;
end;
end { TRARArchive.GetFile };
end.