ROSE 2.1.0
Loading...
Searching...
No Matches
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 loadWarFile(const std::string &);
195
203 bool loadJarFile(const std::string &);
204
210 bool loadJarFile(const std::string &, ModulesJvm::Zipper* zip);
211
218
225
234
243
250 boost::filesystem::path pathToClass(const std::string &fqcn);
251
258 void discoverFunctionCalls(SgAsmJvmMethod*, SgAsmJvmConstantPool*, std::map<std::string,Address> &, std::set<std::string> &);
259
279 virtual PartitionerPtr partition(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
280
282 // Disassembler
284public:
285
287 // Partitioner high-level functions
288 //
289 // top-level: partition
291public:
292
294 virtual void checkCreatePartitionerPrerequisites() const override;
295
301
303 virtual void runPartitionerInit(const PartitionerPtr&) override;
304 virtual void runPartitionerRecursive(const PartitionerPtr&) override;
305 virtual void runPartitionerFinal(const PartitionerPtr&) override;
306
308 // Partitioner mid-level functions
309 //
310 // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
311 // although it is more likely that the high-level stuff is overridden.
313public:
314
322
324 // Partitioner low-level functions
325 //
326 // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
327 // the way the interact with one another.
329public:
330
332 // Build AST
334public:
349 virtual SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
353 // Settings and properties
355public:
361 const std::vector<std::string>& classPath() const;
362
369 const std::string& isaName() const /*final*/;
370 virtual void isaName(const std::string&);
379 const std::vector<Address>& functionStartingVas() const /*final*/;
380 std::vector<Address>& functionStartingVas() /*final*/;
384 SgProject* roseFrontendReplacement(const std::vector<std::string> &fileNames);
385
387 // Internal stuff
389protected:
390 // Similar to ::frontend but a lot less complicated.
391 virtual SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames) override;
392};
393
395// JVM Module
397
399namespace ModulesJvm {
400
404bool isJavaClassFile(const boost::filesystem::path&);
405
409bool isJavaJarFile(const boost::filesystem::path&);
410
414bool isJavaWarFile(const boost::filesystem::path&);
415
432boost::filesystem::path pathToClassFile(const std::string &fqcn, const std::vector<std::string> &cp);
433
446bool present(const std::string &fqcn, const std::string &path);
447
448} // namespace ModulesJvm
449
450} // namespace
451} // namespace
452} // namespace
453
454#endif
455#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.
bool loadJarFile(const std::string &, ModulesJvm::Zipper *zip)
Load a jar file from a zipped container by opening its contents.
const std::vector< std::string > & classPath() const
Setting: JVM class path.
bool loadWarFile(const std::string &)
Load a war file by opening its contents.
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 isJavaWarFile(const boost::filesystem::path &)
True if named file exists and is a Java war file.
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.