huangs | 8d5be25 | 2016-01-29 22:14:18 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COURGETTE_PROGRAM_DETECTOR_H_ |
| 6 | #define COURGETTE_PROGRAM_DETECTOR_H_ |
| 7 | |
| 8 | #include <stddef.h> |
etiennep | 5059bca | 2016-07-08 17:55:20 | [diff] [blame] | 9 | #include <stdint.h> |
huangs | 8d5be25 | 2016-01-29 22:14:18 | [diff] [blame] | 10 | |
mostynb | 1007a4a | 2016-04-11 23:18:06 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
huangs | 8d5be25 | 2016-01-29 22:14:18 | [diff] [blame] | 13 | #include "courgette/courgette.h" |
| 14 | |
| 15 | namespace courgette { |
| 16 | |
huangs | 8845133 | 2017-05-18 19:50:34 | [diff] [blame] | 17 | class Disassembler; |
| 18 | |
| 19 | // Returns a new instance of Disassembler inherited class if binary data given |
| 20 | // in |buffer| and |length| match a known binary format, otherwise null. |
| 21 | std::unique_ptr<Disassembler> DetectDisassembler(const uint8_t* buffer, |
| 22 | size_t length); |
huangs | 8d5be25 | 2016-01-29 22:14:18 | [diff] [blame] | 23 | |
| 24 | // Detects the type of an executable file, and it's length. The length may be |
| 25 | // slightly smaller than some executables (like ELF), but will include all bytes |
| 26 | // the courgette algorithm has special benefit for. |
| 27 | // On success: |
| 28 | // Fills in |type| and |detected_length|, and returns C_OK. |
| 29 | // On failure: |
| 30 | // Fills in |type| with UNKNOWN, |detected_length| with 0, and returns |
| 31 | // C_INPUT_NOT_RECOGNIZED. |
etiennep | 5059bca | 2016-07-08 17:55:20 | [diff] [blame] | 32 | Status DetectExecutableType(const uint8_t* buffer, |
huangs | 8d5be25 | 2016-01-29 22:14:18 | [diff] [blame] | 33 | size_t length, |
| 34 | ExecutableType* type, |
| 35 | size_t* detected_length); |
| 36 | |
huangs | 8d5be25 | 2016-01-29 22:14:18 | [diff] [blame] | 37 | } // namespace courgette |
| 38 | |
mostynb | 1007a4a | 2016-04-11 23:18:06 | [diff] [blame] | 39 | #endif // COURGETTE_PROGRAM_DETECTOR_H_ |