📄 mobilecfg.cpp
字号:
// MobileCfg.cpp: implementation of the CMobileCfg class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MobileCfg.h"
#include "AcesCrypt.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#pragma comment(lib, "AcesCrypt.lib")
#else
#pragma comment(lib, "AcesCrypt.lib")
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMobileCfg::CMobileCfg()
{
}
CMobileCfg::~CMobileCfg()
{
}
const unsigned char key[] = {0xd1,0xc0,0x11,0x40,0xa8,0x82,0x0a,0x00};
BOOL CMobileCfg::CreateCfgFile(LPCSTR lpszFile, LPDEVICEINFO lpDevInfo, int nDevInfo, int ver)
{
HANDLE hFile = CreateFile( lpszFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
//AfxMessageBox("创建失败");
return FALSE;
}
DWORD dwVer = ver;
DWORD dwWrite;
WriteFile(hFile, &dwVer, sizeof(DWORD), &dwWrite, NULL);
WriteFile(hFile, &nDevInfo, sizeof(int), &dwWrite, NULL);
int nByte = nDevInfo*sizeof(DEVICEINFO);
LPBYTE lpBuf = new BYTE[nByte*2];
ZeroMemory(lpBuf, 2*nByte);
memcpy(lpBuf, lpDevInfo, nByte);
nByte = ((nByte+8)/8)*8;
int nDes = crypt_encode(lpBuf, nByte, CRYPT_DES, key);
WriteFile(hFile, &nByte, sizeof(int), &dwWrite, NULL);
WriteFile(hFile, lpBuf, nByte, &dwWrite, NULL);
CloseHandle(hFile);
return TRUE;
}
int CMobileCfg::GetCfgFile(LPCSTR lpszFile, LPDEVICEINFO lpDevInfo, int ver)
{
HANDLE hFile = CreateFile( lpszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
//AfxMessageBox("创建失败");
return 0;
}
DWORD dwVer = ver;
DWORD dwRead;
ReadFile(hFile, &dwVer, sizeof(DWORD), &dwRead, NULL);
if(dwVer != 1)
{
}
int iCnt =0;
ReadFile(hFile, &iCnt, sizeof(int), &dwRead, NULL);
if(iCnt != 0 && lpDevInfo)
{
int nByte = 0;
ReadFile(hFile, &nByte, sizeof(int), &dwRead, NULL);
LPBYTE lpBuf = new BYTE[nByte];
ZeroMemory(lpBuf, nByte);
ReadFile(hFile, lpBuf, nByte, &dwRead, NULL);
crypt_decode(lpBuf, nByte, CRYPT_DES, key);
memcpy(lpDevInfo, lpBuf, iCnt*sizeof(DEVICEINFO));
delete lpBuf;
}
CloseHandle(hFile);
return iCnt;
}
BOOL CMobileCfg::CreateBkBmp(LPCSTR lpDst, LPUIINFOIII lpui)
{
HANDLE hFile = CreateFile( lpDst, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
//AfxMessageBox("创建失败");
return FALSE;
}
DWORD dwVer = 3;
DWORD dwWrite;
WriteFile(hFile, &dwVer, sizeof(DWORD), &dwWrite, NULL);
int nByte = ((sizeof(UIINFOIII)+8)/8)*8;
LPBYTE lpDec = new BYTE[nByte];
ZeroMemory(lpDec, nByte);
memcpy(lpDec, lpui, sizeof(UIINFOIII));
crypt_encode(lpDec, nByte, CRYPT_DES, key);
WriteFile(hFile, &nByte, sizeof(int), &dwWrite, NULL);
WriteFile(hFile, lpDec, nByte, &dwWrite, NULL);
delete [] lpDec;
HANDLE hBmpFile = CreateFile( lpui->lpBmpFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hBmpFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return FALSE;
}
DWORD dwBmpSize = GetFileSize( hBmpFile, NULL );
WriteFile(hFile, &dwBmpSize, sizeof(DWORD), &dwWrite, NULL);
nByte = ((dwBmpSize+8)/8)*8;
WriteFile(hFile, &nByte, sizeof(int), &dwWrite, NULL);
BYTE* lpbmp = new BYTE[nByte+1];
ZeroMemory(lpbmp, nByte+1);
DWORD dwRead;
ReadFile(hBmpFile, lpbmp, dwBmpSize, &dwRead, NULL);
CloseHandle(hBmpFile);
int nDes = crypt_encode(lpbmp, nByte, CRYPT_DES, key);
WriteFile(hFile, lpbmp, nByte, &dwWrite, NULL);
delete [] lpbmp;
CloseHandle(hFile);
return TRUE;
}
BOOL CMobileCfg::GetBkBmp(LPCSTR lpUiFile, LPUIINFOIII lpui,char *BmpPath)
{
HANDLE hBmpFile = CreateFile( lpUiFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hBmpFile == INVALID_HANDLE_VALUE)
{
TRACE("%d\n",GetLastError());
return FALSE;
}
DWORD dwBmpSize = 0;
int iDecLen = 0;
int iUISize=0;
DWORD dwVer =0,dwRead;
ReadFile(hBmpFile, &dwVer, sizeof(DWORD), &dwRead, NULL);
ReadFile(hBmpFile, &iUISize, sizeof(int), &dwRead, NULL);
LPBYTE lpDecUi = new BYTE[iUISize+1];
ZeroMemory(lpDecUi, iUISize+1);
ReadFile(hBmpFile, lpDecUi, iUISize, &dwRead, NULL);
crypt_decode(lpDecUi, iUISize, CRYPT_DES, key);
if(dwVer == 1)
{
typedef struct tagUIInfo{
char szCompanyName[56];
POINT CompanyPos;
char szUrl[128];
POINT UrlPos;
union{
LPCSTR lpBmpFile;
HANDLE hBmp;
};
}UIINFO,*LPUIINFO;
LPUIINFO lpuiold = (LPUIINFO)lpDecUi;
lpui->CompanyPos = lpuiold->CompanyPos;
strcpy(lpui->szCompanyName, lpuiold->szCompanyName);
strcpy(lpui->szUrl, lpuiold->szUrl);
lpui->UrlPos = lpuiold->UrlPos;
}else if(dwVer == 2)
{
typedef struct tagUIInfoII{
char szCompanyName[56];
POINT CompanyPos;
char szUrl[128];
POINT UrlPos;
char szEmail[128];
POINT EmailPos;
union{
LPCSTR lpBmpFile;
HANDLE hBmp;
};
}UIINFOII,*LPUIINFOII;
LPUIINFOII lpuiold = (LPUIINFOII)lpDecUi;
lpui->CompanyPos = lpuiold->CompanyPos;
lpui->EmailPos = lpuiold->EmailPos;
lpui->UrlPos = lpuiold->UrlPos;
strcpy(lpui->szEmail, lpuiold->szEmail);
strcpy(lpui->szUrl, lpuiold->szUrl);
strcpy(lpui->szCompanyName, lpuiold->szCompanyName);
}
else{
memcpy(lpui, lpDecUi, sizeof(UIINFOIII));
}
delete [] lpDecUi;
ReadFile(hBmpFile, &dwBmpSize, sizeof(DWORD), &dwRead, NULL);
ReadFile(hBmpFile, &iDecLen, sizeof(int), &dwRead, NULL);
BYTE* lpZip = new BYTE[iDecLen+1];
ZeroMemory(lpZip, iDecLen+1);
ReadFile(hBmpFile, lpZip, iDecLen, &dwRead, NULL);
CloseHandle( hBmpFile);
crypt_decode(lpZip, iDecLen, CRYPT_DES, key);
/////////
char szCurDir[_MAX_PATH];
GetModuleFileName(NULL, szCurDir, _MAX_PATH);
char *p = strrchr(szCurDir, (int)'\\');
if(p == NULL) {
delete [] lpZip;
return FALSE;
}
*(p+1) = 0;
char szTmpBmpFile[_MAX_PATH];
sprintf(szTmpBmpFile, "%s%ld.bmp", szCurDir, time(NULL));
HANDLE hFile = CreateFile(szTmpBmpFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
delete [] lpZip;
return FALSE;
}
DWORD dwWrite;
WriteFile(hFile, lpZip, dwBmpSize, &dwWrite, NULL);
delete [] lpZip;
CloseHandle(hFile);
if(BmpPath)
{
strcpy(BmpPath, szTmpBmpFile);
}else
{
HANDLE phBitmap = LoadImage( NULL, szTmpBmpFile, IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
DeleteFile( szTmpBmpFile );
lpui->hBmp = phBitmap;
}
return TRUE;
}
void CMobileCfg::ReadStringRes(LPCSTR szFile, LPSTRINGRES lpinfo)
{
//read;
HANDLE hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile && hFile != INVALID_HANDLE_VALUE)
{
DWORD dwVer = 0;
DWORD dwRead = 0;
DWORD dwTmp = 0;
ReadFile(hFile, &dwVer, sizeof(DWORD), &dwRead, NULL);
ReadFile(hFile, &dwTmp, sizeof(DWORD), &dwRead, NULL);
//tcmobiledlg_string
if(dwTmp == 1)
{
ReadFile(hFile, &lpinfo->dwMainStringCnt, sizeof(DWORD), &dwRead, NULL);
if(lpinfo->dwMainStringCnt)
lpinfo->g_main_string = new char*[lpinfo->dwMainStringCnt];
}
//button_string
ReadFile(hFile, &dwTmp, sizeof(DWORD), &dwRead, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -