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 <memory> |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 void AnalyzeDMGFile(base::File dmg_file, ArchiveAnalyzerResults* results) { | 120 void AnalyzeDMGFile(base::File dmg_file, ArchiveAnalyzerResults* results) { |
121 MachOFeatureExtractor feature_extractor; | 121 MachOFeatureExtractor feature_extractor; |
122 results->success = false; | 122 results->success = false; |
123 | 123 |
124 FileReadStream read_stream(dmg_file.GetPlatformFile()); | 124 FileReadStream read_stream(dmg_file.GetPlatformFile()); |
125 DMGIterator iterator(&read_stream); | 125 DMGIterator iterator(&read_stream); |
126 if (!iterator.Open()) | 126 if (!iterator.Open()) |
127 return; | 127 return; |
128 | 128 |
| 129 results->signature_blob.reserve(iterator.GetDmgSignatureLength()); |
| 130 std::copy(iterator.GetDmgSignatureData(), |
| 131 iterator.GetDmgSignatureData() + iterator.GetDmgSignatureLength(), |
| 132 std::back_inserter(results->signature_blob)); |
| 133 |
129 while (iterator.Next()) { | 134 while (iterator.Next()) { |
130 std::unique_ptr<ReadStream> stream = iterator.GetReadStream(); | 135 std::unique_ptr<ReadStream> stream = iterator.GetReadStream(); |
131 if (!stream || !feature_extractor.IsMachO(stream.get())) | 136 if (!stream || !feature_extractor.IsMachO(stream.get())) |
132 continue; | 137 continue; |
133 | 138 |
134 ClientDownloadRequest_ArchivedBinary* binary = | 139 ClientDownloadRequest_ArchivedBinary* binary = |
135 results->archived_binary.Add(); | 140 results->archived_binary.Add(); |
136 binary->set_file_basename(base::UTF16ToUTF8(iterator.GetPath())); | 141 binary->set_file_basename(base::UTF16ToUTF8(iterator.GetPath())); |
137 | 142 |
138 if (feature_extractor.ExtractFeatures(stream.get(), binary)) { | 143 if (feature_extractor.ExtractFeatures(stream.get(), binary)) { |
139 binary->set_download_type( | 144 binary->set_download_type( |
140 ClientDownloadRequest_DownloadType_MAC_EXECUTABLE); | 145 ClientDownloadRequest_DownloadType_MAC_EXECUTABLE); |
141 results->has_executable = true; | 146 results->has_executable = true; |
142 } else { | 147 } else { |
143 results->archived_binary.RemoveLast(); | 148 results->archived_binary.RemoveLast(); |
144 } | 149 } |
145 } | 150 } |
146 | 151 |
147 results->success = true; | 152 results->success = true; |
148 } | 153 } |
149 | 154 |
150 } // namespace dmg | 155 } // namespace dmg |
151 } // namespace safe_browsing | 156 } // namespace safe_browsing |
OLD | NEW |