ROSE 0.11.145.272
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:
81 virtual bool matchFactory(const Sawyer::CommandLine::ParserResult &result, const std::vector<std::string> &specimen) const override;
82
83 virtual EnginePtr instanceFromFactory(const Settings&) override;
84
85 virtual std::list<Sawyer::CommandLine::SwitchGroup> commandLineSwitches() override;
86 virtual std::pair<std::string, std::string> specimenNameDocumentation() override;
87
89 // The very top-level use case
91public:
116 virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
117 const std::string &purpose, const std::string &description) override;
121 // Basic top-level steps
123
125 // Command-line parsing
127public:
128 virtual void checkSettings() override;
129
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
234 boost::filesystem::path pathToClass(const std::string &fqcn);
235
242 void discoverFunctionCalls(SgAsmJvmMethod*, SgAsmJvmConstantPool*, std::map<std::string,Address> &, std::set<std::string> &);
243
263 virtual PartitionerPtr partition(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
264
266 // Disassembler
268public:
269
271 // Partitioner high-level functions
272 //
273 // top-level: partition
275public:
276
278 virtual void checkCreatePartitionerPrerequisites() const override;
279
285
287 virtual void runPartitionerInit(const PartitionerPtr&) override;
288 virtual void runPartitionerRecursive(const PartitionerPtr&) override;
289 virtual void runPartitionerFinal(const PartitionerPtr&) override;
290
292 // Partitioner mid-level functions
293 //
294 // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
295 // although it is more likely that the high-level stuff is overridden.
297public:
298
306
308 // Partitioner low-level functions
309 //
310 // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
311 // the way the interact with one another.
313public:
314
316 // Build AST
318public:
333 virtual SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
337 // Settings and properties
339public:
345 const std::vector<std::string>& classPath() const;
346
353 const std::string& isaName() const /*final*/;
354 virtual void isaName(const std::string&);
363 const std::vector<Address>& functionStartingVas() const /*final*/;
364 std::vector<Address>& functionStartingVas() /*final*/;
368 SgProject* roseFrontendReplacement(const std::vector<std::string> &fileNames);
369
371 // Internal stuff
373protected:
374 // Similar to ::frontend but a lot less complicated.
375 virtual SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames) override;
376};
377
379// JVM Module
381
383namespace ModulesJvm {
384
389bool isJavaClassFile(const boost::filesystem::path&);
390
395bool isJavaJarFile(const boost::filesystem::path&);
396
413boost::filesystem::path pathToClassFile(const std::string &fqcn, const std::vector<std::string> &cp);
414
427bool present(const std::string &fqcn, const std::string &path);
428
429} // namespace ModulesJvm
430
431} // namespace
432} // namespace
433} // namespace
434
435#endif
436#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 Ptr factory()
Allocate a factory.
virtual void checkSettings() override
Check settings after command-line is processed.
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.
const std::vector< std::string > & classPath() const
Setting: JVM class path.
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.
static Sawyer::CommandLine::SwitchGroup jvmSwitches(JvmSettings &)
Command-line switches related to the JVM engine behavior.
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.
bool loadJarFile(const std::string &)
Load a jar file by opening its contents.
virtual bool matchFactory(const Sawyer::CommandLine::ParserResult &result, const std::vector< std::string > &specimen) const override
Predicate for matching a concrete engine factory by command-line parser result and specimen.
virtual PartitionerPtr createPartitioner() override
Parse specimen binary containers.
boost::filesystem::path pathToClass(const std::string &fqcn)
Path to the given fully qualified class name (FQCN).
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.
The result from parsing a command line.
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.
boost::filesystem::path pathToClassFile(const std::string &fqcn, const std::vector< std::string > &cp)
Searchs the classpath setting for the path to a fully qualified class name.
bool present(const std::string &fqcn, const std::string &path)
Searchs the path for the presence of a fully qualified class name.
Sawyer::SharedPointer< EngineJvm > EngineJvmPtr
Shared-ownership pointer for EngineJvm.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.