ROSE 0.11.145.147
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 {
22public:
25
26 //TODO:DELETE_ME/MOVE_ME
28 class Exception: public Rose::Exception {
29 public:
30 Exception(const std::string &mesg)
31 : Rose::Exception(mesg) {}
32 ~Exception() throw () {}
33 };
34
36 // Internal data structures
38private:
39
41 // Data members
43private:
44 // Mapping of class names to virtual address
45 std::map<std::string, SgAsmGenericFile*> classes_;
46
47 // Mapping of function names to virtual address
48 std::map<std::string, rose_addr_t> functions_;
49
50 // Mapping of unresolved (added to partitioner) function names to virtual address
51 std::map<std::string, rose_addr_t> unresolvedFunctions_;
52
53 // Listing of open jar files (maybe should be Zippers with
54 std::vector<ModulesJvm::Zipper*> jars_; // Zipper owns SgAsmGenericFile*, ie, Zipper{gf}, yeah, will have buffer
55 // Zipper.find(className)
56
57 static constexpr rose_addr_t vaDefaultIncrement{4*1024};
58 rose_addr_t nextFunctionVa_;
59
61 // Constructors
63public:
65 EngineJvm() = delete;
66 EngineJvm(const EngineJvm&) = delete;
67 EngineJvm& operator=(const EngineJvm&) = delete;
68
69protected:
70 explicit EngineJvm(const Settings&);
71
72public:
73 ~EngineJvm();
74
76 static Ptr instance();
77
79 static Ptr instance(const Settings&);
80
82 static Ptr factory();
83
84 virtual bool matchFactory(const std::vector<std::string> &specimen) const override;
85 virtual EnginePtr instanceFromFactory(const Settings&) override;
86
88 // The very top-level use case
90public:
115 virtual SgAsmBlock* frontend(const std::vector<std::string> &args,
116 const std::string &purpose, const std::string &description) override;
120 // Basic top-level steps
122public:
123
125 // Command-line parsing
127
128 virtual std::pair<std::string, std::string> specimenNameDocumentation() override;
129
131 // Container parsing
133public:
153 virtual SgAsmInterpretation* parseContainers(const std::vector<std::string> &fileNames) override;
154
159 virtual bool isNonContainer(const std::string&) override;
160
166 virtual bool areContainersParsed() const override;
167
169 // Load specimens
170 //
171 // top-level: loadSpecimens
173public:
174
178 virtual bool areSpecimensLoaded() const override;
179
180 virtual MemoryMapPtr loadSpecimens(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
181
189 bool loadJarFile(const std::string &);
190
196 rose_addr_t loadClassFile(boost::filesystem::path, SgAsmGenericFileList*, rose_addr_t);
197
203 rose_addr_t loadSuperClasses(const std::string &, SgAsmGenericFileList*, rose_addr_t);
204
213
221 rose_addr_t loadClass(uint16_t, SgAsmJvmConstantPool*, SgAsmGenericFileList*, rose_addr_t);
222
228 boost::filesystem::path pathToClass(const std::string &);
229
237 std::map<std::string,rose_addr_t> &, std::set<std::string> &);
238
258 virtual PartitionerPtr partition(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
259
261 // Disassembler
263public:
264
266 // Partitioner high-level functions
267 //
268 // top-level: partition
270public:
271
273 virtual void checkCreatePartitionerPrerequisites() const override;
274
280
282 virtual void runPartitionerInit(const PartitionerPtr&) override;
283 virtual void runPartitionerRecursive(const PartitionerPtr&) override;
284 virtual void runPartitionerFinal(const PartitionerPtr&) override;
285
287 // Partitioner mid-level functions
288 //
289 // These are the functions called by the partitioner high-level stuff. These are sometimes overridden in subclasses,
290 // although it is more likely that the high-level stuff is overridden.
292public:
293
301
303 // Partitioner low-level functions
304 //
305 // These are functions that a subclass seldom overrides, and maybe even shouldn't override because of their complexity or
306 // the way the interact with one another.
308public:
309
311 // Build AST
313public:
328 virtual SgAsmBlock* buildAst(const std::vector<std::string> &fileNames = std::vector<std::string>()) override;
332 // Settings and properties
334public:
341 const std::string& isaName() const /*final*/;
342 virtual void isaName(const std::string&);
351 const std::vector<rose_addr_t>& functionStartingVas() const /*final*/;
352 std::vector<rose_addr_t>& functionStartingVas() /*final*/;
356 SgProject* roseFrontendReplacement(const std::vector<std::string> &fileNames);
357
359 // Internal stuff
361protected:
362 // Similar to ::frontend but a lot less complicated.
363 virtual SgProject* roseFrontendReplacement(const std::vector<boost::filesystem::path> &fileNames) override;
364};
365
367// JVM Module
369
371namespace ModulesJvm {
372
377bool isJavaClassFile(const boost::filesystem::path&);
378
383bool isJavaJarFile(const boost::filesystem::path&);
384
386bool loadClassFile(const std::string &, const std::vector<ModulesJvm::Zipper*> &, rose_addr_t);
387
388} // namespace
389
390} // namespace
391} // namespace
392} // namespace
393
394#endif
395#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.
void discoverFunctionCalls(SgAsmJvmMethod *, SgAsmJvmConstantPool *, std::map< std::string, rose_addr_t > &, std::set< std::string > &)
Discover function calls (invoke instructions) made from a method.
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 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.
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.
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.
virtual std::pair< std::string, std::string > specimenNameDocumentation() override
Documentation about how the specimen is specified.
rose_addr_t loadDiscoverableClasses(SgAsmGenericFileList *, rose_addr_t)
Load classes discoverable from the file list starting at the given address.
virtual EnginePtr instanceFromFactory(const Settings &) override
Virtual constructor for factories.
const std::vector< rose_addr_t > & functionStartingVas() const
Property: Starting addresses for disassembly.
SgProject * roseFrontendReplacement(const std::vector< std::string > &fileNames)
Replacement for frontend for Jvm files only.
rose_addr_t loadSuperClasses(const std::string &, SgAsmGenericFileList *, rose_addr_t)
Recursively find and load all super classes starting at the given address.
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.
rose_addr_t loadClass(uint16_t, SgAsmJvmConstantPool *, SgAsmGenericFileList *, rose_addr_t)
Load class and super class starting at the given address.
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.
rose_addr_t loadClassFile(boost::filesystem::path, SgAsmGenericFileList *, rose_addr_t)
Load a class file by parsing its contents at the given address.
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.
Base class for all ROSE exceptions.
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 is a Java jar file.
bool isJavaClassFile(const boost::filesystem::path &)
True if named file is a Java class file.
Sawyer::SharedPointer< EngineJvm > EngineJvmPtr
Shared-ownership pointer for EngineJvm.
The ROSE library.