E
E
Evgeny Ivanovich2020-01-17 22:48:10
C++ / C#
Evgeny Ivanovich, 2020-01-17 22:48:10

How to determine the parameters of lzma compression by displaying information after a call?

There is a simple code written in lua

ekau.lzma_compress("test", function(data) print("data->", #data, #util.Compress("test"), data == util.Compress("test")) end)...

Expression Output
data->27 22 false

It is obvious that util.Compress produces a smaller compression output length, how to find out, and is it possible to find out the compression parameters of the util.Compress function without reverse engineering? We need to change the lzma_compress function, which is written in C++, so that the output results are the same.
Here is the code for the compression itself in C++
int  
simpleCompress(elzma_file_format format, const unsigned char * inData,  
        size_t inLen, unsigned char ** outData,  
        size_t * outLen)  
{  
  int rc;  
  elzma_compress_handle hand;  
  
  /* allocate compression handle */  
  hand = elzma_compress_alloc();  
  assert(hand != NULL);  
  
  /* configure the compression run with mostly default parameters  */   
  rc = elzma_compress_config(hand, ELZMA_LC_DEFAULT,  
                ELZMA_LP_DEFAULT, ELZMA_PB_DEFAULT,  
                5, (1 << 24) /* 1mb */,  
                format, inLen);  
  
  /* fail if we couldn't allocate */    
  if (rc != ELZMA_E_OK) {  
    elzma_compress_free(&hand);  
    return rc;  
  }  
  
  /* now run the compression */  
  {  
    /* set up the context structure that will be passed to 
      * stream callbacks */    
    struct dataStream ds;  
    ds.inData = inData;  
    ds.inLen = inLen;  
    ds.outData = NULL;  
    ds.outLen = 0;  
  
    /* run the streaming compression */   
    rc = elzma_compress_run(hand, inputCallback, (void *) &ds,  
                outputCallback, (void *) &ds, NULL, NULL);  
      
    if (rc != ELZMA_E_OK) {  
      if (ds.outData != NULL) free(ds.outData);  
      elzma_compress_free(&hand);  
      return rc;  
    }  
  
    *outData = ds.outData;  
    *outLen = ds.outLen;  
  }  
  
  return rc;  
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question