OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/utility/safe_browsing/mac/dmg_analyzer.h" | 5 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | 15 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
16 #include "chrome/common/safe_browsing/csd.pb.h" | 16 #include "chrome/common/safe_browsing/csd.pb.h" |
17 #include "chrome/common/safe_browsing/mach_o_image_reader_mac.h" | 17 #include "chrome/common/safe_browsing/mach_o_image_reader_mac.h" |
18 #include "chrome/utility/safe_browsing/mac/dmg_iterator.h" | 18 #include "chrome/utility/safe_browsing/mac/dmg_iterator.h" |
19 #include "chrome/utility/safe_browsing/mac/read_stream.h" | 19 #include "chrome/utility/safe_browsing/mac/read_stream.h" |
20 #include "crypto/secure_hash.h" | 20 #include "crypto/secure_hash.h" |
21 #include "crypto/sha2.h" | 21 #include "crypto/sha2.h" |
22 | 22 |
23 namespace safe_browsing { | 23 namespace safe_browsing { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
91 bool MachOFeatureExtractor::HashAndCopyStream( | 91 bool MachOFeatureExtractor::HashAndCopyStream( |
92 ReadStream* stream, uint8_t digest[crypto::kSHA256Length]) { | 92 ReadStream* stream, uint8_t digest[crypto::kSHA256Length]) { |
93 if (stream->Seek(0, SEEK_SET) != 0) | 93 if (stream->Seek(0, SEEK_SET) != 0) |
94 return false; | 94 return false; |
95 | 95 |
96 buffer_.clear(); | 96 buffer_.clear(); |
97 scoped_ptr<crypto::SecureHash> sha256( | 97 std::unique_ptr<crypto::SecureHash> sha256( |
98 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 98 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
99 | 99 |
100 size_t bytes_read; | 100 size_t bytes_read; |
101 const size_t kBufferSize = 2048; | 101 const size_t kBufferSize = 2048; |
102 do { | 102 do { |
103 size_t buffer_offset = buffer_.size(); | 103 size_t buffer_offset = buffer_.size(); |
104 | 104 |
105 buffer_.resize(buffer_.size() + kBufferSize); | 105 buffer_.resize(buffer_.size() + kBufferSize); |
106 if (!stream->Read(&buffer_[buffer_offset], kBufferSize, &bytes_read)) | 106 if (!stream->Read(&buffer_[buffer_offset], kBufferSize, &bytes_read)) |
107 return false; | 107 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
121 safe_browsing::zip_analyzer::Results* results) { | 121 safe_browsing::zip_analyzer::Results* results) { |
122 MachOFeatureExtractor feature_extractor; | 122 MachOFeatureExtractor feature_extractor; |
123 results->success = false; | 123 results->success = false; |
124 | 124 |
125 FileReadStream read_stream(dmg_file.GetPlatformFile()); | 125 FileReadStream read_stream(dmg_file.GetPlatformFile()); |
126 DMGIterator iterator(&read_stream); | 126 DMGIterator iterator(&read_stream); |
127 if (!iterator.Open()) | 127 if (!iterator.Open()) |
128 return; | 128 return; |
129 | 129 |
130 while (iterator.Next()) { | 130 while (iterator.Next()) { |
131 scoped_ptr<ReadStream> stream = iterator.GetReadStream(); | 131 std::unique_ptr<ReadStream> stream = iterator.GetReadStream(); |
132 if (!stream || !feature_extractor.IsMachO(stream.get())) | 132 if (!stream || !feature_extractor.IsMachO(stream.get())) |
133 continue; | 133 continue; |
134 | 134 |
135 ClientDownloadRequest_ArchivedBinary* binary = | 135 ClientDownloadRequest_ArchivedBinary* binary = |
136 results->archived_binary.Add(); | 136 results->archived_binary.Add(); |
137 binary->set_file_basename(base::UTF16ToUTF8(iterator.GetPath())); | 137 binary->set_file_basename(base::UTF16ToUTF8(iterator.GetPath())); |
138 | 138 |
139 if (feature_extractor.ExtractFeatures(stream.get(), binary)) { | 139 if (feature_extractor.ExtractFeatures(stream.get(), binary)) { |
140 binary->set_download_type( | 140 binary->set_download_type( |
141 ClientDownloadRequest_DownloadType_MAC_EXECUTABLE); | 141 ClientDownloadRequest_DownloadType_MAC_EXECUTABLE); |
142 results->has_executable = true; | 142 results->has_executable = true; |
143 } else { | 143 } else { |
144 results->archived_binary.RemoveLast(); | 144 results->archived_binary.RemoveLast(); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 results->success = true; | 148 results->success = true; |
149 } | 149 } |
150 | 150 |
151 } // namespace dmg | 151 } // namespace dmg |
152 } // namespace safe_browsing | 152 } // namespace safe_browsing |
OLD | NEW |