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 : // 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/files/file_path.h"
23 : #include "base/files/file_util.h"
24 : #include "base/strings/string_piece.h"
25 : #include "base/strings/string_util.h"
26 : #include "base/time/time.h"
27 : #include "syzygy/application/application.h"
28 : #include "syzygy/block_graph/block_graph.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 application::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 : DecomposeApp()
50 : : application::AppImplBase("Decomposer"),
51 : benchmark_load_(false),
52 : graph_only_(false),
53 E : strip_strings_(false) {
54 E : }
55 :
56 : bool ParseCommandLine(const base::CommandLine* command_line);
57 :
58 : int Run();
59 : // @}
60 :
61 : protected:
62 : // @name Utility functions
63 : // @{
64 : void PrintUsage(const base::FilePath& program,
65 : const base::StringPiece& message);
66 :
67 : bool SaveDecomposedImage(const pe::PEFile& pe_file,
68 : const ImageLayout& image_layout,
69 : const base::FilePath& output_path) const;
70 :
71 : bool LoadDecomposedImage(const base::FilePath& file_path) const;
72 : // @}
73 :
74 : // @name Command-line options.
75 : // @{
76 : base::FilePath image_path_;
77 : base::FilePath output_path_;
78 : bool benchmark_load_;
79 : bool graph_only_;
80 : bool strip_strings_;
81 : // @}
82 :
83 : private:
84 : DISALLOW_COPY_AND_ASSIGN(DecomposeApp);
85 : };
86 :
87 : } // namespace pe
88 :
89 : #endif // SYZYGY_PE_DECOMPOSE_APP_H_
|