Home | History | Annotate | Download | only in safe_browsing
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/common/safe_browsing/zip_analyzer.h"
      6 
      7 #include "base/logging.h"
      8 #include "chrome/common/safe_browsing/download_protection_util.h"
      9 #include "third_party/zlib/google/zip_reader.h"
     10 
     11 namespace safe_browsing {
     12 namespace zip_analyzer {
     13 
     14 void AnalyzeZipFile(base::PlatformFile zip_file, Results* results) {
     15   zip::ZipReader reader;
     16   if (!reader.OpenFromPlatformFile(zip_file)) {
     17     VLOG(1) << "Failed to open zip file";
     18     return;
     19   }
     20 
     21   bool advanced = true;
     22   for (; reader.HasMore(); advanced = reader.AdvanceToNextEntry()) {
     23     if (!advanced) {
     24       VLOG(1) << "Could not advance to next entry, aborting zip scan.";
     25       return;
     26     }
     27     if (!reader.OpenCurrentEntryInZip()) {
     28       VLOG(1) << "Failed to open current entry in zip file";
     29       continue;
     30     }
     31     const base::FilePath& file = reader.current_entry_info()->file_path();
     32     if (download_protection_util::IsBinaryFile(file)) {
     33       // Don't consider an archived archive to be executable, but record
     34       // a histogram.
     35       if (download_protection_util::IsArchiveFile(file)) {
     36         results->has_archive = true;
     37       } else {
     38         VLOG(2) << "Downloaded a zipped executable: " << file.value();
     39         results->has_executable = true;
     40         break;
     41       }
     42     } else {
     43       VLOG(3) << "Ignoring non-binary file: " << file.value();
     44     }
     45   }
     46   results->success = true;
     47 }
     48 
     49 }  // namespace zip_analyzer
     50 }  // namespace safe_browsing
     51