通用是相对的,这里指的是xp和win7(其他版本我没测试过,不要用不要来找我)

#define CMP_FRM     COMPRESSION_FORMAT_LZNT1|COMPRESSION_ENGINE_MAXIMUM

typedef DWORD(__stdcall *RtlCompressBuffer_Fn)(
IN ULONG CompressionFormat,
IN PVOID SourceBuffer,
IN ULONG SourceBufferLength,
OUT PVOID DestinationBuffer,
IN ULONG DestinationBufferLength,
IN ULONG Unknown,
OUT PULONG pDestinationSize,
IN PVOID WorkspaceBuffer); typedef DWORD(__stdcall *RtlDecompressBuffer_Fn)(
IN ULONG CompressionFormat,
OUT PVOID DestinationBuffer,
IN ULONG DestinationBufferLength,
IN PVOID SourceBuffer,
IN ULONG SourceBufferLength,
OUT PULONG pDestinationSize); typedef DWORD(__stdcall *RtlGetCompressionWorkSpaceSize_Fn)(
IN ULONG CompressionFormat,
OUT PULONG pNeededBufferSize,
OUT PULONG pUnknown); LPBYTE CompressBuffer(LPBYTE lpIn, int iInLen, int & iOut); LPBYTE DecompressBuffer(LPBYTE lpIn, int iInlen, int & iOut);
static RtlCompressBuffer_Fn compress = NULL;
static RtlDecompressBuffer_Fn decompress = NULL;
static RtlGetCompressionWorkSpaceSize_Fn getcompressionworkspacesize = NULL;
void GetCompressApis()
{ if (compress && decompress && getcompressionworkspacesize)
{
return;
}
static WCHAR wszntdll[] = { L'n', L't', L'd', L'l', L'l', L'.', L'd', L'l', L'l', L'\0' };
static HMODULE hDll = LoadLibrary(wszntdll);
static char szRtlCompressBuffer[] = { 'R', 't', 'l', 'C', 'o', 'm', 'p', 'r', 'e', 's', 's', 'B', 'u', 'f', 'f', 'e', 'r', '\0' };
static char szRtlDecompressBuffer[] = { 'R', 't', 'l', 'D', 'e', 'c', 'o', 'm', 'p', 'r', 'e', 's', 's', 'B', 'u', 'f', 'f', 'e', 'r', '\0' };
static char szRtlGetCompressionWorkSpaceSize[] = { 'R', 't', 'l', 'G', 'e', 't', 'C', 'o', 'm', 'p', 'r', 'e', 's', 's', 'i', 'o', 'n', 'W', 'o', 'r', 'k', 'S', 'p', 'a', 'c', 'e', 'S', 'i', 'z', 'e', '\0' };
if (hDll)
{
compress = (RtlCompressBuffer_Fn)GetProcAddress(hDll, szRtlCompressBuffer);
decompress = (RtlDecompressBuffer_Fn)GetProcAddress(hDll, szRtlDecompressBuffer);
getcompressionworkspacesize = (RtlGetCompressionWorkSpaceSize_Fn)GetProcAddress(hDll, szRtlGetCompressionWorkSpaceSize); } }
//
// compress buffer
//
LPBYTE CompressBuffer(LPBYTE lpIn, int iInLen, int & iOut)
{
// 压缩格式 |原大小 2 | 压缩后大小 2| 数据 .....|hash 4|
GetCompressApis();
int dwOutBufferLen = iInLen*1.2 + ;
LPBYTE lpOut = (LPBYTE)zMalloc(dwOutBufferLen);
// 获取工作缓冲区大小
DWORD dwNeed, rc;
ULONG unKnow;
void* tempMeme;
rc = getcompressionworkspacesize(CMP_FRM, &dwNeed, &unKnow);
tempMeme = LocalAlloc(LPTR, dwNeed);
iOut = ;
rc = compress(CMP_FRM, lpIn, iInLen, lpOut + , dwOutBufferLen, unKnow, &dwNeed, tempMeme); LocalFree(tempMeme);
if (rc != )
{
zFree(lpOut);
return NULL;
}
*(short*)lpOut = iInLen;
iOut = dwNeed + ; return lpOut; }
//
// decompress buffer
//
LPBYTE DecompressBuffer(LPBYTE lpIn, int iInlen, int & iOut)
{
GetCompressApis();
short len = *(short*)lpIn;
if (len < || len > *)
{
return NULL ;
}
LPBYTE lpOut = (LPBYTE)zMalloc(len);
iOut = ;
DWORD dwRc = decompress(CMP_FRM, lpOut, len, lpIn + , iInlen - , (PULONG)&iOut);
if (dwRc != )
{
zFree(lpOut);
return NULL;
}
return lpOut; }

最新文章

  1. windows下安装kibana出 &quot;EPERM: operation not permitted
  2. SQLPROMPT5.3对各种加密对象的解密测试
  3. 1&#183;3 对 git 的认识
  4. cf 731f
  5. Xcode常用快捷键
  6. adroid 目录
  7. 乱侃c++
  8. Android(java)学习笔记265:Android线程形态之 HandlerThread
  9. hdu4597Play Game(记忆化)
  10. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
  11. fedora 下安装 文泉驿正黑体
  12. 使用SQLServer Audit来监控触发器的启用、禁用情况
  13. 201521123098 《Java程序设计》第7周学习总结
  14. Spring_Aop的xml和注解的使用
  15. makefile讲解
  16. Python Learning - Three
  17. 【十三】jvm 性能调优工具之 jstack
  18. 130、 Android OkHttp完全解析(转载)
  19. python assert断言函数
  20. COGS.1272.[AHOI2009]行星序列(线段树 区间加、乘、求和)

热门文章

  1. 李洪强iOS经典面试题138-Block
  2. iOS音频AAC视频H264编码 推流最佳方案
  3. R中list对象属性以及具有list性质的对象
  4. Hadoop.2.x_集群初建
  5. webapp 侧边导航效果
  6. 2016HUAS暑假集训训练2 K - Hero
  7. 下载包含src,tgz,zip的文件
  8. BizTalk动手实验(八)消息路由
  9. linux命令学习(2):wc 命令
  10. vim正则表达式(转)