| 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 = iterator.GetCodeSignature(); |
| 130 |
| 129 while (iterator.Next()) { | 131 while (iterator.Next()) { |
| 130 std::unique_ptr<ReadStream> stream = iterator.GetReadStream(); | 132 std::unique_ptr<ReadStream> stream = iterator.GetReadStream(); |
| 131 if (!stream || !feature_extractor.IsMachO(stream.get())) | 133 if (!stream || !feature_extractor.IsMachO(stream.get())) |
| 132 continue; | 134 continue; |
| 133 | 135 |
| 134 ClientDownloadRequest_ArchivedBinary* binary = | 136 ClientDownloadRequest_ArchivedBinary* binary = |
| 135 results->archived_binary.Add(); | 137 results->archived_binary.Add(); |
| 136 binary->set_file_basename(base::UTF16ToUTF8(iterator.GetPath())); | 138 binary->set_file_basename(base::UTF16ToUTF8(iterator.GetPath())); |
| 137 | 139 |
| 138 if (feature_extractor.ExtractFeatures(stream.get(), binary)) { | 140 if (feature_extractor.ExtractFeatures(stream.get(), binary)) { |
| 139 binary->set_download_type( | 141 binary->set_download_type( |
| 140 ClientDownloadRequest_DownloadType_MAC_EXECUTABLE); | 142 ClientDownloadRequest_DownloadType_MAC_EXECUTABLE); |
| 141 results->has_executable = true; | 143 results->has_executable = true; |
| 142 } else { | 144 } else { |
| 143 results->archived_binary.RemoveLast(); | 145 results->archived_binary.RemoveLast(); |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 | 148 |
| 147 results->success = true; | 149 results->success = true; |
| 148 } | 150 } |
| 149 | 151 |
| 150 } // namespace dmg | 152 } // namespace dmg |
| 151 } // namespace safe_browsing | 153 } // namespace safe_browsing |
| OLD | NEW |