| 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, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 template <class Traits> | 109 template <class Traits> |
| 110 bool GetProcessBasicInformation(HANDLE process, | 110 bool GetProcessBasicInformation(HANDLE process, |
| 111 bool is_wow64, | 111 bool is_wow64, |
| 112 ProcessInfo* process_info, | 112 ProcessInfo* process_info, |
| 113 WinVMAddress* peb_address) { | 113 WinVMAddress* peb_address, |
| 114 WinVMSize* peb_size) { |
| 114 ULONG bytes_returned; | 115 ULONG bytes_returned; |
| 115 process_types::PROCESS_BASIC_INFORMATION<Traits> process_basic_information; | 116 process_types::PROCESS_BASIC_INFORMATION<Traits> process_basic_information; |
| 116 NTSTATUS status = | 117 NTSTATUS status = |
| 117 crashpad::NtQueryInformationProcess(process, | 118 crashpad::NtQueryInformationProcess(process, |
| 118 ProcessBasicInformation, | 119 ProcessBasicInformation, |
| 119 &process_basic_information, | 120 &process_basic_information, |
| 120 sizeof(process_basic_information), | 121 sizeof(process_basic_information), |
| 121 &bytes_returned); | 122 &bytes_returned); |
| 122 if (!NT_SUCCESS(status)) { | 123 if (!NT_SUCCESS(status)) { |
| 123 NTSTATUS_LOG(ERROR, status) << "NtQueryInformationProcess"; | 124 NTSTATUS_LOG(ERROR, status) << "NtQueryInformationProcess"; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 136 static_cast<DWORD>(process_basic_information.UniqueProcessId); | 137 static_cast<DWORD>(process_basic_information.UniqueProcessId); |
| 137 process_info->inherited_from_process_id_ = static_cast<DWORD>( | 138 process_info->inherited_from_process_id_ = static_cast<DWORD>( |
| 138 process_basic_information.InheritedFromUniqueProcessId); | 139 process_basic_information.InheritedFromUniqueProcessId); |
| 139 | 140 |
| 140 // We now want to read the PEB to gather the rest of our information. The | 141 // We now want to read the PEB to gather the rest of our information. The |
| 141 // PebBaseAddress as returned above is what we want for 64-on-64 and 32-on-32, | 142 // PebBaseAddress as returned above is what we want for 64-on-64 and 32-on-32, |
| 142 // but for Wow64, we want to read the 32 bit PEB (a Wow64 process has both). | 143 // but for Wow64, we want to read the 32 bit PEB (a Wow64 process has both). |
| 143 // The address of this is found by a second call to NtQueryInformationProcess. | 144 // The address of this is found by a second call to NtQueryInformationProcess. |
| 144 if (!is_wow64) { | 145 if (!is_wow64) { |
| 145 *peb_address = process_basic_information.PebBaseAddress; | 146 *peb_address = process_basic_information.PebBaseAddress; |
| 147 *peb_size = sizeof(process_types::PEB<Traits>); |
| 146 } else { | 148 } else { |
| 147 ULONG_PTR wow64_peb_address; | 149 ULONG_PTR wow64_peb_address; |
| 148 status = crashpad::NtQueryInformationProcess(process, | 150 status = crashpad::NtQueryInformationProcess(process, |
| 149 ProcessWow64Information, | 151 ProcessWow64Information, |
| 150 &wow64_peb_address, | 152 &wow64_peb_address, |
| 151 sizeof(wow64_peb_address), | 153 sizeof(wow64_peb_address), |
| 152 &bytes_returned); | 154 &bytes_returned); |
| 153 if (!NT_SUCCESS(status)) { | 155 if (!NT_SUCCESS(status)) { |
| 154 NTSTATUS_LOG(ERROR, status), "NtQueryInformationProcess"; | 156 NTSTATUS_LOG(ERROR, status), "NtQueryInformationProcess"; |
| 155 return false; | 157 return false; |
| 156 } | 158 } |
| 157 if (bytes_returned != sizeof(wow64_peb_address)) { | 159 if (bytes_returned != sizeof(wow64_peb_address)) { |
| 158 LOG(ERROR) << "NtQueryInformationProcess incorrect size"; | 160 LOG(ERROR) << "NtQueryInformationProcess incorrect size"; |
| 159 return false; | 161 return false; |
| 160 } | 162 } |
| 161 *peb_address = wow64_peb_address; | 163 *peb_address = wow64_peb_address; |
| 164 *peb_size = sizeof(process_types::PEB<process_types::internal::Traits32>); |
| 162 } | 165 } |
| 163 | 166 |
| 164 return true; | 167 return true; |
| 165 } | 168 } |
| 166 | 169 |
| 167 template <class Traits> | 170 template <class Traits> |
| 168 bool ReadProcessData(HANDLE process, | 171 bool ReadProcessData(HANDLE process, |
| 169 WinVMAddress peb_address_vmaddr, | 172 WinVMAddress peb_address_vmaddr, |
| 170 ProcessInfo* process_info) { | 173 ProcessInfo* process_info) { |
| 171 Traits::Pointer peb_address; | 174 Traits::Pointer peb_address; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { | 256 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { |
| 254 } | 257 } |
| 255 | 258 |
| 256 ProcessInfo::Module::~Module() { | 259 ProcessInfo::Module::~Module() { |
| 257 } | 260 } |
| 258 | 261 |
| 259 ProcessInfo::ProcessInfo() | 262 ProcessInfo::ProcessInfo() |
| 260 : process_id_(), | 263 : process_id_(), |
| 261 inherited_from_process_id_(), | 264 inherited_from_process_id_(), |
| 262 command_line_(), | 265 command_line_(), |
| 266 peb_address_(0), |
| 267 peb_size_(0), |
| 263 modules_(), | 268 modules_(), |
| 264 is_64_bit_(false), | 269 is_64_bit_(false), |
| 265 is_wow64_(false), | 270 is_wow64_(false), |
| 266 initialized_() { | 271 initialized_() { |
| 267 } | 272 } |
| 268 | 273 |
| 269 ProcessInfo::~ProcessInfo() { | 274 ProcessInfo::~ProcessInfo() { |
| 270 } | 275 } |
| 271 | 276 |
| 272 bool ProcessInfo::Initialize(HANDLE process) { | 277 bool ProcessInfo::Initialize(HANDLE process) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 286 system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64; | 291 system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64; |
| 287 } | 292 } |
| 288 | 293 |
| 289 #if ARCH_CPU_32_BITS | 294 #if ARCH_CPU_32_BITS |
| 290 if (is_64_bit_) { | 295 if (is_64_bit_) { |
| 291 LOG(ERROR) << "Reading x64 process from x86 process not supported"; | 296 LOG(ERROR) << "Reading x64 process from x86 process not supported"; |
| 292 return false; | 297 return false; |
| 293 } | 298 } |
| 294 #endif | 299 #endif |
| 295 | 300 |
| 296 WinVMAddress peb_address; | |
| 297 #if ARCH_CPU_64_BITS | 301 #if ARCH_CPU_64_BITS |
| 298 bool result = GetProcessBasicInformation<process_types::internal::Traits64>( | 302 bool result = GetProcessBasicInformation<process_types::internal::Traits64>( |
| 299 process, is_wow64_, this, &peb_address); | 303 process, is_wow64_, this, &peb_address_, &peb_size_); |
| 300 #else | 304 #else |
| 301 bool result = GetProcessBasicInformation<process_types::internal::Traits32>( | 305 bool result = GetProcessBasicInformation<process_types::internal::Traits32>( |
| 302 process, false, this, &peb_address); | 306 process, false, this, &peb_address_, &peb_size_); |
| 303 #endif // ARCH_CPU_64_BITS | 307 #endif // ARCH_CPU_64_BITS |
| 304 | 308 |
| 305 if (!result) { | 309 if (!result) { |
| 306 LOG(ERROR) << "GetProcessBasicInformation failed"; | 310 LOG(ERROR) << "GetProcessBasicInformation failed"; |
| 307 return false; | 311 return false; |
| 308 } | 312 } |
| 309 | 313 |
| 310 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( | 314 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( |
| 311 process, peb_address, this) | 315 process, peb_address_, this) |
| 312 : ReadProcessData<process_types::internal::Traits32>( | 316 : ReadProcessData<process_types::internal::Traits32>( |
| 313 process, peb_address, this); | 317 process, peb_address_, this); |
| 314 if (!result) { | 318 if (!result) { |
| 315 LOG(ERROR) << "ReadProcessData failed"; | 319 LOG(ERROR) << "ReadProcessData failed"; |
| 316 return false; | 320 return false; |
| 317 } | 321 } |
| 318 | 322 |
| 319 INITIALIZATION_STATE_SET_VALID(initialized_); | 323 INITIALIZATION_STATE_SET_VALID(initialized_); |
| 320 return true; | 324 return true; |
| 321 } | 325 } |
| 322 | 326 |
| 323 bool ProcessInfo::Is64Bit() const { | 327 bool ProcessInfo::Is64Bit() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 339 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 343 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 340 return inherited_from_process_id_; | 344 return inherited_from_process_id_; |
| 341 } | 345 } |
| 342 | 346 |
| 343 bool ProcessInfo::CommandLine(std::wstring* command_line) const { | 347 bool ProcessInfo::CommandLine(std::wstring* command_line) const { |
| 344 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 348 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 345 *command_line = command_line_; | 349 *command_line = command_line_; |
| 346 return true; | 350 return true; |
| 347 } | 351 } |
| 348 | 352 |
| 353 void ProcessInfo::Peb(WinVMAddress* peb_address, WinVMSize* peb_size) const { |
| 354 *peb_address = peb_address_; |
| 355 *peb_size = peb_size_; |
| 356 } |
| 357 |
| 349 bool ProcessInfo::Modules(std::vector<Module>* modules) const { | 358 bool ProcessInfo::Modules(std::vector<Module>* modules) const { |
| 350 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 359 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 351 *modules = modules_; | 360 *modules = modules_; |
| 352 return true; | 361 return true; |
| 353 } | 362 } |
| 354 | 363 |
| 355 } // namespace crashpad | 364 } // namespace crashpad |
| OLD | NEW |