News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

LZO/MiniLZO - cant get it working

Started by fearless, November 30, 2023, 03:37:00 AM

Previous topic - Next topic

fearless

I was recently looking at LZO/MiniLZO for inclusion in another project, but cant seem to get it to work. I figured I might post it here in case someone else can spot something that I might have missed.

I tried using LZO and MiniLZO, using cmake to compile them and create the appropriate libs. I also managed to download a nupkg and extract an LZO2 lib to test out, all seem to crash at the compress stage. I tried varying the size of the work buffer but nothing seems to be working. Probably something obvious, but fresh eyes might see something.

2B||!2B

That has some issues assembling. vcruntime.lib/ucrt.lib/Debug32.lib/Assert.lib not there.
Also, for some reason, my DbgWin.exe has a different Edit Control ID than what you're using. Causing it to fail to print. GetDlgItem fails.

Anyway,

The 4th parameter of the functions lzo1x_1_compress/lzo1x_decompress expects a pointer, not a value.

See https://github.com/yuhaoth/minilzo/blob/b088e80336ef11c5a29ec949a950d4f0fec9ec05/testmini.c#L111

Also, why are you using == 0 for compress and != 0 for decompress? They both report 0 on success.
The size of compressed/decompressed is reported back in the 4th parameter.

Line 121: eax = 8352 (0x000020A0)
Line 127: DbgVal = 2.10
Line 131: LZO1X_MEM_COMPRESS = 131072 (0x00020000)
Line 147: MiniLZO GlobalAlloc WorkSpace OK
Line 171: MiniLZO GlobalAlloc OK
Line 181: MiniLZO lzo1x_1_compress Success
Line 182: dwCompressedSize = 294 (0x00000126)
Line 202: MiniLZO GlobalAlloc WorkSpace OK
Line 217: MiniLZO GlobalAlloc OK
Line 225: MiniLZO lzo1x_decompress Success
Line 226: dwUncompressedSize = 708 (0x000002C4)

fearless

Thank you for looking at this. The extra pair of eyes 100% works :D

Looking at that line in the github link, you are totally correct.

I have been using a similar process when translating all other compression libraries and testing them out - each have a similar project to the LZO/MiniLZO one attached in the first post and so I was used to looking at the .h files to see if any had a * to indicate pointer rather than value - some libraries do and some dont, and some require extra stuff like workspace buffers etc.

Looking at the .h file again:

lzo1x_1_compress        ( const lzo_bytep src, lzo_uint  src_len,
                                lzo_bytep dst, lzo_uintp dst_len,
                                lzo_voidp wrkmem );

At a glance it doesnt have any *, but now that you pointed out that it does require it, I now see the lzo_uintp - which i guess is a reference to use a pointer. I totally did not see that before.

I hadn't even got to the part about testing for the return as I had assumed it was returned in eax and not in the dst_len and it was crashing at that point.

Anyhow much appreciated, I can get round to adding that compression library to the project I'm currently working on.

Also: if anyone is interesting in the radasm test projects for each of the compression libraries I can upload them to the forum - each is just a quick test for the main compressing/decompressing memory to memory functions, but might be useful to someone to see examples of such.

TimoVJL

With cl.exe option -P is possible to check headers.
/P preprocess to file
extern  int  __cdecl
lzo1x_1_compress        ( const unsigned char  * src, lzo_uint  src_len,
                                unsigned char  * dst, lzo_uint  * dst_len,
                                void  * wrkmem );

extern  int  __cdecl
lzo1x_decompress        ( const unsigned char  * src, lzo_uint  src_len,
                                unsigned char  * dst, lzo_uint  * dst_len,
                                void  * wrkmem  );

extern  int  __cdecl
lzo1x_decompress_safe  ( const unsigned char  * src, lzo_uint  src_len,
                                unsigned char  * dst, lzo_uint  * dst_len,
                                void  * wrkmem  );
May the source be with you

fearless