简易解包程序
来源:互联网 发布:汽车钥匙套真皮 淘宝 编辑:程序博客网 时间:2024/06/05 10:41
对压缩包进行解压。
简易压缩程序请参考博客的另外一篇文章:
http://blog.csdn.net/yi_ming_he/article/details/77689405
解包方式:
根据打包建立的索引表,找到对应的文件信息,逐个释放出来即可。
使用方法:
1.可以直接运行UnpacketFiles.exe进行解包,只需要把files.pak文件放入和UnpacketFiles.exe同一级目录即可,生成的文件位于和UnpacketFiles.exe的同一级目录的output文件夹中(如果该文件夹不存在会自动创建)
2.另外一种解包方式是通过指定命令行参数指定打包的文件路径和解包的目录,如下图所示:
UnPacketFiles.h
#pragma onceusing std::fstream;struct MyFileData{ int nOffset;//文件相对于压缩包文件的偏移 int nFileSize;//文件的Size int nFileNameLength;//文件名包含的字符个数 CString strFileName;//文件名 MyFileData() { nOffset = 0; nFileSize = 0; nFileNameLength = 0; }};class CUnPacketFiles{public: CUnPacketFiles(); ~CUnPacketFiles(); void UnPacketFiles(LPCTSTR lpInputFilePath, LPCTSTR lpOutDir);private: void _GetPacketInfo(LPCTSTR lpInputFilePath); void _DoUnPacketFiles(LPCTSTR lpOutDir); void _PathAddBackSlach(CString& strPath);private: int m_nIndexTableSize;//索引表Size int m_nIndexTableElementCount;//索引表包含元素个数 std::vector<MyFileData> m_vecFileData; fstream m_file;};
UnPacketFiles.cpp
#include "stdafx.h"#include "UnPacketFiles.h"CUnPacketFiles::CUnPacketFiles(){ m_nIndexTableSize = 0; m_nIndexTableElementCount = 0; m_vecFileData.clear();}CUnPacketFiles::~CUnPacketFiles(){ m_file.close();}void CUnPacketFiles::UnPacketFiles(LPCTSTR lpInputFilePath, LPCTSTR lpOutDir){ if (NULL == lpInputFilePath || NULL == lpOutDir) return; _GetPacketInfo(lpInputFilePath); _DoUnPacketFiles(lpOutDir);}void CUnPacketFiles::_GetPacketInfo(LPCTSTR lpInputFilePath){ CString strInputFilePath(lpInputFilePath); m_file.open(CW2A(strInputFilePath), std::ios::in | std::ios::binary); m_file.read((char *)&m_nIndexTableSize, sizeof(int)); m_file.read((char *)&m_nIndexTableElementCount, sizeof(int)); for (int i = 0; i < m_nIndexTableElementCount; i++) { MyFileData myFileData; m_file.read((char *)&myFileData.nOffset, sizeof(int)); m_file.read((char *)&myFileData.nFileSize, sizeof(int)); m_file.read((char *)&myFileData.nFileNameLength, sizeof(int)); CStringA strTemp; m_file.read(strTemp.GetBuffer(myFileData.nFileNameLength), myFileData.nFileNameLength); strTemp.ReleaseBuffer(myFileData.nFileNameLength); myFileData.strFileName = CA2W(strTemp); m_vecFileData.push_back(myFileData); }}void CUnPacketFiles::_DoUnPacketFiles(LPCTSTR lpOutDir){ CString strDir(lpOutDir); _PathAddBackSlach(strDir); fstream destFile; for (int i = 0; i < (int)m_vecFileData.size(); ++i) { CString strFilePath = strDir + m_vecFileData[i].strFileName; destFile.open(CW2A(strFilePath), std::ios::out | std::ios::binary); m_file.seekp(m_nIndexTableSize + 4 + m_vecFileData[i].nOffset, std::ios::beg); for (int m = 0; m < m_vecFileData[i].nFileSize; ++m) { destFile.put(m_file.get()); } destFile.close(); }}void CUnPacketFiles::_PathAddBackSlach(CString& strPath){ CString strTemp; strTemp = strPath.Right(1); if (strTemp != _T("\\") && strTemp != _T("/")) strPath.Append(_T("\\"));}
main.cpp
#include "stdafx.h"#include "UnPacketFiles.h"CString GetCurrentModuleDir(){ TCHAR szPath[MAX_PATH + 1] = { 0 }; if (0 == ::GetModuleFileName((HMODULE)&__ImageBase, szPath, MAX_PATH)) return L""; ::PathRemoveFileSpec(szPath); CString strDir = szPath; return strDir;}void CorrectPath(CString& strPath){ strPath.Replace(_T('/'), _T('\\')); do { if (strPath.Find(_T("\\\\")) == -1) break; strPath.Replace(_T("\\\\"), _T("\\")); } while (true);}void PathRemoveFileSpec(CString& strPath){ CorrectPath(strPath); int nPos = strPath.ReverseFind(_T('\\')); if (nPos == -1) { strPath.Empty(); } else { strPath = strPath.Left(nPos); }}BOOL CreateDeepDirectory(LPCTSTR szPath){ BOOL bRetCode = FALSE; CString strPath(szPath); if (GetFileAttributes(szPath) != INVALID_FILE_ATTRIBUTES) return TRUE; bRetCode = ::CreateDirectory(szPath, NULL); if (!bRetCode && ::GetLastError() != ERROR_ALREADY_EXISTS) { PathRemoveFileSpec(strPath); if (strPath.IsEmpty()) return FALSE; bRetCode = CreateDeepDirectory(strPath); if (!bRetCode) return FALSE; bRetCode = ::CreateDirectory(szPath, NULL); if (!bRetCode && ::GetLastError() != ERROR_ALREADY_EXISTS) return FALSE; } return TRUE;}void PathAddBackSlach(CString& strPath){ CString strTemp; strTemp = strPath.Right(1); if (strTemp != _T("\\") && strTemp != _T("/")) strPath.Append(_T("\\"));}int _tmain(int argc, _TCHAR* argv[]){ CString strInputFilePath = GetCurrentModuleDir() + L"\\files.pak"; CString strOutDir = GetCurrentModuleDir() + L"\\output\\"; if (argc == 3) { strInputFilePath = argv[1]; strOutDir = argv[2]; } PathAddBackSlach(strOutDir); CreateDeepDirectory(strOutDir); CUnPacketFiles files; files.UnPacketFiles(strInputFilePath, strOutDir); return 0;}
阅读全文
0 0
- 简易解包程序
- 数据库简易帮助包
- 简易协议帧的基于状态机解包方法
- 简易电子邮件发送程序!
- 简易电梯模拟程序
- 简易远程遥控程序
- 简易万年历程序源码
- 简易的TTS程序
- 简易清理垃圾程序
- NTP简易客户端程序
- Java 简易计算器程序
- 简易局域网聊天室程序
- 简易ping程序
- 简易视频程序
- 简易java签到程序
- 简易的sniffer程序
- 简易tps统计程序
- Android 简易计算器程序
- Unity3D
- mongodb的c++接口说明
- JQuery ui 简单应用
- 缓存击穿
- MongoDB MapReduce 性能提升20倍的优化宝典
- 简易解包程序
- 局部变量和全局变量的作用域的首次理解
- idea2017.2普通web工程将lib包导入到artifact中
- MongoDB配置Sharding (负载均衡)
- OpenGL中glBegin()绘制图形GLenum参数的理解
- 迷宫最短路径 广度优先搜索—C
- 数据脱敏——什么是数据脱敏
- 老生常谈 MongoDB---分片简析
- Python2.7 爬虫实践:豆瓣电影影评分析