decompiler  1.0.0
Public Member Functions | Protected Attributes | List of all members
LoadImage Class Referenceabstract

An interface into a particular binary executable image. More...

#include <loadimage.hh>

Inheritance diagram for LoadImage:
LoadImageGhidra LoadImageXml RawLoadImage

Public Member Functions

 LoadImage (const string &f)
 LoadImage constructor. More...
 
virtual ~LoadImage (void)
 LoadImage destructor. More...
 
const string & getFileName (void) const
 Get the name of the LoadImage. More...
 
virtual void loadFill (uint1 *ptr, int4 size, const Address &addr)=0
 Get data from the LoadImage. More...
 
virtual void openSymbols (void) const
 Prepare to read symbols. More...
 
virtual void closeSymbols (void) const
 Stop reading symbols. More...
 
virtual bool getNextSymbol (LoadImageFunc &record) const
 Get the next symbol record. More...
 
virtual void openSectionInfo (void) const
 Prepare to read section info. More...
 
virtual void closeSectionInfo (void) const
 Stop reading section info. More...
 
virtual bool getNextSection (LoadImageSection &sec) const
 Get info on the next section. More...
 
virtual void getReadonly (RangeList &list) const
 Return list of readonly address ranges. More...
 
virtual string getArchType (void) const =0
 Get a string indicating the architecture type. More...
 
virtual void adjustVma (long adjust)=0
 Adjust load addresses with a global offset. More...
 
uint1 * load (int4 size, const Address &addr)
 Load a chunk of image. More...
 

Protected Attributes

string filename
 Name of the loadimage.
 

Detailed Description

An interface into a particular binary executable image.

This class provides the abstraction needed by the decompiler for the numerous load file formats used to encode binary executables. The data encoding the machine instructions for the executable can be accessed via the addresses where that data would be loaded into RAM. Properties other than the main data and instructions of the binary are not supposed to repeatedly queried through this interface. This information is intended to be read from this class exactly once, during initialization, and used to populate the main decompiler database. This class currently has only rudimentary support for accessing such properties.

Constructor & Destructor Documentation

LoadImage::LoadImage ( const string &  f)
inline

LoadImage constructor.

For the base class there is no relevant initialization except the name of the image.

Parameters
fis the name of the image
LoadImage::~LoadImage ( void  )
inlinevirtual

LoadImage destructor.

The destructor for the load image object.

Member Function Documentation

void LoadImage::adjustVma ( long  adjust)
pure virtual

Adjust load addresses with a global offset.

Most load image formats automatically encode information about the true loading address(es) for the data in the image. But if this is missing or incorrect, this routine can be used to make a global adjustment to the load address. Only one adjustment is made across all addresses in the image. The offset passed to this method is added to the stored or default value for any address queried in the image. This is most often used in a raw binary file format. In this case, the entire executable file is intended to be read straight into RAM, as one contiguous chunk, in order to be executed. In the absence of any other info, the first byte of the image file is loaded at offset 0. This method then would adjust the load address of the first byte.

Parameters
adjustis the offset amount to be added to default values

Implemented in RawLoadImage, LoadImageXml, and LoadImageGhidra.

void LoadImage::closeSectionInfo ( void  ) const
inlinevirtual

Stop reading section info.

Once all the section information is read from the load image using the getNextSection() method, this method should be called to free up any resources used in parsing the section info.

void LoadImage::closeSymbols ( void  ) const
inlinevirtual

Stop reading symbols.

Once all the symbol information has been read out from the load image via the openSymbols() and getNextSymbol() calls, the application should call this method to free up resources used in parsing the symbol information.

string LoadImage::getArchType ( void  ) const
pure virtual

Get a string indicating the architecture type.

The load image class is intended to be a generic front-end to the large variety of load formats in use. This method should return a string that identifies the particular architecture this particular image is intended to run on. It is currently the responsibility of any derived LoadImage class to establish a format for this string, but it should generally contain some indication of the operating system and the processor.

Returns
the identifier string

Implemented in RawLoadImage, LoadImageXml, and LoadImageGhidra.

const string & LoadImage::getFileName ( void  ) const
inline

Get the name of the LoadImage.

The loadimage is usually associated with a file. This routine retrieves the name as a string.

Returns
the name of the image
bool LoadImage::getNextSection ( LoadImageSection record) const
inlinevirtual

Get info on the next section.

This method is used to read out a record that describes a single section of bytes mapped by the load image. This method can be called repeatedly until it returns false, to get info on additional sections.

Parameters
recordis a reference to the info record to be filled in
Returns
true if there are more records to read
bool LoadImage::getNextSymbol ( LoadImageFunc record) const
inlinevirtual

Get the next symbol record.

This method is used to read out an individual symbol record, LoadImageFunc, from the load image. Right now, the only information that can be read out are function starts and the associated function name. This method can be called repeatedly to iterate through all the symbols, until it returns false. This indicates the end of the symbols.

Parameters
recordis a reference to the symbol record to be filled in
Returns
true if there are more records to read

Reimplemented in LoadImageXml.

void LoadImage::getReadonly ( RangeList list) const
inlinevirtual

Return list of readonly address ranges.

This method should read out information about all address ranges within the load image that are known to be readonly. This method is intended to be called only once, so all information should be written to the passed RangeList object.

Parameters
listis where readonly info will get put

Reimplemented in LoadImageXml.

uint1 * LoadImage::load ( int4  size,
const Address addr 
)

Load a chunk of image.

This is a convenience method wrapped around the core loadFill() routine. It automatically allocates an array of the desired size, and then fills it with load image data. If the array cannot be allocated, an exception is thrown. The caller assumes the responsibility of freeing the array after it has been used.

Parameters
sizeis the number of bytes to read from the image
addris the address of the first byte being read
Returns
a pointer to the desired bytes

References loadFill().

void LoadImage::loadFill ( uint1 *  ptr,
int4  size,
const Address addr 
)
pure virtual

Get data from the LoadImage.

This is the core routine of a LoadImage. Given a particular address range, this routine retrieves the exact byte values that are stored at that address when the executable is loaded into RAM. The caller must supply a pre-allocated array of bytes where the returned bytes should be stored. If the requested address range does not exist in the image, or otherwise can't be retrieved, this method throws an DataUnavailError exception.

Parameters
ptrpoints to where the resulting bytes will be stored
sizeis the number of bytes to retrieve from the image
addris the starting address of the bytes to retrieve

Implemented in RawLoadImage, LoadImageXml, and LoadImageGhidra.

Referenced by Funcdata::fillinExtrapop(), Funcdata::fillinReadOnly(), EmulatePcodeOp::getLoadImageValue(), EmulateSnippet::getLoadImageValue(), StringManagerUnicode::getStringData(), load(), and JumpBasic::sanityCheck().

void LoadImage::openSectionInfo ( void  ) const
inlinevirtual

Prepare to read section info.

This method initializes iteration over all the sections of bytes that are mapped by the load image. Once this is called, information on individual sections should be read out with the getNextSection() method.

void LoadImage::openSymbols ( void  ) const
inlinevirtual

Prepare to read symbols.

This routine should read in and parse any symbol information that the load image contains about executable. Once this method is called, individual symbol records are read out using the getNextSymbol() method.

Reimplemented in LoadImageXml.


The documentation for this class was generated from the following files: