123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- #include "stdafx.h"
- #include "AutoRun3.h"
- #include "AutoRun3Dlg.h"
- #include <initguid.h>
- #include <afxsock.h>//<Winsock2.h>
- #include <wincrypt.h>
- #include "DBConfig.h"
- #include "Lzari.h"
- #define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
- #define KEYLENGTH 0x00800000
- #define ENCRYPT_ALGORITHM CALG_RC4
- #define ENCRYPT_BLOCK_SIZE 8
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CDatabase g_db;
- extern CDatabase *g_curdb;
- CString g_server;
- CString g_server2;
- CString g_localip;
- CAutoRun3Dlg *g_pMainWnd=NULL;
- BOOL g_bSendOK=0;
- SENDHEAD g_sendhead;
- #pragma comment(lib, "Shlwapi.lib")
- void MyGetIPByName(CString &name)
- {
- CString strIP=name;
- name.Empty ();
- DWORD dwServerIP=0;
- HOSTENT *host = gethostbyname(strIP);
- struct in_addr addr;
- if (host != NULL)
- {
- for(int i = 0; host-> h_addr_list[i] != NULL; i ++)
- {
- memset(&addr, 0, sizeof(addr));
- memcpy(&addr.S_un.S_addr, host-> h_addr_list[i], host-> h_length);
- dwServerIP = ntohl(addr.S_un.S_addr);
- }
- BYTE* pIP = (BYTE*)&dwServerIP;
- name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
- }
- }
- BEGIN_MESSAGE_MAP(CAutoRun3App, CWinApp)
-
-
-
-
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- CAutoRun3App::CAutoRun3App()
- {
-
-
- }
- CAutoRun3App theApp;
- BOOL CAutoRun3App::InitInstance()
- {
- HANDLE hObject = CreateMutex(NULL,FALSE,_T("CAutoRun3AppXiao"));
- if(GetLastError() == ERROR_ALREADY_EXISTS)
- {
- return false;
- }
- int nResult = Transport_Init();
- if( TRANSPORT_OK != nResult)
- {
- return false;
- }
- g_server="lijiafz.vicp.net" ;
- MyGetIPByName(g_server);
-
-
-
-
- SetRegistryKey(_T("LYFZ-AutoRun3"));
- CAutoRun3Dlg dlg;
- m_pMainWnd = &dlg;
- int nResponse = dlg.DoModal();
- if (nResponse == IDOK)
- {
-
-
- }
- else if (nResponse == IDCANCEL)
- {
-
-
- }
-
-
- return FALSE;
- }
- int CAutoRun3App::ExitInstance()
- {
- return CWinApp::ExitInstance();
- }
- BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword)
- {
- try
- {
- HCRYPTPROV hCryptProv;
- HCRYPTKEY hKey;
- HCRYPTHASH hHash;
- PBYTE pbBuffer;
- DWORD dwBlockLen;
- DWORD dwBufferLen;
- DWORD dwCount;
-
- if(CryptAcquireContext(
- &hCryptProv,
- NULL,
- NULL,
- PROV_RSA_FULL,
- 0))
- {
- printf("A cryptographic provider has been acquired. \n");
- }
- else
- {
- if(CryptAcquireContext(
- &hCryptProv,
- NULL,
- NULL,
- PROV_RSA_FULL,
- CRYPT_NEWKEYSET))
- {
-
- printf("A new key container has been created.\n");
- }
- else
- {
- return 0;
- }
- }
-
-
-
-
-
-
-
- if(CryptCreateHash(
- hCryptProv,
- CALG_MD5,
- 0,
- 0,
- &hHash))
- {
- printf("A hash object has been created. \n");
- }
- else
- {
- return 0;
- }
-
-
- if(CryptHashData(
- hHash,
- (BYTE *)szPassword,
- strlen(szPassword),
- 0))
- {
- printf("The password has been added to the hash. \n");
- }
- else
- {
- return 0;
- }
-
-
- if(CryptDeriveKey(
- hCryptProv,
- ENCRYPT_ALGORITHM,
- hHash,
- KEYLENGTH,
- &hKey))
- {
- printf("An encryption key is derived from the password hash. \n");
- }
- else
- {
- return 0;
- }
-
-
- CryptDestroyHash(hHash);
- hHash = NULL;
-
-
-
-
-
-
- dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
-
-
-
- if(ENCRYPT_BLOCK_SIZE > 1)
- dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE;
- else
- dwBufferLen = dwBlockLen;
- dwCount=dwBufferLen;
-
-
- int count;
-
- count=leng/dwBufferLen;
-
-
- for(int i=0; i<count; i++)
- {
- pbBuffer=buffer+i*dwBufferLen;
-
- if(!CryptEncrypt(
- hKey,
- 0,
- 0,
-
- 0,
- pbBuffer,
- &dwCount,
- dwBufferLen))
- {
- return 0;
- }
- }
- if(leng%dwBlockLen)
- {
- pbBuffer=buffer+i*dwBufferLen;
- dwCount=leng-i*dwBufferLen;
- if(!CryptEncrypt(
- hKey,
- 0,
- TRUE,
-
- 0,
- pbBuffer,
- &dwCount,
- dwBufferLen))
- {
- return 0;
- }
- }
-
-
- if(hKey)
- CryptDestroyKey(hKey);
-
-
- if(hHash)
- CryptDestroyHash(hHash);
-
-
- if(hCryptProv)
- CryptReleaseContext(hCryptProv, 0);
- return(TRUE);
- }
- catch(...)
- {
- }
- }
- extern CArray<CStringArray, CStringArray>g_List1array;
- extern DWORD g_nLeng;
- extern BYTE *g_pData;
- extern CString g_str;
- void DataToArray(CArray<CStringArray, CStringArray>*List1array)
- {
- List1array->RemoveAll ();
- if(g_nLeng==0)return;
- if(g_sendhead.code[0])
- {
- BYTE *lpszOut = NULL;
- int nOutSize = 0;
- LZARI Lzari;
- Lzari.UnCompress(g_pData,g_nLeng,lpszOut,nOutSize);
- CMemFile memfile;
- memfile.Attach (lpszOut,nOutSize);
- Lzari.Release();
- CArchive ar(&memfile, CArchive::load);
- List1array->SetSize(g_sendhead.count[0]);
- for(int ii=0; ii<List1array->GetSize (); ii++)
- {
- List1array->ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- memfile.Detach ();
- }
- else
- {
- CMemFile memfile;
- memfile.Attach (g_pData,g_nLeng);
- CArchive ar(&memfile, CArchive::load);
- List1array->SetSize(g_sendhead.count[0]);
- for(int ii=0; ii<List1array->GetSize (); ii++)
- {
- List1array->ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- memfile.Detach ();
- }
- }
- void DataToArray(CArray<CStringArray, CStringArray>*List1array, CArray<CStringArray, CStringArray>*List2array)
- {
- CArray<CStringArray, CStringArray>*parray[2]={List1array,List2array};
- DWORD bytereads=0;
- for(int i=0; i<2; i++)
- {
- parray[i]->RemoveAll ();if(g_sendhead.length[i]==0)continue;
- if(g_sendhead.code[i])
- {
- BYTE *lpszOut = NULL;
- int nOutSize = 0;
- LZARI Lzari;
- Lzari.UnCompress(g_pData+bytereads,g_sendhead.length[i],lpszOut,nOutSize);
- CMemFile memfile;
- memfile.Attach (lpszOut,nOutSize);
- Lzari.Release();
- bytereads+=g_sendhead.length[i];
- CArchive ar(&memfile, CArchive::load);
- parray[i]->SetSize(g_sendhead.count[i]);
- for(int ii=0; ii<parray[i]->GetSize (); ii++)
- {
- parray[i]->ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- memfile.Detach ();
- }
- else
- {
- CMemFile memfile;
- memfile.Attach (g_pData+bytereads,g_sendhead.length[i]);
- bytereads+=g_sendhead.length[i];
- CArchive ar(&memfile, CArchive::load);
- parray[i]->SetSize(g_sendhead.count[i]);
- for(int ii=0; ii<parray[i]->GetSize (); ii++)
- {
- parray[i]->ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- memfile.Detach ();
- }
- }
- }
|