1#ifndef ROSE_BinaryAnalysis_Partitioner2_EngineJvm_H
2#define ROSE_BinaryAnalysis_Partitioner2_EngineJvm_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
6#include <Rose/BinaryAnalysis/ByteCode/Jvm.h>
7#include <Rose/BinaryAnalysis/Partitioner2/Engine.h>
8#include <Rose/BinaryAnalysis/Partitioner2/ModulesJvm.h>
10#include <Sawyer/ProgressBar.h>
16namespace BinaryAnalysis {
17namespace Partitioner2 {
40 struct ArchiveProgress {
41 enum class Kind { JAR, WAR };
43 Kind kind = Kind::JAR;
45 size_t nClassFiles = 0;
46 size_t nClassesHandled = 0;
48 size_t nJarsHandled = 0;
49 std::vector<ModulesJvm::Zipper*> childJars;
50 std::unique_ptr<Sawyer::ProgressBar<size_t>> classProgressBar;
51 std::unique_ptr<Sawyer::ProgressBar<size_t>> jarProgressBar;
55 std::map<std::string, Address> functions_;
58 std::map<std::string, Address> unresolvedFunctions_;
61 std::vector<ModulesJvm::Zipper*> jars_;
67 std::map<ModulesJvm::Zipper*, std::map<std::string, std::string>> archivePreferredClassFiles_;
70 std::map<ModulesJvm::Zipper*, ArchiveProgress> archiveProgress_;
72 static constexpr Address vaDefaultIncrement{4*1024};
143 const std::string &purpose,
const std::string &description)
override;
289 const std::map<std::string, std::string>& preferredArchiveClassFiles(
ModulesJvm::Zipper*);
295 void updateLoaderProgress(
size_t current,
size_t total)
const;
296 void createClassProgressBar(ArchiveProgress&,
const std::string&)
const;
297 void createJarProgressBar(ArchiveProgress&,
const std::string&)
const;
382 virtual SgAsmBlock*
buildAst(
const std::vector<std::string> &fileNames = std::vector<std::string>())
override;
434namespace ModulesJvm {
467boost::filesystem::path
pathToClassFile(
const std::string &fqcn,
const std::vector<std::string> &cp);
481bool present(
const std::string &fqcn,
const std::string &path);
Engine for Java Virtual Machine (JVM) specimens.
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.
std::pair< std::string, std::string > specimenNameDocumentation() override
Documentation about how the specimen is specified.
virtual void runPartitionerInit(const PartitionerPtr &) override
Parse specimen binary containers.
virtual void runPartitionerFinal(const PartitionerPtr &) override
Parse specimen binary containers.
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.
PartitionerPtr createJvmTunedPartitioner()
Create a partitioner for JVM.
static Ptr instance(const Settings &)
Allocating constructor with settings.
std::list< Sawyer::CommandLine::SwitchGroup > commandLineSwitches() override
Command-line switches for a particular engine.
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.
EnginePtr instanceFromFactory(const Settings &) override
Virtual constructor for factories.
Address loadClassFile(boost::filesystem::path, SgAsmGenericFileList *, Address)
Load a class file by parsing its contents at the given address.
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.
Address loadBaseClassAndInterfaces(const std::string &, SgAsmGenericFileList *, Address)
Recursively find and load all super classes starting at the given address.
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.
Architecture::BaseConstPtr obtainArchitecture() override
Determine the architecture.
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.
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.
Settings for controlling JVM partitioning behavior.