Test.cpp
资源名称:PEPack.rar [点击查看]
上传用户:sdguojin
上传日期:2022-07-31
资源大小:1726k
文件大小:2k
源码类别:
系统编程
开发平台:
Visual C++
- // Test.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "aplib.h"
- #include <windows.h>
- #include <malloc.h>
- #include "PELib.h"
- #pragma comment(lib,"aplib")
- using namespace PELib;
- int testcase1()
- {
- TCHAR szFileName[MAX_PATH] = _T("C:\Documents and Settings\Administrator\桌面\1.txt");
- TCHAR szDstFile[MAX_PATH] = _T("C:\Documents and Settings\Administrator\桌面\pack.txt");
- HANDLE hOpenFile = CreateFile(
- szFileName,
- GENERIC_READ,
- NULL,NULL,
- OPEN_EXISTING,
- NULL,NULL);
- if(hOpenFile == INVALID_HANDLE_VALUE)
- goto Exit0;
- DWORD dwSize = GetFileSize(hOpenFile, NULL);
- LPVOID lpSrc = malloc(dwSize);
- if ( !lpSrc )
- {
- goto Exit0;
- }
- memset(lpSrc, 0, dwSize);
- DWORD dwTempNum = 0;
- ReadFile(hOpenFile, lpSrc, dwSize, &dwTempNum, NULL);
- size_t stSize = aP_workmem_size(dwSize);
- if(!stSize)
- goto Exit0;
- LPVOID lpWork = malloc(stSize);
- if(!lpWork)
- goto Exit0;
- memset(lpWork,0,stSize);
- size_t stDst = aP_max_packed_size(dwSize);
- if( !stDst )
- goto Exit0;
- LPVOID lpDst = malloc(stDst);
- if ( !stDst )
- goto Exit0;
- memset(lpDst, 0, stDst);
- size_t stPack = aP_pack(lpSrc, lpDst, dwSize, lpWork, NULL, NULL);
- if( stPack == APLIB_ERROR )
- goto Exit0;
- HANDLE hDstFile = CreateFile(
- szDstFile,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if( hDstFile == INVALID_HANDLE_VALUE )
- goto Exit0;
- WriteFile(hDstFile, lpDst, stDst, &dwTempNum, NULL);
- Exit0:
- if( hOpenFile )
- CloseHandle(hOpenFile);
- if ( lpSrc )
- free(lpSrc);
- if( lpWork )
- free(lpWork);
- if( lpDst )
- free(lpDst);
- if( hDstFile )
- CloseHandle(hDstFile);
- getchar();
- return 0;
- }
- #pragma comment(lib "BeginPack")
- int testcase2()
- {
- wstring strFileName = L"E:\学习工程\Begin09Pack\Test.exe";
- CPELib pe;
- pe.Init(strFileName);
- return 0;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- testcase2();
- return 0;
- }