zip_analyzer.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "chrome/common/zip_reader.h" 10 11namespace safe_browsing { 12namespace zip_analyzer { 13 14void 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 for (; reader.HasMore(); reader.AdvanceToNextEntry()) { 22 if (!reader.OpenCurrentEntryInZip()) { 23 VLOG(1) << "Failed to open current entry in zip file"; 24 continue; 25 } 26 const base::FilePath& file = reader.current_entry_info()->file_path(); 27 if (download_protection_util::IsBinaryFile(file)) { 28 // Don't consider an archived archive to be executable, but record 29 // a histogram. 30 if (download_protection_util::IsArchiveFile(file)) { 31 results->has_archive = true; 32 } else { 33 VLOG(2) << "Downloaded a zipped executable: " << file.value(); 34 results->has_executable = true; 35 break; 36 } 37 } else { 38 VLOG(3) << "Ignoring non-binary file: " << file.value(); 39 } 40 } 41 results->success = true; 42} 43 44} // namespace zip_analyzer 45} // namespace safe_browsing 46