示例#1
0
long RegistryRW::GetInfoKey(const HKEY& key ,DWORD & numItems,DWORD & biggestValueSize) const
{
	long ret;

    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
    DWORD    cchClassName = MAX_PATH;  // size of class string 
    DWORD    cValues;              // number of values for key 
    DWORD    maxValueSize; // size of security descriptor 
   

	 ret = RegQueryInfoKey(
        key,                    // key handle 
        achClass,                // buffer for class name 
        &cchClassName,           // size of class string 
        NULL,                    // reserved 
        NULL,               // number of subkeys 
        NULL,            // longest subkey size 
        NULL,            // longest class string 
        &cValues,                // number of values for this key 
        NULL,            // longest value name 
        &maxValueSize,         // longest value data 
	    NULL,			// security descriptor 
        NULL);

	 numItems = cValues;
	 biggestValueSize = maxValueSize;
	 return ret;
}
//------------------------------------------------------------------------------
void EnumPath_local(HKEY hk,char *chk, char*key_before,char *key_after,unsigned int session_id, sqlite3 *db)
{
  HKEY CleTmp;
  if (RegOpenKey(hk,key_before,&CleTmp)!=ERROR_SUCCESS)return;

  DWORD nbSubKey=0,i;
  if (RegQueryInfoKey (CleTmp,NULL,NULL,NULL,&nbSubKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL)!=ERROR_SUCCESS)
  {
    RegCloseKey(CleTmp);
    return;
  }

  char key[MAX_PATH], tmp_key[MAX_PATH];
  DWORD key_size;
  for (i=0;i<nbSubKey && start_scan;i++)
  {
    key[0]    = 0;
    key_size  = MAX_PATH;
    if (RegEnumKeyEx (CleTmp,i,key,(LPDWORD)&key_size,NULL,NULL,NULL,NULL)==ERROR_SUCCESS)
    {
      if (key_after!=NULL)snprintf(tmp_key,MAX_PATH,"%s\\%s\\%s",key_before,key,key_after);
      else snprintf(tmp_key,MAX_PATH,"%s\\%s",key_before,key);
      reg_read_enum_PathValues(hk,chk,tmp_key,session_id,db);
    }
  }
  RegCloseKey(CleTmp);
}
示例#3
0
文件: crypt.c 项目: AmesianX/RosWine
static BOOL FindProvRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszProvName, 
			    DWORD *pcbProvName, DWORD *pdwProvCount)
{
	HKEY hKey;
	HKEY subkey;
	DWORD size = sizeof(DWORD);
	
	if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider", &hKey))
		return FALSE;
	
	RegQueryInfoKey(hKey, NULL, NULL, NULL, pdwProvCount, pcbProvName, 
				 NULL, NULL, NULL, NULL, NULL, NULL);
	(*pcbProvName)++;

	if (!(*pszProvName = LocalAlloc(LMEM_ZEROINIT, *pcbProvName)))
		return FALSE;
	
	RegEnumKeyEx(hKey, dwIndex, *pszProvName, pcbProvName, NULL, NULL, NULL, NULL);
	(*pcbProvName)++;

	RegOpenKey(hKey, *pszProvName, &subkey);
	RegQueryValueEx(subkey, "Type", NULL, NULL, (LPBYTE)pdwProvType, &size);
	
	RegCloseKey(subkey);
	RegCloseKey(hKey);
	
	return TRUE;
}
示例#4
0
bool RegKey::open(HKEY hKey, tstring lpSubKey,REGSAM samDesired,bool createIfNotExists)
{
	if(m_hKeyHandle != NULL) close();
	LONG lResult;
	m_pAccess = samDesired;
	if(createIfNotExists)
		lResult = RegCreateKeyEx(hKey,lpSubKey.c_str(),0,NULL,REG_OPTION_NON_VOLATILE, samDesired, NULL, &m_hKeyHandle, &m_dwDisposition);
	else {
		m_dwDisposition = REG_OPENED_EXISTING_KEY;
		lResult = RegOpenKeyEx(hKey, lpSubKey.c_str(), 0, samDesired, &m_hKeyHandle);
	}
	if(lResult != ERROR_SUCCESS) return false;
	lResult = RegQueryInfoKey(
		m_hKeyHandle,						// key handle 
		REGKEYINFO.achClass,                // buffer for class name 
		&REGKEYINFO.cchClassName,           // size of class string 
		NULL,								// reserved 
		&REGKEYINFO.cSubKeys,               // number of subkeys 
		&REGKEYINFO.cbMaxSubKey,            // longest subkey size 
		&REGKEYINFO.cchMaxClass,            // longest class string 
		&REGKEYINFO.cValues,                // number of values for this key 
		&REGKEYINFO.cchMaxValue,            // longest value name 
		&REGKEYINFO.cbMaxValueData,         // longest value data 
		&REGKEYINFO.cbSecurityDescriptor,   // security descriptor 
		&REGKEYINFO.ftLastWriteTime);       // last write time
	return true;
}
int DeviceManagementNode::getChildrenMaxCount() {
    HKEY key;
    ULONG howMany = 0;

    RegOpenKeyEx(
            HKEY_DM_ROOT,
            fullContext,
            0,
            KEY_READ,
            &key
            );

    if (key == 0) {
        //lastErrorCode = ERR_INVALID_CONTEXT;
        //sprintf(lastErrorMsg, "Invalid context path: %s", fullContext);
        setErrorF(ERR_INVALID_CONTEXT, "Invalid context path: %s", fullContext);

        goto finally;
    }

    RegQueryInfoKey(
            key, NULL, NULL, NULL, &howMany, NULL, NULL, NULL, NULL, NULL, NULL, NULL
            );


finally:

    if (key != 0) {
        RegCloseKey(key);
    }

    return howMany;
}
示例#6
0
bool CTestResource::SaveToRegistry(HKEY key,LPCTSTR psz)
{
  bool rc=false;    
  ENTERCRITICAL;
  // Delete all the keys under "psz"
  HKEY hKey;
  if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){
    TCHAR szName[256];
    DWORD dwSizeName=sizeof szName;
    FILETIME ftLastWriteTime;
    DWORD dwIndex;
    if(ERROR_SUCCESS==RegQueryInfoKey(hKey,0,0,0,&dwIndex,0,0,0,0,0,0,0)){
      while((signed)--dwIndex>=0){
        if(ERROR_SUCCESS!=RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime) ||
          ERROR_SUCCESS!=RegDeleteKey(hKey,szName)){
          rc=false;
        }
        dwSizeName=sizeof szName;
      }
    }
    RegCloseKey(hKey);
  }
  rc=true;
  for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
    CTestResourceProperties prop1(pResource);
    rc&=prop1.SaveToRegistry(key,pResource->FileName());
  }

  LEAVECRITICAL;
  return rc;
}
  std::list<std::wstring> getAllKeys()
  {
    std::list<std::wstring> result;
    HKEY hKey;
    RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY"), 0, KEY_READ, &hKey);

    TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
    DWORD    cbName;                   // size of name string
    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name
    DWORD    cchClassName = MAX_PATH;  // size of class string
    DWORD    cSubKeys=0;               // number of subkeys
    DWORD    cbMaxSubKey;              // longest subkey size
    DWORD    cchMaxClass;              // longest class string
    DWORD    cValues;              // number of values for key
    DWORD    cchMaxValue;          // longest value name
    DWORD    cbMaxValueData;       // longest value data
    DWORD    cbSecurityDescriptor; // size of security descriptor
    FILETIME ftLastWriteTime;      // last write time

    DWORD i, retCode;

    // Get the class name and the value count.
    retCode = RegQueryInfoKey(
          hKey,                    // key handle
          achClass,                // buffer for class name
          &cchClassName,           // size of class string
          NULL,                    // reserved
          &cSubKeys,               // number of subkeys
          &cbMaxSubKey,            // longest subkey size
          &cchMaxClass,            // longest class string
          &cValues,                // number of values for this key
          &cchMaxValue,            // longest value name
          &cbMaxValueData,         // longest value data
          &cbSecurityDescriptor,   // security descriptor
          &ftLastWriteTime);       // last write time

    // Enumerate the subkeys, until RegEnumKeyEx fails.

    if (cSubKeys)
    {
      //std::cout << "Number of subkeys: " << cSubKeys <<std::endl;

      for (i=0; i<cSubKeys; i++)
      {
        cbName = MAX_KEY_LENGTH;
        retCode = RegEnumKeyEx(hKey, i,
                               achKey,
                               &cbName,
                               NULL,
                               NULL,
                               NULL,
                               &ftLastWriteTime);
        if (retCode == ERROR_SUCCESS)
          result.push_back(achKey);
      }
    }
    RegCloseKey(hKey);
    return result;
  }
        void EnumerateSubKeys(HKEY RootKey, char* subKey, unsigned int tabs = 0)
        {
                 HKEY hKey;
                    DWORD cSubKeys;        //Used to store the number of Subkeys
                    DWORD maxSubkeyLen;    //Longest Subkey name length
                    DWORD cValues;        //Used to store the number of Subkeys
                    DWORD maxValueLen;    //Longest Subkey name length
                    DWORD retCode;        //Return values of calls

                 RegOpenKeyEx(RootKey, subKey, 0, KEY_ALL_ACCESS, &hKey);

                    RegQueryInfoKey(hKey,            // key handle
                                    NULL,            // buffer for class name
                                    NULL,            // size of class string
                                    NULL,            // reserved
                                    &cSubKeys,        // number of subkeys
                                    &maxSubkeyLen,    // longest subkey length
                                    NULL,            // longest class string
                                    &cValues,        // number of values for this key
                                    &maxValueLen,    // longest value name
                                    NULL,            // longest value data
                                    NULL,            // security descriptor
                                    NULL);            // last write time

                    if(cSubKeys>0)
                 {
                        char currentSubkey[MAX_PATH];

                        for(int i=0;i < cSubKeys;i++){
                   DWORD currentSubLen=MAX_PATH;

                            retCode=RegEnumKeyEx(hKey,    // Handle to an open/predefined key
                            i,                // Index of the subkey to retrieve.
                            currentSubkey,            // buffer to receives the name of the subkey
                            &currentSubLen,            // size of that buffer
                            NULL,                // Reserved
                            NULL,                // buffer for class string
                            NULL,                // size of that buffer
                            NULL);                // last write time

                            if(retCode==ERROR_SUCCESS)
                   {
                                for (int i = 0; i < tabs; i++)
                                    printf("\t");
                                printf("(%d) %s\n", i+1, currentSubkey);

                                char* subKeyPath = new char[currentSubLen + strlen(subKey)];
                                sprintf(subKeyPath, "%s\\%s", subKey, currentSubkey);
                    EnumerateSubKeys(RootKey, subKeyPath, (tabs + 1));
                   }
                  }
                 }
                    else
                 {
                  EnumerateValues(hKey, cValues);
                 }

                 RegCloseKey(hKey);
        }
示例#9
0
/* delete all subkeys in the given key */
bool
RegDeleteSubKeys (HKEY hKey)
{
  DWORD dwSubKeyCnt, dwMaxSubKey;
  if (RegQueryInfoKey (hKey, NULL, NULL, 0, &dwSubKeyCnt, &dwMaxSubKey,
                         NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
    {
      if (dwSubKeyCnt)
        {
          LPTSTR pszKeyName = (LPTSTR) malloc (dwMaxSubKey += 1);
          if (pszKeyName)
            {
              do
                {
                  if (RegEnumKey (hKey, --dwSubKeyCnt, pszKeyName, dwMaxSubKey) == ERROR_SUCCESS)
                    {
                      HKEY hSubKey = RegOpen (hKey, pszKeyName, KEY_READ | KEY_WRITE);
                      if (hSubKey)
                        {
                          if (RegDeleteSubKeys (hSubKey))
                            {
                              RegClose (hSubKey);
                              if (RegDeleteKey (hKey, pszKeyName) != ERROR_SUCCESS)
                                {
                                  free (pszKeyName);
                                  return false;
                                }
                            }
                          else
                            {
                              RegClose (hSubKey);
                              free (pszKeyName);
                              return false;
                            }
                        }
                      else
                        {
                          free (pszKeyName);
                          return false;
                        }
                    }
                  else
                    {
                      free (pszKeyName);
                      return false;
                    }
                }
              while (dwSubKeyCnt);
              free (pszKeyName);
            }
          else
            {
              return false;
            }
        }
      return true;
    }
  return false;
}
示例#10
0
void GetRegistryChanges(HKEY hKey) 
{ 
    TCHAR    szKey[MAX_KEY_LENGTH];  
    DWORD    cbName;                  
    DWORD    cSubKeys=0;                    
    FILETIME ftWrite;      
    DWORD    i, ret; 
	HKEY     hNewKey;
	ULARGE_INTEGER tmWrite;
	TCHAR    szName[MAX_KEY_LENGTH];
 
    // get the number of subkeys 
    ret = RegQueryInfoKey(		// WinReg.h
        hKey,                   
        NULL, NULL, NULL,               
        &cSubKeys,              
        NULL, NULL, NULL, NULL, 
		NULL, NULL, NULL);      
    
    // for each subkey, see if it changed based on its
    // last write timestamp
    for (i=0; i<cSubKeys; i++) 
    { 
        cbName = MAX_KEY_LENGTH;

        ret = RegEnumKeyEx(		// WinReg.h
					hKey, i, szKey, &cbName, 
					NULL, NULL, NULL, &ftWrite); 

        if (ret == ERROR_SUCCESS) 
        {
			tmWrite.HighPart = ftWrite.dwHighDateTime;
			tmWrite.LowPart  = ftWrite.dwLowDateTime;

            // it changed if the last write is greater than 
            // our start time
			if (tmWrite.QuadPart > g_tmStart.QuadPart)
			{
				memset(szName, 0, sizeof(szName));
				GetKeyName(hKey, szName);

				_tcscat(szName, _T("\\"));	// 문자열 추가 strcat_s
				_tcscat(szName, szKey);
				
				if (!IsWhitelisted(szName)) { 
					Output(FOREGROUND_BLUE, _T("[REGISTRY] %s\n"), szName);
				}
			}

			ret = RegOpenKeyEx(hKey, szKey, 0, KEY_READ, &hNewKey);

			if (ret == ERROR_SUCCESS) 
			{ 
				GetRegistryChanges(hNewKey);
				RegCloseKey(hNewKey);
			}
		}
    }
}
示例#11
0
static BOOL
fix_value_result(RegPort* rp, LONG result, DWORD type,
		 LPSTR name, DWORD nameSize, LPSTR value, DWORD valueSize)
{
    if (result == ERROR_MORE_DATA) {
	DWORD max_name1;
	DWORD max_name2;
	DWORD max_value;
	int ok;

	ok = RegQueryInfoKey(rp->hkey, NULL, NULL, NULL,
			     NULL, &max_name1, NULL, NULL, &max_name2,
			     &max_value, NULL, NULL);
#ifdef DEBUG
	if (ok != ERROR_SUCCESS) {
	    char buff[256];
	    sprintf(buff,"Failure in registry_drv line %d, error = %d",
		    __LINE__, GetLastError());
	    MessageBox(NULL, buff, "Internal error", MB_OK);
	    ASSERT(ok == ERROR_SUCCESS);
	}
#endif
	rp->name_buf_size = (max_name1 > max_name2 ? max_name1 : max_name2) 
	    + 1;
	rp->value_buf_size = max_value + 1;
	rp->name_buf = driver_realloc(rp->name_buf, rp->name_buf_size);
	rp->value_buf = driver_realloc(rp->value_buf, rp->value_buf_size);
	return FALSE;
    } else if (result != ERROR_SUCCESS) {
	reply(rp, result);
	return TRUE;
    }
  
    /*
     * Do some data conversion which is easier to do here
     * than in Erlang.
     */

    switch (type) {
    case REG_SZ:
    case REG_EXPAND_SZ:
	valueSize--;		/* No reason to send the '\0' to Erlang. */
	break;
    case REG_DWORD_LITTLE_ENDIAN:
    case REG_DWORD_BIG_ENDIAN:
	/*
	 * The value is a DWORD stored in host byte order.
	 * We must retrieve it and store it in network byte order.
	 */
	{
	    DWORD dword = * ((DWORD *) value);
	    put_int32(dword, value);
	    type = REG_DWORD;	/* Simplify life for Erlang code. */
	    break;
	}
    }

    return value_reply(rp, type, name, nameSize, value, valueSize);
}
示例#12
0
文件: crypt.c 项目: Fredz66/wine
static BOOL FindProvTypesRegVals(DWORD *pdwIndex, DWORD *pdwProvType, LPSTR *pszTypeName,
				 DWORD *pcbTypeName, DWORD *pdwTypeCount)
{
	HKEY hKey;
	HKEY hSubKey;
	PSTR ch;
	LPSTR szName;
	DWORD cbName;
	BOOL ret = FALSE;

	if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey))
		return FALSE;

	if (RegQueryInfoKey(hKey, NULL, NULL, NULL, pdwTypeCount, &cbName, NULL,
			NULL, NULL, NULL, NULL, NULL))
		goto cleanup;
	cbName++;

	if (!(szName = LocalAlloc(LMEM_ZEROINIT, cbName)))
		goto cleanup;

	while (!RegEnumKeyEx(hKey, *pdwIndex, szName, &cbName, NULL, NULL, NULL, NULL))
	{
		cbName++;
		ch = szName + strlen(szName);
		/* Convert "Type 000" to 0, etc/ */
		*pdwProvType = *(--ch) - '0';
		*pdwProvType += (*(--ch) - '0') * 10;
		*pdwProvType += (*(--ch) - '0') * 100;

		if (RegOpenKey(hKey, szName, &hSubKey))
			break;

		if (!RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, NULL, pcbTypeName))
		{
			if (!(*pszTypeName = LocalAlloc(LMEM_ZEROINIT, *pcbTypeName)))
				break;

			if (!RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, (LPBYTE)*pszTypeName, pcbTypeName))
			{
				ret = TRUE;
				break;
			}

			LocalFree(*pszTypeName);
		}

		RegCloseKey(hSubKey);

		(*pdwIndex)++;
	}
	RegCloseKey(hSubKey);
	LocalFree(szName);

cleanup:
	RegCloseKey(hKey);

	return ret;
}
示例#13
0
bool TRegistry::GetKeyInfo(TRegKeyInfo & Value) const
{
  ClearStruct(Value);
  bool Result = RegQueryInfoKey(GetCurrentKey(), nullptr, nullptr, nullptr, &Value.NumSubKeys,
    &Value.MaxSubKeyLen, nullptr, &Value.NumValues, &Value.MaxValueLen,
    &Value.MaxDataLen, nullptr, &Value.FileTime) == ERROR_SUCCESS;
  return Result;
}
示例#14
0
static void get_child_count(HKEY key, DWORD* count, DWORD* largest_subkey)
{
  if(RegQueryInfoKey(key, NULL, NULL, NULL, count, largest_subkey, NULL, NULL,
    NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
  {
    *count = 0;
    *largest_subkey = 0;
  }
}
示例#15
0
static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildSpec spec)
{
    QStringList result;
    DWORD numKeys;
    DWORD maxKeySize;
    DWORD numSubgroups;
    DWORD maxSubgroupSize;

    // Find the number of keys and subgroups, as well as the max of their lengths.
    LONG res = RegQueryInfoKey(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
                               &numKeys, &maxKeySize, 0, 0, 0);

    if (res != ERROR_SUCCESS) {
        qWarning("QSettings: RegQueryInfoKey() failed: %s", errorCodeToString(res).toLatin1().data());
        return result;
    }

    ++maxSubgroupSize;
    ++maxKeySize;

    int n;
    int m;
    if (spec == QSettingsPrivate::ChildKeys) {
        n = numKeys;
        m = maxKeySize;
    } else {
        n = numSubgroups;
        m = maxSubgroupSize;
    }

    /* The size does not include the terminating null character. */
    ++m;

    // Get the list
    QByteArray buff(m * sizeof(wchar_t), 0);
    for (int i = 0; i < n; ++i) {
        QString item;
        DWORD l = buff.size() / sizeof(wchar_t);
        if (spec == QSettingsPrivate::ChildKeys) {
            res = RegEnumValue(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
        } else {
            res = RegEnumKeyEx(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
        }
        if (res == ERROR_SUCCESS)
            item = QString::fromWCharArray((const wchar_t *)buff.constData(), l);

        if (res != ERROR_SUCCESS) {
            qWarning("QSettings: RegEnumValue failed: %s", errorCodeToString(res).toLatin1().data());
            continue;
        }
        if (item.isEmpty())
            item = QLatin1String(".");
        result.append(item);
    }
    return result;
}
示例#16
0
/* helper function to start enumeration of names */
static int startNameEnumeration(JNIEnv* env, jobject this_obj, jclass this_class)
{  
   jfieldID id_index;
   jfieldID id_count;
   jfieldID id_root;
   jfieldID id_path;
   jfieldID id_hkey;
   jfieldID id_maxsize;

   HKEY root;
   jstring path;
   const char* cpath;
   HKEY hkey;
   DWORD maxsize = 0;
   DWORD count = 0;

   /* get the field IDs */
   id_root = (*env)->GetFieldID(env, this_class, "root", "I");
   id_path = (*env)->GetFieldID(env, this_class, "path", "Ljava/lang/String;");
   id_hkey = (*env)->GetFieldID(env, this_class, "hkey", "I");
   id_maxsize = (*env)->GetFieldID(env, this_class, "maxsize", "I");
   id_index = (*env)->GetFieldID(env, this_class, "index", "I");
   id_count = (*env)->GetFieldID(env, this_class, "count", "I");

   /* get the field values */
   root = (HKEY)(*env)->GetIntField(env, this_obj, id_root);
   path = (jstring)(*env)->GetObjectField(env, this_obj, id_path);
   cpath = (*env)->GetStringUTFChars(env, path, NULL);

   /* open the registry key */
   if (RegOpenKeyEx(root, cpath, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
   {  
      (*env)->ThrowNew(env, (*env)->FindClass(env, "Win32RegKeyException"),
         "Open key failed");
      (*env)->ReleaseStringUTFChars(env, path, cpath);
      return -1;
   }
   (*env)->ReleaseStringUTFChars(env, path, cpath);

   /* query count and max length of names */
   if (RegQueryInfoKey(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &count, &maxsize, 
          NULL, NULL, NULL) != ERROR_SUCCESS)
   {  
      (*env)->ThrowNew(env, (*env)->FindClass(env, "Win32RegKeyException"),
         "Query info key failed");
      RegCloseKey(hkey);
      return -1;
   }

   /* set the field values */
   (*env)->SetIntField(env, this_obj, id_hkey, (DWORD) hkey);
   (*env)->SetIntField(env, this_obj, id_maxsize, maxsize + 1);
   (*env)->SetIntField(env, this_obj, id_index, 0);
   (*env)->SetIntField(env, this_obj, id_count, count);
   return count;
}
示例#17
0
std::vector<std::wstring> c_tun_device_windows::get_subkeys(HKEY hKey) {
	TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
	DWORD    cbName;                   // size of name string
	TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name
	DWORD    cchClassName = MAX_PATH;  // size of class string
	DWORD    cSubKeys = 0;               // number of subkeys
	DWORD    cbMaxSubKey;              // longest subkey size
	DWORD    cchMaxClass;              // longest class string
	DWORD    cValues;              // number of values for key
	DWORD    cchMaxValue;          // longest value name
	DWORD    cbMaxValueData;       // longest value data
	DWORD    cbSecurityDescriptor; // size of security descriptor
	FILETIME ftLastWriteTime;      // last write time
	DWORD retCode;
	std::vector<std::wstring> ret;
	TCHAR  achValue[MAX_VALUE_NAME];
	DWORD cchValue = MAX_VALUE_NAME;

	// Get the class name and the value count.
	_fact("Query windows registry for infokeys");
	retCode = RegQueryInfoKey(
		hKey,                    // key handle
		achClass,                // buffer for class name
		&cchClassName,           // size of class string
		nullptr,                 // reserved
		&cSubKeys,               // number of subkeys
		&cbMaxSubKey,            // longest subkey size
		&cchMaxClass,            // longest class string
		&cValues,                // number of values for this key
		&cchMaxValue,            // longest value name
		&cbMaxValueData,         // longest value data
		&cbSecurityDescriptor,   // security descriptor
		&ftLastWriteTime);       // last write time
								 // Enumerate the subkeys, until RegEnumKeyEx fails.
	if (retCode != ERROR_SUCCESS) throw std::runtime_error("RegQueryInfoKey error, error code " + std::to_string(GetLastError()));
	if (cSubKeys > 0) {
		_fact("Number of subkeys: " << cSubKeys);

		for (DWORD i = 0; i < cSubKeys; i++) {
			_dbg1("Add subkey " << i);
			cbName = MAX_KEY_LENGTH;
			retCode = RegEnumKeyEx(hKey, i,
				achKey,
				&cbName,
				nullptr,
				nullptr,
				nullptr,
				&ftLastWriteTime);
			if (retCode == ERROR_SUCCESS) {
				ret.emplace_back(std::wstring(achKey)); // Exception safety: strong guarantee (23.3.6.5, std::wstring is no-throw moveable 21.4.2)
			}
		}
	}
	return ret;
}
示例#18
0
文件: io_winapi.c 项目: kebkal/evins
int io_enumerate(char *buf, size_t len) {
    HKEY SERIALCOMM;
    TCHAR *name = NULL;
    BYTE *value = NULL;
    size_t d_len;

    buf[0] = '\0';
    len -= 1;

    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &SERIALCOMM) == ERROR_SUCCESS) {
        DWORD maxNameLen, maxValueLen, queryInfo;

        if ((queryInfo = RegQueryInfoKey(SERIALCOMM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &maxNameLen, &maxValueLen, NULL, NULL)) == ERROR_SUCCESS) {
            DWORD nameLen = maxNameLen + 1, nameSize = nameLen * sizeof(TCHAR),
                  valueLen = maxValueLen / sizeof(TCHAR) + 1, valueSize = valueLen * sizeof(TCHAR);

            if ((name = (TCHAR *)malloc(nameSize)) && (value = (BYTE *)malloc(valueSize))) {
                DWORD idx = 0, type, nameWritten = nameLen, valueWritten = valueSize;
                DWORD nEnum;

                memset(name, '\0', nameSize);
                memset(value, '\0', valueSize);

                while ((nEnum = RegEnumValue(SERIALCOMM, idx++, name, &nameWritten, NULL, &type, value, &valueWritten)) == ERROR_SUCCESS) {
                    if (type == REG_SZ) {
                        if (len < (d_len = strlen((char *)value) + (buf[0] ? 1 : 0)))
                            break;

                        if (buf[0])
                            strcat(buf, ",");

                        strcat(buf, (char *)value);

                        len -= d_len;
                        buf += d_len - 1; // leave last non-zero byte
                    }

                    memset(name, '\0', nameWritten);
                    memset(value, '\0', valueWritten);

                    nameWritten = nameLen;
                    valueWritten = valueSize;
                }
            } else
                return -1;
        } else
            return -1;

        RegCloseKey(SERIALCOMM);
    }

    free(name);
    free(value);
    return 0;
}
示例#19
0
long cm_EnumerateCellRegistry(afs_uint32 client, cm_enumCellProc_t *procp, void *rockp)
{
    HKEY hkCellServDB = 0;
    DWORD dwSize;
    DWORD dwCells;
    DWORD dwIndex;
    LONG code;
    FILETIME ftLastWriteTime;
    char szCellName[CELL_MAXNAMELEN];

    /* No server CellServDB in the registry. */
    if (!client || procp == NULL)
        return 0;

    if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                      AFSREG_CLT_OPENAFS_SUBKEY "\\CellServDB",
                      0,
                      KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
                      &hkCellServDB) != ERROR_SUCCESS)
        return 0;

    code = RegQueryInfoKey( hkCellServDB,
                            NULL,  /* lpClass */
                            NULL,  /* lpcClass */
                            NULL,  /* lpReserved */
                            &dwCells,  /* lpcSubKeys */
                            NULL,  /* lpcMaxSubKeyLen */
                            NULL,  /* lpcMaxClassLen */
                            NULL,  /* lpcValues */
                            NULL,  /* lpcMaxValueNameLen */
                            NULL,  /* lpcMaxValueLen */
                            NULL,  /* lpcbSecurityDescriptor */
                            &ftLastWriteTime /* lpftLastWriteTime */
                            );
    if (code != ERROR_SUCCESS)
        dwCells = 0;

    /* 
     * Enumerate each Cell and 
     */
    for ( dwIndex = 0; dwIndex < dwCells; dwIndex++ ) {
        dwSize = CELL_MAXNAMELEN;
        code = RegEnumKeyEx( hkCellServDB, dwIndex, szCellName, &dwSize, NULL, 
                             NULL, NULL, &ftLastWriteTime);
        if (code != ERROR_SUCCESS)
            continue;
        szCellName[CELL_MAXNAMELEN-1] = '\0';
        strlwr(szCellName);

        (*procp)(rockp, szCellName);
    }

    RegCloseKey(hkCellServDB);
    return 0;
}
示例#20
0
static SshRegSize
ssh_registry_platform_get_key_info(SshRegKey key,
                                   SshRegKeyQueryType query_type)
{
  SshRegSize ret_value = 0;
  LPDWORD subkeys_ptr = NULL;
  LPDWORD values_ptr = NULL;
  LPDWORD subkey_len_ptr = NULL;
  LPDWORD value_len_ptr = NULL;
  LPDWORD data_len_ptr = NULL;

  switch (query_type)
    {
      case SSH_REG_KEY_INFO_SUBKEYS:
        subkeys_ptr = &ret_value;
        break;

      case SSH_REG_KEY_INFO_SUBKEY_SIZE:
        subkey_len_ptr = &ret_value;
        break;

      case SSH_REG_KEY_INFO_VALUES:
        values_ptr = &ret_value;
        break;

      case SSH_REG_KEY_INFO_VALUE_SIZE:
        value_len_ptr = &ret_value;
        break;
  
      case SSH_REG_KEY_INFO_DATA_SIZE:
        data_len_ptr = &ret_value;
        break;

      default:
        SSH_NOTREACHED;
        break;
    }

  if (RegQueryInfoKey(key, NULL, NULL, NULL, 
                      subkeys_ptr, subkey_len_ptr, 
                      NULL, values_ptr, value_len_ptr, 
                      data_len_ptr, NULL, NULL) == ERROR_SUCCESS)
    {
      switch (query_type)
        {
          case SSH_REG_KEY_INFO_SUBKEY_SIZE:
          case SSH_REG_KEY_INFO_VALUE_SIZE:
          case SSH_REG_KEY_INFO_DATA_SIZE: 
            ret_value += sizeof(TCHAR); /* Space for terminating NULL */ 
            break;
        }
    }

  return (ret_value);
}
示例#21
0
static INT
PrintAllAssociations()
{
    DWORD return_val = 0;
    HKEY hKey = NULL;
    DWORD numKeys = 0;

    DWORD extLength = 0;
    LPTSTR extName = NULL;
    DWORD keyCtr = 0;

    return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);

    if (return_val != ERROR_SUCCESS)
    {
        RegCloseKey(hKey);
        return -1;
    }

    return_val = RegQueryInfoKey(hKey, NULL, NULL, NULL, &numKeys, &extLength, NULL, NULL, NULL, NULL, NULL, NULL);

    if (return_val != ERROR_SUCCESS)
    {
        RegCloseKey(hKey);
        return -2;
    }

    extLength++;
    extName = cmd_alloc(extLength * sizeof(TCHAR));

    for(keyCtr = 0; keyCtr < numKeys; keyCtr++)
    {
        DWORD buffer_size = extLength;
        return_val = RegEnumKeyEx(hKey, keyCtr, extName, &buffer_size, NULL, NULL, NULL, NULL);

        if (return_val == ERROR_SUCCESS || return_val == ERROR_MORE_DATA)
        {
            if (*extName == _T('.'))
                PrintAssociation(extName);
        }
        else
        {
            cmd_free(extName);
            RegCloseKey(hKey);
            return -1;
        }
    }

    RegCloseKey(hKey);

    if (extName)
        cmd_free(extName);

    return numKeys;
}
示例#22
0
void WriteDriveMappings (PDRIVEMAPLIST pList)
{
    HKEY hkMappings;
    RegCreateKeyEx( HKEY_CURRENT_USER,
                    cszSECTION_MAPPINGS,
                    0,
                    "AFS",
                    REG_OPTION_NON_VOLATILE,
                    KEY_READ|KEY_QUERY_VALUE|KEY_WRITE,
                    NULL,
                    &hkMappings,
                    NULL );

    DWORD dwMappings;
    RegQueryInfoKey( hkMappings,
                     NULL,  /* lpClass */
                     NULL,  /* lpcClass */
                     NULL,  /* lpReserved */
                     NULL,  /* lpcSubKeys */
                     NULL,  /* lpcMaxSubKeyLen */
                     NULL,  /* lpcMaxClassLen */
                     &dwMappings, /* lpcValues */
                     NULL,  /* lpcMaxValueNameLen */
                     NULL,  /* lpcMaxValueLen */
                     NULL,  /* lpcbSecurityDescriptor */
                     NULL   /* lpftLastWriteTime */
                     );

    if ( dwMappings > 0 ) {
        for ( long dwIndex = dwMappings - 1; dwIndex >= 0; dwIndex-- ) {
            TCHAR drive[MAX_PATH];
            DWORD driveLen = MAX_PATH;

            RegEnumValue( hkMappings, dwIndex, drive, &driveLen, NULL, NULL, NULL, NULL);
            RegDeleteValue( hkMappings, drive );
        }
    }

   for (size_t iDrive = 0; iDrive < 26; ++iDrive)
   {
       if (pList->aDriveMap[iDrive].szMapping[0] != TEXT('\0'))
       {
           TCHAR szLHS[] = TEXT("*");
           szLHS[0] = pList->aDriveMap[iDrive].chDrive;

           TCHAR szRHS[MAX_PATH];
           AdjustAfsPath (szRHS, pList->aDriveMap[iDrive].szMapping, TRUE, TRUE);
           if (!pList->aDriveMap[iDrive].fPersistent)
               lstrcat (szRHS, TEXT("*"));

           RegSetValueEx( hkMappings, szLHS, 0, REG_EXPAND_SZ, (const BYTE *)szRHS, lstrlen(szRHS) + 1);
       }
   }
   RegCloseKey( hkMappings );
}
示例#23
0
int Registry(int isitget, const char *keyName, char *ItemName, char *buffer, char *errstr)
{
	bool done(false);
    char achClass[MAX_PATH], achValue[MAX_VALUE_NAME];
    DWORD  cchClassName(MAX_PATH), cSubKeys(0), cbMaxSubKey, cchMaxClass, cValues, cchMaxValue, cbMaxValueData, cbSecurityDescriptor, cchValue(MAX_VALUE_NAME);
	DWORD  retCode, i;
    FILETIME ftLastWriteTime;      // last write time 

	HKEY key;
	DWORD dw(0), dwres, dwType, cbData(MAX_PATH);
	BYTE btdata[MAX_PATH];
	achClass[0]='\0'; 

	LONG ln = RegCreateKeyEx( HKEY_CURRENT_USER, keyName, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, &dwres);
	if (!isitget) // Set values in the registry 
	{
		if (RegSetValueEx(key, ItemName, 0, REG_SZ, (const BYTE*)&buffer[0], (DWORD)strlen(buffer))!=ERROR_SUCCESS)
		{	strcpy(errstr,"error on RegSetValueEx()"); return 0;  }
	}
	else // Get values from the registry 
	{
		if (dwres==REG_CREATED_NEW_KEY)
		{	strcpy(errstr,"The registry key does not exist (just created now)"); return 0; }
		else if (dwres==REG_OPENED_EXISTING_KEY)
		{
			retCode = RegQueryInfoKey(key, achClass, &cchClassName, NULL,
				&cSubKeys, &cbMaxSubKey, &cchMaxClass, &cValues, &cchMaxValue, 
				&cbMaxValueData, &cbSecurityDescriptor, &ftLastWriteTime);
			if (cValues) 
			{
				for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++) 
				{ 
					achValue[0] = '\0'; 
					cchValue = cbData = MAX_PATH;
					retCode = RegEnumValue(key, i, achValue, &cchValue, NULL, &dwType, btdata, &cbData);
					if (retCode == ERROR_SUCCESS) 
					{ 
						if (!strcmp(achValue,ItemName))
						{
							done = true;
							strcpy(buffer, (LPCSTR)btdata);
						}
					}
					else
					{   strcpy(errstr,"error on RegEnumValue()"); return 0;    }
				}
				if (!done)  { sprintf(errstr,"The registry key item %s does not exist.",ItemName ); return 0; }
			}
			else
			{	sprintf(errstr,"No key associated with %s found.", keyName); return 0; }
		}
	}
	RegCloseKey(key);
	return 1;
}
示例#24
0
int main()
{
    // there we go
    LoadLibrary("../cuckoomon.dll");

    FILE *fp = fopen("test-hello", "r");
    if(fp != NULL) fclose(fp);

    fp = fopen("test-hello", "wb");
    fwrite("whatsup", 1, 6, fp);
    fclose(fp);

    fp = fopen("test-hello", "rb");
    char buf[6];
    fread(buf, 1, 6, fp);
    fclose(fp);

    _mkdir("abc");

    DeleteFile("test-hello");

    HKEY hKey;
    if(RegCreateKeyEx(HKEY_CURRENT_USER,
            "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0,
            KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS) {
        RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
            NULL, NULL, NULL);
        RegSetValueEx(hKey, "TestApiHooks", 0, REG_SZ, (BYTE *) "Hoi", 3);
        RegDeleteValue(hKey, "TestApiHooks");
        RegCloseKey(hKey);
    }

    system("echo hai");

    WinExec("echo hi there", SW_SHOW);

    CreateMutex(NULL, FALSE, "MutexNam3");
    OpenMutex(MUTEX_ALL_ACCESS, FALSE, "OpenMutexName");

    // just some random dll
    LoadLibrary("urlmon.dll");

    FARPROC sleep = GetProcAddress(GetModuleHandle("kernel32"), "Sleep");
    sleep(1000);

    printf("debugger: %d\n", IsDebuggerPresent());

    CloseHandle(CreateThread(NULL, 0, &dummy, NULL, 0, NULL));

    HANDLE thread_handle = CreateRemoteThread(GetCurrentProcess(), NULL, 0,
        &dummy, NULL, 0, NULL);
    WaitForSingleObject(thread_handle, INFINITE);
    CloseHandle(thread_handle);
}
示例#25
0
文件: utils.c 项目: oeli/yafra
/************************************************************
 * IPC get the local hostname
 *
 * retreives the hostname of the current machine resp. the
 * local hostname. Under Windows NT it's getting it from the
 * registry settings from the TCP/IP DNS configuration, cause of
 * some problems with Exceed or other gethostbyname problems.
 * You can specify if you need only hostname or FQDN with aFlag.
 * aFlag == 0 means only hostname and aFlag == 1 means FQDN.
 *
 * returns     int as an error code
 *
 * library:    libpsipc.a
 *
 * copyright:  Yafra.org, Switzerland, 1997
 *
 * author:     Administrator
 **************************************************************/
PS_DLLAPI int PSIPCgetHostname(char *aName,  /* IP hostname */
                               int aNamelen, /* length of aName pointer */
                               int aFlag     /* Flag if FQDN or not */)
{
	int cret;
	size_t len;

#ifdef ps_win
	HKEY hKey;
	LONG cbMaxValueLen, cbMRUList = 25;
	LPDWORD hostlen = IPCMAXHOSTLEN - 1;
	LPBYTE hostname[IPCMAXHOSTLEN];
#endif

#ifdef ps_unix
	char hostname[IPCMAXHOSTLEN];
	int hostlen = IPCMAXHOSTLEN - 1;
#endif

	cret = (int)IPCOK;
	(void)strcpy(hostname, PSIPC_DEFNAME);

#ifdef ps_win
	if (RegOpenKey(HKEY_LOCAL_MACHINE, PSIPC_DEFREGKEY, &hKey) == ERROR_SUCCESS)
		{
		RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
		    NULL, &cbMaxValueLen, NULL, NULL ) ;
		if (cbMaxValueLen > 0)
			{
			// Get MRUList value
#ifdef ps_winnt
			RegQueryValueEx(hKey, "Hostname", NULL, NULL, hostname, &hostlen) ;
#else
			RegQueryValueEx(hKey, "ComputerName", NULL, NULL, hostname, &hostlen) ;
#endif
			}   
		// Close registry key
		RegCloseKey(hKey) ;
		}
#endif

#ifdef ps_unix
	cret = gethostname(hostname, hostlen);
#endif

	len = strlen((char *)hostname);
	if (len > (size_t)aNamelen)
		{
		}
	else
		(void)strcpy(aName, (char *)hostname);

	return(IPCOK);
}
示例#26
0
/*
 * Recursively dump a registry node
 * Each key can have a number of subkeys and a number of values
 */
static int
print_registry(char *pkeyname)
{
	int i, err;
	HKEY key;
	char *keyname, *subkeypos;
	DWORD keynamelen;
	DWORD skeynamelen, oskeynamelen;
	LONG ret;

	if ((ret = RegOpenKeyEx(rootkey, pkeyname, 0, KEY_READ, &key)) != ERROR_SUCCESS) {
		wperror(pkeyname, ret);
		return (-1);
	}

	print_key(key, pkeyname);
	if ((ret = RegQueryInfoKey(key, NULL, NULL, NULL,
			    NULL, &skeynamelen, NULL,
			    NULL,
			    NULL, NULL, NULL, NULL)) != ERROR_SUCCESS) {
		wperror("RegQueryInfoKey", ret);
		RegCloseKey(key);
		return (-1);
	}
	skeynamelen++;
	if (pkeyname)
		keynamelen = skeynamelen + strlen(pkeyname) + 1;	/* To hold the \ */
	else
		keynamelen = skeynamelen;
	subkeypos = keyname = malloc(keynamelen);
	if (pkeyname) {
		strcpy(keyname, pkeyname);
		strcat(keyname, "\\");
		subkeypos += strlen(pkeyname) + 1;
	}
	for (i = 0; ; i++) {
		oskeynamelen = skeynamelen;
		switch (err = RegEnumKeyEx(key, i, subkeypos, &oskeynamelen, NULL, NULL, NULL, NULL)) {
		case ERROR_SUCCESS:
			print_registry(keyname);
			break;
		case ERROR_NO_MORE_ITEMS:
			RegCloseKey(key);
			free(keyname);
			return (0);
		default:
			wperror("RegEnumKeyEx", err);
			RegCloseKey(key);
			free(keyname);
			return (-1);
		}
	}
	/* NOTREACHED */
}
示例#27
0
void CPlayerDialog::RestoreRegValue(HKEY root, PWCHAR szSubKey, PWCHAR szValueName, PWCHAR szBakValueName)
{
	HKEY hkey;

	if (RegOpenKeyEx(root, szSubKey, 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS) 
	{
		DWORD dwType = 0;
		DWORD dwSize = 0;
		DWORD		cbValueName = MAX_VALUE_NAME;
		DWORD		retCode;

		TCHAR		ClassName[MAX_PATH];
		DWORD		dwcClassLen = MAX_PATH;
		DWORD		dwcSubKeys;
		DWORD		dwcMaxSubKey;
		DWORD		dwcMaxClass;
		DWORD		dwcValues;
		DWORD		dwcMaxValueName;
		DWORD		dwcMaxValueData;
		DWORD		dwcSecDesc;
		FILETIME	ftLastWriteTime;

		retCode =
			RegQueryInfoKey (hkey,              // Key handle.
			ClassName,         // Buffer for class name.
			&dwcClassLen,      // Length of class string.
			NULL,              // Reserved.
			&dwcSubKeys,       // Number of sub keys.
			&dwcMaxSubKey,     // Longest sub key size.
			&dwcMaxClass,      // Longest class string.
			&dwcValues,        // Number of values for this key.
			&dwcMaxValueName,  // Longest Value name.
			&dwcMaxValueData,  // Longest Value data.
			&dwcSecDesc,       // Security descriptor.
			&ftLastWriteTime); // Last write time.			

		BYTE* bData = (BYTE *) LocalAlloc(LMEM_FIXED, dwcMaxValueData);
		dwSize = dwcMaxValueData;

		//读取
		if( RegQueryValueEx(hkey, szBakValueName, NULL, &dwType, bData, &dwSize) == ERROR_SUCCESS )
		{
			//还原
			RegSetValueEx(hkey, szValueName, NULL, dwType, bData, dwSize);

		}
		LocalFree ((HLOCAL)bData);
		RegCloseKey(hkey);
	}
	else
	{
		Log() << _T( "RestoreRegValue 打开注册表失败!" ) << endl;
	}
}
示例#28
0
BOOL makfc_REG_GetValueNumber(HKEY hKey, LPCTSTR szSubKey, LPTSTR szValueName, LPDWORD dwNameSize,
							  LPVOID lpValueData, LPDWORD dwValueSize, DWORD uNumber)
{
	BOOL ret = 0;
	HKEY hKeysSet = NULL;
	TCHAR * szName = NULL;
	TCHAR * data = NULL;
	DWORD count = 0;
	DWORD keys = 0, NameLength = 0, DataLength = 0;

	szName = (TCHAR*)malloc((*dwNameSize) * sizeof(TCHAR));
	if (!szName)
		return ret;
	data = (TCHAR*)malloc((*dwValueSize));
	if (!data)
		return ret;
	if (RegOpenKeyEx(hKey, szSubKey, 0, KEY_ALL_ACCESS, &hKeysSet) == ERROR_SUCCESS)
	{
		LONG regret;
		if (RegQueryInfoKey(hKeysSet,0,0,0,0,0,0,&keys,0,0,0,0) == ERROR_SUCCESS
			&& keys && keys > uNumber)
		{
			NameLength = *dwNameSize;
			DataLength = *dwValueSize;
			while (count <= uNumber &&
				((regret = RegEnumValue(hKeysSet, count, szName, &NameLength, 0, 0,
										(BYTE*)data, &DataLength)) == ERROR_SUCCESS))
			{
				if (count == uNumber && regret == ERROR_SUCCESS)
				{
					ret = 1;
					memcpy(szValueName, szName, NameLength + sizeof(TCHAR));
					memcpy(lpValueData, data, DataLength);
					*dwValueSize = DataLength;
					*dwNameSize = NameLength;
					break;
				}
				DataLength = *dwValueSize;
				NameLength = *dwNameSize;
				count++;
			}
		}
		RegCloseKey(hKeysSet);
	}
	free(data);
	free(szName);
	if (!ret)
	{
		*dwValueSize = 0;
		*dwNameSize = 0;
	}
	return ret;
}
示例#29
0
// Initialise toutes les sessions avec une valeur
void QuerySubKey( HKEY hMainKey, LPCTSTR lpSubKey, FILE * fp_out, char * text  ) { 
	HKEY hKey ;
    TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
    DWORD    cbName;                   // size of name string 
    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
    DWORD    cchClassName = MAX_PATH;  // size of class string 
    DWORD    cSubKeys=0;               // number of subkeys 
    DWORD    cbMaxSubKey;              // longest subkey size 
    DWORD    cchMaxClass;              // longest class string 
    DWORD    cValues;              // number of values for key 
    DWORD    cchMaxValue;          // longest value name 
    DWORD    cbMaxValueData;       // longest value data 
    DWORD    cbSecurityDescriptor; // size of security descriptor 
    FILETIME ftLastWriteTime;      // last write time 
    DWORD i, retCode; 
	
	char * buffer = NULL ;

	// On ouvre la clé
	if( RegOpenKeyEx( hMainKey, TEXT(lpSubKey), 0, KEY_READ, &hKey) != ERROR_SUCCESS ) return ;

    // Get the class name and the value count. 
    retCode = RegQueryInfoKey(
        hKey,                    // key handle 
        achClass,                // buffer for class name 
        &cchClassName,           // size of class string 
        NULL,                    // reserved 
        &cSubKeys,               // number of subkeys 
        &cbMaxSubKey,            // longest subkey size 
        &cchMaxClass,            // longest class string 
        &cValues,                // number of values for this key 
        &cchMaxValue,            // longest value name 
        &cbMaxValueData,         // longest value data 
        &cbSecurityDescriptor,   // security descriptor 
        &ftLastWriteTime);       // last write time 
 
	// Enumerate the subkeys, until RegEnumKeyEx fails.
	if (cSubKeys) {
		for (i=0; i<cSubKeys; i++) { 
			cbName = MAX_KEY_LENGTH;
			retCode = RegEnumKeyEx(hKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime); 
			if (retCode == ERROR_SUCCESS) {
				buffer = (char*) malloc( strlen( TEXT(lpSubKey) ) + strlen( achKey ) + 100 ) ;
				sprintf( buffer, "[HKEY_CURRENT_USER\\%s\\%s]", TEXT(lpSubKey), achKey ) ;
				fprintf( fp_out, "\r\n%s\r\n", buffer ) ;
				if( text!=NULL ) 
					if( strlen( text ) > 0 ) fprintf( fp_out, "%s\r\n", text ) ;
				free( buffer );				
				}
			}
		} 
	RegCloseKey( hKey ) ;
	}
示例#30
0
bool CeCosTestPlatform::Load()
{
  TRACE(_T("CeCosTestPlatform::Load\n"));
  srand( (unsigned)time( NULL ) );
  
#ifdef _WIN32

  // get target info from the registry
  String strPlatformsKey = _T("Software\\eCos Configuration Tool\\Platforms");
//  strPlatformsKey += GetGreatestSubkey (_T("Software\\eCos"));
//  strPlatformsKey += _T("\\Platforms");

  HKEY hKey;
  bool rc=ERROR_SUCCESS==RegOpenKeyEx (HKEY_CURRENT_USER, strPlatformsKey, 0L, KEY_READ, &hKey);
  DWORD dwSubKeys=0;
  if(rc){
    // Found the given key.
    // Subkeys' names are the target image names:
    // Subkeys's values are:
    //      Prefix  String
    //      Type    String 
    //      GdbCmd  String [optional]
    FILETIME ftLastWriteTime;
    DWORD dwMaxSubKeyLen;
    if(ERROR_SUCCESS==RegQueryInfoKey(hKey,NULL,NULL,NULL,&dwSubKeys,&dwMaxSubKeyLen,NULL,NULL,NULL,NULL,NULL,NULL)){
      TCHAR *szName=new TCHAR[1+dwMaxSubKeyLen];
      DWORD dwSizeName=sizeof(TCHAR)*(1+dwMaxSubKeyLen);
      for(DWORD dwIndex=0;ERROR_SUCCESS==RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime); dwIndex++){
        CeCosTestPlatform t;
        if(t.LoadFromRegistry(hKey,szName)){
          t.m_strName=szName;
          CeCosTestPlatform::Add(t);
        }
        dwSizeName=sizeof(TCHAR)*(1+dwMaxSubKeyLen);
      }
      delete [] szName;
    }
    RegCloseKey(hKey);
  }
#endif
  const String strDir(CeCosTestUtils::HomeFile(_T(".eCosPlatforms")));
#ifdef _WIN32
  if(!CeCosTestUtils::Exists(strDir)){
    return true;
  }
#endif
  LoadFromDir(strDir);
  if(0==Count()){
    ERROR(_T("Failed to initialize any targets\n"));
  }
  return true;
}