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.timestamp = ldr_data_table_entry.TimeDateStamp; | |
150 process_info->modules_.push_back(module); | 154 process_info->modules_.push_back(module); |
151 | 155 |
152 // Walk the PEB LDR structure (doubly-linked list) to get the list of loaded | 156 // 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 | 157 // modules. We use this method rather than EnumProcessModules to get the |
154 // modules in initialization order rather than memory order. | 158 // modules in initialization order rather than memory order. |
155 Traits::Pointer last = peb_ldr_data.InInitializationOrderModuleList.Blink; | 159 Traits::Pointer last = peb_ldr_data.InInitializationOrderModuleList.Blink; |
156 for (Traits::Pointer cur = peb_ldr_data.InInitializationOrderModuleList.Flink; | 160 for (Traits::Pointer cur = peb_ldr_data.InInitializationOrderModuleList.Flink; |
157 ; | 161 ; |
158 cur = ldr_data_table_entry.InInitializationOrderLinks.Flink) { | 162 cur = ldr_data_table_entry.InInitializationOrderLinks.Flink) { |
159 // |cur| is the pointer to the LIST_ENTRY embedded in the | 163 // |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 | 164 // 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 | 165 // to read from the target, and also offset back to the beginning of the |
162 // structure. | 166 // structure. |
163 if (!ReadStruct(process, | 167 if (!ReadStruct(process, |
164 reinterpret_cast<uintptr_t>( | 168 reinterpret_cast<uintptr_t>( |
165 reinterpret_cast<const char*>(cur) - | 169 reinterpret_cast<const char*>(cur) - |
166 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, | 170 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, |
167 InInitializationOrderLinks)), | 171 InInitializationOrderLinks)), |
168 &ldr_data_table_entry)) { | 172 &ldr_data_table_entry)) { |
169 break; | 173 break; |
170 } | 174 } |
171 // TODO(scottmg): Capture TimeDateStamp, Checksum, etc. too? | 175 // TODO(scottmg): Capture Checksum, etc. too? |
172 if (!ReadUnicodeString(process, ldr_data_table_entry.FullDllName, &module)) | 176 if (!ReadUnicodeString( |
177 process, ldr_data_table_entry.FullDllName, &module.name)) { | |
173 break; | 178 break; |
179 } | |
180 module.dll_base = ldr_data_table_entry.DllBase; | |
181 module.timestamp = ldr_data_table_entry.TimeDateStamp; | |
174 process_info->modules_.push_back(module); | 182 process_info->modules_.push_back(module); |
175 if (cur == last) | 183 if (cur == last) |
176 break; | 184 break; |
177 } | 185 } |
178 | 186 |
179 return true; | 187 return true; |
180 } | 188 } |
181 | 189 |
190 ProcessInfo::Module::Module() : name(), timestamp(0) { | |
Mark Mentovai
2015/04/29 19:37:16
dll_base(0)
scottmg
2015/04/30 03:31:32
Done.
| |
191 } | |
192 | |
193 ProcessInfo::Module::~Module() { | |
194 } | |
195 | |
182 ProcessInfo::ProcessInfo() | 196 ProcessInfo::ProcessInfo() |
183 : process_id_(), | 197 : process_id_(), |
184 inherited_from_process_id_(), | 198 inherited_from_process_id_(), |
185 command_line_(), | 199 command_line_(), |
186 modules_(), | 200 modules_(), |
187 is_64_bit_(false), | 201 is_64_bit_(false), |
188 is_wow64_(false), | 202 is_wow64_(false), |
189 initialized_() { | 203 initialized_() { |
190 } | 204 } |
191 | 205 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 316 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
303 return inherited_from_process_id_; | 317 return inherited_from_process_id_; |
304 } | 318 } |
305 | 319 |
306 bool ProcessInfo::CommandLine(std::wstring* command_line) const { | 320 bool ProcessInfo::CommandLine(std::wstring* command_line) const { |
307 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 321 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
308 *command_line = command_line_; | 322 *command_line = command_line_; |
309 return true; | 323 return true; |
310 } | 324 } |
311 | 325 |
312 bool ProcessInfo::Modules(std::vector<std::wstring>* modules) const { | 326 bool ProcessInfo::Modules(std::vector<Module>* modules) const { |
313 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 327 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
314 *modules = modules_; | 328 *modules = modules_; |
315 return true; | 329 return true; |
316 } | 330 } |
317 | 331 |
318 } // namespace crashpad | 332 } // namespace crashpad |
OLD | NEW |