Jump to content

Zlib UDF


monoceres
 Share

Recommended Posts

I wrote this because I wanted a simple way to compress data in memory instead of files.

And because rasim has done an excellent job with his 7Zip udf that handle files I did not include any file support.

Following functions exists:

_Zlib_Version()

_Zlib_Shutdown()

_Zlib_Startup($Filename = "zlibwapi.dll")

_Zlib_CalculateAdler32($DataPtr, $DataSize)

_Zlib_Uncompress($CompressedPtr, $CompressedSize, $UncompressedPtr, $UncompressedSize)

_Zlib_Compress($InBufferPtr, $InBufferSize, $OutBufferPtr, ByRef $OutBufferSize, $CompressionLevel = $Z_DEFAULT_COMPRESSION)

_Zlib_CompressBinary($binary, $CompressionLevel = $Z_DEFAULT_COMPRESSION)

_Zlib_UncompressBinary($compressedbinary, $UncompressedBinaryLength)

More info in the UDF.

Example:

#include "zlib udf.au3"
  _Zlib_Startup()
  $bin=StringToBinary("hahahahahahahahahahahehe")
  $binlen=BinaryLen($bin)
  
  $compressed=_Zlib_CompressBinary($bin)
  
  $uncompressed=_Zlib_UncompressBinary($compressed,$binlen)
  
  MsgBox(64,BinaryToString($bin),"Original:"&@CRLF&$bin&@CRLF&@CRLF&"Compressed: "&@CRLF&$compressed&@CRLF&@CRLF&"Uncompressed: "&@CRLF&$uncompressed)
  _Zlib_Shutdown()

Download:

zlib_udf.au3

Previous downloads: 33

Zlib dll download:

http://www.zlib.net/

:)

Ps. If anyone want to continue adding functions to this, go ahead I won't probably work anymore one this anyway :o

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

WOW i already thought of a way to include more dll sources in binary string form in my sources but lower the size.. this is the perfect way to do so, THANK YOU VERY MUCH.

Edited by JRSmile
$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

Figured I'd test this out. I'm not sure what version everyone is using, but I just downloaded v1.2.3, and the function calls use cdecl, so the UDF crashes in current form. And the filename is zlib1.dll.

Edited by wraithdu
Link to comment
Share on other sites

Figured I'd test this out. I'm not sure what version everyone is using, but I just downloaded v1.2.3, and the function calls use cdecl, so the UDF crashes in current form. And the filename is zlib1.dll.

I'm using the one from zlib.net and it's named zlibwapi.dll (_Zlib_Startup has an optional parameter specifying the dll name though). I'm also pretty sure that the __stdcall calling convention is used because when I called the dll from a vc++ app with the cdecl calling convention the app crashed and the debugger whined about "wrong calling convention used"

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Yeah, that's weird. I downloaded it just last night from the link in your first post. I know you know what you're talking about, so it's strange.

Here's the link I used - http://www.zlib.net/zlib123-dll.zip

It has the different filename and calling convention.

You're right Posted Image

I downloaded the dll from here:

http://www.winimage.com/zLibDll/

Very stupid mistake and I will update the UDF to use the standard dll from the official zlib website :)

Edit: Done!

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

I'm thinking of changing the behaviour of _Zlib_CompressBinary so it adds a 4 byte header that contains the length of the original data, any thoughts of that? It would be much easier to use the compressed data in your script if you don't have to pass around the original length all the time :)

?

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

  • 10 months later...

Any ideea why

_Zlib_CompressBinary(0xff00ff00,9); (0x78DA63F8CFF09F010005FF01FF)

returns a different value than php's gzcompress ?

php:

echo bin2hex(gzcompress(convert('ff00ff00'),9));




        function convert($hexString) // converts a hexstring to a binary string
        {
                $hexLenght = strlen($hexString);
                // only hex numbers is allowed
                if ($hexLenght % 2 != 0 || preg_match("/[^\da-fA-F]/",$hexString)) return FALSE;

                unset($binString);
                for ($x = 1; $x <= $hexLenght/2; $x++)
                {
                        $binString .= chr(hexdec(substr($hexString,2 * $x - 2,2)));
                }

                return $binString;
        }

// php output: 0x78dafbcff09f010005fe01ff

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Any ideea why

_Zlib_CompressBinary(0xff00ff00,9); (0x78DA63F8CFF09F010005FF01FF)

returns a different value than php's gzcompress ?

The data is not 9 bytes long. It's an integer so it's 4 bytes.

You might also want to use a binary string in autoit as well. "0xff00ff00" is the way to do it.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

  • 3 months later...

This is my Code I tried & it results in -3

What does -3 mean?

#include <INet.au3>
#include "zlib_udf.au3"

  _Zlib_Startup()
  $bin=_INetGetSource('http://g.e-hentai.org/non-h')
  $binlen=BinaryLen($bin)
  
  $uncompressed=_Zlib_UncompressBinary($bin,$binlen)
  
  ConsoleWrite($uncompressed & @CRLF & @CRLF)  
  
  
  _Zlib_Shutdown()
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

  • 7 months later...

Thats have incompatibilities with general zlib.

If you try to using gz_uncompress($string) in php

or using other zlib library will give you

uncompressed data plus sign: "?".

For example:

Compress this string with script.

"The quick brown fox jumped over the lazy dog."

will output decompressed data in other decompressor

program:

"The quick brown fox jumped over the lazy dog.?"

I'm saw in hex editor and compare output of your

script and general zlib output and in a few last

byte are differs.

So here is my problem.

Oh man do you have problem solving?

# Button. Progressbar - Graphical AutoIt3 Control (UDF) # GTK on AutoIt3 - GTK+ Framework | Widgets

Link to comment
Share on other sites

  • 2 months later...

This is my Code I tried & it results in -3

What does -3 mean?

#include <INet.au3>
#include "zlib_udf.au3"

  _Zlib_Startup()
  $bin=_INetGetSource('http://g.e-hentai.org/non-h')
  $binlen=BinaryLen($bin)
  
  $uncompressed=_Zlib_UncompressBinary($bin,$binlen)
  
  ConsoleWrite($uncompressed & @CRLF & @CRLF)  
  
  
  _Zlib_Shutdown()

'$bin' in '$binlen=BinaryLen($bin)' should be the size of original data
Link to comment
Share on other sites

  • 4 months later...

Hi monoceres.

Good work, simple and effective solution!

Did you implemented your idea about storing uncompressed data size?

It's very strange the DLL needs that information, is there any other call in the library that doesn't have that requirement?

It's very limited, to decompress you must now the size of the original data, it's almost as having to know the original data itself...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...