ROSE  0.11.131.0
EngineJvm.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_EngineJvm_H
2 #define ROSE_BinaryAnalysis_Partitioner2_EngineJvm_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/ByteCode/Jvm.h>
7 #include <Rose/BinaryAnalysis/Partitioner2/Engine.h>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 namespace Partitioner2 {
12 
20 class EngineJvm: public Engine {
21 public:
23  using Ptr = EngineJvmPtr;
24 
25  //TODO:DELETE_ME/MOVE_ME
27  class Exception: public Rose::Exception {
28  public:
29  Exception(const std::string &mesg)
30  : Rose::Exception(mesg) {}
31  ~Exception() throw () {}
32  };
33 
35  // Internal data structures
37 private:
38 
40  // Data members
42 private:
43 
45  // Constructors
47 public:
49  EngineJvm() = delete;
50  EngineJvm(const EngineJvm&) = delete;
51  EngineJvm& operator=(const EngineJvm&) = delete;
52 
53 protected:
54  explicit EngineJvm(const Settings &settings);
55 
56 public:
57  ~EngineJvm();
58 
60  static Ptr instance(const Settings&);
61 
63  static Ptr factory();
64 
65  virtual bool matchFactory(const std::vector<std::string> &specimen) const override;
66  virtual EnginePtr instanceFromFactory(const Settings&) override;
67 
69  // The very top-level use case
71 public:
96  virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
97  const std::string &purpose, const std::string &description) override;
100  // Basic top-level steps
103 public:
104 
106  // Command-line parsing
108 
109  virtual std::pair<std::string, std::string> specimenNameDocumentation() override;
110 
112  // Container parsing
114 public:
134  virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames) override;
135 
140  virtual bool isNonContainer(const std::string&) override;
141 
147  virtual bool areContainersParsed() const override;
148 
150  // Load specimens
151  //
152  // top-level: loadSpecimens
154 public:
155 
159  virtual bool areSpecimensLoaded() const override;
160 
181  virtual MemoryMapPtr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
182 
202  virtual PartitionerPtr partition(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
203 
205  // Disassembler
207 public:
208 
210  // Partitioner high-level functions
211  //
212  // top-level: partition
214 public:
215 
217  virtual void checkCreatePartitionerPrerequisites() const override;
218 
225 
230  virtual PartitionerPtr createPartitioner() override;
231 
235  virtual void runPartitionerInit(const PartitionerPtr&) override;
236 
240  virtual void runPartitionerRecursive(const PartitionerPtr&) override;
241 
246  virtual void runPartitionerFinal(const PartitionerPtr&) override;
247 
249  // Partitioner mid-level functions
250  //
251  // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
252  // although it is more likely that the high-level stuff is overridden.
254 public:
255 
262  virtual void discoverBasicBlocks(const PartitionerPtr&, const ByteCode::Method*);
263 
270  virtual void discoverFunctions(const PartitionerPtr&, const ByteCode::Class*);
271 
273  // Partitioner low-level functions
274  //
275  // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
276  // the way the interact with one another.
278 public:
279 
281  // Build AST
283 public:
298  virtual SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
301  // Settings and properties
304 public:
311  const std::string& isaName() const /*final*/;
312  virtual void isaName(const std::string&);
321  const std::vector<rose_addr_t>& functionStartingVas() const /*final*/;
322  std::vector<rose_addr_t>& functionStartingVas() /*final*/;
325  // Internal stuff
328 protected:
329  // Similar to ::frontend but a lot less complicated.
330  virtual SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames) override;
331 };
332 
334 // JVM Module
336 
338 namespace ModulesJvm {
339 
344 bool isJavaClassFile(const boost::filesystem::path&);
345 
346 } // namespace
347 
348 } // namespace
349 } // namespace
350 } // namespace
351 
352 #endif
353 #endif
virtual void discoverFunctions(const PartitionerPtr &, const ByteCode::Class *)
Discover as many functions as possible.
virtual void runPartitionerInit(const PartitionerPtr &) override
Finds interesting things to work on initially.
Instruction basic block.
virtual SgAsmBlock * frontend(const std::vector< std::string > &args, const std::string &purpose, const std::string &description) override
Most basic usage of the partitioner.
Base class for engines driving the partitioner.
virtual MemoryMapPtr loadSpecimens(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Load and/or link interpretation.
virtual void runPartitionerFinal(const PartitionerPtr &) override
Runs the final parts of partitioning.
virtual bool areSpecimensLoaded() const override
Returns true if specimens are loaded.
virtual bool areContainersParsed() const override
Returns true if containers are parsed.
STL namespace.
static Ptr factory()
Allocate a factory.
Main namespace for the ROSE library.
virtual SgAsmInterpretation * parseContainers(const std::vector< std::string > &fileNames) override
Parse specimen binary containers.
const std::vector< rose_addr_t > & functionStartingVas() const
Property: Starting addresses for disassembly.
virtual PartitionerPtr partition(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Partition instructions into basic blocks and functions.
virtual void checkCreatePartitionerPrerequisites() const override
Check that we have everything necessary to create a partitioner.
const std::string & isaName() const
Property: Instruction set architecture name.
virtual void discoverBasicBlocks(const PartitionerPtr &, const ByteCode::Method *)
Discover as many basic blocks as possible.
virtual bool isNonContainer(const std::string &) override
Determine whether a specimen name is a non-container.
EngineJvm()=delete
Default constructor.
Sawyer::SharedPointer< EngineJvm > EngineJvmPtr
Shared-ownership pointer for EngineJvm.
static Ptr instance(const Settings &)
Allocating constructor with settings.
This class represents a source project, with a list of SgFile objects and global information about th...
virtual SgAsmBlock * buildAst(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Obtain an abstract syntax tree.
PartitionerPtr createJvmTunedPartitioner()
Create a partitioner for JVM.
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
bool isJavaClassFile(const boost::filesystem::path &)
True if named file is a Java class file.
virtual void runPartitionerRecursive(const PartitionerPtr &) override
Runs the recursive part of partioning.
Represents an interpretation of a binary container.
Engine for Java Virtual Machine (JVM) specimens.
Definition: EngineJvm.h:20
virtual PartitionerPtr createPartitioner() override
Create partitioner.