C/C++操作加密与不加密的zip文件

news2024/10/10 10:32:09

    为了后续的方便操作zip文件, 将所有的操作封装成了一个动态库了。

/**
 * \description 从压缩包文件中解压出指定的文件到指定的目录.
 * \author sunsz
 * \date   2023/09/09
 *
 */
LIBZIP_API int  UnpackFile(const char* password, char zipfilename[], char filename_to_extract[], char filepath_to_extract[]);

/**
 * \description .从压缩包文件中读出指定的文件到buffer中.
 * 
 * \author sunsz
 * \date   2023/09/09 
 * 
 */
LIBZIP_API int  UnpackBuffer(const char* password, char zipfilename[],char filenameinzip[], char *buffer,unsigned int *buffer_size);

/**
 * \description 获取指定文件的大小.
 * 
 * \author sunsz
 * \date   2023/09/09 
 * 
 */
LIBZIP_API int  UnpackBufferSize(const char* password, char zipfilename[], char filenameinzip[]);


/**
 * \description 从压缩包中获取文件列表.
 * 
 * \author sunsz
 * \date   2023/09/09 
 * 
 */
LIBZIP_API int UnpackFileList(const char* password, char zipfilename[], char filename_list[256][256]);


/**
 * \description 将指定的文件写入到压缩包文件中.
 *  opt_overwrite = 0 重新新建文件 opt_overwrite = 2 以追加的方式添加到压缩包不存在则创建  
 * \author sunsz
 * \date   2023/09/09 
 * 
 */
LIBZIP_API int PackFile(const char* password,char m_zipname[],char filein[],int opt_overwrite);

/**
 * \description 将内容以指定的文件名称存入到压缩包文件中.
 *  opt_overwrite = 0 重新新建文件 opt_overwrite = 2 以追加的方式添加到压缩包不存在则创建
 * \author sunsz
 * \date   2023/09/09
 *
 */
LIBZIP_API int PackBuffer(const char* password, char m_zipname[], char filenameinzip[], char* buffer, unsigned int buffer_size, int opt_overwrite);

 示例代码:


//依赖头文件
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <exception>

//定义函数指针

//typedef  int(WINAPI*S_dll_callback_demo1)(unsigned char*,unsigned char*);
typedef  int(WINAPI*ZipRead)(const char*, char*, char*, char*);
typedef  int(WINAPI*ZipReadFileList)(const char*, char*, char**);
typedef  int(WINAPI*ZipWrite)(const char*, char*, char*,int);
typedef  int(WINAPI* ZipWriteBuffter)(const char* , char *, char*, char* , unsigned int , int );
typedef  int(WINAPI* ZipReadBuffer)(const char* , char *, char *, char *, unsigned int* );
typedef  int(WINAPI* ZipReadBufferSize)(const char* , char *, char *);
//定义API函数变量
static ZipWrite	zipWriteFile;
static ZipRead	zipReadFile;
static ZipReadFileList	readList;
static ZipWriteBuffter	zipWriteBuffter;
static ZipReadBuffer	zipReadBuffter;
static ZipReadBufferSize	zipReadBuffterSize;
int main(){
	int i = 0;
	int j = 0;
	int malloclen = 0;
	unsigned int len = 0;
	char* dataout = NULL;
	char* passwd = "123456";
	int filenum = 0;
	char filelist[256][256] = { 0x00 };
	char data[] = "hello zip!";
	char path[] = ".//libzip.dll";
	HMODULE hDll = LoadLibrary(path);
	if (hDll != NULL) {
	    zipWriteFile = (ZipWrite)GetProcAddress(hDll, "PackFile");
		zipReadFile = (ZipRead)GetProcAddress(hDll, "UnpackFile");
		readList = (ZipReadFileList)GetProcAddress(hDll, "UnpackFileList");
		zipWriteBuffter = (ZipWriteBuffter)GetProcAddress(hDll, "PackBuffer");
		zipReadBuffter = (ZipReadBuffer)GetProcAddress(hDll, "UnpackBuffer");
		zipReadBuffterSize = (ZipReadBufferSize)GetProcAddress(hDll, "UnpackBufferSize");
		/*if (zipWriteFile) {
			zipWriteFile(passwd, "2.zip", "D:\\D-Pro\\Test\\test_zip\\test_zip\\test.S19",0);
		}
		else {
			printf("\nZipWriteFile\n");
		}
		if (zipReadFile) {
			zipReadFile(passwd, "2.zip", "test.S19",".//test//11111.s19");
		}
		else {
			printf("\nZipReadFile\n");
		}*/
		
		if (zipWriteBuffter) {
			zipWriteBuffter(passwd, "3.zip", "11112.txt", data, sizeof(data), 2);
		}
		else {
			printf("\nzipWriteBuffter \n");
		}
		
		if (zipReadBuffter) {
			if (zipReadBuffterSize) {
				malloclen = zipReadBuffterSize(passwd, "3.zip", "11112.txt");
				if (malloclen) {
					dataout = (char*)malloc(malloclen + 8);
					zipReadBuffter(passwd, "3.zip", "11112.txt", dataout, &len);
					printf("%s\n", dataout);
					if (dataout != NULL) {
						free(dataout);
						dataout = NULL;
					}
				}
			}
		}
		else {
			printf("\nzipWriteBuffter \n");
		}
	}
	else
	{
		printf("\n加载失败!\n");
	}
	printf("\n请按任意键结束!\n");
	_getch();
	return 0;
}

示例测试: 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/993759.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

rt-thread------任务调度

rt-thread------任务调度 1. 线程初始化 在rt-thread中线程主要包括以下一些内容&#xff0c;线程控制块、线程栈、函数入口。 1.1线程创建函数 RTOS基本都包括两种线程方式&#xff1a;动态创建rt_thread_create()和静态创建rt_thread_init()。 因为有些系统设计时对安全…

硬件学习件Cadence day13 PCB设计中一些设置, 铜皮到钻孔的距离设置, 差分线的设置,板层信息表

1. 设置铺铜中铜皮到钻口&#xff0c;连线的距离。 1. 打开设置界面 2. 设计界面 调整到 铜皮设置界面 2. 高速线的设置 &#xff08;差分对传输线的设置&#xff09; 1. 打开设置界面 2. 来到 差分线设置界面 3. 把界面往右看&#xff0c; 设置差分线的之间距离&#xff0c;…

Python之并发编程介绍

一、并发编程介绍 1.1、串行、并行与并发的区别 串行(serial)&#xff1a;一个CPU上&#xff0c;按顺序完成多个任务并行(parallelism)&#xff1a;指的是任务数小于等于cpu核数&#xff0c;即任务真的是一起执行的并发(concurrency)&#xff1a;一个CPU采用时间片管理方式&am…

TrOCR – 基于 Transformer 的 OCR 入门指南

多年来,光学字符识别 (OCR) 出现了多项创新。它对零售、医疗保健、银行和许多其他行业的影响是巨大的。尽管有着悠久的历史和多种最先进的模型,研究人员仍在不断创新。与深度学习的许多其他领域一样,OCR 也看到了变压器神经网络的重要性和影响。如今,我们拥有像TrOCR(Tran…

franka_ros中的一些子包的使用

franka_visualization包 该软件包包含连接到机器人并发布机器人和夹爪关节状态以在 RViz 中进行可视化的发布者。要运行此包启动&#xff1a; roslaunch franka_visualization franka_visualization.launch robot_ip:<fci-ip> \load_gripper:<true|false> 比如&a…

UI自动化测试工具详解

常用工具 1、QTP&#xff1a;商业化的功能测试工具&#xff0c;收费&#xff0c;可用于web自动化测试 2、Robot Framework&#xff1a;基于Python可扩展的关键字驱动的测试自动化框架 3、Selenium &#xff1a;开源的web自动化测试工具&#xff0c;免费&#xff0c;主要用于功…

SpringCloud-微服务CAP原则

接上文 SpringCloud-Config配置中心 到此部分即微服务的入门。 总的来说&#xff0c;数据存放的节点数越多&#xff0c;分区容忍性就越高&#xff0c;但要复制更新的次数就越多&#xff0c;一致性就越难保证。同时为了保证一致性&#xff0c;更新所有节点数据所需要的时间就…

Python教程33:关于在使用zipfile模块,出现中文乱码的解决办法

zipfile是Python标准库中的一个模块&#xff0c;zipfile里有两个class, 分别是ZipFile和ZipInfo&#xff0c;用来创建和读取zip文件&#xff0c;而ZipInfo是存储的zip文件的每个文件的信息的。ZIP文件是一种常见的存档文件格式&#xff0c;它可以将多个文件和目录压缩为一个文件…

帝国cms后台访问链接提示“非法来源”解决方法

提示“非法来源”的原因 帝国CMS更新升级7.2后,新增了后台安全模式,后台推出了金刚模式来验证链接来源。后台所有链接都需要登录后才能访问,直接强制访问后台页面链接都会提示“非法来源”。不是正常登录后台的用户无法直接访问到内容,保证了后台数据安全。 那么我们在日常…

Table of Laplace Transforms

https://www.math.uh.edu/~etgen/LaplaceT.pdf http://web.mit.edu/2.737/www/handouts/LaplaceTransforms.pdf https://www.integral-table.com/downloads/LaplaceTable.pdf https://www.math.purdue.edu/~caiz/MA527-cai/lectures/Table%20of%20Laplace%20Transforms.pdf

阅读源码工具Sourcetrail

收费工具Source Insight、Understand Sourcetrail开源工具 一、下载安装 接下来就是download&#xff0c;在GitHub的release页面选择自己系统对应的发布版本下载安装&#xff1a; 安装好后&#xff0c;运行程序&#xff0c;会出现这样的界面&#xff1a; 二、应用 选择“New…

2023年最佳研发管理平台评选:哪家表现出色?

“研发管理平台哪家好&#xff1f;以下是一些知名的研发管理软件品牌&#xff1a;Zoho Projects、JIRA、Trello、Microsoft Teams、GitLab。’” 企业需要不断创新以保持竞争力。研发是企业创新的核心&#xff0c;而研发管理平台则为企业提供了一个有效的工具来支持和管理其研发…

SpringMvc第四战-【SpringMvc文件上传,下载】

目录 一.SpringMvc文件上传 1.导入依赖&#xff08;在pom.xml中&#xff09; 2.配置文件上传解析器&#xff08;在spring-mvc.xml中&#xff09; 3.前端标记多功能表单&#xff08;构建一个jsp界面来操作&#xff09; 4.将文件写出流&#xff0c;然后写入服务器 5.配置映…

【ccf-csp题解】第1次csp认证-第三题-命令行选项-字符串模拟

题目描述 思路讲解 本题是一个简单的字符串模拟题&#xff0c;这种题目是csp认证第三题的常客 大致思路是用两个bool数组记录某一个选项&#xff08;0--25下标对应小写字母a--z&#xff09;&#xff0c;第一个数组中无参选项为true&#xff0c;第二个数组中有参选项为true&a…

Pandas数据中的浅拷贝与深拷贝

pandas库主要有两种数据结构DataFrames和Series。这些数据结构在内部用索引数组和数据数组表示&#xff0c;索引数组标记数据&#xff0c;数据数组包含实际数据。现在&#xff0c;当我们试图复制这些数据结构&#xff08;DataFrames和Series&#xff09;时&#xff0c;我们实际…

如何使用PySide2将designer设计的ui文件加载到Python类上鼠标拖拽显示路径

应用场景&#xff1a; designer快速设计好UI文件后&#xff0c;需要增加一些特别的界面功能&#xff0c;如文件拖拽显示文件路径功能。 方法如下&#xff1a; from PySide2.QtWidgets import QApplication, QMainWindow from PySide2.QtUiTools import loadUiTypeUi_MainWindo…

Linux:LVS (DR群集搭建)

环境 dr服务器&#xff1a; ens33网络接口ip&#xff1a;192.168.254.4 ens33:0接口&#xff1a;192.168.254.66 web1服务器&#xff1a;ens33ip:192.168.254.1 lo:0接口ip:192.168.254.66 web2服务器&#xff1a;ens33ip:192.168.254.2 lo:0接口ip:192.168.254.66 nfs数据…

web 学习之 超链接文本

前言 HTML中的超链接文本用于创建可点击的链接&#xff0c;允许用户跳转到其他网页、文件或资源。超链接文本通常是可识别的文本或图像&#xff0c;当用户点击它时&#xff0c;浏览器会加载链接指定的目标。在HTML中&#xff0c;超链接文本使用标签&#xff08;anchor标签&…

OPC UA协议基础

C#开发使用参考github地址&#xff1a;GitHub - OPCFoundation/UA-.NETStandard: OPC Unified Architecture .NET Standard 同步到gitee的地址&#xff1a;UA-.NETStandard: github导入&#xff1a;https://github.com/OPCFoundation/UA-.NETStandard 协议参考网站&#xff1…

【23种设计模式】组合模式【⭐】

个人主页&#xff1a;金鳞踏雨 个人简介&#xff1a;大家好&#xff0c;我是金鳞&#xff0c;一个初出茅庐的Java小白 目前状况&#xff1a;22届普通本科毕业生&#xff0c;几经波折了&#xff0c;现在任职于一家国内大型知名日化公司&#xff0c;从事Java开发工作 我的博客&am…