ROSE 0.11.145.237
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#include <Rose/BinaryAnalysis/Partitioner2/ModulesJvm.h>
9
10namespace Rose {
11namespace BinaryAnalysis {
12namespace Partitioner2 {
13
21class EngineJvm: public Engine {
23 // Types
25public:
28
29private:
30 using Super = Engine;
31
33 // Data members
35private:
36 // Mapping of class names to virtual address
37 std::map<std::string, SgAsmGenericFile*> classes_;
38
39 // Mapping of function names to virtual address
40 std::map<std::string, Address> functions_;
41
42 // Mapping of unresolved (added to partitioner) function names to virtual address
43 std::map<std::string, Address> unresolvedFunctions_;
44
45 // Listing of open jar files (maybe should be Zippers with
46 std::vector<ModulesJvm::Zipper*> jars_; // Zipper owns SgAsmGenericFile*, ie, Zipper{gf}, yeah, will have buffer
47 // Zipper.find(className)
48
49 static constexpr Address vaDefaultIncrement{4*1024};
50 Address nextFunctionVa_;
51
53 // Constructors
55public:
57 EngineJvm() = delete;
58 EngineJvm(const EngineJvm&) = delete;
59 EngineJvm& operator=(const EngineJvm&) = delete;
60
61protected:
62 explicit EngineJvm(const Settings&);
63
64public:
65 ~EngineJvm();
66
68 static Ptr instance();
69
71 static Ptr instance(const Settings&);
72
74 static Ptr factory();
75
77 // Overrides documented in the base class
79public:
80 virtual bool matchFactory(const std::vector<std::string> &specimen) const override;
81 virtual EnginePtr instanceFromFactory(const Settings&) override;
82
83 virtual std::list<Sawyer::CommandLine::SwitchGroup> commandLineSwitches() override;
84 virtual std::pair<std::string, std::string> specimenNameDocumentation() override;
85
87 // The very top-level use case
89public:
114 virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
115 const std::string &purpose, const std::string &description) override;
119 // Basic top-level steps
121
123 // Command-line parsing
125public:
126
131
132 // Flag to load all classes in jar files listed on the command line
133 static bool loadAllClasses;
134
136 // Container parsing
138public:
158 virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames) override;
159
164 virtual bool isNonContainer(const std::string&) override;
165
171 virtual bool areContainersParsed() const override;
172
174 // Load specimens
175 //
176 // top-level: loadSpecimens
178public:
179
183 virtual bool areSpecimensLoaded() const override;
184
185 virtual MemoryMapPtr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
186
194 bool loadJarFile(const std::string &);
195
202
209
218
227
233 boost::filesystem::path pathToClass(const std::string &);
234
241 void discoverFunctionCalls(SgAsmJvmMethod*, SgAsmJvmConstantPool*, std::map<std::string,Address> &, std::set<std::string> &);
242
262 virtual PartitionerPtr partition(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
263
265 // Disassembler
267public:
268
270 // Partitioner high-level functions
271 //
272 // top-level: partition
274public:
275
277 virtual void checkCreatePartitionerPrerequisites() const override;
278
284
286 virtual void runPartitionerInit(const PartitionerPtr&) override;
287 virtual void runPartitionerRecursive(const PartitionerPtr&) override;
288 virtual void runPartitionerFinal(const PartitionerPtr&) override;
289
291 // Partitioner mid-level functions
292 //
293 // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
294 // although it is more likely that the high-level stuff is overridden.
296public:
297
305
307 // Partitioner low-level functions
308 //
309 // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
310 // the way the interact with one another.
312public:
313
315 // Build AST
317public:
332 virtual SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
336 // Settings and properties
338public:
345 const std::string& isaName() const /*final*/;
346 virtual void isaName(const std::string&);
355 const std::vector<Address>& functionStartingVas() const /*final*/;
356 std::vector<Address>& functionStartingVas() /*final*/;
360 SgProject* roseFrontendReplacement(const std::vector<std::string> &fileNames);
361
363 // Internal stuff
365protected:
366 // Similar to ::frontend but a lot less complicated.
367 virtual SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames) override;
368};
369
371// JVM Module
373
375namespace ModulesJvm {
376
381bool isJavaClassFile(const boost::filesystem::path&);
382
387bool isJavaJarFile(const boost::filesystem::path&);
388
389} // namespace ModulesJvm
390
391} // namespace
392} // namespace
393} // namespace
394
395#endif
396#endif
Engine for Java Virtual Machine (JVM) specimens.
Definition EngineJvm.h:21
virtual MemoryMapPtr loadSpecimens(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Parse specimen binary containers.
EngineJvm()=delete
Default constructor.
static Sawyer::CommandLine::SwitchGroup engineSwitches(EngineSettings &)
Command-line switches related to the JVM engine behavior.
static Ptr factory()
Allocate a factory.
virtual void discoverBasicBlocks(const PartitionerPtr &, const ByteCode::Method *)
Discover as many basic blocks as possible.
virtual void runPartitionerInit(const PartitionerPtr &) override
Parse specimen binary containers.
virtual void runPartitionerFinal(const PartitionerPtr &) override
Parse specimen binary containers.
virtual std::list< Sawyer::CommandLine::SwitchGroup > commandLineSwitches() override
Command-line switches for a particular engine.
const std::vector< Address > & functionStartingVas() const
Property: Starting addresses for disassembly.
virtual SgAsmBlock * frontend(const std::vector< std::string > &args, const std::string &purpose, const std::string &description) override
Most basic usage of the partitioner.
virtual SgAsmBlock * buildAst(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Obtain an abstract syntax tree.
void discoverFunctionCalls(SgAsmJvmMethod *, SgAsmJvmConstantPool *, std::map< std::string, Address > &, std::set< std::string > &)
Discover function calls (invoke instructions) made from a method.
virtual SgAsmInterpretation * parseContainers(const std::vector< std::string > &fileNames) override
Parse specimen binary containers.
virtual bool isNonContainer(const std::string &) override
Determine whether a specimen name is a non-container.
virtual bool areSpecimensLoaded() const override
Returns true if specimens are loaded.
Address loadSuperClasses(const std::string &, SgAsmGenericFileList *, Address)
Recursively find and load all super classes starting at the given address.
PartitionerPtr createJvmTunedPartitioner()
Create a partitioner for JVM.
static Ptr instance(const Settings &)
Allocating constructor with settings.
virtual PartitionerPtr partition(const std::vector< std::string > &fileNames=std::vector< std::string >()) override
Partition instructions into basic blocks and functions.
const std::string & isaName() const
Property: Instruction set architecture name.
Address loadDiscoverableClasses(SgAsmGenericFileList *, Address)
Load classes discoverable from the file list starting at the given address.
virtual std::pair< std::string, std::string > specimenNameDocumentation() override
Documentation about how the specimen is specified.
Address loadClassFile(boost::filesystem::path, SgAsmGenericFileList *, Address)
Load a class file by parsing its contents at the given address.
virtual EnginePtr instanceFromFactory(const Settings &) override
Virtual constructor for factories.
Address loadClass(uint16_t, SgAsmJvmConstantPool *, SgAsmGenericFileList *, Address)
Load class and super class starting at the given address.
SgProject * roseFrontendReplacement(const std::vector< std::string > &fileNames)
Replacement for frontend for Jvm files only.
virtual void checkCreatePartitionerPrerequisites() const override
Check that we have everything necessary to create a partitioner.
virtual bool matchFactory(const std::vector< std::string > &specimen) const override
Predicate for matching a concrete engine factory by settings and specimen.
bool loadJarFile(const std::string &)
Load a jar file by opening its contents.
boost::filesystem::path pathToClass(const std::string &)
Path to the given class.
virtual PartitionerPtr createPartitioner() override
Parse specimen binary containers.
virtual bool areContainersParsed() const override
Returns true if containers are parsed.
static Ptr instance()
Allocating constructor.
virtual void runPartitionerRecursive(const PartitionerPtr &) override
Parse specimen binary containers.
Base class for engines driving the partitioner.
const std::vector< std::string > & specimen() const
Property: specimen.
Engine()=delete
Default constructor.
A collection of related switch declarations.
Reference-counting intrusive smart pointer.
Instruction basic block.
List of AST file node pointers.
Represents an interpretation of a binary container.
Represents an JVM constant pool.
This class represents a source project, with a list of SgFile objects and global information about th...
bool isJavaJarFile(const boost::filesystem::path &)
True if named file exists and is a Java jar file.
bool isJavaClassFile(const boost::filesystem::path &)
True if named file exists and is a Java class file.
Sawyer::SharedPointer< EngineJvm > EngineJvmPtr
Shared-ownership pointer for EngineJvm.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.