Beispiel #1
0
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;
}
Beispiel #2
0
// рекурсивная ф-я
void EnumRegistry(PWCHAR RootKey/* должно быть выделено MAX_REGPATH_LEN WCHARов*/, ULONG Depth)
{
// не будем перегружать стек
	PWCHAR KeyName = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*MAX_KEYVALUENAME_LEN);
	if (!KeyName)
		return;
	PWCHAR ValueName = (PWCHAR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*MAX_KEYVALUENAME_LEN);
	if (!ValueName)
	{
		HeapFree(GetProcessHeap(), 0, KeyName);
		return;
	}

// енумерим валушки, начиная с дефолтовой
	PrintTabs(Depth);
	printf("Values:\n");

// дефолтовая не установлена
	if (!PrintValue(RootKey, L"", Depth))
	{
		PrintTabs(Depth);
		printf("(Default):\tvalue not set\n");
	}
	for (ULONG ValueIndex = 0; EnumValues(RootKey, ValueIndex, ValueName); ValueIndex++)
	{
// пропускаем установленное дефолтовое значение
		if (ValueName[0])
			PrintValue(RootKey, ValueName, Depth);
	}

	ULONG OldLen = lstrlenW(RootKey);
	for (ULONG KeyIndex = 0; EnumKeys(RootKey, KeyIndex, KeyName); KeyIndex++)
	{
		lstrcatW(RootKey, L"\\");
		lstrcatW(RootKey, KeyName);

		PrintTabs(Depth);
		printf("%S\n", KeyName);

		EnumRegistry(RootKey, Depth+1);

		RootKey[OldLen] = 0;
	}

	HeapFree(GetProcessHeap(), 0 ,ValueName);
	HeapFree(GetProcessHeap(), 0, KeyName);
}
void DoRegistryFile(CStringA resToken)
{
	int nBrace = -1;
	int nBraceCnt = 1;
	for (int i = 2; i < resToken.GetLength(); i++)
	{
		if (resToken.GetAt(i) == '[')
			nBraceCnt++;
		else if (resToken.GetAt(i) == ']')
		{
			nBraceCnt--;
			if (nBraceCnt == 0)
			{
				nBrace = i;
				break;
			}
		}
	}

	if (nBrace == -1)
		return;

	USES_CONVERSION;

	CStringA strRegPath = resToken.Mid(2, nBrace - 2);

	std::vector<CStringA> vecOutRegPaths;
	EnumRegistry(strRegPath, vecOutRegPaths);

	int cnt = vecOutRegPaths.size();
	for (int i = 0; i < cnt; i++)
	{
		CStringA strFilePath;
		if (QueryRegistryValue(vecOutRegPaths.at(i), strFilePath))
		{
			CHAR expName[MAX_PATH + 1];
			ExpandEnvironmentStringsA(strFilePath, expName, MAX_PATH);
			strFilePath = expName;

			if (strFilePath.Find('\\') != -1)
				DoFilePathName(strFilePath);
			else
				DoOnlyFileName(strFilePath);
		}
	}
}
void DoRegistryPath(CStringA resToken)
{	
	int nBrace = -1;
	int nBraceCnt = 1;
	for (int i = 2; i < resToken.GetLength(); i++)
	{
		if (resToken.GetAt(i) == '{')
			nBraceCnt++;
		else if (resToken.GetAt(i) == '}')
		{
			nBraceCnt--;
			if (nBraceCnt == 0)
			{
				nBrace = i;
				break;
			}
		}
	}

	if (nBrace == -1)
		return;

	USES_CONVERSION;

	bool bIsPath = true;
	CStringA strRegPath = resToken.Mid(2, nBrace - 2);
	int nLength = strRegPath.GetLength();
	if (nLength > 2 && strRegPath.Mid(nLength - 2).MakeLower() == "|p")
	{
		bIsPath = true;
		strRegPath = strRegPath.Mid(0, nLength - 2);
	}
	else if (nLength > 2 && strRegPath.Mid(nLength - 2).MakeLower() == "|f")
	{
		bIsPath = false;
		strRegPath = strRegPath.Mid(0, nLength - 2);
	}

	std::vector<CStringA> vecOutRegPaths;
	EnumRegistry(strRegPath, vecOutRegPaths);

	int cnt = vecOutRegPaths.size();
	for (int i = 0; i < cnt; i++)
	{
		CStringA strFilePath;
		if (QueryRegistryValue(vecOutRegPaths.at(i), strFilePath))
		{
			if (!bIsPath)
			{
				strFilePath.Replace('/', '\\');
				int nEndSlash = strFilePath.ReverseFind('\\');
				if (nEndSlash == -1)
					continue;

				strFilePath = strFilePath.Mid(0, nEndSlash);
			}

			strFilePath += resToken.Mid(nBrace + 1);			
			DoFilePathName(strFilePath);
		}
	}
}