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

Side by Side Diff: chrome/common/safe_browsing/pe_image_reader_win.cc

Issue 1880143002: Convert chrome/common to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/safe_browsing/pe_image_reader_win.h" 5 #include "chrome/common/safe_browsing/pe_image_reader_win.h"
6 6
7 #include <wintrust.h> 7 #include <wintrust.h>
8 8
9 #include <memory>
10
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/macros.h" 12 #include "base/macros.h"
11 13
12 namespace safe_browsing { 14 namespace safe_browsing {
13 15
14 // A class template of traits pertaining to IMAGE_OPTIONAL_HEADER{32,64}. 16 // A class template of traits pertaining to IMAGE_OPTIONAL_HEADER{32,64}.
15 template<class HEADER_TYPE> 17 template<class HEADER_TYPE>
16 struct OptionalHeaderTraits { 18 struct OptionalHeaderTraits {
17 }; 19 };
18 20
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 const size_t optional_header_offset = 239 const size_t optional_header_offset =
238 GetDosHeader()->e_lfanew + offsetof(IMAGE_NT_HEADERS32, OptionalHeader); 240 GetDosHeader()->e_lfanew + offsetof(IMAGE_NT_HEADERS32, OptionalHeader);
239 const size_t optional_header_size = file_header->SizeOfOptionalHeader; 241 const size_t optional_header_size = file_header->SizeOfOptionalHeader;
240 const WORD* optional_header_magic = NULL; 242 const WORD* optional_header_magic = NULL;
241 243
242 if (optional_header_size < sizeof(*optional_header_magic) || 244 if (optional_header_size < sizeof(*optional_header_magic) ||
243 !GetStructureAt(optional_header_offset, &optional_header_magic)) { 245 !GetStructureAt(optional_header_offset, &optional_header_magic)) {
244 return false; 246 return false;
245 } 247 }
246 248
247 scoped_ptr<OptionalHeader> optional_header; 249 std::unique_ptr<OptionalHeader> optional_header;
248 if (*optional_header_magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { 250 if (*optional_header_magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
249 optional_header.reset(new OptionalHeaderImpl<IMAGE_OPTIONAL_HEADER32>( 251 optional_header.reset(new OptionalHeaderImpl<IMAGE_OPTIONAL_HEADER32>(
250 image_data_ + optional_header_offset)); 252 image_data_ + optional_header_offset));
251 } else if (*optional_header_magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { 253 } else if (*optional_header_magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
252 optional_header.reset(new OptionalHeaderImpl<IMAGE_OPTIONAL_HEADER64>( 254 optional_header.reset(new OptionalHeaderImpl<IMAGE_OPTIONAL_HEADER64>(
253 image_data_ + optional_header_offset)); 255 image_data_ + optional_header_offset));
254 } else { 256 } else {
255 return false; 257 return false;
256 } 258 }
257 259
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if (data_offset >= header->SizeOfRawData || 371 if (data_offset >= header->SizeOfRawData ||
370 header->SizeOfRawData - data_offset < entry->Size) { 372 header->SizeOfRawData - data_offset < entry->Size) {
371 return NULL; 373 return NULL;
372 } 374 }
373 375
374 *data_length = entry->Size; 376 *data_length = entry->Size;
375 return image_data_ + header->PointerToRawData + data_offset; 377 return image_data_ + header->PointerToRawData + data_offset;
376 } 378 }
377 379
378 } // namespace safe_browsing 380 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/common/safe_browsing/pe_image_reader_win.h ('k') | chrome/common/safe_browsing/zip_analyzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698