首页 文章

无法提取根据IETF RFC 1951压缩的数据:“DEFLATE压缩数据格式规范版本1.3”

提问于
浏览
0

我想在RFC 1951中指定的DEFLATE压缩格式中解压缩(或者应该按照我所指的规范)的数据 . 我在C中使用zlib库 . 我在github中引用了这个例子:https://gist.github.com/gaurav1981/9f8d9bb7542b22f575df

并修改它只是为了解压缩我的数据:

char dData[MAX_LENGTH];
    char cData[MAX_LENGTH]; 

    for(i=0; i < (size-4); i++)
    {
        cData[i] = *(data + i);
    }
    //cData[i] = '\0';
    printf("Compressed size is: %lu\n", strlen(cData));

    z_stream infstream;
    infstream.zalloc = Z_NULL;
    infstream.zfree = Z_NULL;
    infstream.opaque = Z_NULL;
    // setup "b" as the input and "c" as the compressed output
    //infstream.avail_in = (uInt)((char*)defstream.next_out - b); // size of input
    //infstream.avail_in = (uInt)((char*)defstream.next_out - cData);
    infstream.avail_in = (uInt)(size - 4);
    infstream.next_in = (Bytef *)cData; // input char array
    infstream.avail_out = (uInt)sizeof(dData); // size of output
    infstream.next_out = (Bytef *)dData; // output char array

    // the actual DE-compression work.
    inflateInit(&infstream);
    inflate(&infstream, Z_NO_FLUSH);
    inflateEnd(&infstream);

    printf("Uncompressed size is: %lu\n", strlen(dData));

    size = strlen(dData);

我的未压缩大小为0.那么有人可以告诉我的代码有什么问题吗?

我甚至将数据写入文件并将其保存为.gz和.zip,但是当我尝试提取它时出现错误(我正在运行ubuntu 14.04)

并且有人可以善待分析我的数据并在可能的情况下提取数据 . 我的数据:

6374 492d 2d29 4ece c849 cc4b
294a 4cc9 cc57 f02e cd29 292d 6292 7780
30f2 1293 338a 3293 334a 52f3 98c4 0b9c
4a93 33b2 8b32 4b32 b399 d405 4212 d353
8b4b 320b 0a00

2 回答

  • 0

    您的数据以\ 0开头,因此strlen将返回0,表示您打印的是未压缩数据的长度

  • 0

    而不是 inflate() ,您需要使用第二个参数 -15 调用 inflateInit2() ,以便解压缩原始deflate数据 .

相关问题