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 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/file_path.h"
22 : #include "syzygy/block_graph/basic_block_subgraph.h"
23 : #include "syzygy/block_graph/block_graph.h"
24 : #include "syzygy/common/application.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 common::AppImplBase {
33 m : public:
34 m : DecomposeImageToTextApp();
35 :
36 : // @name Implementation of the AppImplBase interface.
37 : // @{
38 m : bool ParseCommandLine(const 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::BasicBlockSubGraph BasicBlockSubGraph;
47 :
48 m : void DecomposeImageToTextApp::PrintUsage(const FilePath& program,
49 m : const base::StringPiece& message);
50 :
51 : // Given @p address_space, dump it in text format to out().
52 m : void DumpAddressSpaceToText(const BlockGraph::AddressSpace& address_space);
53 :
54 : // Given @p subgraph, dump it in text format to out().
55 m : void DumpSubGraphToText(BasicBlockSubGraph& subgraph);
56 :
57 : // Given the code basic block @p bb, dump it in text format to out().
58 m : void DumpCodeBBToText(const BlockGraph::Block* block,
59 m : const BasicBlock* bb);
60 : // Given the data basic block @p bb, dump it in text format to out().
61 m : void DumpDataBBToText(const BlockGraph::Block* block,
62 m : const BasicBlock* bb);
63 :
64 : // Dump @p block at @p addr in text format to out().
65 m : void DumpBlockToText(core::RelativeAddress addr,
66 m : const BlockGraph::Block* block);
67 :
68 : // Dump the image at @p image_path to out().
69 m : bool DumpImageToText(const FilePath& image_path);
70 :
71 : // The image to decompose.
72 m : FilePath image_path_;
73 :
74 : // True if we're to dump basic block information.
75 m : bool dump_basic_blocks_;
76 :
77 : // Number of references we've encountered.
78 m : size_t num_refs_;
79 m : };
80 :
81 m : } // namespace pe
82 :
83 : #endif // SYZYGY_PE_DECOMPOSE_IMAGE_TO_TEXT_APP_H_
|