//--------------------------------------------------------------------------- #include #pragma hdrstop #include "setup.h" #include "main.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TsetupF *setupF; //--------------------------------------------------------------------------- __fastcall TsetupF::TsetupF(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TsetupF::Button1Click(TObject *Sender) { String name_prov="SOFTWARE\\Microsoft\\Cryptography\\Defaults\\Provider\\";; String type_prov="SOFTWARE\\Microsoft\\Cryptography\\Defaults\\Provider Types\\Type "; String file_prov; String file_sig; DWORD dwIgn=NULL; HKEY hKey=NULL; DWORD err=NULL; DWORD dwValue=NULL; HANDLE hFileSig=NULL; DWORD NumBytesRead=NULL; DWORD lpdwFileSizeHigh=NULL; LPVOID lpvAddress=NULL; DWORD NumBytes=NULL; bool flag=true; mainF->Memo1->Clear(); if(Edit1->Text!="" && Edit2->Text!="" && Edit3->Text!="" && Edit4->Text!="") { name_prov=name_prov+Edit1->Text; type_prov=type_prov+Edit2->Text; file_sig=OpenDialog1->FileName; file_prov=OpenDialog2->FileName; //Преобразуем из строки в char char* name_prov_char = new char[name_prov.Length()+1]; StrCopy(name_prov_char, name_prov.c_str()); char* file_prov_char = new char[file_prov.Length()+1]; StrCopy(file_prov_char, file_prov.c_str()); char* file_sig_char = new char[file_sig.Length()+1]; StrCopy(file_sig_char, file_sig.c_str()); char* type_prov_char = new char[type_prov.Length()+1]; StrCopy(type_prov_char, type_prov.c_str()); char* CSP_PROV = new char[(Edit1->Text.Length())+1]; StrCopy(CSP_PROV, Edit1->Text.c_str()); if ((hFileSig = CreateFile(file_sig_char,GENERIC_READ, 0, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0)) != INVALID_HANDLE_VALUE) { if (((NumBytes = GetFileSize((HANDLE) hFileSig, &lpdwFileSizeHigh))==0xffffffff) && flag) { CloseHandle(hFileSig); mainF->Memo1->Lines->Add("GetFileSize - bad"); flag=false; } else { mainF->Memo1->Lines->Add("GetFileSize - good"); } if ((lpvAddress = VirtualAlloc(NULL, NumBytes, MEM_RESERVE | MEM_COMMIT,PAGE_READWRITE)) == NULL && flag) { flag=false; CloseHandle(hFileSig); mainF->Memo1->Lines->Add("VirtualAlloc - bad"); } else { mainF->Memo1->Lines->Add("VirtualAlloc - good"); } if ((!ReadFile((HANDLE) hFileSig, lpvAddress, NumBytes,&NumBytesRead, 0))&& flag) { flag=false; CloseHandle(hFileSig); mainF->Memo1->Lines->Add("ReadFile - bad"); VirtualFree(lpvAddress, 0, MEM_RELEASE); } else { mainF->Memo1->Lines->Add("ReadFile - good"); } if(flag) { CloseHandle(hFileSig); } if ((err = RegCreateKeyEx(HKEY_LOCAL_MACHINE,(const char *)name_prov_char,0L, "", REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, NULL, &hKey,&dwIgn)) != ERROR_SUCCESS) { } if ((err = RegSetValueEx(hKey, "Image Path", 0L, REG_SZ, file_prov_char,strlen(file_prov_char)+1)) != ERROR_SUCCESS) { } dwValue = StrToInt(Edit2->Text); if ((err = RegSetValueEx(hKey, "Type", 0L, REG_DWORD,(LPTSTR) &dwValue,sizeof(DWORD))) != ERROR_SUCCESS) { } if ((err = RegSetValueEx(hKey, "Signature", 0L, REG_BINARY,(LPTSTR) lpvAddress,NumBytes)) != ERROR_SUCCESS) { } RegCloseKey(hKey); VirtualFree(lpvAddress, 0, MEM_RELEASE); //тип if ((err = RegCreateKeyEx(HKEY_LOCAL_MACHINE,(const char *) type_prov_char,0L, "", REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, NULL, &hKey,&dwIgn)) != ERROR_SUCCESS) { } if ((err = RegSetValueEx(hKey, "Name", 0L, REG_SZ, CSP_PROV,strlen(CSP_PROV)+1)) != ERROR_SUCCESS) { } } delete [] name_prov_char; delete [] file_prov_char; delete [] file_sig_char; delete [] type_prov_char; delete [] CSP_PROV; } else { ShowMessage("Заполните все поля"); } Close(); } //--------------------------------------------------------------------------- void __fastcall TsetupF::Edit4Click(TObject *Sender) { OpenDialog2->FileName=""; if(OpenDialog2->Execute()) { Edit4->Text=OpenDialog2->FileName; Button1->SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TsetupF::Edit3Click(TObject *Sender) { OpenDialog1->FileName=""; if(OpenDialog1->Execute()) { Edit3->Text=OpenDialog1->FileName; Button1->SetFocus(); } } //---------------------------------------------------------------------------