I have a zip & unzip app on my todo list. After a quick attempt in the installer thread (http://masm32.com/board/index.php?topic=417.msg2856#msg2856), I investigated a bit into zlib, and my impression is that the lib is powerful but kind of messy.
For example, there seems no straightforward way to get file info (time & date, size) of individual files in zlib1.dll (the 1 stands there for historical reasons - zlib.dll was buggy, apparently, so they chose zlib1.dll to distinguish good code from bad code :eusa_boohoo:)
Intense researchTM leads to a function called unzGetCurrentFileInfo which can extract vital info; however, it is badly documented, and nope, it's not included in zlib1.dll. Further intense researchTM finds unzGetCurrentFileInfo in zlibwapi.dll (the wapi seems to stand for "Windows API"). It is also contained in zlibstat.lib ... undocumented, of course.
Then there are MiniZip and MiniZ based on zlib, which seem to be wrappers or clones or whatever, it is all a bit opaque.
Alternatively, there is Igor Pavlov's LZMA SDK, source code available, lots of interesting error messages when used with Visual Studio - many nights of fun solving mysteries in options and header files and the like guaranteed. No DLL or lib files, though, and Igor apologises occasionally for lousy documentation...
Does anybody have experience to share, especially documentation?? Zlib does not offer the highest compression ratios, but at least it looks feasible...
Actually the entyre 7Zip library is opensource it even has some interesting MASM code in it. :eusa_dance:
Like how to calculate CRC32 with a smarth macro-set to compile 32/64 bit respectivelly.
Quote from: Ficy on July 09, 2012, 06:27:17 AM
Actually the entyre 7Zip library is opensource...
Great. So your C compiler doesn't throw error messages? Could you produce a lib or obj file from the source?
In the meantime, I found a partial manual here (http://www.abdn.ac.uk/local/php/doc/ref.zlib.html), and discovered that gzwrite returns different values when used from zlib1 (correct #bytes) resp. zlibwapi (too high). But it works fine with both dlls.
QuoteCould you produce a lib or obj file from the source?
Of curse.
1.) Open a VisualStudion Command promt for 32-bit build.
2.) Go to "k:\CPP\7zip\Bundles\Format7zF\" - Assuming you unpaked the package on "k:\" -
3.) Execute "nmake NEW_COMPILER=1 MY_STATIC_LINK=1" - for example depends what you wanna make -
;)
Just to make sure:
I am not talking about the "LZMA SDK" I am talking about the "7-Zip Source code" but I assume the SDK has a simile concept for build.
If zip is not mandatory:
http://www.ibsensoftware.com/products_aPLib.html
I've used aPLib with a number of languages ( I assume I used masm/jwasm at one point but where the code is???)
James
James,
Thanks for reminding me. I used ApLib a long time ago with GfaBasic (16-bit!).
Most of the time I will just shuffle my own data around, so ApLib would be an option. On the other hand, being compatible to the zip world would be an argument for zlib... will see.
Jochen
http://www.winimage.com/zLibDll/minizip.html
download the zlib125dll.zip and extract files
under /static32 folder you will find a zlibstat.lib
RadASM 3.0 source shows examples of using it with update plugin, and i think i remember a zlibstat.inc file being available there that has the protos defined for use in the library.
Thanks, fearless. I eventually found zlibstat.inc at http://www.masmforum.com/archive2005/zlibstat.inc.zip
There is one thing that intrigues me:
curfile_info STRUCT
stream z_stream <>
stream_initialised SDWORD ?
pos_in_buffered_data DWORD ?
pos_local_header DWORD ?
central_header DWORD ?
size_centralheader DWORD ?
flag DWORD ?
method SDWORD ?
raw SDWORD ?
buffered_data Byte 16384t DUP (?)
dosDate DWORD ?
crc32 DWORD ?
curfile_info ENDS
Is the "t" a typo, or does it have some special meaning?
Another problem is that the linker complains about not finding uuid.lib :(
When adding uuid.lib from PellesC, the linker complains about unresolved _main. Oh well.
I could not find binaries for zlib 1.2.7, so I started with the zlib125dll.zip from here:
http://www.winimage.com/zLibDll/index.html
And using pexports (from an older version of MinGW) I got this DEF file for the 32-bit zlibwapi.dll:
LIBRARY zlibwapi.dll
EXPORTS
adler32
adler32_combine
compress
compress2
compressBound
crc32
crc32_combine
deflate
deflateBound
deflateCopy
deflateEnd
deflateInit2_
deflateInit_
deflateParams
deflatePrime
deflateReset
deflateSetDictionary
deflateSetHeader
deflateTune
fill_win32_filefunc
fill_win32_filefunc64
fill_win32_filefunc64A
fill_win32_filefunc64W
get_crc_table
gzbuffer
gzclearerr
gzclose
gzclose_r
gzclose_w
gzdirect
gzdopen
gzeof
gzerror
gzflush
gzgetc
gzgets
gzoffset
gzopen
gzprintf
gzputc
gzputs
gzread
gzrewind
gzseek
gzsetparams
gztell
gzungetc
gzwrite
inflate
inflateBack
inflateBackEnd
inflateBackInit_
inflateCopy
inflateEnd
inflateGetHeader
inflateInit2_
inflateInit_
inflateMark
inflatePrime
inflateReset
inflateReset2
inflateSetDictionary
inflateSync
inflateSyncPoint
inflateUndermine
uncompress
unzClose
unzCloseCurrentFile
unzGetCurrentFileInfo
unzGetCurrentFileInfo64
unzGetCurrentFileZStreamPos64
unzGetFilePos
unzGetFilePos64
unzGetGlobalComment
unzGetGlobalInfo
unzGetGlobalInfo64
unzGetLocalExtrafield
unzGoToFilePos
unzGoToFilePos64
unzGoToFirstFile
unzGoToNextFile
unzLocateFile
unzOpen
unzOpen2
unzOpen2_64
unzOpen64
unzOpenCurrentFile
unzOpenCurrentFile2
unzOpenCurrentFile3
unzOpenCurrentFilePassword
unzReadCurrentFile
unzStringFileNameCompare
unzeof
unztell
unztell64
zError
zipClose
zipCloseFileInZip
zipCloseFileInZipRaw
zipCloseFileInZipRaw64
zipOpen
zipOpen2
zipOpen2_64
zipOpen64
zipOpenNewFileInZip
zipOpenNewFileInZip2
zipOpenNewFileInZip2_64
zipOpenNewFileInZip3
zipOpenNewFileInZip3_64
zipOpenNewFileInZip4_64
zipOpenNewFileInZip64
zipWriteInFileInZip
zlibCompileFlags
zlibVersion
I'm assuming that the static library contains the same functions, but I have not tested this.
I tried to use Japheth's h2incx to convert zlib.h and zconf.h from the 1.2.5 source, but when I tried to assemble an ASM source, that did not reference anything in the include files, but with the files included, I got one error for zconf.inc, and after I eliminated that ~90 errors for zlib.inc.
If I am not wrong, Masm32 v7 provided uuid.lib
QuoteIs the "t" a typo, or does it have some special meaning?
I have the same thing in my .inc file, weird. I would assume as well that its a typo.
Other older post in the archive forum in relation to using gzipinflate (with the zlib library): http://www.masmforum.com/board/index.php?topic=9039.0
Thanks, fearless and Vortex. I will have a closer look, although I am tempted to stick with the current MasmBasic implementation because FreeArc is just incredibly efficient - see http://www.maximumcompression.com/data/summary_mf.php#data
The downside is there is no dll - you are forced to use the FreeArc executable, and that costs quite a bit of milliseconds...
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
Init
GetFiles \Masm32\m32lib\*.asm ; load Files$() array
push eax ; save # of files
NanoTimer()
ZipFiles "Lib32" ; the name of the *.arc archive
pop eax
Inkey Str$("%i files compressed", eax), Str$(" in %i ms\n", NanoTimer(ms)), "See details (y)?"
.if eax=="y"
Launch ExpandEnv$(Chr$(34, "%ProgramFiles%\FreeArc\bin\Arc.exe", 34, " v Lib32.arc"))
Inkey
.endif
Exit
end start
The resulting arc file is 55951 bytes, as compared to 191020 for WinZip's max portable mode. And FreeArc is still twice as fast...!
The v option, by the way, is meant for developers and produces archive info:
Listing archive: Lib32.arc
Date/time Attr Size Packed CRC Filename
-----------------------------------------------------------------------------
2000-06-02 16:24:14 ....... 1364 48790 c2249beb Masm32\m32lib\a2dw.asm
2004-05-21 07:38:48 ....... 3399 0 50c16759 Masm32\m32lib\a2dw_ex.asm
2004-03-29 11:15:22 ....... 1221 0 7ee82d23 Masm32\m32lib\a2wc.asm
2003-01-12 07:01:56 ....... 6833 0 b1818c69 Masm32\m32lib\about.asm
2006-07-04 09:01:38 ....... 3749 0 69296e9a Masm32\m32lib\acisort.asm
P.S.: You need %ProgramFiles%\FreeArc\bin\Arc.exe to get the attachment working. Another weak point of FreeArc.
Quote from: fearless on July 09, 2012, 10:05:31 AM
http://www.winimage.com/zLibDll/minizip.html
download the zlib125dll.zip and extract files
under /static32 folder you will find a zlibstat.lib
RadASM 3.0 source shows examples of using it with update plugin, and i think i remember a zlibstat.inc file being available there that has the protos defined for use in the library.
First off the whole point I think is making a zip-unzip with zlib
Not another compression method ( there are a few)
I have tried this wich I have found on another site as a base start
http://www.asmcommunity.net/board/index.php?topic=6863.0
First I am wondering why not use the zlib.dll? If we get that working than try a .lib version!
Second thing is... In the zlib125.dll there is a demo zip-unzip which you need to run with a batch file
And they don't use commands like "compress" they use "inflate" deflate" if I am not mistaken.
It would be cool to make a simple zip-unzip using zlib
But I think we sould try the above example with a .dll for now they seem to have a working copy!
I added that example with all the lib's needed... so you don't have to hunt for them
Been playing around with the zlib static library and looking at KetilO's code for a while and decided to put together a basic Extract (Inflate/Expand/Unzip or whatever you want to call it) function. I've packaged it into a small lib file for handyness. Source is included as well. I'm hoping to expand on it by implementing a few other options at a later date. But i figured it would be worth uploading, and letting peeps take a looksee at it. I've wrote some stuff about it on my website/blog thingy. If anyones interested feel free to take a look (website link in sig)
Done some limited testing, but usual disclaimer applies, so maybe be careful with it, you dont want to overwrite any important files! :D
Include zlibextract.inc
Includelib zlibstat.lib
Includelib zlibextract.lib
.code
Invoke ZL_Extract, Addr szZipFile, Addr szFileNameOrFileSpec, Addr szOutputFolder
1st param is the name of your zip file, 2nd and 3rd param are optional.
If 2nd param is NULL assumes '*.*' = all files. Can be a specific filename or wildcards ? * (well, hopefully it should)
If 3rd param is NULL assumes '.\' = current folder. Should handle relative paths stored in the zip and output with them appended to specified outputfolder (or current folder+internalpath) if NULL specified. (Again hopefully)
Anyhows, feel free to test away, throw stones at it, shout at it, then crawl over to it in a drunken stupor and hug it, before passing out. Have fun.
Update 18.04.2013 15:49pm: Fixed 2 bugs. Fingers crossed it works ok now.
Hello,
I am not having any luck , what am I doing wrong?
Also when I DO NOT Leave 2nd and 3rd Parameters NULL I get it crashing
Do We need to add ".IF eax==ZLE_EXTRACT_SUCCESS"
I have tried that too
Thank You ....
EDIT:
Posted updated Example.zip in my next Post
My bad, left an Addr instruction in where it wasnt needed for the 3rd param. Fingers crossed it works now - updated my previous post with the newer version. Let me know how it goes.
Quote from: fearless on April 18, 2013, 07:45:48 PM
My bad, left an Addr instruction in where it wasnt needed for the 3rd param. Fingers crossed it works now - updated my previous post with the newer version. Let me know how it goes.
Hello , It works now with the 2nd and 3rd Parameters as NULL !
But It wont take a second and 3rd parameters...It crashes! I have tried different folder destinations and different extensions :(
By the way . Still nice job getting zlib to work :t
Thanks :D
Downloaded example. Will take a closer look tonight - just on break at work at the mo.
Although this works just fine if you want to select a file to extract.....
I modified a CRC32 check tool that I have made , so this was so quick to do :biggrin:
Uploaded a newer version in other post above. Had a few spare mins at lunch, so spotted the problem with the path name, looking for \ or / at end of outputfolder specified. Was adding addr of outputfolder to esi, instead of length of output folder - silly mistake. I think it might be fixed now. Thanks for testing it. Let me know if anything else looks odd or if there are any other crashes etc. Cheers.
Quote from: fearless on April 19, 2013, 12:51:56 AM
Uploaded a newer version in other post above. Had a few spare mins at lunch, so spotted the problem with the path name, looking for \ or / at end of outputfolder specified. Was adding addr of outputfolder to esi, instead of length of output folder - silly mistake. I think it might be fixed now. Thanks for testing it. Let me know if anything else looks odd or if there are any other crashes etc. Cheers.
:greenclp: :greenclp: :greenclp:
ALL works %100 Here
Also Here are the 2 attachments with the updated Libs
Updated zlibextract to v1.1
- New ZL_SetProcessInfoCallback proc for user to define own callback function to receive info whilst listing files or extracting files, or just zip archive info. Reworked code to implement that function.
- Added zlibextract.chm to help document the functions and show some basic usage/examples. Most of the info is also in the zlibextract.inc file as well.
- ZL_Extract: added dwOptions param - used for extract, list, info mode. Trying to forward think about possible cmd line usage, passing -e, v, -n, -r, -whatever switches.
- ZL_Extract: added lpszExcludeFileSpec param - not currently implemented, so just pass NULL for the moment.
- Created a zlibextract logo - yay! lol.
- Updated project page on my website to add new lib and chm file for download.
Should be possible to get each file info (via user defined callback proc) and add to a listview if someone wanted to do that. And/or show progress bar whilst extracting. Fingers crossed it all works as planned. The user defined callback function will receive all error or status return codes (as defined in the zlibextract.inc file) via the dwStatus param. Use of the Zl_SetProcessInfoCallback is optional, without it, the lib should work as before if just extracting files.
Let me know if there are any bugs, or things i should add to it. Not sure how much i will continue to add to it, only time will tell ;)
Enjoy
Hello,
I noticed no zlibextract.asm or zlibextract_build.bat with this version 8)
Few changes to make, and test - noticed two issues.
- Filling in szFullFilename in listmode was based on lpszOutputFile param, when it should just show the internal path/name stored in zip
- Some archives with relative paths and stored as empty folder (not a file) where being passed back to the callback proc in my example.
Once i fix those up ill post up the new lib with the .asm and build. And hopefully ill post up an example prog as well with a listview being filled, and allow user to extract selected file in listview (or all files)
Fixed the two issues i had - i hope. Included source and build batch file.
Also made a simple gui - winzip like clone. Works for listing contents of zip files. Basic prog to show some usage. Left out the extract of files for the mo - might add it in later, or maybe ill leave it for someone who wants to make a winzip clone. Either way its there as a simple example.
Enjoy.
Update: fixed chm not displaying functions correctly, reuploaded zlibextract_1.1.zip to add the correct chm file.
Nice thank you :t
yes - nice work fearless :t
i wonder if we could use the other functions in zlib ?
I think (and hope) that ive managed to compile an updated zlib v1.2.8 static library.
Ive created a simple radasm project that only calls zlibversion. If anyone has time to spare, could you download and compile it to see if it links properly.
I cant be 100% certain that my environment is not pulling in other references for other libs and whatnot, so just want to make sure it does work on other peoples computers.
Ive re-compiled my zlibextract library with the updated static version and ran the gui example listed in one of the above posts, and it seems to work fine. So fingers crossed.
i would remove these lines from ZlibTest.inc
include windows.inc
include user32.inc
include kernel32.inc
include shell32.inc
include comctl32.inc
includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
includelib comctl32.lib
include msvcrt.inc ; required for zlibstat _malloc & _free
includelib msvcrt.lib ; required for zlibstat _malloc & _free
part of the reason.....
in the ASM file
.686
.MMX
.XMM
.model flat,stdcall
option casemap:none
include \masm32\macros\macros.asm
include ZlibTest.inc
include zlibstat.inc
includelib zlibstat128.lib
windows.inc should be first in the list
and, most of us use hard-coded paths because that's how the masm32 package is designed to be used
i removed all that stuff from the INC file
and modified the ASM file to start like this
include \masm32\include\masm32rt.inc
.686
include ZlibTest.inc
include zlibstat.inc
includelib zlibstat128.lib
.code
notice that, by using masm32rt.inc, i only have to set 1 path :biggrin:
the program seems to assemble and run ok
Cheers Dave :D
Hopefully someone will find it useful and can test out a few of the other functions in zlib
maybe i am doing something wrong - lol
these do not appear to be exported by the LIB
fclose_file_func PROTO :DWORD,:DWORD
ferror_file_func PROTO :DWORD,:DWORD
fopen_file_func PROTO :DWORD,:DWORD,:DWORD
fread_file_func PROTO :DWORD,:DWORD,:DWORD,:DWORD
fseek_file_func PROTO :DWORD,:DWORD,:DWORD,:DWORD
ftell_file_func PROTO :DWORD,:DWORD
fwrite_file_func PROTO :DWORD,:DWORD,:DWORD,:DWORD
i used Vortex's Lib2Def program - it shows....
"fill_fopen64_filefunc"
"fill_fopen_filefunc"
"fill_zlib_filefunc64_32_def_from_filefunc32"
those are probably data symbols, as they do not have @(n) at the end (or maybe macros ?)
maybe the original header file aliases those names to some API or CRT functions
Searching the entire set of files downloaded from the zlib128.zip from the zlib website, the only reference to those functions are in contrib\minizip\ioapi.c
In the main zlibstat.lib there are references to gzopen, unzOpen, call_zopen64 instead of fopen_file_func. In the zlibextract.lib i created, i used the unz functions: unzGoToFirstFile, unzGetCurrentFileInfo, unzOpenCurrentFile, unzReadCurrentFile, unzCloseCurrentFile & unzGoToNextFile to read a file (unzips it) into a buffer (GlobalAlloc) and write it out using WriteFile.
Not sure how the fopen_file_func and the others are used - possibly they are a wrapper for some of the main zlib functions?
ok - found them
they are CALLBACK function prototypes :biggrin:
voidpf ZCALLBACK fopen_file_func (
voidpf opaque,
const char* filename,
int mode);
uLong ZCALLBACK fread_file_func (
voidpf opaque,
voidpf stream,
void* buf,
uLong size);
uLong ZCALLBACK fwrite_file_func (
voidpf opaque,
voidpf stream,
const void* buf,
uLong size);
long ZCALLBACK ftell_file_func (
voidpf opaque,
voidpf stream);
long ZCALLBACK fseek_file_func (
voidpf opaque,
voidpf stream,
uLong offset,
int origin);
int ZCALLBACK fclose_file_func (
voidpf opaque,
voidpf stream);
int ZCALLBACK ferror_file_func (
voidpf opaque,
voidpf stream);
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
voidpf opaque;
const char* filename;
int mode;