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.
5 #include "chrome/common/safe_browsing/download_protection_util.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
10 namespace safe_browsing
{
11 namespace download_protection_util
{
13 bool IsArchiveFile(const base::FilePath
& file
) {
14 // TODO(mattm): should .dmg be checked here instead of IsBinaryFile?
15 return file
.MatchesExtension(FILE_PATH_LITERAL(".zip"));
18 bool IsBinaryFile(const base::FilePath
& file
) {
19 const base::FilePath::CharType
* kSupportedBinaryFileTypes
[] = {
20 // Executable extensions for MS Windows.
21 FILE_PATH_LITERAL(".cab"),
22 FILE_PATH_LITERAL(".cmd"),
23 FILE_PATH_LITERAL(".com"),
24 FILE_PATH_LITERAL(".dll"),
25 FILE_PATH_LITERAL(".exe"),
26 FILE_PATH_LITERAL(".msc"),
27 FILE_PATH_LITERAL(".msi"),
28 FILE_PATH_LITERAL(".msp"),
29 FILE_PATH_LITERAL(".mst"),
30 FILE_PATH_LITERAL(".pif"),
31 FILE_PATH_LITERAL(".scr"),
32 // Not binary, but still contain executable code, or can be used to launch
34 FILE_PATH_LITERAL(".bas"),
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"),
62 // Chrome extensions and android APKs are also reported.
63 FILE_PATH_LITERAL(".apk"),
64 FILE_PATH_LITERAL(".crx"),
66 FILE_PATH_LITERAL(".app"),
67 FILE_PATH_LITERAL(".dmg"),
68 FILE_PATH_LITERAL(".osx"),
69 FILE_PATH_LITERAL(".pkg"),
71 for (const auto& extension
: kSupportedBinaryFileTypes
)
72 if (file
.MatchesExtension(extension
))
75 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures.
76 return IsArchiveFile(file
);
79 ClientDownloadRequest::DownloadType
GetDownloadType(
80 const base::FilePath
& file
) {
81 DCHECK(IsBinaryFile(file
));
82 if (file
.MatchesExtension(FILE_PATH_LITERAL(".apk")))
83 return ClientDownloadRequest::ANDROID_APK
;
84 else if (file
.MatchesExtension(FILE_PATH_LITERAL(".crx")))
85 return ClientDownloadRequest::CHROME_EXTENSION
;
86 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send
87 // the pingback if we find an executable inside the zip archive.
88 else if (file
.MatchesExtension(FILE_PATH_LITERAL(".zip")))
89 return ClientDownloadRequest::ZIPPED_EXECUTABLE
;
90 else if (file
.MatchesExtension(FILE_PATH_LITERAL(".dmg")) ||
91 file
.MatchesExtension(FILE_PATH_LITERAL(".pkg")) ||
92 file
.MatchesExtension(FILE_PATH_LITERAL(".osx")) ||
93 file
.MatchesExtension(FILE_PATH_LITERAL(".app")))
94 return ClientDownloadRequest::MAC_EXECUTABLE
;
95 return ClientDownloadRequest::WIN_EXECUTABLE
;
98 } // namespace download_protection_util
99 } // namespace safe_browsing