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_PE_SERIALIZATION_H_
16 : #define SYZYGY_PE_SERIALIZATION_H_
17 :
18 : #include "base/files/file_path.h"
19 : #include "syzygy/block_graph/block_graph_serializer.h"
20 : #include "syzygy/core/serialization.h"
21 : #include "syzygy/pe/pe_file.h"
22 :
23 m : namespace pe {
24 :
25 : // Forward declarations.
26 m : struct ImageLayout;
27 :
28 : // Serializes the decomposition of a PE file, as represented by a BlockGraph
29 : // and an ImageLayout. The @p pe_file must correspond exactly to the
30 : // @p block_graph and @p image_layout pair.
31 : // @param pe_file the PE file that the decomposition represents.
32 : // @param attributes the attributes to be used in serializing @p block_graph.
33 : // @param image_layout the layout of @p block_graph in @p pe_file.
34 : // @param out_archive the archive object to receive the serialized
35 : // decomposition.
36 : // @returns true on success, false otherwise.
37 m : bool SaveBlockGraphAndImageLayout(
38 m : const PEFile& pe_file,
39 m : block_graph::BlockGraphSerializer::Attributes attributes,
40 m : const ImageLayout& image_layout,
41 m : core::OutArchive* out_archive);
42 :
43 : // Deserializes the decomposition of a PE file, as represented by a BlockGraph
44 : // and an ImageLayout. If already initialized, @p pe_file must correspond
45 : // exactly to the one referred to by the serialized contents of @p in_archive.
46 : // @param attributes the attributes used in serializing the block-graph. This
47 : // may be NULL.
48 : // @param pe_file the PE file that the decomposition represents.
49 : // As a const reference, this will be used strictly for
50 : // setting data pointers, and no search will be performed. If the provided
51 : // PEFile does not match the metadata in the serialized stream then the
52 : // call will fail.
53 : // As a pointer, the use is different. If the PEFile has already been
54 : // initialized and it matches the signature of the PE file referred to in
55 : // the archive, it will be used to populate block data. Otherwise, a search
56 : // for a matching PE file will be launched and this will be initialized to
57 : // that PE file, if found.
58 : // @param image_layout the layout of @p block_graph in @p pe_file.
59 : // @param in_archive the archive object storing the serialized block-graph and
60 : // image layout.
61 : // @returns true on success, false otherwise.
62 m : bool LoadBlockGraphAndImageLayout(
63 m : const PEFile& pe_file,
64 m : block_graph::BlockGraphSerializer::Attributes* attributes,
65 m : ImageLayout* image_layout,
66 m : core::InArchive* in_archive);
67 m : bool LoadBlockGraphAndImageLayout(
68 m : PEFile* pe_file,
69 m : block_graph::BlockGraphSerializer::Attributes* attributes,
70 m : ImageLayout* image_layout,
71 m : core::InArchive* in_archive);
72 :
73 m : } // namespace pe
74 :
75 : #endif // SYZYGY_PE_SERIALIZATION_H_
|