1 // Copyright 2014 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 // Utility functions to extract file features for malicious binary detection.
6 // Each platform has its own implementation of this class.
8 #ifndef CHROME_COMMON_SAFE_BROWSING_BINARY_FEATURE_EXTRACTOR_H_
9 #define CHROME_COMMON_SAFE_BROWSING_BINARY_FEATURE_EXTRACTOR_H_
11 #include "base/basictypes.h"
12 #include "base/files/file.h"
13 #include "base/memory/ref_counted.h"
19 namespace safe_browsing
{
20 class ClientDownloadRequest_Digests
;
21 class ClientDownloadRequest_ImageHeaders
;
22 class ClientDownloadRequest_SignatureInfo
;
24 class BinaryFeatureExtractor
25 : public base::RefCountedThreadSafe
<BinaryFeatureExtractor
> {
27 // The type and defined values for a bitfield that controls aspects of image
29 typedef uint32_t ExtractHeadersOption
;
30 static const ExtractHeadersOption kDefaultOptions
= 0;
31 static const ExtractHeadersOption kOmitExports
= 1U << 0;
33 BinaryFeatureExtractor();
35 // Fills in the DownloadRequest_SignatureInfo for the given file path.
36 // This method may be called on any thread.
37 virtual void CheckSignature(
38 const base::FilePath
& file_path
,
39 ClientDownloadRequest_SignatureInfo
* signature_info
);
41 // Populates |image_headers| with the PE image headers of |file_path|.
42 // |options| is a bitfield controlling aspects of extraction. Returns true if
43 // |image_headers| is populated with any information.
44 virtual bool ExtractImageHeaders(
45 const base::FilePath
& file_path
,
46 ExtractHeadersOption options
,
47 ClientDownloadRequest_ImageHeaders
* image_headers
);
49 // As above, but works with an already-opened file. BinaryFeatureExtractor
50 // takes ownership of |file| and closes it when done.
51 virtual bool ExtractImageHeadersFromFile(
53 ExtractHeadersOption options
,
54 ClientDownloadRequest_ImageHeaders
* image_headers
);
56 // Populates |digests.sha256| with the SHA256 digest of |file_path|.
57 virtual void ExtractDigest(const base::FilePath
& file_path
,
58 ClientDownloadRequest_Digests
* digests
);
61 friend class base::RefCountedThreadSafe
<BinaryFeatureExtractor
>;
62 virtual ~BinaryFeatureExtractor();
65 DISALLOW_COPY_AND_ASSIGN(BinaryFeatureExtractor
);
67 } // namespace safe_browsing
69 #endif // CHROME_COMMON_SAFE_BROWSING_BINARY_FEATURE_EXTRACTOR_H_