/* (C) 2003-2007 Willem Jan Hengeveld * Web: http://www.xs4all.nl/~itsme/ * http://wiki.xda-developers.com/ * * $Id: pregdmp.cpp 1749 2008-03-11 17:12:13Z itsme $ */ //******************************************************************************************* // // Filename : pregdmp.c // // Copyright (c) 1997 Microsoft Corporation. All rights reserved // //******************************************************************************************* #include #include #include #include "debug.h" #include #include typedef std::vector StringList; typedef std::vector WSTRING; bool fDebug= false; #define MAX_NAME_BUF_SIZE 256 #define MAX_VALUE_BUF_SIZE 1024 void indent(int level) { while(level--) putchar('\t'); } void DumpChild(HKEY hKey, int level) { // first dump values int k= 0; while(1) { DWORD cbName = MAX_NAME_BUF_SIZE; DWORD cbData = MAX_VALUE_BUF_SIZE; DWORD dwType; // Throw a pair of NULLS on end of string so printfs don't run off the end of max size strings WCHAR Name[MAX_NAME_BUF_SIZE+2]; memset(Name, 0, sizeof(Name)); BYTE lpData[MAX_VALUE_BUF_SIZE+2]; memset(lpData, 0, sizeof(lpData)); LONG res= CeRegEnumValue(hKey, k, Name, &cbName, NULL, &dwType, lpData, &cbData); if (res==ERROR_NO_MORE_ITEMS) break; printf( "(%04ld) ", k++); // <<< here is the loop variable indent(level+1); if (res!=ERROR_SUCCESS) { error(res, "ERROR"); continue; } if (fDebug) { printf("T=%04x ", dwType); for (DWORD ii=0 ; ii ", i++); // <<< here is the loop variable indent(level); if (res!=ERROR_SUCCESS) { error(res, "ERROR"); continue; } printf("[%ls]\n", Name); HKEY hChildKey; res= CeRegOpenKeyEx(hKey, Name, 0, 0, &hChildKey); if (res != ERROR_SUCCESS) { error(res, "Failed to open subkey '%ls'", Name); continue; } DumpChild(hChildKey, level+1); CeRegCloseKey(hChildKey); } } void DumpKey(const std::string& key) { HKEY hRoot; std::string path; std::string rootname; size_t slashpos= key.find_first_of("/\\"); if (slashpos==0) slashpos= key.find_first_of("/\\", slashpos+1); if (stricmp(key.substr(0,slashpos).c_str(), "hkcr")==0) { hRoot= HKEY_CLASSES_ROOT; rootname= "HKEY_CLASSES_ROOT"; if (slashpos==key.npos) path= ""; else path= key.substr(slashpos+1); } else if (stricmp(key.substr(0,slashpos).c_str(), "hkcu")==0) { hRoot= HKEY_CURRENT_USER; rootname= "HKEY_CURRENT_USER"; if (slashpos==key.npos) path= ""; else path= key.substr(slashpos+1); } else if (stricmp(key.substr(0,slashpos).c_str(), "hklm")==0) { hRoot= HKEY_LOCAL_MACHINE; rootname= "HKEY_LOCAL_MACHINE"; if (slashpos==key.npos) path= ""; else path= key.substr(slashpos+1); } else { hRoot= HKEY_LOCAL_MACHINE; rootname= "HKEY_LOCAL_MACHINE"; if (key.find_first_of("/\\")==0) path= key.substr(1); else path= key; } if (!path.empty()) { WSTRING wpath; wpath.resize(path.size()+1); _snwprintf(&wpath[0], wpath.size(), L"%hs", path.c_str()); LONG res= CeRegOpenKeyEx(hRoot, &wpath[0], 0, 0, &hRoot); if (res!=ERROR_SUCCESS) { error(res, "Failed to open key '%ls'", &wpath[0]); hRoot=NULL; return; } printf("%hs : %hs\n", rootname.c_str(), path.c_str()); } else { printf("%hs\n", rootname.c_str()); } DumpChild(hRoot, 1); return; } void usage() { printf("(C) 2003-2008 Willem jan Hengeveld itsme@xs4all.nl\n"); printf("Usage: pregdmp [-d] [hklm|hkcr|hkcu]\\path\n"); } int main(int argc, char *argv[]) { DebugStdOut(); StringList keys; for (int i=1 ; i