| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/tools/goopdump/data_dumper.h" | |
| 17 | |
| 18 #include "omaha/common/reg_key.h" | |
| 19 #include "omaha/tools/goopdump/dump_log.h" | |
| 20 | |
| 21 namespace omaha { | |
| 22 | |
| 23 DataDumper::DataDumper() { | |
| 24 } | |
| 25 | |
| 26 DataDumper::~DataDumper() { | |
| 27 } | |
| 28 | |
| 29 void DataDumper::DumpRegValueStr(const DumpLog& dump_log, | |
| 30 const TCHAR* full_key_name, | |
| 31 const TCHAR* value_name) { | |
| 32 DumpRegValueStrRet(dump_log, full_key_name, value_name, NULL); | |
| 33 } | |
| 34 | |
| 35 void DataDumper::DumpRegValueStrRet(const DumpLog& dump_log, | |
| 36 const TCHAR* full_key_name, | |
| 37 const TCHAR* value_name, | |
| 38 CString* str) { | |
| 39 CString val; | |
| 40 CString key = full_key_name; | |
| 41 HRESULT hr = RegKey::GetValue(key, value_name, &val); | |
| 42 | |
| 43 CString value_name_str = value_name ? value_name : _T("default"); | |
| 44 | |
| 45 if (SUCCEEDED(hr)) { | |
| 46 dump_log.WriteLine(_T("%s[%s] = %s"), key, value_name_str, val); | |
| 47 } else { | |
| 48 dump_log.WriteLine(_T("%s HAS NO VALUE"), key); | |
| 49 } | |
| 50 | |
| 51 if (str) { | |
| 52 *str = val; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 DumpHeader::DumpHeader(const DumpLog& dump_log, const TCHAR* header_name) | |
| 57 : dump_log_(dump_log) { | |
| 58 dump_log_.WriteLine(_T("")); | |
| 59 dump_log_.WriteLine(_T("--------------------------------------------------")); | |
| 60 dump_log_.WriteLine(header_name); | |
| 61 dump_log_.WriteLine(_T("--------------------------------------------------")); | |
| 62 } | |
| 63 | |
| 64 DumpHeader::~DumpHeader() { | |
| 65 dump_log_.WriteLine(_T("--------------------------------------------------")); | |
| 66 dump_log_.WriteLine(_T("")); | |
| 67 } | |
| 68 | |
| 69 void DataDumper::RecursiveDumpRegistryKey(const DumpLog& dump_log, | |
| 70 RegKey* key, | |
| 71 const int indent) { | |
| 72 ASSERT1(key); | |
| 73 CString indent_string; | |
| 74 for (int i = 0; i < indent; ++i) { | |
| 75 indent_string.Append(_T(" ")); | |
| 76 } | |
| 77 uint32 value_count = key->GetValueCount(); | |
| 78 for (uint32 idx = 0; idx < value_count; ++idx) { | |
| 79 CString value_name; | |
| 80 DWORD value_type = 0; | |
| 81 key->GetValueNameAt(idx, &value_name, &value_type); | |
| 82 CString value_name_disp = | |
| 83 value_name.IsEmpty() ? _T("[default]") : value_name; | |
| 84 switch (value_type) { | |
| 85 case REG_SZ: { | |
| 86 CString value; | |
| 87 key->GetValue(value_name, &value); | |
| 88 dump_log.WriteLine(_T("%s%s: (REG_SZ): %s"), | |
| 89 indent_string, | |
| 90 value_name_disp, | |
| 91 value); | |
| 92 break; | |
| 93 } | |
| 94 case REG_DWORD: { | |
| 95 DWORD value = 0; | |
| 96 key->GetValue(value_name, &value); | |
| 97 dump_log.WriteLine(_T("%s%s: (REG_DWORD): %d (0x%x)"), | |
| 98 indent_string, | |
| 99 value_name_disp, | |
| 100 value, | |
| 101 value); | |
| 102 break; | |
| 103 } | |
| 104 case REG_BINARY: | |
| 105 dump_log.WriteLine(_T("%s%s: (REG_BINARY)"), | |
| 106 indent_string, | |
| 107 value_name_disp); | |
| 108 break; | |
| 109 case REG_MULTI_SZ: | |
| 110 dump_log.WriteLine(_T("%s%s: (REG_MULTI_SZ)"), | |
| 111 indent_string, | |
| 112 value_name_disp); | |
| 113 break; | |
| 114 default: | |
| 115 dump_log.WriteLine(_T("%s%s: (TYPE: %d)"), | |
| 116 indent_string, | |
| 117 value_name_disp, | |
| 118 value_type); | |
| 119 break; | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 uint32 subkey_count = key->GetSubkeyCount(); | |
| 124 for (uint32 idx = 0; idx < subkey_count; ++idx) { | |
| 125 CString subkey_name; | |
| 126 key->GetSubkeyNameAt(idx, &subkey_name); | |
| 127 RegKey subkey; | |
| 128 subkey.Open(key->Key(), subkey_name, KEY_READ); | |
| 129 dump_log.WriteLine(_T("%sSUBKEY: %s"), indent_string, subkey_name); | |
| 130 RecursiveDumpRegistryKey(dump_log, &subkey, indent+1); | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 void DataDumper::DumpRegistryKeyData(const DumpLog& dump_log, | |
| 135 const CString& key_name) { | |
| 136 RegKey key_root; | |
| 137 if (FAILED(key_root.Open(key_name, KEY_READ))) { | |
| 138 dump_log.WriteLine(_T("Key (%s) could not be opened"), key_name); | |
| 139 return; | |
| 140 } | |
| 141 dump_log.WriteLine(_T("ROOT KEY: %s"), key_name); | |
| 142 RecursiveDumpRegistryKey(dump_log, &key_root, 1); | |
| 143 } | |
| 144 | |
| 145 } // namespace omaha | |
| 146 | |
| OLD | NEW |