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 an image to a human-readable,
16 : // textual description.
17 :
18 : #ifndef SYZYGY_PE_DECOMPOSE_IMAGE_TO_TEXT_APP_H_
19 : #define SYZYGY_PE_DECOMPOSE_IMAGE_TO_TEXT_APP_H_
20 :
21 : #include "base/files/file_path.h"
22 : #include "syzygy/application/application.h"
23 : #include "syzygy/block_graph/basic_block_subgraph.h"
24 : #include "syzygy/block_graph/block_graph.h"
25 :
26 m : namespace pe {
27 :
28 : // This class implements the decompose image to text command-line utility.
29 : //
30 : // See the description given in PrintUsage() for information about running
31 : // this utility.
32 m : class DecomposeImageToTextApp : public application::AppImplBase {
33 m : public:
34 m : DecomposeImageToTextApp();
35 :
36 : // @name Implementation of the AppImplBase interface.
37 : // @{
38 m : bool ParseCommandLine(const base::CommandLine* command_line);
39 :
40 m : int Run();
41 : // @}
42 :
43 m : protected:
44 m : typedef block_graph::BlockGraph BlockGraph;
45 m : typedef block_graph::BasicBlock BasicBlock;
46 m : typedef block_graph::BasicCodeBlock BasicCodeBlock;
47 m : typedef block_graph::BasicDataBlock BasicDataBlock;
48 m : typedef block_graph::BasicEndBlock BasicEndBlock;
49 m : typedef block_graph::BasicBlockSubGraph BasicBlockSubGraph;
50 :
51 m : void PrintUsage(const base::FilePath& program,
52 m : const base::StringPiece& message);
53 :
54 : // Given @p address_space, dump it in text format to out().
55 m : void DumpAddressSpaceToText(const BlockGraph::AddressSpace& address_space);
56 :
57 : // Given @p subgraph, dump it in text format to out().
58 m : void DumpSubGraphToText(BasicBlockSubGraph& subgraph);
59 :
60 : // Given the code basic block @p bb, dump it in text format to out().
61 m : void DumpCodeBBToText(const BlockGraph::Block* block,
62 m : const BasicCodeBlock* bb);
63 : // Given the data basic block @p bb, dump it in text format to out().
64 m : void DumpDataBBToText(const BlockGraph::Block* block,
65 m : const BasicDataBlock* bb);
66 : // Given the end basic block @p bb, dump it in text format to out().
67 m : void DumpEndBBToText(const BlockGraph::Block* block,
68 m : const BasicEndBlock* bb);
69 :
70 : // Dump @p block at @p addr in text format to out().
71 m : void DumpBlockToText(core::RelativeAddress addr,
72 m : const BlockGraph::Block* block);
73 :
74 : // Dump the image at @p image_path to out().
75 m : bool DumpImageToText(const base::FilePath& image_path);
76 :
77 : // The image to decompose.
78 m : base::FilePath image_path_;
79 :
80 : // True if we're to dump basic block information.
81 m : bool dump_basic_blocks_;
82 :
83 : // Number of references we've encountered.
84 m : size_t num_refs_;
85 m : };
86 :
87 m : } // namespace pe
88 :
89 : #endif // SYZYGY_PE_DECOMPOSE_IMAGE_TO_TEXT_APP_H_
|