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

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: sync Created 4 years, 5 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
« no previous file with comments | « courgette/disassembler_win32_x86_unittest.cc ('k') | courgette/program_detector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
9 #include <stdint.h>
9 10
10 #include <memory> 11 #include <memory>
11 12
12 #include "courgette/courgette.h" 13 #include "courgette/courgette.h"
13 14
14 namespace courgette { 15 namespace courgette {
15 16
16 class AssemblyProgram; 17 class AssemblyProgram;
17 18
18 // Detects the type of an executable file, and it's length. The length may be 19 // 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 20 // slightly smaller than some executables (like ELF), but will include all bytes
20 // the courgette algorithm has special benefit for. 21 // the courgette algorithm has special benefit for.
21 // On success: 22 // On success:
22 // Fills in |type| and |detected_length|, and returns C_OK. 23 // Fills in |type| and |detected_length|, and returns C_OK.
23 // On failure: 24 // On failure:
24 // Fills in |type| with UNKNOWN, |detected_length| with 0, and returns 25 // Fills in |type| with UNKNOWN, |detected_length| with 0, and returns
25 // C_INPUT_NOT_RECOGNIZED. 26 // C_INPUT_NOT_RECOGNIZED.
26 Status DetectExecutableType(const void* buffer, 27 Status DetectExecutableType(const uint8_t* buffer,
27 size_t length, 28 size_t length,
28 ExecutableType* type, 29 ExecutableType* type,
29 size_t* detected_length); 30 size_t* detected_length);
30 31
32 // Same as above, takes void* instead.
33 // TODO(etiennep): Propagate "const uint8_t*" upwards.
34 inline Status DetectExecutableType(const void* buffer,
35 size_t length,
36 ExecutableType* type,
37 size_t* detected_length) {
38 return DetectExecutableType(reinterpret_cast<const uint8_t*>(buffer), length,
39 type, detected_length);
40 }
41
31 // Attempts to detect the type of executable, and parse it with the appropriate 42 // Attempts to detect the type of executable, and parse it with the appropriate
32 // tools. 43 // tools.
33 // On success: 44 // On success:
34 // Parses the executable into a new AssemblyProgram in |*output|, and returns 45 // Parses the executable into a new AssemblyProgram in |*output|, and returns
35 // C_OK. 46 // C_OK.
36 // On failure: 47 // On failure:
37 // Returns an error status and assigns |*output| to null. 48 // Returns an error status and assigns |*output| to null.
38 Status ParseDetectedExecutable(const void* buffer, 49 Status ParseDetectedExecutable(const uint8_t* buffer,
39 size_t length, 50 size_t length,
40 std::unique_ptr<AssemblyProgram>* output); 51 std::unique_ptr<AssemblyProgram>* output);
41 52
53 // Same as above, takes void* instead.
54 // TODO(etiennep): Propagate "const uint8_t*" upwards.
55 inline Status ParseDetectedExecutable(
56 const void* buffer,
57 size_t length,
58 std::unique_ptr<AssemblyProgram>* output) {
59 return ParseDetectedExecutable(reinterpret_cast<const uint8_t*>(buffer),
60 length, output);
61 }
62
42 } // namespace courgette 63 } // namespace courgette
43 64
44 #endif // COURGETTE_PROGRAM_DETECTOR_H_ 65 #endif // COURGETTE_PROGRAM_DETECTOR_H_
OLDNEW
« no previous file with comments | « courgette/disassembler_win32_x86_unittest.cc ('k') | courgette/program_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698