Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: courgette/program_detector.h

Issue 2055343002: Courgette: Add static method QuickDetect() to optimize program detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Propagate uint8_t* to unittests and Nits Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef COURGETTE_PROGRAM_DETECTOR_H_ 5 #ifndef COURGETTE_PROGRAM_DETECTOR_H_
6 #define COURGETTE_PROGRAM_DETECTOR_H_ 6 #define COURGETTE_PROGRAM_DETECTOR_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
huangs 2016/06/15 00:13:05 #include <stdint.h>
etiennep 2016/06/15 20:38:07 Done.
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "courgette/courgette.h" 12 #include "courgette/courgette.h"
13 13
14 namespace courgette { 14 namespace courgette {
15 15
16 class AssemblyProgram; 16 class AssemblyProgram;
17 17
18 // Detects the type of an executable file, and it's length. The length may be 18 // Detects the type of an executable file, and it's length. The length may be
19 // slightly smaller than some executables (like ELF), but will include all bytes 19 // slightly smaller than some executables (like ELF), but will include all bytes
20 // the courgette algorithm has special benefit for. 20 // the courgette algorithm has special benefit for.
21 // On success: 21 // On success:
22 // Fills in |type| and |detected_length|, and returns C_OK. 22 // Fills in |type| and |detected_length|, and returns C_OK.
23 // On failure: 23 // On failure:
24 // Fills in |type| with UNKNOWN, |detected_length| with 0, and returns 24 // Fills in |type| with UNKNOWN, |detected_length| with 0, and returns
25 // C_INPUT_NOT_RECOGNIZED. 25 // C_INPUT_NOT_RECOGNIZED.
26 Status DetectExecutableType(const void* buffer, 26 Status DetectExecutableType(const uint8_t* buffer,
27 size_t length, 27 size_t length,
28 ExecutableType* type, 28 ExecutableType* type,
29 size_t* detected_length); 29 size_t* detected_length);
30 30
31 // Same as above, takes void* instead.
32 // TODO(etiennep): Propagate "const uint8_t*" upwards.
33 inline Status DetectExecutableType(const void* buffer,
34 size_t length,
35 ExecutableType* type,
36 size_t* detected_length) {
37 return DetectExecutableType(reinterpret_cast<const uint8_t*>(buffer), length,
38 type, detected_length);
39 }
40
31 // Attempts to detect the type of executable, and parse it with the appropriate 41 // Attempts to detect the type of executable, and parse it with the appropriate
32 // tools. 42 // tools.
33 // On success: 43 // On success:
34 // Parses the executable into a new AssemblyProgram in |*output|, and returns 44 // Parses the executable into a new AssemblyProgram in |*output|, and returns
35 // C_OK. 45 // C_OK.
36 // On failure: 46 // On failure:
37 // Returns an error status and assigns |*output| to null. 47 // Returns an error status and assigns |*output| to null.
38 Status ParseDetectedExecutable(const void* buffer, 48 Status ParseDetectedExecutable(const uint8_t* buffer,
39 size_t length, 49 size_t length,
40 std::unique_ptr<AssemblyProgram>* output); 50 std::unique_ptr<AssemblyProgram>* output);
41 51
52 // Same as above, takes void* instead.
53 // TODO(etiennep): Propagate "const uint8_t*" upwards.
54 inline Status ParseDetectedExecutable(
55 const void* buffer,
56 size_t length,
57 std::unique_ptr<AssemblyProgram>* output) {
58 return ParseDetectedExecutable(reinterpret_cast<const uint8_t*>(buffer),
59 length, output);
60 }
61
42 } // namespace courgette 62 } // namespace courgette
43 63
44 #endif // COURGETTE_PROGRAM_DETECTOR_H_ 64 #endif // COURGETTE_PROGRAM_DETECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698