OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/zip_analyzer.h" | 5 #include "chrome/common/safe_browsing/zip_analyzer.h" |
6 | 6 |
| 7 #include <set> |
| 8 |
7 #include "base/i18n/streaming_utf8_validator.h" | 9 #include "base/i18n/streaming_utf8_validator.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | 12 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
11 #include "chrome/common/safe_browsing/csd.pb.h" | 13 #include "chrome/common/safe_browsing/csd.pb.h" |
12 #include "chrome/common/safe_browsing/download_protection_util.h" | 14 #include "chrome/common/safe_browsing/download_protection_util.h" |
13 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | 15 #include "chrome/common/safe_browsing/zip_analyzer_results.h" |
14 #include "crypto/secure_hash.h" | 16 #include "crypto/secure_hash.h" |
15 #include "crypto/sha2.h" | 17 #include "crypto/sha2.h" |
16 #include "third_party/zlib/google/zip_reader.h" | 18 #include "third_party/zlib/google/zip_reader.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 archived_binary->clear_signature(); | 85 archived_binary->clear_signature(); |
84 } | 86 } |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 } // namespace | 90 } // namespace |
89 | 91 |
90 void AnalyzeZipFile(base::File zip_file, | 92 void AnalyzeZipFile(base::File zip_file, |
91 base::File temp_file, | 93 base::File temp_file, |
92 Results* results) { | 94 Results* results) { |
| 95 std::set<base::FilePath::StringType> archived_archive_filetypes; |
93 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( | 96 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( |
94 new BinaryFeatureExtractor()); | 97 new BinaryFeatureExtractor()); |
95 zip::ZipReader reader; | 98 zip::ZipReader reader; |
96 if (!reader.OpenFromPlatformFile(zip_file.GetPlatformFile())) { | 99 if (!reader.OpenFromPlatformFile(zip_file.GetPlatformFile())) { |
97 DVLOG(1) << "Failed to open zip file"; | 100 DVLOG(1) << "Failed to open zip file"; |
98 return; | 101 return; |
99 } | 102 } |
100 | 103 |
101 bool advanced = true; | 104 bool advanced = true; |
102 for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) { | 105 for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) { |
103 if (!advanced) { | 106 if (!advanced) { |
104 DVLOG(1) << "Could not advance to next entry, aborting zip scan."; | 107 DVLOG(1) << "Could not advance to next entry, aborting zip scan."; |
105 return; | 108 return; |
106 } | 109 } |
107 if (!reader.OpenCurrentEntryInZip()) { | 110 if (!reader.OpenCurrentEntryInZip()) { |
108 DVLOG(1) << "Failed to open current entry in zip file"; | 111 DVLOG(1) << "Failed to open current entry in zip file"; |
109 continue; | 112 continue; |
110 } | 113 } |
111 const base::FilePath& file = reader.current_entry_info()->file_path(); | 114 const base::FilePath& file = reader.current_entry_info()->file_path(); |
112 if (download_protection_util::IsBinaryFile(file)) { | 115 if (download_protection_util::IsArchiveFile(file)) { |
113 // Don't consider an archived archive to be executable, but record | 116 DVLOG(2) << "Downloaded a zipped archive: " << file.value(); |
114 // a histogram. | 117 results->has_archive = true; |
115 if (download_protection_util::IsArchiveFile(file)) { | 118 archived_archive_filetypes.insert(file.FinalExtension()); |
116 results->has_archive = true; | 119 } else if (download_protection_util::IsSupportedBinaryFile(file)) { |
117 } else { | 120 DVLOG(2) << "Downloaded a zipped executable: " << file.value(); |
118 DVLOG(2) << "Downloaded a zipped executable: " << file.value(); | 121 results->has_executable = true; |
119 results->has_executable = true; | 122 AnalyzeContainedFile(binary_feature_extractor, file, &reader, &temp_file, |
120 AnalyzeContainedFile(binary_feature_extractor, file, &reader, | 123 results->archived_binary.Add()); |
121 &temp_file, results->archived_binary.Add()); | |
122 } | |
123 } else { | 124 } else { |
124 DVLOG(3) << "Ignoring non-binary file: " << file.value(); | 125 DVLOG(3) << "Ignoring non-binary file: " << file.value(); |
125 } | 126 } |
126 } | 127 } |
| 128 results->archived_archive_filetypes.assign(archived_archive_filetypes.begin(), |
| 129 archived_archive_filetypes.end()); |
127 results->success = true; | 130 results->success = true; |
128 } | 131 } |
129 | 132 |
130 } // namespace zip_analyzer | 133 } // namespace zip_analyzer |
131 } // namespace safe_browsing | 134 } // namespace safe_browsing |
OLD | NEW |