1 #ifndef ROSE_BinaryAnalysis_BinaryLoader_H
2 #define ROSE_BinaryAnalysis_BinaryLoader_H
4 #include "Sawyer/Message.h"
80 Exception(
const std::string &reason): std::runtime_error(reason) {}
81 void print(std::ostream&)
const;
82 friend std::ostream& operator<<(std::ostream&,
const Exception&);
92 : p_perform_dynamic_linking(false), p_perform_remap(true), p_perform_relocations(false)
96 : p_perform_dynamic_linking(other.p_perform_dynamic_linking),
97 p_perform_remap(other.p_perform_remap), p_perform_relocations(other.p_perform_relocations) {
98 preloads = other.preloads;
99 directories = other.directories;
102 virtual ~BinaryLoader(){}
109 static void initclass();
188 preloads.push_back(libname);
203 directories.push_back(dirname);
210 directories.insert(directories.end(), dirnames.begin(), dirnames.end());
220 virtual std::string
find_so_file(
const std::string &libname)
const;
276 typedef std::vector<Exception> FixupErrors;
332 static int64_t
gcd(int64_t a, int64_t b, int64_t *x=NULL, int64_t *y=NULL);
339 rose_addr_t
bialign(rose_addr_t val1, rose_addr_t align1,
340 rose_addr_t val2, rose_addr_t align2);
383 rose_addr_t *malign_lo, rose_addr_t *malign_hi,
384 rose_addr_t *va, rose_addr_t *mem_size,
385 rose_addr_t *offset, rose_addr_t *file_size,
bool *map_private,
386 rose_addr_t *va_offset,
bool *anon_lo,
bool *anon_hi,
400 SgAsmGenericHeaderPtrList &candidateHeaders);
417 static std::vector<BinaryLoader*> loaders;
418 std::vector<std::string> preloads;
419 std::vector<std::string> directories;
421 bool p_perform_dynamic_linking;
422 bool p_perform_remap;
423 bool p_perform_relocations;
void set_perform_dynamic_linking(bool b)
Set whether this loader will perform the linking step.
static int64_t gcd(int64_t a, int64_t b, int64_t *x=NULL, int64_t *y=NULL)
Extended Euclid Algorithm.
const std::vector< std::string > & get_preloads() const
Returns the list of libraries that will be pre-loaded.
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.
Section is subtracted from the mapping.
static SgAsmGenericHeaderPtrList findSimilarHeaders(SgAsmGenericHeader *matchHeader, SgAsmGenericHeaderPtrList &candidateHeaders)
Find all headers in candidateHeaders that are similar to matchHeader.
virtual void fixup(SgAsmInterpretation *interp, FixupErrors *errors=NULL)
Performs relocation fixups on the specified interpretation.
const std::vector< std::string > & get_directories() const
Returns the list of shared object search directories.
virtual std::vector< std::string > dependencies(SgAsmGenericHeader *)
Finds shared object dependencies of a single binary header.
bool get_perform_remap() const
Returns whether this loader will perform the mapping step.
virtual std::string find_so_file(const std::string &libname) const
Given the name of a shared object, return the fully qualified name where the library is located in th...
virtual bool can_load(SgAsmGenericHeader *) const
Predicate determining the suitability of a loader for a specific file header.
Main namespace for the ROSE library.
virtual MappingContribution align_values(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...
virtual void addSectionsForRemap(SgAsmGenericHeader *header, SgAsmGenericSectionPtrList &allSections)
Selects those sections which should be layed out by the Loader and inserts them into the allSections ...
Base class for exceptions thrown by loaders.
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.
void set_perform_remap(bool b)
Set whether this loader will perform the mapping step.
void set_perform_relocations(bool b)
Set whether this loader will perform the relocation step.
void add_directories(const std::vector< std::string > &dirnames)
Adds directories to the list of directories searched for libraries.
Section is added to the mapping.
static bool isHeaderSimilar(SgAsmGenericHeader *, SgAsmGenericHeader *)
Determines whether two headers are similar enough to be in the same interpretation.
static void load(SgBinaryComposite *composite, bool read_executable_file_format_only=false)
Class method to parse, map, link, and/or relocate all interpretations of the specified binary composi...
static Sawyer::Message::Facility mlog
Logging facility initialized by initDiagnostics().
virtual BinaryLoader * clone() const
Creates a new copy of a loader.
void add_directory(const std::string &dirname)
Adds a directory to the list of directories searched for libraries.
MappingContribution
Describes how a section contributes to the overall memory map.
Free the part of the original mapping that is in conflict.
bool get_perform_dynamic_linking() const
Returns whether this loader will perform the linking step.
static void initDiagnostics()
Initialize diagnostic streams for binary loaders.
static SgAsmGenericFile * createAsmAST(SgBinaryComposite *composite, std::string filePath)
Parses a single binary file.
ConflictResolution
Describes how conflicts are resolved when mapping a section.
Base class for loading a static or dynamic object.
static void register_subclass(BinaryLoader *)
Register a loader instance.
bool get_perform_relocations() const
Returns whether this loader will perform the relocation step.
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.
void add_preload(const std::string &libname)
Adds a library to the list of pre-loaded libraries.
virtual void link(SgAsmInterpretation *interp)
Links an interpretation by parsing all shared objects required by that interpretation.
static BinaryLoader * lookup(SgAsmGenericHeader *)
Finds a suitable loader.
Represents an interpretation of a binary container.
virtual SgAsmGenericSectionPtrList get_remap_sections(SgAsmGenericHeader *header)
Selects those sections of a header that should be mapped.
virtual bool is_linked(SgBinaryComposite *composite, const std::string &filename)
Returns true if the specified file name is already linked into the AST.
Section does not contribute to final mapping.
Base class for binary files.