1 #ifndef ROSE_BinaryAnalysis_BinaryLoader_H
2 #define ROSE_BinaryAnalysis_BinaryLoader_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Rose/Exception.h>
8 #include <Sawyer/Message.h>
9 #include <Sawyer/SharedObject.h>
10 #include <Sawyer/SharedPointer.h>
13 namespace BinaryAnalysis {
86 void print(std::ostream&)
const;
88 friend std::ostream& operator<<(std::ostream&,
const Exception&);
98 static std::vector<Ptr> loaders_;
99 std::vector<std::string> preloads_;
100 std::vector<std::string> directories_;
101 bool performingDynamicLinking_;
102 bool performingRemap_;
103 bool performingRelocations_;
110 : performingDynamicLinking_(false), performingRemap_(true), performingRelocations_(false)
115 :
Sawyer::
SharedObject(other), performingDynamicLinking_(other.performingDynamicLinking_),
116 performingRemap_(other.performingRemap_), performingRelocations_(other.performingRelocations_) {
117 preloads_ = other.preloads_;
118 directories_ = other.directories_;
142 static void initclass();
234 const std::vector<std::string>&
preloads()
const {
return preloads_; }
235 std::vector<std::string>&
preloads() {
return preloads_; }
236 void preloads(
const std::vector<std::string> &v) { preloads_ = v; }
245 const std::vector<std::string>&
directories()
const {
return directories_; }
247 void directories(
const std::vector<std::string> &v) { directories_ = v; }
255 directories_.insert(directories_.end(), dirnames.begin(), dirnames.end());
262 virtual std::string
findSoFile(
const std::string &libname)
const;
324 typedef std::vector<Exception> FixupErrors;
394 static int64_t
gcd(int64_t a, int64_t b, int64_t *x=NULL, int64_t *y=NULL);
402 rose_addr_t
bialign(rose_addr_t val1, rose_addr_t align1,
403 rose_addr_t val2, rose_addr_t align2);
446 rose_addr_t *malign_lo, rose_addr_t *malign_hi,
447 rose_addr_t *va, rose_addr_t *mem_size,
448 rose_addr_t *offset, rose_addr_t *file_size,
bool *map_private,
449 rose_addr_t *va_offset,
bool *anon_lo,
bool *anon_hi,
467 SgAsmGenericHeaderPtrList &candidateHeaders);
std::vector< std::string > & directories()
Property: List of directories searched for libraries.
bool performingRelocations() const
Property: Whether this loader will perform the relocation step.
virtual MappingContribution alignValues(SgAsmGenericSection *, const MemoryMap::Ptr &, rose_addr_t *malign_lo, rose_addr_t *malign_hi, rose_addr_t *va, rose_addr_t *mem_size, rose_addr_t *offset, rose_addr_t *file_size, bool *map_private, rose_addr_t *va_offset, bool *anon_lo, bool *anon_hi, ConflictResolution *resolve)
For a given section, return information about how the section contributes to the memory map...
static int64_t gcd(int64_t a, int64_t b, int64_t *x=NULL, int64_t *y=NULL)
Extended Euclid Algorithm.
SharedObject()
Default constructor.
static void registerSubclass(const Ptr &)
Register a loader instance.
bool performingRemap() const
Property: Whether this loader will perform the mapping step.
Contiguous region of a file.
Move the section to a higher unused part of the address space.
virtual rose_addr_t rebase(const MemoryMap::Ptr &, SgAsmGenericHeader *header, const SgAsmGenericSectionPtrList &)
Returns an alternate base virtual address if necessary for remapping.
Throw an exception such as MemoryMap::Inconsistent.
BinaryLoaderPtr Ptr
Referenc counting pointer to BinaryLoader.
Section is subtracted from the mapping.
static SgAsmGenericHeaderPtrList findSimilarHeaders(SgAsmGenericHeader *matchHeader, SgAsmGenericHeaderPtrList &candidateHeaders)
Find headers similar to given header.
virtual void fixup(SgAsmInterpretation *interp, FixupErrors *errors=NULL)
Performs relocation fixups on the specified interpretation.
std::vector< std::string > & preloads()
Property: List of libraries that will be pre-loaded.
virtual std::vector< std::string > dependencies(SgAsmGenericHeader *)
Finds shared object dependencies of a single binary header.
void performingDynamicLinking(bool b)
Property: Whether this loader will perform the linking step.
Sawyer::SharedPointer< BinaryLoader > BinaryLoaderPtr
Reference counting pointer.
virtual unsigned mappingPermissions(SgAsmGenericSection *) const
MemoryMap permissions.
void print(std::ostream &) const
Emit the error message to an output stream.
void preloads(const std::vector< std::string > &v)
Property: List of libraries that will be pre-loaded.
Main namespace for the ROSE library.
void performingRemap(bool b)
Property: Whether this loader will perform the mapping step.
Reference-counting intrusive smart pointer.
Name space for the entire library.
virtual void addSectionsForRemap(SgAsmGenericHeader *header, SgAsmGenericSectionPtrList &allSections)
Selects loadable sections.
Base class for exceptions thrown by loaders.
void appendDirectories(const std::vector< std::string > &dirnames)
Appends directories to the list of directories searched for libraries.
Move the section to any unused part of the address space.
virtual void remap(SgAsmInterpretation *interp)
Maps sections of the interpretation into the virtual address space.
const std::vector< std::string > & preloads() const
Property: List of libraries that will be pre-loaded.
virtual bool canLoad(SgAsmGenericHeader *) const
Predicate determining the suitability of a loader for a specific file header.
Exception(const std::string &reason)
Construcor that takes a message.
Section is added to the mapping.
static bool isHeaderSimilar(SgAsmGenericHeader *, SgAsmGenericHeader *)
Determines whether two headers are similar.
static void load(SgBinaryComposite *composite, bool read_executable_file_format_only=false)
Top-level method to do everything.
BinaryLoader(const BinaryLoader &other)
Copy constructor.
virtual Ptr clone() const
Creates a new copy of a loader.
static Sawyer::Message::Facility mlog
Logging facility initialized by initDiagnostics().
MappingContribution
Describes how a section contributes to the overall memory map.
Free the part of the original mapping that is in conflict.
virtual bool isLinked(SgBinaryComposite *composite, const std::string &filename)
Returns true if the specified file name is already linked into the AST.
static void initDiagnostics()
Initialize diagnostic streams for binary loaders.
Base class for reference counted objects.
static SgAsmGenericFile * createAsmAST(SgBinaryComposite *composite, std::string filePath)
Parses a single binary file.
ConflictResolution
Describes how conflicts are resolved when mapping a section.
void directories(const std::vector< std::string > &v)
Property: List of directories searched for libraries.
Base class for loading a static or dynamic object.
static Ptr lookup(SgAsmGenericHeader *)
Finds a suitable loader.
bool performingDynamicLinking() const
Property: Whether this loader will perform the linking step.
virtual SgAsmGenericSectionPtrList getRemapSections(SgAsmGenericHeader *header)
Selects those sections of a header that should be mapped.
rose_addr_t bialign(rose_addr_t val1, rose_addr_t align1, rose_addr_t val2, rose_addr_t align2)
Calculate adjustment to cause two values to be aligned to two different alignments.
virtual std::string findSoFile(const std::string &libname) const
Convert name to fully qualified name.
virtual void link(SgAsmInterpretation *interp)
Finds and parses all shared objects needed by an interpretation.
Base class for all ROSE exceptions.
Represents an interpretation of a binary container.
void performingRelocations(bool b)
Property: Whether this loader will perform the relocation step.
const std::vector< std::string > & directories() const
Property: List of directories searched for libraries.
Section does not contribute to final mapping.
Base class for binary files.
static Ptr instance()
Allocating constructor.