判断zip,rar 文件是否加密
来源:互联网 发布:etl算法 编辑:程序博客网 时间:2024/05/17 06:48
// 原创如果引用请注明出处
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
/*
返回值:
-1 : 文件操作出错
0 : 文件未加密
1: 文件加密
*/
int CheckZipFile(const char* aszFileName)
{
HANDLE hFile = CreateFile(aszFileName,
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
std::cout << "read file :" << aszFileName << " error: " << GetLastError() << std::endl;
return -1;
}
DWORD dwReadBytes = 0;
const int kZipMagic = 0x04034b50;
int nZipFlag = 0;
ReadFile(hFile, &nZipFlag, sizeof(nZipFlag), &dwReadBytes, NULL);
if(nZipFlag != kZipMagic)
{
std::cout << "file : " << aszFileName << "is not normal zip file !" << std::endl;
CloseHandle(hFile);
return -1;
}
unsigned short usCheckValue = 0;
ReadFile(hFile, &usCheckValue, sizeof(usCheckValue), &dwReadBytes, NULL);
ReadFile(hFile, &usCheckValue, sizeof(usCheckValue), &dwReadBytes, NULL);
int iEncryptFlag = 0;
if(usCheckValue&0x01)
{
std::cout << "file : " << aszFileName << " is encrypted !" << std::endl;
iEncryptFlag = 1;
}
else
{
std::cout << "file: " << aszFileName << " no encrypted !" << std::endl;
}
CloseHandle(hFile);
return iEncryptFlag;
}
/*
返回值:
-1 : 文件操作出错
0 : 文件未加密
1: 文件加密
*/
int CheckRARFile(const char* aszFileName)
{
HANDLE hFile = CreateFile(aszFileName,
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
std::cout << "read file :" << aszFileName << " error: " << GetLastError() << std::endl;
return -1;
}
DWORD dwReadBytes = 0;
//0x52 0x61 0x72 0x21 0x1a 0x07 0x00
const int kMagicSize = 7;
const char kFileMagic[kMagicSize] = {0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};
char RarFlag[kMagicSize] = {0};
ReadFile(hFile, RarFlag, kMagicSize, &dwReadBytes, NULL);
if(memcmp(kFileMagic, RarFlag, kMagicSize) != 0)
{
std::cout << "read file: " << aszFileName << "is not rar !" << std::endl ;
return -1;
}
char dummy[16] = {0};
ReadFile(hFile, dummy, 16, &dwReadBytes, NULL);
unsigned short usCheckValue = 0;
ReadFile(hFile, &usCheckValue, sizeof(usCheckValue), &dwReadBytes, NULL);
if(usCheckValue&0x04)
{
std::cout << "rar file : " << aszFileName << " is encrypted !" << std::endl;
return 1;
}
else
{
std::cout << "rar file: " << aszFileName << " no encrypted !" << std::endl;
return 0;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
CheckZipFile("d:\\chd\\t1.zip");
CheckZipFile("d:\\chd\\t1x.zip");
CheckRARFile("d:\\chd\\t1.rar");
CheckRARFile("d:\\chd\\t1x.rar");
CheckRARFile("d:\\chd\\t1x.rar");
system("pause");
return 0;
}
阅读全文
0 0
- 判断zip,rar 文件是否加密
- rar和zip文件加密的破解
- 解压zip rar文件
- 图片rar 加密文件
- Java解压ZIP、RAR文件
- java 解压zip、rar文件
- JAVA 解压ZIP RAR文件
- node判断文件是否为加密文件
- <input type="file" >判断上传的文件是zip和rar类型
- Java解压zip和rar文件
- Java 解压zip和rar文件
- linux下打开rar/zip文件
- ubuntu下解压.zip和.rar文件
- 【Codeigniter-Upload类】上传zip/rar文件
- java压缩解压缩rar、zip文件
- linux下解压缩rar、zip文件方法
- Linux下解压.zip和.rar文件
- java 实现解压缩文件(ZIP/rar)
- 【CUGBACM15级BC第1场 B】hdu 4858 项目管理
- [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher L(kmp扩展)
- 2004-2005 Summer Petrozavodsk Camp, Andrew Stankevich Contest 9 (ASC 9)
- iOS-美颜相机 by GPUImage
- Oracle11g创建表空间和用户,并授权
- 判断zip,rar 文件是否加密
- java面试题全集(中)
- 孩子们的游戏(圆圈中最后剩下的数)
- zabbix3.4 监控tomcat多实例(一)
- UGUI新手引导系统
- 1481:Maximum sum(2.6基本算法之动态规划)
- 51Nod-1430-奇偶游戏
- GIT gitk图形界面中文乱码修改
- Java高并发编程(一)