| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) { | 110 for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) { |
| 110 if (!advanced) { | 111 if (!advanced) { |
| 111 DVLOG(1) << "Could not advance to next entry, aborting zip scan."; | 112 DVLOG(1) << "Could not advance to next entry, aborting zip scan."; |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 if (!reader.OpenCurrentEntryInZip()) { | 115 if (!reader.OpenCurrentEntryInZip()) { |
| 115 DVLOG(1) << "Failed to open current entry in zip file"; | 116 DVLOG(1) << "Failed to open current entry in zip file"; |
| 116 continue; | 117 continue; |
| 117 } | 118 } |
| 118 const base::FilePath& file = reader.current_entry_info()->file_path(); | 119 const base::FilePath& file = reader.current_entry_info()->file_path(); |
| 119 if (download_protection_util::IsArchiveFile(file)) { | 120 if (FileTypePolicies::GetInstance()->IsArchiveFile(file)) { |
| 120 DVLOG(2) << "Downloaded a zipped archive: " << file.value(); | 121 DVLOG(2) << "Downloaded a zipped archive: " << file.value(); |
| 121 results->has_archive = true; | 122 results->has_archive = true; |
| 122 archived_archive_filenames.insert(file.BaseName()); | 123 archived_archive_filenames.insert(file.BaseName()); |
| 123 } else if (download_protection_util::IsSupportedBinaryFile(file)) { | 124 } else if (FileTypePolicies::GetInstance()->IsCheckedBinaryFile(file)) { |
| 124 DVLOG(2) << "Downloaded a zipped executable: " << file.value(); | 125 DVLOG(2) << "Downloaded a zipped executable: " << file.value(); |
| 125 results->has_executable = true; | 126 results->has_executable = true; |
| 126 AnalyzeContainedFile(binary_feature_extractor, file, &reader, &temp_file, | 127 AnalyzeContainedFile(binary_feature_extractor, file, &reader, &temp_file, |
| 127 results->archived_binary.Add()); | 128 results->archived_binary.Add()); |
| 128 } else { | 129 } else { |
| 129 DVLOG(3) << "Ignoring non-binary file: " << file.value(); | 130 DVLOG(3) << "Ignoring non-binary file: " << file.value(); |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 results->archived_archive_filenames.assign(archived_archive_filenames.begin(), | 133 results->archived_archive_filenames.assign(archived_archive_filenames.begin(), |
| 133 archived_archive_filenames.end()); | 134 archived_archive_filenames.end()); |
| 134 results->success = true; | 135 results->success = true; |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace zip_analyzer | 138 } // namespace zip_analyzer |
| 138 } // namespace safe_browsing | 139 } // namespace safe_browsing |
| OLD | NEW |