Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: snapshot/win/pe_image_reader.cc

Issue 1430773003: win: Handle binary with embedded CodeView debug record (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « snapshot/win/module_snapshot_win.cc ('k') | util/win/process_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 if (!CheckedReadMemory(Address() + data_directory.VirtualAddress + offset, 169 if (!CheckedReadMemory(Address() + data_directory.VirtualAddress + offset,
170 sizeof(debug_directory), 170 sizeof(debug_directory),
171 &debug_directory)) { 171 &debug_directory)) {
172 LOG(WARNING) << "could not read data directory"; 172 LOG(WARNING) << "could not read data directory";
173 return false; 173 return false;
174 } 174 }
175 175
176 if (debug_directory.Type != IMAGE_DEBUG_TYPE_CODEVIEW) 176 if (debug_directory.Type != IMAGE_DEBUG_TYPE_CODEVIEW)
177 continue; 177 continue;
178 178
179 if (debug_directory.SizeOfData < sizeof(CodeViewRecordPDB70)) { 179 if (debug_directory.AddressOfRawData) {
180 LOG(WARNING) << "CodeView debug entry of unexpected size"; 180 if (debug_directory.SizeOfData < sizeof(CodeViewRecordPDB70)) {
181 continue; 181 LOG(WARNING) << "CodeView debug entry of unexpected size";
182 continue;
183 }
184
185 scoped_ptr<char[]> data(new char[debug_directory.SizeOfData]);
186 if (!CheckedReadMemory(Address() + debug_directory.AddressOfRawData,
187 debug_directory.SizeOfData,
188 data.get())) {
189 LOG(WARNING) << "could not read debug directory";
190 return false;
191 }
192
193 if (*reinterpret_cast<DWORD*>(data.get()) !=
194 CodeViewRecordPDB70::kSignature) {
195 LOG(WARNING) << "encountered non-7.0 CodeView debug record";
196 continue;
197 }
198
199 CodeViewRecordPDB70* codeview =
200 reinterpret_cast<CodeViewRecordPDB70*>(data.get());
201 *uuid = codeview->uuid;
202 *age = codeview->age;
203 // This is a NUL-terminated string encoded in the codepage of the system
204 // where the binary was linked. We have no idea what that was, so we just
205 // assume ASCII.
206 *pdbname = std::string(reinterpret_cast<char*>(&codeview->pdb_name[0]));
207 return true;
208 } else if (debug_directory.PointerToRawData) {
209 // This occurs for non-PDB based debug information. We simply ignore these
210 // as we don't expect to encounter modules that will be in this format
211 // for which we'll actually have symbols. See
212 // https://crashpad.chromium.org/bug/47.
182 } 213 }
183 scoped_ptr<char[]> data(new char[debug_directory.SizeOfData]);
184 if (!CheckedReadMemory(Address() + debug_directory.AddressOfRawData,
185 debug_directory.SizeOfData,
186 data.get())) {
187 LOG(WARNING) << "could not read debug directory";
188 return false;
189 }
190
191 if (*reinterpret_cast<DWORD*>(data.get()) !=
192 CodeViewRecordPDB70::kSignature) {
193 // TODO(scottmg): Consider supporting other record types, see
194 // https://crashpad.chromium.org/bug/47.
195 LOG(WARNING) << "encountered non-7.0 CodeView debug record";
196 continue;
197 }
198
199 CodeViewRecordPDB70* codeview =
200 reinterpret_cast<CodeViewRecordPDB70*>(data.get());
201 *uuid = codeview->uuid;
202 *age = codeview->age;
203 // This is a NUL-terminated string encoded in the codepage of the system
204 // where the binary was linked. We have no idea what that was, so we just
205 // assume ASCII.
206 *pdbname = std::string(reinterpret_cast<char*>(&codeview->pdb_name[0]));
207 return true;
208 } 214 }
209 215
210 return false; 216 return false;
211 } 217 }
212 218
213 template <class NtHeadersType> 219 template <class NtHeadersType>
214 bool PEImageReader::ReadNtHeaders(NtHeadersType* nt_headers, 220 bool PEImageReader::ReadNtHeaders(NtHeadersType* nt_headers,
215 WinVMAddress* nt_headers_address) const { 221 WinVMAddress* nt_headers_address) const {
216 IMAGE_DOS_HEADER dos_header; 222 IMAGE_DOS_HEADER dos_header;
217 if (!CheckedReadMemory(Address(), sizeof(IMAGE_DOS_HEADER), &dos_header)) { 223 if (!CheckedReadMemory(Address(), sizeof(IMAGE_DOS_HEADER), &dos_header)) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Explicit instantiations with the only 2 valid template arguments to avoid 301 // Explicit instantiations with the only 2 valid template arguments to avoid
296 // putting the body of the function in the header. 302 // putting the body of the function in the header.
297 template bool PEImageReader::GetCrashpadInfo<process_types::internal::Traits32>( 303 template bool PEImageReader::GetCrashpadInfo<process_types::internal::Traits32>(
298 process_types::CrashpadInfo<process_types::internal::Traits32>* 304 process_types::CrashpadInfo<process_types::internal::Traits32>*
299 crashpad_info) const; 305 crashpad_info) const;
300 template bool PEImageReader::GetCrashpadInfo<process_types::internal::Traits64>( 306 template bool PEImageReader::GetCrashpadInfo<process_types::internal::Traits64>(
301 process_types::CrashpadInfo<process_types::internal::Traits64>* 307 process_types::CrashpadInfo<process_types::internal::Traits64>*
302 crashpad_info) const; 308 crashpad_info) const;
303 309
304 } // namespace crashpad 310 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/module_snapshot_win.cc ('k') | util/win/process_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698