首页
社区
课程
招聘
一个压缩率很高的优化压缩算法
发表于: 2024-7-27 10:41 2092

一个压缩率很高的优化压缩算法

2024-7-27 10:41
2092

优化后的压缩算法:JJJsafe.

经测试其压缩率高于aplib,upx,,,等等常见的压缩算法。

压缩算法以静态库的形式提供给大家使用(进行过上千万次的压缩解压测试),详细的接口和示例如下:

JJJsafe.h 内容如下:

/*

  • JJJsafeLib compression library
  • COFF format header file
  • Copyright (c) 2010-2024 Beijing JJJsafe Technology
  • All Rights Reserved
  • http://www.910safe.com/
    */

#ifndef JJJSAFELIB_H_INCLUDED
#define JJJSAFELIB_H_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

////////////////////////////////////////////////////////////////////////////////
// 函数名称:BOOL Jsafe_compress(unsigned char *dest, unsigned int *destLen, unsigned char *source, unsigned int sourceLen, int(__cdecl *pcallback) (unsigned int, unsigned int))
// 实现功能:压缩数据
// 对全局变量的影响:无
// 参数说明:
// dest - 输出缓冲区
// destLen - 压缩后长度返回指针
// source - 输入缓冲区
// sourceLen - 输入长度
// pcallback - 进度显示
// 返回结果说明: - TRUE :压缩完成,FASLE:压缩失败。
////////////////////////////////////////////////////////////////////////////////

BOOL Jsafe_compress(unsigned char *dest, unsigned int *destLen, unsigned char *source, unsigned int sourceLen, int(__cdecl *pcallback) (unsigned int, unsigned int));

////////////////////////////////////////////////////////////////////////////////
// 函数名称:BOOL Jsafe_uncompress(unsigned char *dest, unsigned int *destLen, unsigned char *source, unsigned int sourceLen, int(__cdecl *pcallback) (unsigned int, unsigned int))
// 实现功能:解压数据
// 对全局变量的影响:无
// 参数说明:
// dest - 输出缓冲区
// destLen - 解压后长度返回指针
// source - 输入缓冲区
// sourceLen - 输入长度
// pcallback - 进度显示
// 返回结果说明: - TRUE :压缩完成,FASLE:压缩失败。
////////////////////////////////////////////////////////////////////////////////

BOOL Jsafe_uncompress(unsigned char *dest, unsigned int *destLen, unsigned char *source, unsigned int sourceLen, int(__cdecl *pcallback) (unsigned int, unsigned int));

////////////////////////////////////////////////////////////////////////////////
// 函数名称:unsigned int Jsafe_max_packed_size(unsigned int inputsize)
// 实现功能:返回压缩所需输出缓冲区的大小
// 对全局变量的影响:无
// 参数说明:
// inputsize - 压缩数据长度
// 返回结果说明: 所需输出缓冲区的大小
////////////////////////////////////////////////////////////////////////////////

unsigned int Jsafe_max_packed_size(unsigned int inputsize);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* JJJSAFELIB_H_INCLUDED */

test_jsafe.cpp 测试样例:

// test_jsafe.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <malloc.h>
#include <windows.h>
#include "JJJsafe.h"

#pragma comment(lib,"JJJsafe.lib")

//#pragma comment (linker,"/NODEFAULTLIB:libcmt.lib")

#pragma warning(disable: 4996)

unsigned char rotator[] = "-\|/";
int rotatorpos = 0;

int __cdecl Jsafe_PercentPrinter(unsigned int inpos, unsigned int insize)
{
printf("\r%c Packing data -> %2.2f%%", rotator[rotatorpos], 100.0*(double)inpos / (double)insize);
rotatorpos = (rotatorpos + 1) & 0x0003;
return 0;
}

int main(int argc, char* argv[])
{
FILE *ifile, *ofile;
unsigned char *src, *dst;
BOOL bret = FALSE;
unsigned int oldsize = 0, dst_size = 0,src_size = 0;
char sz_ratio[MAX_PATH];

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
if((ifile = fopen("1.exe", "rb")) == NULL)
{
    printf("open file error!\n");
    return 0;
}
 
fseek(ifile, 0, SEEK_END);
oldsize = ftell(ifile);
fseek(ifile, 0, SEEK_SET);
src = (unsigned char*)malloc(oldsize);
if(src == NULL)
{
    fclose(ifile);
    printf("alloc memory error!\n");
    return 0;
}
 
 
fread(src, oldsize, 1, ifile);
fclose(ifile);
 
dst = (unsigned char*)malloc(Jsafe_max_packed_size(oldsize));
if(dst == NULL)
{
    fclose(ifile);
    free(src);
    printf("alloc memory error!\n");
    return 0;
}
 
bret = Jsafe_compress(dst,&dst_size,src,oldsize,Jsafe_PercentPrinter);
if(bret == FALSE)
{
    fclose(ifile);
    free(src);
    free(dst);
    printf("Compression error!\n");
    return 0;
}
 
sprintf(sz_ratio,"%2.1f%%",(double)dst_size*100.0/(double)oldsize);
printf("\nCompression ratio : %s\n",sz_ratio);
 
//清空原始数据。
memset(src, 0, oldsize);
 
bret = Jsafe_uncompress(src,&src_size,dst,dst_size,Jsafe_PercentPrinter);
if(bret == FALSE)
{
    fclose(ifile);
    free(src);
    free(dst);
    printf("Decompression error!\n");
    return 0;
}
 
fclose(ifile);
free(dst);
 
printf("\n");
 
if((ofile = fopen("2.exe", "wb")) == NULL)
{
    free(src);
    printf("open file error!\n");
    return 0;
}
 
fwrite(src, src_size, 1, ofile);
fclose(ofile);
free(src);
 
printf("over!!!\n");
 
getchar();
 
return 0;

}

附件中有测试程序和测试样本。

解压工具(WinUar)下载地址:http://910safe.com/pages/down/setup2.zip


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2024-7-28 09:18 被910编辑 ,原因:
上传的附件:
收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 223
活跃值: (932)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
带加密的压缩也发下
2024-7-28 08:48
0
雪    币: 43
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
910
3
解压工具下载地址:http://910safe.com/pages/down/setup2.zip
2024-7-28 09:14
0
雪    币: 43
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
910
4
#pragma pack(1)

typedef struct _tagCompressParameterInfo
{
       unsigned char        *dest;
       unsigned int        *destLen;
       unsigned char        *source;
       unsigned int        sourceLen;
       
       int                                (__cdecl *pcallback) (unsigned int, unsigned int);
       void                        *p;                //reserved,Extended pointer.


} CompressParameterInfo, *PCompressParameterInfo;

#pragma pack()

如果传递参数有点多,建议用结构体的形式传递参数,并且在结构体里预留一个用于扩展的指针!
2024-7-29 09:10
0
游客
登录 | 注册 方可回帖
返回
//