| 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/download_protection_util.h" | 5 #include "chrome/common/safe_browsing/download_protection_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 namespace safe_browsing { | 10 namespace safe_browsing { |
| 11 namespace download_protection_util { | 11 namespace download_protection_util { |
| 12 | 12 |
| 13 bool IsArchiveFile(const base::FilePath& file) { | 13 bool IsArchiveFile(const base::FilePath& file) { |
| 14 // TODO(mattm): should .dmg be checked here instead of IsBinaryFile? | 14 // TODO(mattm): should .dmg be checked here instead of IsBinaryFile? |
| 15 return file.MatchesExtension(FILE_PATH_LITERAL(".zip")); | 15 return file.MatchesExtension(FILE_PATH_LITERAL(".zip")); |
| 16 } | 16 } |
| 17 | 17 |
| 18 bool IsBinaryFile(const base::FilePath& file) { | 18 bool IsBinaryFile(const base::FilePath& file) { |
| 19 return ( | 19 const base::FilePath::CharType* kSupportedBinaryFileTypes[] = { |
| 20 // Executable extensions for MS Windows. | 20 // Executable extensions for MS Windows. |
| 21 file.MatchesExtension(FILE_PATH_LITERAL(".bas")) || | 21 FILE_PATH_LITERAL(".cab"), |
| 22 file.MatchesExtension(FILE_PATH_LITERAL(".bat")) || | 22 FILE_PATH_LITERAL(".cmd"), |
| 23 file.MatchesExtension(FILE_PATH_LITERAL(".cab")) || | 23 FILE_PATH_LITERAL(".com"), |
| 24 file.MatchesExtension(FILE_PATH_LITERAL(".cmd")) || | 24 FILE_PATH_LITERAL(".dll"), |
| 25 file.MatchesExtension(FILE_PATH_LITERAL(".com")) || | 25 FILE_PATH_LITERAL(".exe"), |
| 26 file.MatchesExtension(FILE_PATH_LITERAL(".exe")) || | 26 FILE_PATH_LITERAL(".msc"), |
| 27 file.MatchesExtension(FILE_PATH_LITERAL(".hta")) || | 27 FILE_PATH_LITERAL(".msi"), |
| 28 file.MatchesExtension(FILE_PATH_LITERAL(".msi")) || | 28 FILE_PATH_LITERAL(".msp"), |
| 29 file.MatchesExtension(FILE_PATH_LITERAL(".pif")) || | 29 FILE_PATH_LITERAL(".mst"), |
| 30 file.MatchesExtension(FILE_PATH_LITERAL(".reg")) || | 30 FILE_PATH_LITERAL(".pif"), |
| 31 file.MatchesExtension(FILE_PATH_LITERAL(".scr")) || | 31 FILE_PATH_LITERAL(".scr"), |
| 32 file.MatchesExtension(FILE_PATH_LITERAL(".url")) || | 32 // Not binary, but still contain executable code, or can be used to launch |
| 33 file.MatchesExtension(FILE_PATH_LITERAL(".vb")) || | 33 // other executables. |
| 34 file.MatchesExtension(FILE_PATH_LITERAL(".vbs")) || | 34 FILE_PATH_LITERAL(".bas"), |
| 35 file.MatchesExtension(FILE_PATH_LITERAL(".website")) || | 35 FILE_PATH_LITERAL(".bat"), |
| 36 FILE_PATH_LITERAL(".hta"), |
| 37 FILE_PATH_LITERAL(".js"), |
| 38 FILE_PATH_LITERAL(".jse"), |
| 39 FILE_PATH_LITERAL(".mht"), |
| 40 FILE_PATH_LITERAL(".mhtml"), |
| 41 FILE_PATH_LITERAL(".msh"), |
| 42 FILE_PATH_LITERAL(".msh1"), |
| 43 FILE_PATH_LITERAL(".msh1xml"), |
| 44 FILE_PATH_LITERAL(".msh2"), |
| 45 FILE_PATH_LITERAL(".msh2xml"), |
| 46 FILE_PATH_LITERAL(".mshxml"), |
| 47 FILE_PATH_LITERAL(".ps1"), |
| 48 FILE_PATH_LITERAL(".ps1xml"), |
| 49 FILE_PATH_LITERAL(".ps2"), |
| 50 FILE_PATH_LITERAL(".ps2xml"), |
| 51 FILE_PATH_LITERAL(".psc1"), |
| 52 FILE_PATH_LITERAL(".psc2"), |
| 53 FILE_PATH_LITERAL(".reg"), |
| 54 FILE_PATH_LITERAL(".scf"), |
| 55 FILE_PATH_LITERAL(".sct"), |
| 56 FILE_PATH_LITERAL(".url"), |
| 57 FILE_PATH_LITERAL(".vb"), |
| 58 FILE_PATH_LITERAL(".vbe"), |
| 59 FILE_PATH_LITERAL(".vbs"), |
| 60 FILE_PATH_LITERAL(".website"), |
| 61 FILE_PATH_LITERAL(".wsf"), |
| 36 // Chrome extensions and android APKs are also reported. | 62 // Chrome extensions and android APKs are also reported. |
| 37 file.MatchesExtension(FILE_PATH_LITERAL(".crx")) || | 63 FILE_PATH_LITERAL(".apk"), |
| 38 file.MatchesExtension(FILE_PATH_LITERAL(".apk")) || | 64 FILE_PATH_LITERAL(".crx"), |
| 39 // Mac extensions. | 65 // Mac extensions. |
| 40 file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) || | 66 FILE_PATH_LITERAL(".app"), |
| 41 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) || | 67 FILE_PATH_LITERAL(".dmg"), |
| 42 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) || | 68 FILE_PATH_LITERAL(".osx"), |
| 43 file.MatchesExtension(FILE_PATH_LITERAL(".app")) || | 69 FILE_PATH_LITERAL(".pkg"), |
| 44 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures. | 70 }; |
| 45 IsArchiveFile(file)); | 71 for (const auto& extension : kSupportedBinaryFileTypes) |
| 72 if (file.MatchesExtension(extension)) |
| 73 return true; |
| 74 |
| 75 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures. |
| 76 return IsArchiveFile(file); |
| 46 } | 77 } |
| 47 | 78 |
| 48 ClientDownloadRequest::DownloadType GetDownloadType( | 79 ClientDownloadRequest::DownloadType GetDownloadType( |
| 49 const base::FilePath& file) { | 80 const base::FilePath& file) { |
| 50 DCHECK(IsBinaryFile(file)); | 81 DCHECK(IsBinaryFile(file)); |
| 51 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk"))) | 82 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk"))) |
| 52 return ClientDownloadRequest::ANDROID_APK; | 83 return ClientDownloadRequest::ANDROID_APK; |
| 53 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx"))) | 84 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx"))) |
| 54 return ClientDownloadRequest::CHROME_EXTENSION; | 85 return ClientDownloadRequest::CHROME_EXTENSION; |
| 55 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send | 86 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send |
| 56 // the pingback if we find an executable inside the zip archive. | 87 // the pingback if we find an executable inside the zip archive. |
| 57 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip"))) | 88 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip"))) |
| 58 return ClientDownloadRequest::ZIPPED_EXECUTABLE; | 89 return ClientDownloadRequest::ZIPPED_EXECUTABLE; |
| 59 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) || | 90 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) || |
| 60 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) || | 91 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) || |
| 61 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) || | 92 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) || |
| 62 file.MatchesExtension(FILE_PATH_LITERAL(".app"))) | 93 file.MatchesExtension(FILE_PATH_LITERAL(".app"))) |
| 63 return ClientDownloadRequest::MAC_EXECUTABLE; | 94 return ClientDownloadRequest::MAC_EXECUTABLE; |
| 64 return ClientDownloadRequest::WIN_EXECUTABLE; | 95 return ClientDownloadRequest::WIN_EXECUTABLE; |
| 65 } | 96 } |
| 66 | 97 |
| 67 } // namespace download_protection_util | 98 } // namespace download_protection_util |
| 68 } // namespace safe_browsing | 99 } // namespace safe_browsing |
| OLD | NEW |