0% found this document useful (0 votes)
20 views

Adaed

This program repairs a compressed Seagate F3 module (module 0x34) so it can be opened by tools like 7-Zip or WinRAR. It does this by modifying the ZIP file headers and central directory records to match the expected standards, and writing the compressed module data and modified headers to a new ZIP file.

Uploaded by

Raphael Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Adaed

This program repairs a compressed Seagate F3 module (module 0x34) so it can be opened by tools like 7-Zip or WinRAR. It does this by modifying the ZIP file headers and central directory records to match the expected standards, and writing the compressed module data and modified headers to a new ZIP file.

Uploaded by

Raphael Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

' This program "repairs" a Seagate F3 packed Congen XML module (module 0x34) so

that it
' can be opened by tools such as 7-Zip or WinRAR.

' The structure of a PKZip file is explained at the following URLs:

' https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html
' https://www.pkware.com/documents/casestudies/APPNOTE.TXT

#include "vbcompat.bi"

Type locfilhdr Field = 1


As ULong sig ' should be 0x04034B50 = "PK" 0x03 0x04
As UShort needed_ver ' should be 0x30 0x12 but change to 0x14
0x00
As UShort flags ' warn if not 0x0000
As UShort comptyp ' should be 0x0008 = deflated ???
As UShort timestamp ' warn if not 0x0000
As UShort datestamp ' warn if not 0x0000
As ULong crc32
As ULong compsiz ' abort if compsiz > (modsize - 0x2E)
As ULong uncompsiz
As UShort lenfilnam ' abort if not 0x0000
As UShort lenextfld ' abort if not 0x0000
End Type

Type centdirfilhdr Field = 1


As ULong sig = &H02014B50 ' "PK" 0x01 0x02
As UShort zipmade_ver = &H0014
As UShort needed_ver = &H0014 ' change from 0x30 0x12 to make WinRAR
happy
As UShort flags
As UShort comptyp
As UShort timestamp
As UShort datestamp
As ULong crc32
As ULong compsiz
As ULong uncompsiz
As UShort lenfilnam ' XML filname length
As UShort lenextfld = &H0000
As UShort filcommlen = &H0000
As UShort disknumstart = &H0000
As UShort intattribs = &H0000
As ULong extattribs = &H00000020
As ULong lochdroffst = &H00000000
End Type

Type endcentdirrec Field = 1


As ULong sig = &H06054B50 ' "PK" 0x05 0x06
As UShort disknum = &H0000
As UShort diskwcd = &H0000
As UShort diskents = &H0001
As UShort totalents = &H0001
As ULong centdirsiz ' 0x2E + filename length
As ULong centdiroffst ' compressed size + 0x1E + XML filname
length
As UShort commlen = &H0000
End Type
Dim mod34ziphdr As locfilhdr
Dim outcdfilhdr As centdirfilhdr
Dim outendcdrec As endcentdirrec
Dim infil As String
Dim outfil As String
Dim f1 As Long
Dim f2 As Long
Dim bytvar As UByte
Dim mod34siz As ULong
Dim lenxmlfil As UShort
Dim zipfilnam As String
Dim dotpos As UShort
Dim xmlfilnam As String
Dim filbuff As UByte Ptr

Declare Sub Usage

Sub Usage
Print "This program ""repairs"" a Seagate F3 packed Congen XML module (module
0x34)"
Print "so that it can be opened by tools such as 7-Zip or WinRAR."
Print
Print "Usage: CGZIPFIX infil=[""input filename""] outfil=[""output
filename""]"
Print "Example: CGZIPFIX infil=34.rpm outfil=congen.zip"
Print
End Sub

If Command( 3 ) <> "" Then


Usage
End
End If

infil = Lcase( Command( 1 ) )

If Left( infil, 6 ) <> "infil=" Then


Usage
End
End If

infil = Mid( infil, 7 )

If infil ="" Then


Usage
End
End If

If Not FileExists( infil ) Then


Print "File not found: " & infil
End
End If

outfil = LCase( Command( 2 ) )

If Left( outfil, 7 ) <> "outfil=" Then


Usage
End
End If
outfil = Mid( outfil, 8 )

If outfil ="" Then


Usage
End
End If

If FileExists( outfil ) Then


Print "Output file already exists: " & outfil
End
End If

' determine filename and filename length of decompressed XML file

zipfilnam = Mid( outfil, Instrrev( outfil, "\" ) + 1 )


dotpos = Instrrev( zipfilnam, "." )

If dotpos <> 0 Then


xmlfilnam = Left( zipfilnam, dotpos - 1 )
End If

xmlfilnam = xmlfilnam + ".xml"


lenxmlfil = Len( xmlfilnam )

f1 = FreeFile
Open infil For Binary Access Read As #f1

' read module size at offset 0 and abort if greater than 1 MiB

Get #f1, , mod34siz

If mod34siz > &H100000 Then


Print "Size of ZIP is larger than 1MiB (0x"; Hex(mod34siz); ") -- infil not
converted"
Close
End
End If

' read PK local file header at offset 0x10

Get #f1, &H11, mod34ziphdr

' confirm integrity of local file header

If (mod34ziphdr.sig <> &H04034B50) Then


Print "ERROR: Bad signature in local file header"
Print "-- expecting ""PK"" 0x03 0x04"
Print "-- found 0x"; Hex( mod34ziphdr.sig )
Print
Close
End
End If

If (mod34ziphdr.needed_ver <> &H1230) Then


Print "WARNING: ZIP version needed for decompression is 0x";
Hex(mod34ziphdr.needed_ver, 4)
Print "-- expected 0x1230"
Print
End If
If (mod34ziphdr.flags <> 0) Then
Print "WARNING: non-zero ZIP flags (0x"; Hex(mod34ziphdr.flags, 4); ")"
Print
End If

If (mod34ziphdr.comptyp <> &H0008) Then


Print "WARNING: ZIP compression type is 0x"; Hex(mod34ziphdr.comptyp, 4)
Print "-- expected 0x0008 (deflated)"
Print
End If

If (mod34ziphdr.timestamp <> 0) Or (mod34ziphdr.datestamp <> 0) Then


Print "WARNING: non-zero date/time stamp"
Print
End If

' abort if compressed size > (module size - 0x2E)

If mod34ziphdr.compsiz > (mod34siz - &H2E) Then


Print "ERROR: ZIP data area extends beyond size reported in module header"
Print "-- ZIP compressed size = 0x"; Hex( mod34ziphdr.compsiz )
Print "-- size in header = 0x"; Hex( mod34siz )
Close
End
End If

If (mod34ziphdr.lenfilnam <> 0) Then


Print "ERROR: non-zero XML filename length (0x"; Hex(mod34ziphdr.lenfilnam,
4); ")"
Close
End
End If

If (mod34ziphdr.lenextfld <> 0) Then


Print "ERROR: non-zero extra field length (0x"; Hex(mod34ziphdr.lenextfld,
4); ")"
Close
End
End If

With mod34ziphdr
.lenfilnam = lenxmlfil
.needed_ver = &H0014
End With

With outcdfilhdr
.flags = mod34ziphdr.flags
.comptyp = mod34ziphdr.comptyp
.timestamp = mod34ziphdr.timestamp
.datestamp = mod34ziphdr.datestamp
.crc32 = mod34ziphdr.crc32
.compsiz = mod34ziphdr.compsiz
.uncompsiz = mod34ziphdr.uncompsiz
.lenfilnam = lenxmlfil
.needed_ver = &H0014
End With

With outendcdrec
.centdirsiz = &H2E + lenxmlfil
.centdiroffst = mod34ziphdr.compsiz + &H1E + lenxmlfil
End With

' read ZIP data into buffer (offset 0x2E + compressed size)

filbuff = Allocate( mod34ziphdr.compsiz )

If filbuff = 0 Then
Print "ERROR: could not allocate buffer memory"
Close
End
End If

Get #f1, &H2F, filbuff[ 0 ], mod34ziphdr.compsiz

f2 = FreeFile
Open outfil For Binary Access Write As #f2

' Write repaired ZIP file

Put #f2,, mod34ziphdr


Put #f2,, xmlfilnam
Put #f2,, filbuff[ 0 ], mod34ziphdr.compsiz
Put #f2,, outcdfilhdr
Put #f2,, xmlfilnam
Put #f2,, outendcdrec

Close
End

You might also like