#include "stdafx.h" #include<windows.h> void Decrypt4k(TCHAR *str) { HANDLE hFile = CreateFile(str, GENERIC_READ|GENERIC_WRITE , 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile==NULL||hFile==INVALID_HANDLE_VALUE) { OutputDebugString(_T("release_con_file CreateFile Error")); return ; } DWORD filesize=4096; char* buffer=new char[4096]; DWORD readsize; ReadFile(hFile,buffer,filesize,&readsize,NULL); for(int i=0;i<4096;i++) { buffer[i]=buffer[i]-1; printf("%d ",buffer[i]); } SetFilePointer(hFile, 0, NULL, FILE_BEGIN); DWORD dw_size; WriteFile(hFile,buffer,filesize,&dw_size,0); delete[] buffer; // 注意是delete[] 而不是 delete CloseHandle(hFile); // 关闭句柄。 } void Encryption4k(TCHAR* str) { HANDLE hFile = CreateFile(str, GENERIC_READ|GENERIC_WRITE , 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile==NULL||hFile==INVALID_HANDLE_VALUE) { OutputDebugString(_T("release_con_file CreateFile Error")); return ; } DWORD filesize=4096; char* buffer=new char[4096]; DWORD readsize; ReadFile(hFile,buffer,filesize,&readsize,NULL); for(int i=0;i<4096;i++) { buffer[i]=buffer[i]+1; printf("%d ",buffer[i]); } SetFilePointer(hFile, 0, NULL, FILE_BEGIN); DWORD dw_size; WriteFile(hFile,buffer,filesize,&dw_size,0); delete[] buffer; // 注意是delete[] 而不是 delete CloseHandle(hFile); // 关闭句柄。 } int _tmain(int argc, _TCHAR* argv[]) { Encryption4k(_T("c:\Test.exe")); return 0; }