Latest News

R

Monday, 7 March 2011 , Posted by genesisdatabase at 17:46

For those that are interested in contacting the windows registry via C, here's a list of WinAPI functions that you need to know.

RegOpenKeyEx
RegCreateKeyEx
RegSetValueEx
RegQueryValueEx
RegCloseKey

Complete list of registry functions - MSDN

If you need a tutorial on step by step for each functions, read LeetCoders - Registry Operations using Win32

Now here's a shortcut function which is usually developed for retrieving (stealing) serials for games and applications.  It is called GetKeyData(HKEY, char *, char *, LPBYTE, DWORD).  To use it simply place the code below.  storeHere would be a variable to store the retrieved value of the key.

GetKeyData(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", "ApplicationName", storeHere, strlen(storeHere));

[code]
int GetKeyData(HKEY hRootKey, char *subKey, char *value, LPBYTE data, DWORD cbData)
{
HKEY hKey;
if(RegOpenKeyEx(hRootKey, subKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
return 0;

if(RegQueryValueEx(hKey, value, NULL, NULL, data, &cbData) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return 0;
}

RegCloseKey(hKey);
return 1;
}
[/code]



Since there is the GetKeyData, there should also be the SetKeyData(HKEY, char *, DWORD, char *, LPBYTE, DWORD). An example to use would be

SetKeyData(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", REG_SZ, "ApplicationName", "C:\ApplicationPath\ApplicationName.exe", strlen("C:\ApplicationPath\ApplicationName.exe"));

[code]

int SetKeyData(HKEY hRootKey, char *subKey, DWORD dwType, char *value, LPBYTE data, DWORD cbData)
{
HKEY hKey;
if(RegCreateKey(hRootKey, subKey, &hKey) != ERROR_SUCCESS)
return 0;

if(RegSetValueEx(hKey, value, 0, dwType, data, cbData) != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return 0;
}

RegCloseKey(hKey);
return 1;
}
[/code]

Currently have 0 comments:

Leave a Reply

Post a Comment