Quote: " I assume with this method, one could theoretically find and/or remove a password for a zip file."
I don't think it's quite that easy. I haven't looked at the passwords yet, but I believe they're coded into each file perhaps.
Update: As of zip 5.2, the format allows for AES encryption. And no I don't know how to crack it.
Quote: " find the dictionary of redundant replacement data(an index at the beginning of the .zip?),"
The index of all archived files is actually at the end of the file.
I've updated the code slightly. It should find the central directory more efficiently now. The time difference noticed is most likely negligible on smaller files.
V.2
Rem **********************************
Rem Title: Zip Decompression
Rem Created: Monday, January 28, 2013
Rem Updated: Tuesday, February 5, 2013
Rem Author: Phaelax
Rem **********************************
#CONSTANT START_CENTRAL_DIRECTORY_FILE_HEADER_SIG = 33639248
#CONSTANT END_CENTRAL_DIRECTORY_FILE_HEADER_SIG = 101010256
#CONSTANT LOCAL_FILE_HEADER_SIGNATURE = 67324752
rem path to extract files
exPath$ = "c:\"
rem create a memblock from the file to allow random access.
filename$ = "c:\test2.zip"
open to read 1, filename$
make memblock from file 1, 1
close file 1
rem To find the list of archived files, we need to find the
rem beginning of the central directory. The directory comes at
rem the end of the file and contains a central directory file
rem header followed by a record marking the end of the central
rem directory. That end, the last 22+ bytes of data, starts with
rem a 4 byte signature of 0x06054b50. The end of this record data
rem is 2 bytes representing a comment length followed finally by the
rem comment itself. Since the comment is last and has an unknown
rem length until we determine where to find the length value at, we
rem start looking for the signature at 22 bytes from the end of the
rem file. If there are no comments, the signature should be right there.
rem If there are comments present, we'll need to keep moving backwards
rem until we find the 4 byte header.
pos = get memblock size(1) - 22
while memblock dword(1, pos) <> END_CENTRAL_DIRECTORY_FILE_HEADER_SIG
dec pos
endwhile
pos = memblock dword(1, pos+16)
repeat
rem If the prior while loop performed its search correctly,
rem the memblock position should always start at a central
rem directory file header signature.
if memblock dword(1, pos) <> START_CENTRAL_DIRECTORY_FILE_HEADER_SIG
print "ERROR READING FILE"
exit
endif
print "Version made by: ", memblock word(1, pos+4)
print "Version needed: ", memblock word(1, pos+6)
print "General purpose bit flag: ", memblock word(1, pos+8)
print "Compression method: ", memblock word(1, pos+10)
rem parse last modification time and date
h10 = memblock word(1, pos+12)
h12 = memblock word(1, pos+14)
hour = h10 >> 11
minutes = (h10 && %0000011111100000) >> 5
seconds = (h10 && %0000000000011111) * 2
t$ = "AM"
if hour > 11 then t$ = "PM"
if hour > 12 then dec hour, 12
year = (h12 >> 9) + 1980
month = (h12 && %000000111100000) >> 5
day = (h12 && %0000000000011111)
date$ = str$(month)+"/"+str$(day)+"/"+str$(year)+" "+str$(hour)+":"+str$(minutes)+":"+str$(seconds)+" "+t$
print "Modification date: ", date$
print "CRC-32: ", hex$(memblock dword(1, pos+16))
print "Compressed Size: ", memblock dword(1, pos+20)
print "Uncompressed Size: ", memblock dword(1, pos+24)
rem file name length
fnl = memblock word(1, pos+28)
rem extra field length
efl = memblock word(1, pos+30)
rem file comment length
fcl = memblock word(1, pos+32)
rem disk number where file starts (when multiple files make up the archive)
disk = memblock word(1, pos+34)
rem internal file attributes
int_atts = memblock word(1, pos+36)
rem external file attributes
ext_atts = memblock dword(1, pos+38)
rem relative offset of local file header
fileOffset = memblock dword(1, pos+42)
print "Disk: ", disk
name$ = ""
rem filename
for i = 0 to fnl-1
c = memblock byte(1, pos+46+i)
name$ = name$ + chr$(c)
next i
print "Filename: ", name$
rem extra field
extra$ = ""
for i = 0 to efl-1
c = memblock byte(1, pos+fnl+46+i)
extra$ = extra$ + chr$(c)
next i
print "Extra field: " + extra$
rem file comment
comment$ = ""
for i = 0 to fcl-1
c = memblock byte(1, pos+fnl+efl+46+i)
comment$ = comment$ + chr$(c)
next i
print "File Comment: " + comment$
print "==========================================================="
print
pos = pos+fnl+efl+fcl+46
rem check if the next file header is the end of the directory
long = memblock dword(1, pos)
extractFile(fileOffset, exPath$)
until long = END_CENTRAL_DIRECTORY_FILE_HEADER_SIG
wait key
delete memblock 1
end
function extractFile(pos, path$)
if memblock dword(1, pos) <> LOCAL_FILE_HEADER_SIGNATURE then exitfunction
minVersion = memblock word(1, pos+4)
bitFlag = memblock word(1, pos+6)
compression = memblock word(1, pos+8)
compressedSize = memblock dword(1, pos+18)
uncompressedSize = memblock dword(1, pos+22)
fnl = memblock word(1, pos+26)
efl = memblock word(1, pos+28)
name$ = ""
for i = 0 to fnl-1
c = memblock byte(1, pos+30+i)
name$ = name$ + chr$(c)
next i
pos = pos + 30 + fnl + efl
select compression
case 0
decompressStore(pos, path$, name$, compressedSize)
endcase
case 8
decompressDeflate()
endcase
endselect
endfunction
function decompressStore(pos, path$, filename$, size)
open to write 1, path$+filename$
for i = 0 to size-1
write byte 1, memblock byte(1, pos+i)
next i
close file 1
endfunction
function decompressDeflate()
endfunction
"You're not going crazy. You're going sane in a crazy world!" ~Tick