bool CProperties::SaveToRegistry(HKEY hTopKey,LPCTSTR szRegKey) const { HKEY hKey; CreateKey(szRegKey); bool rc=(ERROR_SUCCESS==RegOpenKeyEx (hTopKey, szRegKey, 0L, KEY_SET_VALUE, &hKey)); if(rc){ for(int i=ar.size()-1;i>=0;--i){ // Initializations are simply to avoid compiler warnings. DWORD dwDatalen=0; DWORD dwType=REG_DWORD; BYTE *Data=0; // strValue and dw *must* be in scope for RegSetValueEx below. DWORD dw; String strValue; const CProperty &p=ar[i]; switch(p.Type){ case CProperties::CProperty::Integer: case CProperties::CProperty::Bool: case CProperties::CProperty::Char: case CProperties::CProperty::Short: dwType=REG_DWORD; dwDatalen=sizeof(DWORD); dw=p.GetValue(); Data=(BYTE *)&dw; break; case CProperties::CProperty::Float: case CProperties::CProperty::Double: case CProperties::CProperty::szString: strValue=p.GetStringValue(); Data=(BYTE *)(LPCTSTR)strValue; dwType=REG_SZ; dwDatalen=(1+strValue.size())*sizeof(_TCHAR); break; case CProperties::CProperty::Void: Data=(BYTE *)p.pData; dwType=REG_BINARY; dwDatalen=p.nLength; break; default: assert(false); break; } rc&=(ERROR_SUCCESS==RegSetValueEx(hKey,p.strName,0,dwType,Data,dwDatalen)); } } RegCloseKey(hKey); return rc; }
void NotificationCenter::SendNotification(const char *notify_name_ptr, boost::shared_ptr<void> data, bool single_thread) const { boost::mutex::scoped_lock lk(observer_list_mtx); boost::shared_ptr<std::string> notify_name; if(notify_name_ptr != NULL) { notify_name.reset(new std::string(notify_name_ptr)); } { std::pair<const_iterator, const_iterator> values = observer_list.equal_range(boost::none); SendNotificationImpl(values.first, values.second, notify_name, data, single_thread); } if(notify_name != NULL) { boost::optional<std::string> key = CreateKey(notify_name_ptr); std::pair<const_iterator, const_iterator> values = observer_list.equal_range(key); SendNotificationImpl(values.first, values.second, notify_name, data, single_thread); } }
LSTATUS APIENTRY RegTree::RegCreateKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition) { RegPath path; if (ResolveKey(hKey, lpSubKey, path)) { RegNode *node = CreateKey(path, lpdwDisposition); if (node != NULL) { *phkResult = node->AsKey(); return ERROR_SUCCESS; } else return ERROR_ACCESS_DENIED; } else return Real_RegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); }
CDR_DATA_STRUCT* CDRCache::MatchCDRSumRow(CDR_DATA_STRUCT *cdr) { char str[1024]; memset(str,'\0', sizeof(str) ); consolidation_key_str(cdr, str); std::string key = CreateKey(str); CDRMAP::iterator pos = _cdrMap.find(key); if(pos != _cdrMap.end() ) { return (pos->second); } return NULL; }
//IniKey function IniKey* IniSection::GetKey(const string& keyName, bool create) { //Go trough the key list and return key with key name KeyItor k_pos; for (k_pos = mKeys.begin(); k_pos != mKeys.end(); k_pos++) { if ( compareNoCase( (*k_pos)->mKey, keyName ) == 0 ) return *k_pos; } if(create) { CreateKey(keyName); return GetKey(keyName, false); } return NULL; }
bool CRegEdit::WriteValue(HKEY hKey, LPCTSTR szSubKey, LPCTSTR szValueName, CString &strValue) { HKEY hSubKey; if (!CreateKey(hKey, szSubKey, hSubKey)) return false; DWORD nLen = (strValue.GetLength()+1)*sizeof(TCHAR); LPBYTE pByte = new BYTE[nLen]; if (pByte == nullptr) return false; memset(pByte, 0, nLen); memcpy_s(pByte, nLen, (LPBYTE)strValue.GetBuffer(), nLen - sizeof(TCHAR)); int nRet = RegSetValueEx(hSubKey, szValueName, 0, REG_SZ, (const LPBYTE)strValue.GetBuffer(), nLen); RegCloseKey(hSubKey); delete[] pByte; if (nRet != ERROR_SUCCESS) return false; return true; }
KeyValues *KeyValues::CreateNewKey(void) { int newID = 1; for (KeyValues *dat = m_pSub; dat != NULL; dat = dat->m_pPeer) { int val = atoi(dat->GetName()); if (newID <= val) { newID = val + 1; } } char buf[12]; Q_snprintf(buf, sizeof(buf), "%d", newID); return CreateKey(buf); }
int decode(std::string file_path, std::string &decode_content) { BYTE init_array[16] = {0}; FILE *data_file = fopen(file_path.c_str(), "rb"); if (data_file == NULL) { return -1; } size_t file_size = get_file_size(data_file); BYTE *file_buffer = new BYTE[file_size]; fread(file_buffer, 1, file_size, data_file); fclose(data_file); //_maxthon3_default_storage_ //Maxthon3_MxCmpUrl_Mood //Maxthon__WebSIteBooster //guestmaxthon3_favdb_txmood //guestmaxthon3_config_txmood //username+maxthon3_favdb_txmood HCRYPTKEY hCryptKey = CreateKey((BYTE *)"guestmaxthon3_favdb_txmood", 0x1a); for (int page_index = 0; page_index < file_size / PAGE_SIZE; page_index++) { DWORD dwPageSize = PAGE_SIZE; BYTE *page_content = &file_buffer[page_index * PAGE_SIZE]; CryptDecrypt(hCryptKey, 0, 1, 0, page_content, &dwPageSize); } FILE *fOut = fopen("maxthon_a.db", "wb"); fwrite(file_buffer, 1, file_size, fOut); decode_content.assign((char *)file_buffer, file_size); fclose(fOut); return 0; }
void RawGenBook::linkEntry(const SWKey *inkey) { TreeKeyIdx *srckey = 0; TreeKeyIdx *key = ((TreeKeyIdx *)&(getTreeKey())); // see if we have a VerseKey * or decendant SWTRY { srckey = SWDYNAMIC_CAST(TreeKeyIdx, inkey); } SWCATCH ( ... ) {} // if we don't have a VerseKey * decendant, create our own if (!srckey) { srckey = (TreeKeyIdx *)CreateKey(); (*srckey) = *inkey; } key->setUserData(srckey->getUserData(), 8); key->save(); if (inkey != srckey) // free our key if we created a VerseKey delete srckey; }
bool StdCompilerConfigWrite::Name(const char *szName) { // Open parent key (if not already done so) CreateKey(); // Push new subkey onto the stack Key *pnKey = new Key(); pnKey->Handle = 0; pnKey->subindex = 0; if (pKey->LastChildName == szName) pnKey->Name.Format("%s%d", szName, (int)++pKey->subindex); else { pnKey->Name = szName; pKey->LastChildName = szName; } pnKey->Parent = pKey; pKey = pnKey; iDepth++; LastString.Clear(); return true; }
void CDRCache::AddToCDRMap(CDR_DATA_STRUCT *cdr, int doConsolTask) { char str[1024]; memset(str,'\0', sizeof(str) ); consolidation_key_str(cdr, str); std::string key = CreateKey(str); CDRMAP::iterator pos = _cdrMap.find(key); if(pos != _cdrMap.end() ) { AddCDRToSUM(pos->second, cdr, doConsolTask); } else { CDR_DATA_STRUCT *ptr = NewCDRData(); // copy data to the new allocated cdr... InitializeSummaryRow(cdr, ptr); _cdrMap.insert(CDRMAP::value_type(key, ptr)); } }
int main(int argc, char* argv[]) { Init(); ULONG Type = 0; ULONG DataLen = 0; CHAR Buffer[0x200]; ZeroMemory( Buffer, sizeof(Buffer) ); for (ULONG i = 0; i < 10000; i++) { BOOL bResult = QueryValue(L"\\registry\\machine\\system\\controlset003\\services\\mup", L"ImagePath", &Type, &DataLen, Buffer, sizeof(Buffer)); printf( "bResult = %d string = %S\n", bResult, Buffer ); } return 0; CreateKey(); printf("\n"); SetValue(); printf("\n"); //--------------------------------------------------------------------------------------------------------- WCHAR RootKey[MAX_REGPATH_LEN]; printf("MACHINE\n"); lstrcpyW(RootKey, L"\\registry\\machine"); EnumRegistry(RootKey, 1); printf("USER\n"); lstrcpyW(RootKey, L"\\registry\\user"); EnumRegistry(RootKey, 1); //--------------------------------------------------------------------------------------------------------- DeInit(); return 0; }
void KeyValues::RecursiveLoadFromBuffer(char const *resourceName, CUtlBuffer &buf) { CKeyErrorContext errorReport(this); bool wasQuoted; CKeyErrorContext errorKey(INVALID_KEY_SYMBOL); while (1) { const char *name = ReadToken(buf, wasQuoted); if (!name) { g_KeyValuesErrorStack.ReportError("RecursiveLoadFromBuffer: got EOF instead of keyname"); break; } if (!*name) { g_KeyValuesErrorStack.ReportError("RecursiveLoadFromBuffer: got empty keyname"); break; } if (*name == '}' && !wasQuoted ) break; KeyValues *dat = CreateKey(name); errorKey.Reset(dat->GetNameSymbol()); const char *value = ReadToken(buf, wasQuoted); if (!value) { g_KeyValuesErrorStack.ReportError("RecursiveLoadFromBuffer: got NULL key"); break; } if (*value == '}' && !wasQuoted) { g_KeyValuesErrorStack.ReportError("RecursiveLoadFromBuffer: got } in key"); break; } if (*value == '{' && !wasQuoted) { errorKey.Reset(INVALID_KEY_SYMBOL); dat->RecursiveLoadFromBuffer(resourceName, buf); } else { if (dat->m_sValue) { delete [] dat->m_sValue; dat->m_sValue = NULL; } int len = Q_strlen(value); char *pIEnd; char *pFEnd; const char *pSEnd = value + len; int ival = strtol(value, &pIEnd, 10); float fval = (float)strtod(value, &pFEnd); if (*value == 0) { dat->m_iDataType = TYPE_STRING; } else if ((18 == len) && (value[0] == '0') && (value[1] == 'x')) { int64 retVal = 0; for (int i = 2; i < 2 + 16; i++) { char digit = value[i]; if (digit >= 'a') digit -= 'a' - ('9' + 1); else if (digit >= 'A') digit -= 'A' - ('9' + 1); retVal = (retVal * 16) + (digit - '0'); } dat->m_sValue = new char [sizeof(uint64)]; *((uint64 *)dat->m_sValue) = retVal; dat->m_iDataType = TYPE_UINT64; } else if ((pFEnd > pIEnd) && (pFEnd == pSEnd)) { dat->m_flValue = fval; dat->m_iDataType = TYPE_FLOAT; } else if (pIEnd == pSEnd) { dat->m_iValue = ival; dat->m_iDataType = TYPE_INT; } else { dat->m_iDataType = TYPE_STRING; } if (dat->m_iDataType == TYPE_STRING) { dat->m_sValue = new char[len + 1]; Q_memcpy(dat->m_sValue, value, len + 1); } } } }
bool NotificationCenter::RemoveObserver(const char *notify_name, observer proc) { boost::optional<std::string> key = CreateKey(notify_name); boost::mutex::scoped_lock lk(observer_list_mtx); std::pair<iterator, iterator> values = observer_list.equal_range(key); return RemoveObserverImpl(values.first, values.second, proc, &observer_list); }
APIRET xprfWriteProfileData(PXINI pXIni, // in: profile opened with xprfOpenProfile const char *pcszApp, // in: application name const char *pcszKey, // in: key name or NULL PVOID pData, // in: data to write or NULL ULONG ulDataLen) // in: sizeof(*pData) or null { APIRET arc = NO_ERROR; if ( (!pXIni) || (memcmp(pXIni->acMagic, XINI_MAGIC_BYTES, sizeof(XINI_MAGIC_BYTES))) ) arc = ERROR_INVALID_PARAMETER; else { // check if application exists PXINIAPPDATA pAppData; if (FindApp(pXIni, pcszApp, &pAppData)) // not found: pAppData = NULL; // now check: does caller want entire application deleted? if (!pcszKey) { // yes, delete application: did we find it? if (pAppData) { // yes: kill that FreeApp(pAppData); // and remove from list lstRemoveItem(&pXIni->llApps, pAppData); // rewrite profile on close pXIni->fDirty = TRUE; } // else application doesn't exist: // nothing to do return NO_ERROR } else { // caller has specified key: // does caller want a key to be deleted? if (!ulDataLen) { // yes: delete key: if (pAppData) { // app exists: FreeKeyIfExists(pXIni, pAppData, (PCHAR)pcszKey); } // else app doesn't even exist: // nothing to do, return NO_ERROR } else { // key and data specified: let's add something... if (!pAppData) // app doesn't exist yet: // create arc = CreateApp(pXIni, pcszApp, &pAppData); if (!arc) { // found or created app: // delete existing key if it exists PXINIKEYDATA pKeyData; FreeKeyIfExists(pXIni, pAppData, (PCHAR)pcszKey); // now create new key if (!(arc = CreateKey(pAppData, pcszKey, (PBYTE)pData, ulDataLen, &pKeyData))) // mark as dirty pXIni->fDirty = TRUE; } } } } return arc; }
int main(int argc, char* argv[]) { if (argc >= 2) { LOGIT = false; PrintLog((DEST,"%s",WindowsName[WhatWindowsVer()])); WinVer(); InitVars(CSP_NAME, &iWinVer, &iCryptVer, &MAXKEYLEN); if (WhatWindowsVer() >= WINXP) CSP_NAME[0] = '\0'; else strcpy(CSP_NAME,MS_ENHANCED_PROV); DebugLog((DEST,"CSP=%s WinVer=%d CryptVer=%d MaxKeyLen=%d",CSP_NAME, iWinVer, iCryptVer, MAXKEYLEN)); iProv = arProv[iProv]; switch(argv[1][1]) // second character of the first parameter -e = 'e' { case 'e': Encrypt(argv[2],argv[3], argv[4]); break; case 'd': Decrypt(argv[2],argv[3], argv[4]); break; case 'k': CreateKey(argv[2], MAXKEYLEN); break; case 'l': ListProviders(); break; case 'x': WriteDebugInfo(); break; case 'v': Version(); break; case 'r': LOGIT = true; DEBUGIT = true; if (argc == 3) DeleteContainer(argv[2]); else DeleteContainer(CTX); LOGIT = false; DEBUGIT = false; break; case 'c': LOGIT = true; DEBUGIT = true; if (argc == 3) CreateContainer(argv[2]); else CreateContainer(CTX); LOGIT = false; DEBUGIT = false; break; default: Usage(); break; } } else Usage(); return(0); }
int WriteDebugInfo () { //do some "crypto stuff" and log the output to a file for debugging const IN_BUFFER_SIZE = 2048; const OUT_BUFFER_SIZE = IN_BUFFER_SIZE + 64; // extra padding HANDLE hKeyFile = 0; BYTE pbBuffer[OUT_BUFFER_SIZE]; BOOL finished = 1; HCRYPTPROV hProvider = 0; HCRYPTKEY hKey = 0, hExchangeKey = 0; DWORD dwByteCount; long rc=0; char * keyFile = "crypto.key"; const char * test = "This is a test..."; char sProgramFiles[KEYFILENAME_SIZE]; ///////////////////////////// DWORD dwMode; BYTE pbData[16]; DWORD dwCount; DWORD i; ////////////////////////////// LOGIT = true; DEBUGIT = true; PrintLog((DEST,"%s",WindowsName[WhatWindowsVer()])); WinVer(); InitVars(CSP_NAME, &iWinVer, &iCryptVer, &MAXKEYLEN); DebugLog((DEST,"CSP=%s WinVer=%d CryptVer=%d MaxKeyLen=%d",CSP_NAME, iWinVer, iCryptVer, MAXKEYLEN)); DebugLog((DEST,"Testing some environment variables.")); GetEnvVar(PROGRAMFILES, sProgramFiles, BufSize); GetEnvVar("temp", sProgramFiles, BufSize); GetEnvVar("path", sProgramFiles, BufSize); CreateKey(keyFile, MAXKEYLEN); DebugLog((DEST,"PrepContext")); PrepContext(iWinVer, &hProvider); hKeyFile = CreateFile(keyFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DebugLog((DEST,"ImportCryptKey")); ImportCryptKey(hProvider, &hKey, hKeyFile); CloseHandle(hKeyFile); //////////////////////////////////////////////////////// // Read the cipher mode. dwCount = sizeof(DWORD); if(!CryptGetKeyParam(hKey, KP_MODE, (BYTE *)&dwMode, &dwCount, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Print out the cipher mode. printf("Default cipher mode: %d\n", dwMode); // Read the salt. dwCount = 16; if(!CryptGetKeyParam(hKey, KP_SALT, pbData, &dwCount, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Print out the initialization vector. printf("Default IV:"); for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]); printf("\n"); // Read the initialization vector. dwCount = 16; if(!CryptGetKeyParam(hKey, KP_IV, pbData, &dwCount, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Print out the initialization vector. printf("Default IV:"); for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]); printf("\n"); // Set the cipher mode. dwMode = CRYPT_MODE_OFB; if(!CryptSetKeyParam(hKey, KP_MODE, (BYTE *)&dwMode, 0)) { printf("Error %x during CryptSetKeyParam!\n", GetLastError()); return 1; } // Read the cipher mode. dwCount = sizeof(DWORD); if(!CryptGetKeyParam(hKey, KP_MODE, (BYTE *)&dwMode, &dwCount, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Print out the cipher mode. printf("Default cipher mode: %d\n", dwMode); dwCount = 16; BYTE pbIV[17]; CryptGenRandom(hProvider, dwCount, pbIV); if(!CryptSetKeyParam(hKey, KP_IV, pbIV, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Read the initialization vector. dwCount = 16; if(!CryptGetKeyParam(hKey, KP_IV, pbData, &dwCount, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Print out the initialization vector. printf("Default IV:"); for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]); printf("\n"); if(!CryptSetKeyParam(hKey, KP_SALT, pbIV, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Read the salt. dwCount = 16; if(!CryptGetKeyParam(hKey, KP_SALT, pbData, &dwCount, 0)) { printf("Error %x during CryptGetKeyParam!\n", GetLastError()); return 1; } // Print out the initialization vector. printf("Default IV:"); for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]); printf("\n"); //////////////////////////////////////////// strcpy((char *)pbBuffer, test); DebugLog((DEST,"%s",(char *)pbBuffer)); dwByteCount = strlen((char *)pbBuffer); rc = CryptEncrypt(hKey, 0, finished, 0, pbBuffer, &dwByteCount, OUT_BUFFER_SIZE); DebugLog((DEST,"Encrypted buffer")); rc = CryptDecrypt(hKey, 0, finished, 0, pbBuffer, &dwByteCount); DebugLog((DEST,"Decrypted buffer")); DebugLog((DEST,"%s",(char *)pbBuffer)); if (strcmp((char *)pbBuffer,test) ==0) { DebugLog((DEST,"Encrypt/Decrypt Succeeded")); } else { DebugLog((DEST,"Encrypt/Decrypt Failed")); } CleanupCryptoKey(hExchangeKey); CleanupCryptoKey(hKey); CleanupCryptoContext(hProvider); DebugLog((DEST,"Listing Providers.")); ListProviders(); return(0); }
STATIC APIRET ReadINI(PXINI pXIni) // in: profile opened with xprfOpenProfile { APIRET arc; FILESTATUS3 fs3; if (!(arc = DosQueryFileInfo(pXIni->hFile, FIL_STANDARD, &fs3, sizeof(fs3)))) { PBYTE pbFileData; if (!(pbFileData = (PBYTE)malloc(fs3.cbFile))) arc = ERROR_NOT_ENOUGH_MEMORY; else { ULONG ulSet = 0; if (!(arc = DosSetFilePtr(pXIni->hFile, 0, FILE_BEGIN, &ulSet))) { ULONG cbRead = 0; if (!(arc = DosRead(pXIni->hFile, pbFileData, fs3.cbFile, &cbRead))) { if (cbRead != fs3.cbFile) arc = ERROR_NO_DATA; else { PINIFILE_HEADER pHeader = (PINIFILE_HEADER)pbFileData; if (pHeader->magic == 0xFFFFFFFF) { ULONG ulAppOfs = pHeader->offFirstApp; // create-applications loop while ((ulAppOfs) && (!arc)) { // application struct PINIFILE_APP pApp = (PINIFILE_APP)(pbFileData + ulAppOfs); ULONG ulKeysOfs = pApp->offFirstKeyInApp; PXINIAPPDATA pIniApp; if (arc = CreateApp(pXIni, (PCHAR)(pbFileData + pApp->offAppName), &pIniApp)) break; // create-keys loop while ((ulKeysOfs) && (!arc)) { PINIFILE_KEY pKey = (PINIFILE_KEY)(pbFileData + ulKeysOfs); PXINIKEYDATA pIniKey; if (arc = CreateKey(pIniApp, (PSZ)(pbFileData + pKey->offKeyName), (PBYTE)(pbFileData + pKey->offKeyData), pKey->lenKeyData, &pIniKey)) break; // next key; can be null ulKeysOfs = pKey->offNextKeyInApp; } // next application; can be null ulAppOfs = pApp->offNextApp; } } } } } free(pbFileData); } } return arc; }
void NotificationCenter::AddObserver(const char *notify_name, observer proc, boost::shared_ptr<void> user_data) { boost::optional<std::string> key = CreateKey(notify_name); boost::tuple<observer, boost::shared_ptr<void> > value = boost::make_tuple<observer, boost::shared_ptr<void> >(proc, user_data); boost::mutex::scoped_lock lk(observer_list_mtx); observer_list.insert(map_value(key, value)); }