| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "snapshot/win/module_snapshot_win.h" | 15 #include "snapshot/win/module_snapshot_win.h" |
| 16 | 16 |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "snapshot/win/pe_image_reader.h" | 18 #include "snapshot/win/pe_image_reader.h" |
| 19 #include "util/misc/tri_state.h" | 19 #include "util/misc/tri_state.h" |
| 20 #include "util/misc/uuid.h" | 20 #include "util/misc/uuid.h" |
| 21 #include "util/win/module_version.h" |
| 21 | 22 |
| 22 namespace crashpad { | 23 namespace crashpad { |
| 23 namespace internal { | 24 namespace internal { |
| 24 | 25 |
| 25 ModuleSnapshotWin::ModuleSnapshotWin() | 26 ModuleSnapshotWin::ModuleSnapshotWin() |
| 26 : ModuleSnapshot(), | 27 : ModuleSnapshot(), |
| 27 name_(), | 28 name_(), |
| 28 timestamp_(0), | 29 timestamp_(0), |
| 29 process_reader_(nullptr), | 30 process_reader_(nullptr), |
| 30 initialized_() { | 31 initialized_() { |
| 31 } | 32 } |
| 32 | 33 |
| 33 ModuleSnapshotWin::~ModuleSnapshotWin() { | 34 ModuleSnapshotWin::~ModuleSnapshotWin() { |
| 34 } | 35 } |
| 35 | 36 |
| 36 bool ModuleSnapshotWin::Initialize( | 37 bool ModuleSnapshotWin::Initialize( |
| 37 ProcessReaderWin* process_reader, | 38 ProcessReaderWin* process_reader, |
| 38 const ProcessInfo::Module& process_reader_module) { | 39 const ProcessInfo::Module& process_reader_module) { |
| 39 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 40 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
| 40 | 41 |
| 41 process_reader_ = process_reader; | 42 process_reader_ = process_reader; |
| 42 name_ = base::UTF16ToUTF8(process_reader_module.name); | 43 name_ = process_reader_module.name; |
| 43 timestamp_ = process_reader_module.timestamp; | 44 timestamp_ = process_reader_module.timestamp; |
| 44 pe_image_reader_.reset(new PEImageReader()); | 45 pe_image_reader_.reset(new PEImageReader()); |
| 45 if (!pe_image_reader_->Initialize(process_reader_, | 46 if (!pe_image_reader_->Initialize(process_reader_, |
| 46 process_reader_module.dll_base, | 47 process_reader_module.dll_base, |
| 47 process_reader_module.size, | 48 process_reader_module.size, |
| 48 name_)) { | 49 base::UTF16ToUTF8(name_))) { |
| 49 return false; | 50 return false; |
| 50 } | 51 } |
| 51 | 52 |
| 52 INITIALIZATION_STATE_SET_VALID(initialized_); | 53 INITIALIZATION_STATE_SET_VALID(initialized_); |
| 53 return true; | 54 return true; |
| 54 } | 55 } |
| 55 | 56 |
| 56 void ModuleSnapshotWin::GetCrashpadOptions(CrashpadInfoClientOptions* options) { | 57 void ModuleSnapshotWin::GetCrashpadOptions(CrashpadInfoClientOptions* options) { |
| 57 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 58 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 58 | 59 |
| 59 process_types::CrashpadInfo crashpad_info; | 60 process_types::CrashpadInfo crashpad_info; |
| 60 if (!pe_image_reader_->GetCrashpadInfo(&crashpad_info)) { | 61 if (!pe_image_reader_->GetCrashpadInfo(&crashpad_info)) { |
| 61 options->crashpad_handler_behavior = TriState::kUnset; | 62 options->crashpad_handler_behavior = TriState::kUnset; |
| 62 options->system_crash_reporter_forwarding = TriState::kUnset; | 63 options->system_crash_reporter_forwarding = TriState::kUnset; |
| 63 return; | 64 return; |
| 64 } | 65 } |
| 65 | 66 |
| 66 options->crashpad_handler_behavior = | 67 options->crashpad_handler_behavior = |
| 67 CrashpadInfoClientOptions::TriStateFromCrashpadInfo( | 68 CrashpadInfoClientOptions::TriStateFromCrashpadInfo( |
| 68 crashpad_info.crashpad_handler_behavior); | 69 crashpad_info.crashpad_handler_behavior); |
| 69 | 70 |
| 70 options->system_crash_reporter_forwarding = | 71 options->system_crash_reporter_forwarding = |
| 71 CrashpadInfoClientOptions::TriStateFromCrashpadInfo( | 72 CrashpadInfoClientOptions::TriStateFromCrashpadInfo( |
| 72 crashpad_info.system_crash_reporter_forwarding); | 73 crashpad_info.system_crash_reporter_forwarding); |
| 73 } | 74 } |
| 74 | 75 |
| 75 std::string ModuleSnapshotWin::Name() const { | 76 std::string ModuleSnapshotWin::Name() const { |
| 76 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 77 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 77 return name_; | 78 return base::UTF16ToUTF8(name_); |
| 78 } | 79 } |
| 79 | 80 |
| 80 uint64_t ModuleSnapshotWin::Address() const { | 81 uint64_t ModuleSnapshotWin::Address() const { |
| 81 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 82 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 82 return pe_image_reader_->Address(); | 83 return pe_image_reader_->Address(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 uint64_t ModuleSnapshotWin::Size() const { | 86 uint64_t ModuleSnapshotWin::Size() const { |
| 86 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 87 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 87 return pe_image_reader_->Size(); | 88 return pe_image_reader_->Size(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 time_t ModuleSnapshotWin::Timestamp() const { | 91 time_t ModuleSnapshotWin::Timestamp() const { |
| 91 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 92 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 92 return timestamp_; | 93 return timestamp_; |
| 93 } | 94 } |
| 94 | 95 |
| 95 void ModuleSnapshotWin::FileVersion(uint16_t* version_0, | 96 void ModuleSnapshotWin::FileVersion(uint16_t* version_0, |
| 96 uint16_t* version_1, | 97 uint16_t* version_1, |
| 97 uint16_t* version_2, | 98 uint16_t* version_2, |
| 98 uint16_t* version_3) const { | 99 uint16_t* version_3) const { |
| 99 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 100 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 100 CHECK(false) << "TODO(scottmg)"; | 101 VS_FIXEDFILEINFO ffi; |
| 102 if (GetModuleVersionAndType(base::FilePath(name_), &ffi)) { |
| 103 *version_0 = ffi.dwFileVersionMS >> 16; |
| 104 *version_1 = ffi.dwFileVersionMS & 0xffff; |
| 105 *version_2 = ffi.dwFileVersionLS >> 16; |
| 106 *version_3 = ffi.dwFileVersionLS & 0xffff; |
| 107 } else { |
| 108 *version_0 = 0; |
| 109 *version_1 = 0; |
| 110 *version_2 = 0; |
| 111 *version_3 = 0; |
| 112 } |
| 101 } | 113 } |
| 102 | 114 |
| 103 void ModuleSnapshotWin::SourceVersion(uint16_t* version_0, | 115 void ModuleSnapshotWin::SourceVersion(uint16_t* version_0, |
| 104 uint16_t* version_1, | 116 uint16_t* version_1, |
| 105 uint16_t* version_2, | 117 uint16_t* version_2, |
| 106 uint16_t* version_3) const { | 118 uint16_t* version_3) const { |
| 107 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 119 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 108 CHECK(false) << "TODO(scottmg)"; | 120 VS_FIXEDFILEINFO ffi; |
| 121 if (GetModuleVersionAndType(base::FilePath(name_), &ffi)) { |
| 122 *version_0 = ffi.dwProductVersionMS >> 16; |
| 123 *version_1 = ffi.dwProductVersionMS & 0xffff; |
| 124 *version_2 = ffi.dwProductVersionLS >> 16; |
| 125 *version_3 = ffi.dwProductVersionLS & 0xffff; |
| 126 } else { |
| 127 *version_0 = 0; |
| 128 *version_1 = 0; |
| 129 *version_2 = 0; |
| 130 *version_3 = 0; |
| 131 } |
| 109 } | 132 } |
| 110 | 133 |
| 111 ModuleSnapshot::ModuleType ModuleSnapshotWin::GetModuleType() const { | 134 ModuleSnapshot::ModuleType ModuleSnapshotWin::GetModuleType() const { |
| 112 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 135 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 113 CHECK(false) << "TODO(scottmg)"; | 136 VS_FIXEDFILEINFO ffi; |
| 114 return ModuleSnapshot::ModuleType(); | 137 if (GetModuleVersionAndType(base::FilePath(name_), &ffi)) { |
| 138 if (ffi.dwFileType == VFT_APP) |
| 139 return ModuleSnapshot::kModuleTypeExecutable; |
| 140 if (ffi.dwFileType == VFT_DLL) |
| 141 return ModuleSnapshot::kModuleTypeSharedLibrary; |
| 142 if (ffi.dwFileType == VFT_DRV || ffi.dwFileType == VFT_VXD) |
| 143 return ModuleSnapshot::kModuleTypeLoadableModule; |
| 144 } |
| 145 return ModuleSnapshot::kModuleTypeUnknown; |
| 115 } | 146 } |
| 116 | 147 |
| 117 void ModuleSnapshotWin::UUID(crashpad::UUID* uuid) const { | 148 void ModuleSnapshotWin::UUID(crashpad::UUID* uuid) const { |
| 118 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 149 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 119 CHECK(false) << "TODO(scottmg)"; | 150 CHECK(false) << "TODO(scottmg)"; |
| 120 } | 151 } |
| 121 | 152 |
| 122 std::vector<std::string> ModuleSnapshotWin::AnnotationsVector() const { | 153 std::vector<std::string> ModuleSnapshotWin::AnnotationsVector() const { |
| 123 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 154 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 124 CHECK(false) << "TODO(scottmg)"; | 155 CHECK(false) << "TODO(scottmg)"; |
| 125 return std::vector<std::string>(); | 156 return std::vector<std::string>(); |
| 126 } | 157 } |
| 127 | 158 |
| 128 std::map<std::string, std::string> ModuleSnapshotWin::AnnotationsSimpleMap() | 159 std::map<std::string, std::string> ModuleSnapshotWin::AnnotationsSimpleMap() |
| 129 const { | 160 const { |
| 130 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 161 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 131 CHECK(false) << "TODO(scottmg)"; | 162 CHECK(false) << "TODO(scottmg)"; |
| 132 return std::map<std::string, std::string>(); | 163 return std::map<std::string, std::string>(); |
| 133 } | 164 } |
| 134 | 165 |
| 135 } // namespace internal | 166 } // namespace internal |
| 136 } // namespace crashpad | 167 } // namespace crashpad |
| OLD | NEW |