i'm having trouble reading the value data from the values that i'm looking at. they show up as ascii symbols instead of the data that they should represent, or in the case of strings, they just show the first character of the string.
Code:#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;
void CopyAllValues(HKEY subkey, char* path);
const int valueSize=16383;
const int keySize=255;
#define DEBUG
#define INITIALIZE
int main()
{
DWORD status=0;
char* path="SYSTEM\\CurrentControlSet\\Services";
// HKEY hsubkey;
// status=RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &hsubkey);
// if (status==ERROR_SUCCESS)
// {
CopyAllValues(HKEY_LOCAL_MACHINE, path);
// }
return 0;
}
void CopyAllValues(HKEY subkey, char* path)
{
HKEY hsubkey;
char* conString;
DWORD openResult=0;
//value vars
DWORD i, j;
TCHAR valueName[valueSize];
DWORD valueNameSize=0;
DWORD type=0;
BYTE data=0;
DWORD dataSize=0;
DWORD valueResult=0;
//key vars
TCHAR keyName[keySize];
DWORD keyNameSize=keySize;
TCHAR Class='\0';
DWORD ClassSize=0;
FILETIME LastWriteTime;
DWORD keyResult=0;
// bool used;
openResult=RegOpenKeyEx(subkey, path, 0, KEY_READ, &hsubkey);
if (openResult==ERROR_SUCCESS)
{
#ifdef INITIALIZE
//initializing the names to null characters
memset(valueName, '\0', valueSize);
// for (int k=0;k<valueSize;k++)
// {
// valueName[k]='\0';
// }
memset(keyName, '\0', keySize);
// for (int m=0;m<keySize;m++)
// {
// keyName[m]='\0';
// }
#endif
for (j=0, keyResult=ERROR_SUCCESS; keyResult==ERROR_SUCCESS; j++)
{
keyResult=RegEnumKeyEx(hsubkey,
j,
keyName,
&keyNameSize,
NULL,
NULL,
NULL,
&LastWriteTime);
//allocating memory for conString:
conString = (char *)calloc(strlen(path) + strlen(keyName) + 2, sizeof(char));
//concatenating the string to form the new path:
strcat(conString, path);
strcat(conString, "\\");
strcat(conString, keyName);
#ifdef DEBUG
//outputting the complete path and key name:
cout<<"Complete path is: " <<conString <<endl;
// cout<<"key name is: " <<keyName <<endl;
#endif
if (keyResult==ERROR_SUCCESS && openResult==ERROR_SUCCESS)// && keyResult!=ERROR_NO_MORE_ITEMS)
{
CopyAllValues(subkey, conString);
//stop enumerating after using the current subkey?
// used=true;
}
// if (used)
// {
// break;
// }
}
for (i=0, valueResult=ERROR_SUCCESS; valueResult==ERROR_SUCCESS; i++)
{
dataSize=valueSize;
valueNameSize=valueSize;
RegEnumValue(hsubkey, i, valueName, NULL, NULL, &type, NULL, NULL);
valueResult=RegEnumValue(hsubkey,
i,
valueName,
&valueNameSize,
NULL,
&type,
&data,
&dataSize);
#ifdef DEBUG
//outputting value name:
switch (type)
{
case 0:
cout<<valueName <<" REG_NONE " <<data <<endl;
break;
case 1:
cout<<valueName <<" REG_SZ " <<data <<endl;
break;
case 2:
cout<<valueName <<" REG_EXPAND_SZ " <<data <<endl;
break;
case 3:
cout<<valueName <<" REG_BINARY " <<data <<endl;
break;
case 4:
cout<<valueName <<" REG_DWORD " <<data <<endl;
break;
case 5:
cout<<valueName <<" REG_DWORD_BIG_ENDIAN " <<data <<endl;
break;
case 6:
cout<<valueName <<" REG_LINK " <<data <<endl;
break;
case 7:
cout<<valueName <<" REG_MULTI_SZ " <<data <<endl;
break;
case 8:
cout<<valueName <<" REG_RESOURCE_LIST " <<data <<endl;
break;
case 9:
cout<<valueName <<" REG_FULL_RESOURCE_DESCRIPTOR " <<data <<endl;
break;
case 10:
cout<<valueName <<" REG_RESOURCE_REQUIREMENTS_LIST " <<data <<endl;
break;
case 11:
cout<<valueName <<" REG_QWORD " <<data <<endl;
break;
}
// cout<<"value name is: " <<valueName <<"=" <<data <<endl;
#endif
}
RegCloseKey(hsubkey);
}
}