1 : // Copyright 2012 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 : #ifndef SYZYGY_PDB_PDB_WRITER_H_
16 : #define SYZYGY_PDB_PDB_WRITER_H_
17 :
18 : #include <vector>
19 :
20 : #include "base/file_util.h"
21 : #include "base/files/file_path.h"
22 : #include "syzygy/pdb/pdb_file.h"
23 : #include "syzygy/pdb/pdb_stream.h"
24 :
25 m : namespace pdb {
26 :
27 : // This class is used to write a pdb file to disk given a list of PdbStreams.
28 : // It will create a header and directory inside the pdb file that describe
29 : // the page layout of the streams in the file.
30 m : class PdbWriter {
31 m : public:
32 m : PdbWriter();
33 m : ~PdbWriter();
34 :
35 : // Writes the given PdbFile to disk with the given file name.
36 : // @param pdb_path the path of the PDB file to write.
37 : // @param pdb_file the PDB file to be written.
38 : // @returns true on success, false otherwise.
39 m : bool Write(const base::FilePath& pdb_path, const PdbFile& pdb_file);
40 :
41 m : protected:
42 : // Append the contents of the stream onto the file handle at the offset. The
43 : // contents of the file are padded to reach the next page boundary in the
44 : // output stream. The indices of the written pages are appended to
45 : // @p pages_written, while @p page_count is updated to reflect the total
46 : // number of pages written to disk.
47 m : bool AppendStream(PdbStream* stream,
48 m : std::vector<uint32>* pages_written,
49 m : uint32* page_count);
50 :
51 : // Writes the MSF header after the directory has been written.
52 m : bool WriteHeader(const std::vector<uint32>& root_directory_pages,
53 m : size_t directory_size,
54 m : uint32 page_count);
55 :
56 : // The current file handle open for writing.
57 m : file_util::ScopedFILE file_;
58 :
59 m : private:
60 m : DISALLOW_COPY_AND_ASSIGN(PdbWriter);
61 m : };
62 :
63 m : } // namespace pdb
64 :
65 : #endif // SYZYGY_PDB_PDB_WRITER_H_
|