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/download_protection_util.h" 6 7 #include "base/files/file_path.h" 8 #include "base/logging.h" 9 10 namespace safe_browsing { 11 namespace download_protection_util { 12 13 bool IsArchiveFile(const base::FilePath& file) { 14 return file.MatchesExtension(FILE_PATH_LITERAL(".zip")); 15 } 16 17 bool IsBinaryFile(const base::FilePath& file) { 18 return ( 19 // Executable extensions for MS Windows. 20 file.MatchesExtension(FILE_PATH_LITERAL(".bas")) || 21 file.MatchesExtension(FILE_PATH_LITERAL(".bat")) || 22 file.MatchesExtension(FILE_PATH_LITERAL(".cab")) || 23 file.MatchesExtension(FILE_PATH_LITERAL(".cmd")) || 24 file.MatchesExtension(FILE_PATH_LITERAL(".com")) || 25 file.MatchesExtension(FILE_PATH_LITERAL(".exe")) || 26 file.MatchesExtension(FILE_PATH_LITERAL(".hta")) || 27 file.MatchesExtension(FILE_PATH_LITERAL(".msi")) || 28 file.MatchesExtension(FILE_PATH_LITERAL(".pif")) || 29 file.MatchesExtension(FILE_PATH_LITERAL(".reg")) || 30 file.MatchesExtension(FILE_PATH_LITERAL(".scr")) || 31 file.MatchesExtension(FILE_PATH_LITERAL(".vb")) || 32 file.MatchesExtension(FILE_PATH_LITERAL(".vbs")) || 33 // Chrome extensions and android APKs are also reported. 34 file.MatchesExtension(FILE_PATH_LITERAL(".crx")) || 35 file.MatchesExtension(FILE_PATH_LITERAL(".apk")) || 36 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures. 37 IsArchiveFile(file)); 38 } 39 40 ClientDownloadRequest::DownloadType GetDownloadType( 41 const base::FilePath& file) { 42 DCHECK(IsBinaryFile(file)); 43 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk"))) 44 return ClientDownloadRequest::ANDROID_APK; 45 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx"))) 46 return ClientDownloadRequest::CHROME_EXTENSION; 47 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send 48 // the pingback if we find an executable inside the zip archive. 49 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip"))) 50 return ClientDownloadRequest::ZIPPED_EXECUTABLE; 51 return ClientDownloadRequest::WIN_EXECUTABLE; 52 } 53 54 } // namespace download_protection_util 55 } // namespace safe_browsing 56