1 : // Copyright 2013 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // The CoffFileWriter is the final step in the processing pipeline of COFF
16 : // files; it expects a fully laid out image and writes it to disk, only
17 : // performing the most basic sanity checks.
18 :
19 : #ifndef SYZYGY_PE_COFF_FILE_WRITER_H_
20 : #define SYZYGY_PE_COFF_FILE_WRITER_H_
21 :
22 : #include "base/files/file_path.h"
23 : #include "syzygy/pe/image_layout.h"
24 :
25 m : namespace pe {
26 :
27 : // A CoffFileWriter writes a fully laid out COFF image to disk. Contrary to
28 : // its PE counterpart, the COFF writer does not alter the contents of the
29 : // blocks before writing. In particular, it does not patch references.
30 m : class CoffFileWriter {
31 m : public:
32 : // Construct a file writer for the specified COFF image layout. The layout
33 : // must be valid for a COFF file, with all references resolved, offsets
34 : // fixed and relocation data present and accurate.
35 : //
36 : // @param image_layout the image layout to write.
37 m : explicit CoffFileWriter(const ImageLayout* image_layout);
38 :
39 : // Write the image to the specified file. The file is overwritten by this
40 : // call, whether it succeeds or not.
41 : //
42 : // @param path the path of the file to write.
43 : // @returns true on success, false on failure.
44 m : bool WriteImage(const base::FilePath& path);
45 :
46 m : private:
47 : // The image layout to write to disk.
48 m : const ImageLayout* image_layout_;
49 :
50 m : private:
51 m : DISALLOW_COPY_AND_ASSIGN(CoffFileWriter);
52 m : };
53 :
54 m : } // namespace pe
55 :
56 : #endif // SYZYGY_PE_COFF_FILE_WRITER_H_
|