| OLD | NEW |
| 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 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "courgette/courgette.h" | 13 #include "courgette/courgette.h" |
| 14 | 14 |
| 15 namespace courgette { | 15 namespace courgette { |
| 16 | 16 |
| 17 class AssemblyProgram; | 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); |
| 18 | 23 |
| 19 // Detects the type of an executable file, and it's length. The length may be | 24 // Detects the type of an executable file, and it's length. The length may be |
| 20 // slightly smaller than some executables (like ELF), but will include all bytes | 25 // slightly smaller than some executables (like ELF), but will include all bytes |
| 21 // the courgette algorithm has special benefit for. | 26 // the courgette algorithm has special benefit for. |
| 22 // On success: | 27 // On success: |
| 23 // Fills in |type| and |detected_length|, and returns C_OK. | 28 // Fills in |type| and |detected_length|, and returns C_OK. |
| 24 // On failure: | 29 // On failure: |
| 25 // Fills in |type| with UNKNOWN, |detected_length| with 0, and returns | 30 // Fills in |type| with UNKNOWN, |detected_length| with 0, and returns |
| 26 // C_INPUT_NOT_RECOGNIZED. | 31 // C_INPUT_NOT_RECOGNIZED. |
| 27 Status DetectExecutableType(const uint8_t* buffer, | 32 Status DetectExecutableType(const uint8_t* buffer, |
| 28 size_t length, | 33 size_t length, |
| 29 ExecutableType* type, | 34 ExecutableType* type, |
| 30 size_t* detected_length); | 35 size_t* detected_length); |
| 31 | 36 |
| 32 // Attempts to detect the type of executable by parsing it with the appropriate | |
| 33 // tools. | |
| 34 // On success: | |
| 35 // Parses the executable into a new AssemblyProgram in |*output|, and returns | |
| 36 // C_OK. | |
| 37 // On failure: | |
| 38 // Returns an error status and assigns |*output| to null. | |
| 39 Status ParseDetectedExecutable(const uint8_t* buffer, | |
| 40 size_t length, | |
| 41 std::unique_ptr<AssemblyProgram>* output); | |
| 42 | |
| 43 // ParseDetectedExecutable(), with Label annotations generated and stored in | |
| 44 // |output|. | |
| 45 Status ParseDetectedExecutableWithAnnotation( | |
| 46 const uint8_t* buffer, | |
| 47 size_t length, | |
| 48 std::unique_ptr<AssemblyProgram>* output); | |
| 49 | |
| 50 } // namespace courgette | 37 } // namespace courgette |
| 51 | 38 |
| 52 #endif // COURGETTE_PROGRAM_DETECTOR_H_ | 39 #endif // COURGETTE_PROGRAM_DETECTOR_H_ |
| OLD | NEW |