Sign in to follow this  
Followers 0
monoceres

Zlib UDF

25 posts in this topic

#1 ·  Posted (edited)

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!

Share this post


Link to post
Share on other sites



#4 ·  Posted (edited)

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:-)

Share this post


Link to post
Share on other sites

Thanks guys :)

@James

As far as I know there are just the regular autoit limitations :o

@JRSmile

Yeah, compressin' stuff directly in memory is so much cooler than those pesky files :D


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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Nice work, monoceres. :)


When the words fail... music speaks

Share this post


Link to post
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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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!

Share this post


Link to post
Share on other sites

No biggie. Keep up the great work!

Share this post


Link to post
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 :)

?

1 person likes this

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

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

This is nice and useful.

btw, I think I found native api compression method available. Uses LZW algorithm.

edit:

... ok, I got it. Will make new thread not to be offtopic here.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

Try my zlib UDF, uncompressed size is not needed.


新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0