1 : // Copyright 2012 Google Inc.
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 : // A command line application to decompose and image and serialize the
16 : // decomposition to a file.
17 :
18 : #ifndef SYZYGY_PE_DECOMPOSE_APP_H_
19 : #define SYZYGY_PE_DECOMPOSE_APP_H_
20 :
21 : #include "base/command_line.h"
22 : #include "base/file_path.h"
23 : #include "base/file_util.h"
24 : #include "base/string_piece.h"
25 : #include "base/string_util.h"
26 : #include "base/time.h"
27 : #include "syzygy/block_graph/block_graph.h"
28 : #include "syzygy/common/application.h"
29 : #include "syzygy/pe/image_layout.h"
30 : #include "syzygy/pe/pe_file.h"
31 :
32 :
33 : namespace pe {
34 :
35 : // This class implements the decompose command-line utility.
36 : //
37 : // See the description given in DecomposeApp:::PrintUsage() for information
38 : // about running this utility.
39 : class DecomposeApp : public common::AppImplBase {
40 : public:
41 : typedef block_graph::BlockGraph::AddressSpace AddressSpace;
42 : typedef block_graph::BlockGraph::Block Block;
43 : typedef block_graph::BlockGraph BlockGraph;
44 : typedef std::set<const BlockGraph::Block*> BlockSet;
45 : typedef pe::ImageLayout ImageLayout;
46 :
47 : // @name Implementation of the AppImplBase interface.
48 : // @{
49 E : DecomposeApp() : common::AppImplBase("Decomposer"), benchmark_load_(false) {
50 E : }
51 :
52 : bool ParseCommandLine(const CommandLine* command_line);
53 :
54 : int Run();
55 : // @}
56 :
57 : protected:
58 : // @name Utility functions
59 : // @{
60 : void PrintUsage(const FilePath& program,
61 : const base::StringPiece& message);
62 :
63 : bool SaveDecomposedImage(const pe::PEFile& pe_file,
64 : const ImageLayout& image_layout,
65 : const FilePath& output_path) const;
66 :
67 : bool LoadDecomposedImage(const FilePath& file_path) const;
68 : // @}
69 :
70 : // @name Command-line options.
71 : // @{
72 : FilePath image_path_;
73 : FilePath output_path_;
74 : bool benchmark_load_;
75 : bool graph_only_;
76 : bool strip_strings_;
77 : // @}
78 :
79 : private:
80 : DISALLOW_COPY_AND_ASSIGN(DecomposeApp);
81 : };
82 :
83 : } // namespace pe
84 :
85 : #endif // SYZYGY_PE_DECOMPOSE_APP_H_
|