OLD | NEW |
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 "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 // underlying structure type from the point of view of the PeImageReader. | 30 // underlying structure type from the point of view of the PeImageReader. |
31 template<class OPTIONAL_HEADER_TYPE> | 31 template<class OPTIONAL_HEADER_TYPE> |
32 class PeImageReader::OptionalHeaderImpl : public PeImageReader::OptionalHeader { | 32 class PeImageReader::OptionalHeaderImpl : public PeImageReader::OptionalHeader { |
33 public: | 33 public: |
34 typedef OptionalHeaderTraits<OPTIONAL_HEADER_TYPE> TraitsType; | 34 typedef OptionalHeaderTraits<OPTIONAL_HEADER_TYPE> TraitsType; |
35 | 35 |
36 explicit OptionalHeaderImpl(const uint8_t* optional_header_start) | 36 explicit OptionalHeaderImpl(const uint8_t* optional_header_start) |
37 : optional_header_(reinterpret_cast<const OPTIONAL_HEADER_TYPE*>( | 37 : optional_header_(reinterpret_cast<const OPTIONAL_HEADER_TYPE*>( |
38 optional_header_start)) {} | 38 optional_header_start)) {} |
39 | 39 |
40 virtual WordSize GetWordSize() override { | 40 WordSize GetWordSize() override { |
41 return TraitsType::word_size; | 41 return TraitsType::word_size; |
42 } | 42 } |
43 | 43 |
44 virtual size_t GetDataDirectoryOffset() override { | 44 size_t GetDataDirectoryOffset() override { |
45 return offsetof(OPTIONAL_HEADER_TYPE, DataDirectory); | 45 return offsetof(OPTIONAL_HEADER_TYPE, DataDirectory); |
46 } | 46 } |
47 | 47 |
48 virtual DWORD GetDataDirectorySize() override { | 48 DWORD GetDataDirectorySize() override { |
49 return optional_header_->NumberOfRvaAndSizes; | 49 return optional_header_->NumberOfRvaAndSizes; |
50 } | 50 } |
51 | 51 |
52 virtual const IMAGE_DATA_DIRECTORY* GetDataDirectoryEntries() override { | 52 const IMAGE_DATA_DIRECTORY* GetDataDirectoryEntries() override { |
53 return &optional_header_->DataDirectory[0]; | 53 return &optional_header_->DataDirectory[0]; |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 const OPTIONAL_HEADER_TYPE* optional_header_; | 57 const OPTIONAL_HEADER_TYPE* optional_header_; |
58 DISALLOW_COPY_AND_ASSIGN(OptionalHeaderImpl); | 58 DISALLOW_COPY_AND_ASSIGN(OptionalHeaderImpl); |
59 }; | 59 }; |
60 | 60 |
61 PeImageReader::PeImageReader() | 61 PeImageReader::PeImageReader() |
62 : image_data_(), | 62 : image_data_(), |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 if (data_offset >= header->SizeOfRawData || | 368 if (data_offset >= header->SizeOfRawData || |
369 header->SizeOfRawData - data_offset < entry->Size) { | 369 header->SizeOfRawData - data_offset < entry->Size) { |
370 return NULL; | 370 return NULL; |
371 } | 371 } |
372 | 372 |
373 *data_length = entry->Size; | 373 *data_length = entry->Size; |
374 return image_data_ + header->PointerToRawData + data_offset; | 374 return image_data_ + header->PointerToRawData + data_offset; |
375 } | 375 } |
376 | 376 |
377 } // namespace safe_browsing | 377 } // namespace safe_browsing |
OLD | NEW |