我编写了一个小型应用程序,该应用程序应该解压缩以 gzip/deflate 格式编码的数据。
为了实现这一点,我使用 ZLIB 库,使用解压缩功能。
问题是这个功能不起作用!换句话说,数据不是未压缩的!
我在这里发布代码:
int (*decompress)(PBYTE,PULONG,PBYTE,ULONG);
void DecodeData(PBYTE data,ULONG dataSize){
LoadLibrary("C:\\zlib1.dll");
decompress=(int(*)(PBYTE,PULONG,PBYTE,ULONG))GetProcAddress(
GetModuleHandle("zlib1.dll"),"uncompress");
// Yeah I know the size is hardcoded and it's not right, but it's just a test,
// so nevermind
PBYTE decompressedData=(PBYTE)VirtualAlloc(NULL,300,MEM_COMMIT|MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
ULONG maxSize=250;
decompress(decompressedData,&maxSize,data,dataSize);
MessageBox(0,(char*)decompressedData,0,MB_OK);//MessageBox shows no data, it's blank!
}
通过GetProcAddress成功获取了函数的指针,问题是函数返回NULL(甚至没有zlib文档中列出的错误)