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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 if (!ReadUnicodeString(process, | 124 if (!ReadUnicodeString(process, |
125 process_parameters.CommandLine, | 125 process_parameters.CommandLine, |
126 &process_info->command_line_)) { | 126 &process_info->command_line_)) { |
127 return false; | 127 return false; |
128 } | 128 } |
129 | 129 |
130 process_types::PEB_LDR_DATA<Traits> peb_ldr_data; | 130 process_types::PEB_LDR_DATA<Traits> peb_ldr_data; |
131 if (!ReadStruct(process, peb.Ldr, &peb_ldr_data)) | 131 if (!ReadStruct(process, peb.Ldr, &peb_ldr_data)) |
132 return false; | 132 return false; |
133 | 133 |
134 std::wstring module; | |
135 process_types::LDR_DATA_TABLE_ENTRY<Traits> ldr_data_table_entry; | 134 process_types::LDR_DATA_TABLE_ENTRY<Traits> ldr_data_table_entry; |
136 | 135 |
137 // Include the first module in the memory order list to get our the main | 136 // Include the first module in the memory order list to get our the main |
138 // executable's name, as it's not included in initialization order below. | 137 // executable's name, as it's not included in initialization order below. |
139 if (!ReadStruct(process, | 138 if (!ReadStruct(process, |
140 reinterpret_cast<uintptr_t>( | 139 reinterpret_cast<uintptr_t>( |
141 reinterpret_cast<const char*>( | 140 reinterpret_cast<const char*>( |
142 peb_ldr_data.InMemoryOrderModuleList.Flink) - | 141 peb_ldr_data.InMemoryOrderModuleList.Flink) - |
143 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, | 142 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, |
144 InMemoryOrderLinks)), | 143 InMemoryOrderLinks)), |
145 &ldr_data_table_entry)) { | 144 &ldr_data_table_entry)) { |
146 return false; | 145 return false; |
147 } | 146 } |
148 if (!ReadUnicodeString(process, ldr_data_table_entry.FullDllName, &module)) | 147 ProcessInfo::Module module; |
| 148 if (!ReadUnicodeString( |
| 149 process, ldr_data_table_entry.FullDllName, &module.name)) { |
149 return false; | 150 return false; |
| 151 } |
| 152 module.dll_base = ldr_data_table_entry.DllBase; |
| 153 module.size = ldr_data_table_entry.SizeOfImage; |
| 154 module.timestamp = ldr_data_table_entry.TimeDateStamp; |
150 process_info->modules_.push_back(module); | 155 process_info->modules_.push_back(module); |
151 | 156 |
152 // Walk the PEB LDR structure (doubly-linked list) to get the list of loaded | 157 // Walk the PEB LDR structure (doubly-linked list) to get the list of loaded |
153 // modules. We use this method rather than EnumProcessModules to get the | 158 // modules. We use this method rather than EnumProcessModules to get the |
154 // modules in initialization order rather than memory order. | 159 // modules in initialization order rather than memory order. |
155 Traits::Pointer last = peb_ldr_data.InInitializationOrderModuleList.Blink; | 160 Traits::Pointer last = peb_ldr_data.InInitializationOrderModuleList.Blink; |
156 for (Traits::Pointer cur = peb_ldr_data.InInitializationOrderModuleList.Flink; | 161 for (Traits::Pointer cur = peb_ldr_data.InInitializationOrderModuleList.Flink; |
157 ; | 162 ; |
158 cur = ldr_data_table_entry.InInitializationOrderLinks.Flink) { | 163 cur = ldr_data_table_entry.InInitializationOrderLinks.Flink) { |
159 // |cur| is the pointer to the LIST_ENTRY embedded in the | 164 // |cur| is the pointer to the LIST_ENTRY embedded in the |
160 // LDR_DATA_TABLE_ENTRY, in the target process's address space. So we need | 165 // LDR_DATA_TABLE_ENTRY, in the target process's address space. So we need |
161 // to read from the target, and also offset back to the beginning of the | 166 // to read from the target, and also offset back to the beginning of the |
162 // structure. | 167 // structure. |
163 if (!ReadStruct(process, | 168 if (!ReadStruct(process, |
164 reinterpret_cast<uintptr_t>( | 169 reinterpret_cast<uintptr_t>( |
165 reinterpret_cast<const char*>(cur) - | 170 reinterpret_cast<const char*>(cur) - |
166 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, | 171 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, |
167 InInitializationOrderLinks)), | 172 InInitializationOrderLinks)), |
168 &ldr_data_table_entry)) { | 173 &ldr_data_table_entry)) { |
169 break; | 174 break; |
170 } | 175 } |
171 // TODO(scottmg): Capture TimeDateStamp, Checksum, etc. too? | 176 // TODO(scottmg): Capture Checksum, etc. too? |
172 if (!ReadUnicodeString(process, ldr_data_table_entry.FullDllName, &module)) | 177 if (!ReadUnicodeString( |
| 178 process, ldr_data_table_entry.FullDllName, &module.name)) { |
173 break; | 179 break; |
| 180 } |
| 181 module.dll_base = ldr_data_table_entry.DllBase; |
| 182 module.size = ldr_data_table_entry.SizeOfImage; |
| 183 module.timestamp = ldr_data_table_entry.TimeDateStamp; |
174 process_info->modules_.push_back(module); | 184 process_info->modules_.push_back(module); |
175 if (cur == last) | 185 if (cur == last) |
176 break; | 186 break; |
177 } | 187 } |
178 | 188 |
179 return true; | 189 return true; |
180 } | 190 } |
181 | 191 |
| 192 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { |
| 193 } |
| 194 |
| 195 ProcessInfo::Module::~Module() { |
| 196 } |
| 197 |
182 ProcessInfo::ProcessInfo() | 198 ProcessInfo::ProcessInfo() |
183 : process_id_(), | 199 : process_id_(), |
184 inherited_from_process_id_(), | 200 inherited_from_process_id_(), |
185 command_line_(), | 201 command_line_(), |
186 modules_(), | 202 modules_(), |
187 is_64_bit_(false), | 203 is_64_bit_(false), |
188 is_wow64_(false), | 204 is_wow64_(false), |
189 initialized_() { | 205 initialized_() { |
190 } | 206 } |
191 | 207 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 318 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
303 return inherited_from_process_id_; | 319 return inherited_from_process_id_; |
304 } | 320 } |
305 | 321 |
306 bool ProcessInfo::CommandLine(std::wstring* command_line) const { | 322 bool ProcessInfo::CommandLine(std::wstring* command_line) const { |
307 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 323 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
308 *command_line = command_line_; | 324 *command_line = command_line_; |
309 return true; | 325 return true; |
310 } | 326 } |
311 | 327 |
312 bool ProcessInfo::Modules(std::vector<std::wstring>* modules) const { | 328 bool ProcessInfo::Modules(std::vector<Module>* modules) const { |
313 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 329 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
314 *modules = modules_; | 330 *modules = modules_; |
315 return true; | 331 return true; |
316 } | 332 } |
317 | 333 |
318 } // namespace crashpad | 334 } // namespace crashpad |
OLD | NEW |