Anthony:
In win98, I hook some system services including RegOpenKey and
RegCreateKey. (By the way, it seems that there is NO way to hook
RegOpenKeyEx and RegCreateKeyEx in win98?)
From my experience there is no need to worry about hooking
RegOpenKeyEx/RegCreateKeyEx.
I can get the full key path by strcat hKey and lpSubKey. But sometimes
hKey is just a HANDLE not the predefined
keys(HKEY_CLASSES_ROOT,HKEY_CURRENT_CONFIG,HKEY_CURRENT_USER,HKEY_
LOCAL_MACH
INE,HKEY_USERS)
The reason you are seeing RegOpenKey called with an hKey that does not match
one of the root hives is because of the fact that you can use the resultant
HKEY from RegOpenKey and RegCreateKey as the root HKEY, like the root hives,
for further RegOpenKey/RegCreateKey calls.
Example snippet:
HKEY key, subKey;
RegOpenKey(HKEY_LOCAL_MACHINE, “System\CurrentControlSet\Services\IPSec”,
&key);
RegOpenKey(key, “Security”, &subKey);
I do NOT know the way to translate the Handle to the key path.
Forturnately, I find Regmon can do it. And I ask Mr.Mark Russinovich for
help, but he told me “I am really busy, so…”. Now I fell in the puzzle
hole.
There are a few ways to translate the HKEY to a path. The easiest is likely
to be making use of a hash that translates an HKEY, since HKEY’s are
globally unique, into its full ASCII path.
This requires you to do something a little more fancy in that you have to be
able to save the resultant HKEY from calls to RegOpenKey and RegCreateKey in
order to insert them into the hash.
When you insert them into the hash you simply use the hash to resolve the
ASCII name of the root HKEY (the first parameter to RegOpenKey/RegCreateKey)
and concatenate that with the base key (the second parameter to
RegOpenKey/RegCreateKey).
Finally, when RegCloseKey is called you should remove the provided HKEY from
the hash. You have to be careful here, though. Sometimes applications are
written poorly and try to close the root hives.
Hope that helps. I’m pretty sure this is the method that regmon uses on
Windows 9x.
Matt