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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 | 12 |
13 #include "base/i18n/streaming_utf8_validator.h" | 13 #include "base/i18n/streaming_utf8_validator.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | 16 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
17 #include "chrome/common/safe_browsing/csd.pb.h" | 17 #include "chrome/common/safe_browsing/csd.pb.h" |
18 #include "chrome/common/safe_browsing/download_protection_util.h" | 18 #include "chrome/common/safe_browsing/download_protection_util.h" |
| 19 #include "chrome/common/safe_browsing/file_type_policies.h" |
19 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | 20 #include "chrome/common/safe_browsing/zip_analyzer_results.h" |
20 #include "crypto/secure_hash.h" | 21 #include "crypto/secure_hash.h" |
21 #include "crypto/sha2.h" | 22 #include "crypto/sha2.h" |
22 #include "third_party/zlib/google/zip_reader.h" | 23 #include "third_party/zlib/google/zip_reader.h" |
23 | 24 |
24 namespace safe_browsing { | 25 namespace safe_browsing { |
25 namespace zip_analyzer { | 26 namespace zip_analyzer { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 archived_binary->clear_signature(); | 90 archived_binary->clear_signature(); |
90 } | 91 } |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 } // namespace | 95 } // namespace |
95 | 96 |
96 void AnalyzeZipFile(base::File zip_file, | 97 void AnalyzeZipFile(base::File zip_file, |
97 base::File temp_file, | 98 base::File temp_file, |
98 Results* results) { | 99 Results* results) { |
| 100 // Read the the file type policies from disk, since we won't have access |
| 101 // to those read by SafeBrowsingService if we're running in a utility process. |
| 102 safe_browsing::FileTypePoliciesManager file_type_policies_manager; |
| 103 |
99 std::set<base::FilePath> archived_archive_filenames; | 104 std::set<base::FilePath> archived_archive_filenames; |
100 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( | 105 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( |
101 new BinaryFeatureExtractor()); | 106 new BinaryFeatureExtractor()); |
102 zip::ZipReader reader; | 107 zip::ZipReader reader; |
103 if (!reader.OpenFromPlatformFile(zip_file.GetPlatformFile())) { | 108 if (!reader.OpenFromPlatformFile(zip_file.GetPlatformFile())) { |
104 DVLOG(1) << "Failed to open zip file"; | 109 DVLOG(1) << "Failed to open zip file"; |
105 return; | 110 return; |
106 } | 111 } |
107 | 112 |
108 bool advanced = true; | 113 bool advanced = true; |
109 for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) { | 114 for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) { |
110 if (!advanced) { | 115 if (!advanced) { |
111 DVLOG(1) << "Could not advance to next entry, aborting zip scan."; | 116 DVLOG(1) << "Could not advance to next entry, aborting zip scan."; |
112 return; | 117 return; |
113 } | 118 } |
114 if (!reader.OpenCurrentEntryInZip()) { | 119 if (!reader.OpenCurrentEntryInZip()) { |
115 DVLOG(1) << "Failed to open current entry in zip file"; | 120 DVLOG(1) << "Failed to open current entry in zip file"; |
116 continue; | 121 continue; |
117 } | 122 } |
118 const base::FilePath& file = reader.current_entry_info()->file_path(); | 123 const base::FilePath& file = reader.current_entry_info()->file_path(); |
119 if (download_protection_util::IsArchiveFile(file)) { | 124 if (FileTypePolicies::GlobalInstance()->IsArchiveFile(file)) { |
120 DVLOG(2) << "Downloaded a zipped archive: " << file.value(); | 125 DVLOG(2) << "Downloaded a zipped archive: " << file.value(); |
121 results->has_archive = true; | 126 results->has_archive = true; |
122 archived_archive_filenames.insert(file.BaseName()); | 127 archived_archive_filenames.insert(file.BaseName()); |
123 } else if (download_protection_util::IsSupportedBinaryFile(file)) { | 128 } else if (FileTypePolicies::GlobalInstance()->IsCheckedBinaryFile(file)) { |
124 DVLOG(2) << "Downloaded a zipped executable: " << file.value(); | 129 DVLOG(2) << "Downloaded a zipped executable: " << file.value(); |
125 results->has_executable = true; | 130 results->has_executable = true; |
126 AnalyzeContainedFile(binary_feature_extractor, file, &reader, &temp_file, | 131 AnalyzeContainedFile(binary_feature_extractor, file, &reader, &temp_file, |
127 results->archived_binary.Add()); | 132 results->archived_binary.Add()); |
128 } else { | 133 } else { |
129 DVLOG(3) << "Ignoring non-binary file: " << file.value(); | 134 DVLOG(3) << "Ignoring non-binary file: " << file.value(); |
130 } | 135 } |
131 } | 136 } |
132 results->archived_archive_filenames.assign(archived_archive_filenames.begin(), | 137 results->archived_archive_filenames.assign(archived_archive_filenames.begin(), |
133 archived_archive_filenames.end()); | 138 archived_archive_filenames.end()); |
134 results->success = true; | 139 results->success = true; |
135 } | 140 } |
136 | 141 |
137 } // namespace zip_analyzer | 142 } // namespace zip_analyzer |
138 } // namespace safe_browsing | 143 } // namespace safe_browsing |
OLD | NEW |