OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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_COURGETTE_H_ |
| 6 #define COURGETTE_COURGETTE_H_ |
| 7 |
| 8 namespace courgette { |
| 9 |
| 10 // Status codes for Courgette APIs. |
| 11 // |
| 12 // Client code should only rely on the distintion between C_OK and the other |
| 13 // status codes. |
| 14 // |
| 15 enum Status { |
| 16 C_OK = 1, // Successful operation. |
| 17 |
| 18 C_GENERAL_ERROR = 2, // Error other than listed below. |
| 19 |
| 20 C_READ_OPEN_ERROR = 3, // Could not open input file for reading. |
| 21 C_READ_ERROR = 4, // Could not read from opened input file. |
| 22 |
| 23 C_WRITE_OPEN_ERROR = 3, // Could not open output file for writing. |
| 24 C_WRITE_ERROR = 4, // Could not write to opened output file. |
| 25 |
| 26 C_BAD_ENSEMBLE_MAGIC = 5, // Ensemble patch has bad magic. |
| 27 C_BAD_ENSEMBLE_VERSION = 6, // Ensemble patch has wrong version. |
| 28 C_BAD_ENSEMBLE_HEADER = 7, // Ensemble patch has corrupt header. |
| 29 C_BAD_ENSEMBLE_CRC = 8, // Ensemble patch has corrupt header. |
| 30 |
| 31 C_BAD_TRANSFORM = 12, // Transform mis-specified. |
| 32 C_BAD_BASE = 13, // Base for transform malformed. |
| 33 |
| 34 C_BINARY_DIFF_CRC_ERROR = 14, // Internal diff input doesn't have expected |
| 35 // CRC. |
| 36 |
| 37 // Internal errors. |
| 38 C_STREAM_ERROR = 20, // Unexpected error from streams.h. |
| 39 C_STREAM_NOT_CONSUMED = 21, // Stream has extra data, is expected to be |
| 40 // used up. |
| 41 C_SERIALIZATION_FAILED = 22, // |
| 42 C_DESERIALIZATION_FAILED = 23, // |
| 43 C_INPUT_NOT_RECOGNIZED = 24, // Unrecognized input (not an executable). |
| 44 C_DISASSEMBLY_FAILED = 25, // |
| 45 C_ASSEMBLY_FAILED = 26, // |
| 46 C_ADJUSTMENT_FAILED = 27, // |
| 47 |
| 48 |
| 49 }; |
| 50 |
| 51 class SinkStream; |
| 52 class SinkStreamSet; |
| 53 class SourceStream; |
| 54 class SourceStreamSet; |
| 55 |
| 56 class AssemblyProgram; |
| 57 class EncodedProgram; |
| 58 |
| 59 // Applies the patch to the bytes in |old| and writes the transformed ensemble |
| 60 // to |output|. |
| 61 // Returns C_OK unless something went wrong. |
| 62 Status ApplyEnsemblePatch(SourceStream* old, SourceStream* patch, |
| 63 SinkStream* output); |
| 64 |
| 65 // Applies the patch in |patch_file_name| to the bytes in |old_file_name| and |
| 66 // writes the transformed ensemble to |new_file_name|. |
| 67 // Returns C_OK unless something went wrong. |
| 68 // This function first validates that the patch file has a proper header, so the |
| 69 // function can be used to 'try' a patch. |
| 70 Status ApplyEnsemblePatch(const wchar_t* old_file_name, |
| 71 const wchar_t* patch_file_name, |
| 72 const wchar_t* new_file_name); |
| 73 |
| 74 // Generates a patch that will transform the bytes in |old| into the bytes in |
| 75 // |target|. |
| 76 // Returns C_OK unless something when wrong (unexpected). |
| 77 Status GenerateEnsemblePatch(SourceStream* old, SourceStream* target, |
| 78 SinkStream* patch); |
| 79 |
| 80 // Parses a Windows 32-bit 'Portable Executable' format file from memory, |
| 81 // storing the pointer to the AssemblyProgram in |*output|. |
| 82 // Returns C_OK if successful, otherwise returns an error status and sets |
| 83 // |*output| to NULL. |
| 84 Status ParseWin32X86PE(const void* buffer, size_t length, |
| 85 AssemblyProgram** output); |
| 86 |
| 87 // Converts |program| into encoded form, returning it as |*output|. |
| 88 // Returns C_OK if succeeded, otherwise returns an error status and |
| 89 // sets |*output| to NULL |
| 90 Status Encode(AssemblyProgram* program, EncodedProgram** output); |
| 91 |
| 92 |
| 93 // Serializes |encoded| into the stream set. |
| 94 // Returns C_OK if succeeded, otherwise returns an error status. |
| 95 Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink); |
| 96 |
| 97 // Assembles |encoded|, emitting the bytes into |buffer|. |
| 98 // Returns C_OK if succeeded, otherwise returns an error status and leaves |
| 99 // |buffer| in an undefined state. |
| 100 Status Assemble(EncodedProgram* encoded, SinkStream* buffer); |
| 101 |
| 102 // Deserializes program from the stream set. |
| 103 // Returns C_OK if succeeded, otherwise returns an error status and |
| 104 // sets |*output| to NULL |
| 105 Status ReadEncodedProgram(SourceStreamSet* source, EncodedProgram** output); |
| 106 |
| 107 // Used to free an AssemblyProgram returned by other APIs. |
| 108 void DeleteAssemblyProgram(AssemblyProgram* program); |
| 109 |
| 110 // Used to free an EncodedProgram returned by other APIs. |
| 111 void DeleteEncodedProgram(EncodedProgram* encoded); |
| 112 |
| 113 // Adjusts |program| to look more like |model|. |
| 114 // |
| 115 Status Adjust(const AssemblyProgram& model, AssemblyProgram *program); |
| 116 |
| 117 } // namespace courgette |
| 118 #endif // COURGETTE_COURGETTE_H_ |
OLD | NEW |