Chromium Code Reviews| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/common/safe_browsing/download_protection_util.h" | 8 #include "chrome/common/safe_browsing/download_protection_util.h" |
| 9 #include "components/zip/zip_reader.h" | 9 #include "components/zip/zip_reader.h" |
| 10 | 10 |
| 11 namespace safe_browsing { | 11 namespace safe_browsing { |
| 12 namespace zip_analyzer { | 12 namespace zip_analyzer { |
| 13 | 13 |
| 14 void AnalyzeZipFile(base::PlatformFile zip_file, Results* results) { | 14 void AnalyzeZipFile(base::PlatformFile zip_file, Results* results) { |
| 15 zip::ZipReader reader; | 15 zip::ZipReader reader; |
| 16 if (!reader.OpenFromPlatformFile(zip_file)) { | 16 if (!reader.OpenFromPlatformFile(zip_file)) { |
| 17 VLOG(1) << "Failed to open zip file"; | 17 VLOG(1) << "Failed to open zip file"; |
| 18 return; | 18 return; |
| 19 } | 19 } |
| 20 | 20 |
| 21 for (; reader.HasMore(); reader.AdvanceToNextEntry()) { | 21 bool advanced = true; |
| 22 for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) { | |
| 23 if (!advanced) { | |
|
mattm
2013/04/10 20:05:22
maybe cleaner to use a while loop like:
while (has
Brian Ryner
2013/04/10 20:11:47
I'm not sure how much cleaner that turns out to be
mattm
2013/04/10 20:23:27
ah, right.
| |
| 24 VLOG(1) << "Could not advance to next entry, aborting zip scan."; | |
| 25 return; | |
| 26 } | |
| 22 if (!reader.OpenCurrentEntryInZip()) { | 27 if (!reader.OpenCurrentEntryInZip()) { |
| 23 VLOG(1) << "Failed to open current entry in zip file"; | 28 VLOG(1) << "Failed to open current entry in zip file"; |
| 24 continue; | 29 continue; |
| 25 } | 30 } |
| 26 const base::FilePath& file = reader.current_entry_info()->file_path(); | 31 const base::FilePath& file = reader.current_entry_info()->file_path(); |
| 27 if (download_protection_util::IsBinaryFile(file)) { | 32 if (download_protection_util::IsBinaryFile(file)) { |
| 28 // Don't consider an archived archive to be executable, but record | 33 // Don't consider an archived archive to be executable, but record |
| 29 // a histogram. | 34 // a histogram. |
| 30 if (download_protection_util::IsArchiveFile(file)) { | 35 if (download_protection_util::IsArchiveFile(file)) { |
| 31 results->has_archive = true; | 36 results->has_archive = true; |
| 32 } else { | 37 } else { |
| 33 VLOG(2) << "Downloaded a zipped executable: " << file.value(); | 38 VLOG(2) << "Downloaded a zipped executable: " << file.value(); |
| 34 results->has_executable = true; | 39 results->has_executable = true; |
| 35 break; | 40 break; |
| 36 } | 41 } |
| 37 } else { | 42 } else { |
| 38 VLOG(3) << "Ignoring non-binary file: " << file.value(); | 43 VLOG(3) << "Ignoring non-binary file: " << file.value(); |
| 39 } | 44 } |
| 40 } | 45 } |
| 41 results->success = true; | 46 results->success = true; |
| 42 } | 47 } |
| 43 | 48 |
| 44 } // namespace zip_analyzer | 49 } // namespace zip_analyzer |
| 45 } // namespace safe_browsing | 50 } // namespace safe_browsing |
| OLD | NEW |