retdec
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PeLib::BoundImportDirectory Class Reference

Class that handles the BoundImport directory. More...

#include <BoundImportDirectory.h>

Collaboration diagram for PeLib::BoundImportDirectory:
Collaboration graph
[legend]

Public Member Functions

virtual ~BoundImportDirectory ()=default
 
int read (ImageLoader &imageLoader)
 Reads the BoundImport directory table from a PE file. More...
 
int addBoundImport (const std::string &strModuleName, std::uint32_t dwTds, std::uint16_t dwOmn, std::uint16_t wWfr)
 Adds another bound import. More...
 
int getModuleIndex (const std::string &strModuleName) const
 Identifies a module through it's name. More...
 
unsigned int calcNumberOfModules () const
 Returns the number of files in the BoundImport directory. More...
 
int read (unsigned char *pcBuffer, unsigned int uiSize)
 Reads the BoundImport directory table from a PE file. More...
 
void rebuild (std::vector< std::uint8_t > &vBuffer, bool fMakeValid=true) const
 Rebuilds the BoundImport directory. More...
 
void clear ()
 Empties the BoundImport directory. More...
 
void removeBoundImport (const std::string &strModuleName)
 Removes a bound import. More...
 
unsigned int size () const
 Returns the size of the BoundImport directory. More...
 
int write (const std::string &strFilename, std::uint32_t dwOffset, bool fMakeValid=true) const
 Writes the current bound import directory to a file. More...
 
std::uint32_t getTimeDateStamp (std::uint32_t dwBidnr) const
 Retrieves the TimeDateStamp value of a bound import. More...
 
std::uint16_t getOffsetModuleName (std::uint32_t dwBidnr) const
 Retrieves the OffsetModuleName value of a bound import. More...
 
std::uint16_t getNumberOfModuleForwarderRefs (std::uint32_t dwBidnr) const
 Retrieves the NumberOfModuleForwarderRefs value of a bound import. More...
 
std::string getModuleName (std::uint32_t dwBidnr) const
 Retrieves the ModuleName value of a bound import. More...
 
void setTimeDateStamp (std::uint32_t dwBidnr, std::uint32_t dwTds)
 Updates the TimeDateStamp value of a bound import. More...
 
void setOffsetModuleName (std::uint32_t dwBidnr, std::uint16_t wOmn)
 Updates the OffsetModuleName value of a bound import. More...
 
void setNumberOfModuleForwarderRefs (std::uint32_t dwBidnr, std::uint16_t wMfr)
 Updates the NumberOfModuleForwarderRefs value of a bound import. More...
 
void setModuleName (std::uint32_t dwBidnr, const std::string &strModuleName)
 Updates the ModuleName value of a bound import. More...
 
std::uint32_t getTimeDateStamp (std::uint32_t dwBidnr, std::uint32_t forwardedModule) const
 
std::uint16_t getOffsetModuleName (std::uint32_t dwBidnr, std::uint32_t forwardedModule) const
 
std::uint16_t getNumberOfModuleForwarderRefs (std::uint32_t dwBidnr, std::uint32_t forwardedModule) const
 
std::string getModuleName (std::uint32_t dwBidnr, std::uint32_t forwardedModule) const
 
void setTimeDateStamp (std::uint32_t dwBidnr, std::uint32_t forwardedModule, std::uint32_t dwTds)
 
void setOffsetModuleName (std::uint32_t dwBidnr, std::uint32_t forwardedModule, std::uint16_t wOmn)
 
void setNumberOfModuleForwarderRefs (std::uint32_t dwBidnr, std::uint32_t forwardedModule, std::uint16_t wMfr)
 
void setModuleName (std::uint32_t dwBidnr, std::uint32_t forwardedModule, const std::string &strModuleName)
 
std::uint16_t calcNumberOfModuleForwarderRefs (std::uint32_t dwBidnr) const
 
void addForwardedModule (std::uint32_t dwBidnr, const std::string &name, std::uint32_t timeStamp=0, std::uint16_t offsetModuleName=0, std::uint16_t forwardedModules=0)
 
void removeForwardedModule (std::uint32_t dwBidnr, std::uint16_t forwardedModule)
 

Protected Member Functions

int read (InputBuffer &inpBuffer, unsigned char *data, unsigned int dwSize)
 
unsigned int totalModules () const
 

Protected Attributes

std::vector< PELIB_IMAGE_BOUND_DIRECTORYm_vIbd
 Stores the individual BoundImport fields. More...
 

Detailed Description

Class that handles the BoundImport directory.

This class can read and modify the BoundImport directory table of a PE file.

Constructor & Destructor Documentation

◆ ~BoundImportDirectory()

virtual PeLib::BoundImportDirectory::~BoundImportDirectory ( )
virtualdefault

Member Function Documentation

◆ addBoundImport()

int PeLib::BoundImportDirectory::addBoundImport ( const std::string &  strModuleName,
std::uint32_t  dwTds,
std::uint16_t  wOmn,
std::uint16_t  wWfr 
)

Adds another bound import.

Adds another bound import to the BoundImport directory.

Parameters
strModuleNameName of the PE file which will be imported.
dwTdsValue of the TimeDateStamp of the bound import field.
wOmnValue of the OffsetModuleName of the bound import field.
wWfrValue of the NumberOfModuleForwarderRefs of the bound import field.

◆ addForwardedModule()

void PeLib::BoundImportDirectory::addForwardedModule ( std::uint32_t  dwBidnr,
const std::string &  name,
std::uint32_t  timeStamp = 0,
std::uint16_t  offsetModuleName = 0,
std::uint16_t  forwardedModules = 0 
)

◆ calcNumberOfModuleForwarderRefs()

std::uint16_t PeLib::BoundImportDirectory::calcNumberOfModuleForwarderRefs ( std::uint32_t  dwBidnr) const

◆ calcNumberOfModules()

unsigned int PeLib::BoundImportDirectory::calcNumberOfModules ( ) const

Returns the number of files in the BoundImport directory.

Returns
Number of files in the current BoundImport directory.

◆ clear()

void PeLib::BoundImportDirectory::clear ( )

Empties the BoundImport directory.

Removes all bound import files.

◆ getModuleIndex()

int PeLib::BoundImportDirectory::getModuleIndex ( const std::string &  strModuleName) const

Identifies a module through it's name.

Searches for the first instance of a module with the given modulename.

Parameters
strModuleNameThe name of a module.
Returns
The id of the module.

◆ getModuleName() [1/2]

std::string PeLib::BoundImportDirectory::getModuleName ( std::uint32_t  dwBidnr) const

Retrieves the ModuleName value of a bound import.

Retrieves the value of the ModuleName value of a bound import field.

Parameters
dwBidnrNumber of the bound import field.
Returns
Value of the ModuleName of the bound import field.

◆ getModuleName() [2/2]

std::string PeLib::BoundImportDirectory::getModuleName ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule 
) const

◆ getNumberOfModuleForwarderRefs() [1/2]

std::uint16_t PeLib::BoundImportDirectory::getNumberOfModuleForwarderRefs ( std::uint32_t  dwBidnr) const

Retrieves the NumberOfModuleForwarderRefs value of a bound import.

Retrieves the value of the NumberOfModuleForwarderRefs value of a bound import field.

Parameters
dwBidnrNumber of the bound import field.
Returns
Value of the NumberOfModuleForwarderRefs of the bound import field.

◆ getNumberOfModuleForwarderRefs() [2/2]

std::uint16_t PeLib::BoundImportDirectory::getNumberOfModuleForwarderRefs ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule 
) const

◆ getOffsetModuleName() [1/2]

std::uint16_t PeLib::BoundImportDirectory::getOffsetModuleName ( std::uint32_t  dwBidnr) const

Retrieves the OffsetModuleName value of a bound import.

Retrieves the value of the OffsetModuleName value of a bound import field.

Parameters
dwBidnrNumber of the bound import field.
Returns
Value of the OffsetModuleName of the bound import field.

◆ getOffsetModuleName() [2/2]

std::uint16_t PeLib::BoundImportDirectory::getOffsetModuleName ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule 
) const

◆ getTimeDateStamp() [1/2]

std::uint32_t PeLib::BoundImportDirectory::getTimeDateStamp ( std::uint32_t  dwBidnr) const

Retrieves the TimeDateStamp value of a bound import.

Retrieves the value of the TimeDateStamp value of a bound import field.

Parameters
dwBidnrNumber of the bound import field.
Returns
Value of the TimeDateStamp of the bound import field.

◆ getTimeDateStamp() [2/2]

std::uint32_t PeLib::BoundImportDirectory::getTimeDateStamp ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule 
) const

◆ read() [1/3]

int PeLib::BoundImportDirectory::read ( ImageLoader imageLoader)

Reads the BoundImport directory table from a PE file.

Reads the BoundImport directory from a PE file.

Parameters
imageLoaderReference to the image loader

◆ read() [2/3]

int PeLib::BoundImportDirectory::read ( InputBuffer inpBuffer,
unsigned char *  data,
unsigned int  dwSize 
)
protected

Searches for the first instance of a module with the given modulename.

Parameters
inpBufferReference to the input buffer
datasource data
dwSizelength of the source data
Returns
ERROR_NONE if success, otherwise an error code.

◆ read() [3/3]

int PeLib::BoundImportDirectory::read ( unsigned char *  pcBuffer,
unsigned int  uiSize 
)

Reads the BoundImport directory table from a PE file.

◆ rebuild()

void PeLib::BoundImportDirectory::rebuild ( std::vector< std::uint8_t > &  vBuffer,
bool  fMakeValid = true 
) const

Rebuilds the BoundImport directory.

Rebuilds the BoundImport directory. The rebuilded BoundImport directory can then be written back to a PE file.

Parameters
vBufferBuffer where the rebuilt BoundImport directory will be stored.
fMakeValidIf this flag is true a valid directory will be produced.

◆ removeBoundImport()

void PeLib::BoundImportDirectory::removeBoundImport ( const std::string &  strModuleName)

Removes a bound import.

Removes a field specified by the parameter filename from the BoundImport directory.

Parameters
strModuleNameName of the file whose field will be removed from the BoundImport directory.

◆ removeForwardedModule()

void PeLib::BoundImportDirectory::removeForwardedModule ( std::uint32_t  dwBidnr,
std::uint16_t  forwardedModule 
)

◆ setModuleName() [1/2]

void PeLib::BoundImportDirectory::setModuleName ( std::uint32_t  dwBidnr,
const std::string &  strModuleName 
)

Updates the ModuleName value of a bound import.

Changes the ModuleName value of an existing bound import field.

Parameters
dwBidnrNumber of the bound import field which will be changed.
strModuleNameNew value of the ModuleName of the bound import field.

◆ setModuleName() [2/2]

void PeLib::BoundImportDirectory::setModuleName ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule,
const std::string &  strModuleName 
)

◆ setNumberOfModuleForwarderRefs() [1/2]

void PeLib::BoundImportDirectory::setNumberOfModuleForwarderRefs ( std::uint32_t  dwBidnr,
std::uint16_t  wMfr 
)

Updates the NumberOfModuleForwarderRefs value of a bound import.

Changes the NumberOfModuleForwarderRefs value of an existing bound import field.

Parameters
dwBidnrNumber of the bound import field which will be changed.
wMfrNew value of the NumberOfModuleForwarderRefs of the bound import field.

◆ setNumberOfModuleForwarderRefs() [2/2]

void PeLib::BoundImportDirectory::setNumberOfModuleForwarderRefs ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule,
std::uint16_t  wMfr 
)

◆ setOffsetModuleName() [1/2]

void PeLib::BoundImportDirectory::setOffsetModuleName ( std::uint32_t  dwBidnr,
std::uint16_t  wOmn 
)

Updates the OffsetModuleName value of a bound import.

Changes the OffsetModuleName value of an existing bound import field.

Parameters
dwBidnrNumber of the bound import field which will be changed.
wOmnNew value of the OffsetModuleName of the bound import field.

◆ setOffsetModuleName() [2/2]

void PeLib::BoundImportDirectory::setOffsetModuleName ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule,
std::uint16_t  wOmn 
)

◆ setTimeDateStamp() [1/2]

void PeLib::BoundImportDirectory::setTimeDateStamp ( std::uint32_t  dwBidnr,
std::uint32_t  dwTds 
)

Updates the TimeDateStamp value of a bound import.

Changes the TimeDateStamp value of an existing bound import field.

Parameters
dwBidnrNumber of the bound import field which will be changed.
dwTdsNew value of the TimeDateStamp of the bound import field.

◆ setTimeDateStamp() [2/2]

void PeLib::BoundImportDirectory::setTimeDateStamp ( std::uint32_t  dwBidnr,
std::uint32_t  forwardedModule,
std::uint32_t  dwTds 
)

◆ size()

unsigned int PeLib::BoundImportDirectory::size ( ) const

Returns the size of the BoundImport directory.

Returns the size of the rebuilt BoundImportDirectory.

Returns
Size of the rebuilt BoundImportDirectory.

◆ totalModules()

unsigned int PeLib::BoundImportDirectory::totalModules ( ) const
protected

◆ write()

int PeLib::BoundImportDirectory::write ( const std::string &  strFilename,
std::uint32_t  dwOffset,
bool  fMakeValid = true 
) const

Writes the current bound import directory to a file.

Parameters
strFilenameName of the file.
dwOffsetFile offset the bound importdirectory will be written to.
fMakeValidIf this flag is true a valid directory will be produced.

Member Data Documentation

◆ m_vIbd

std::vector<PELIB_IMAGE_BOUND_DIRECTORY> PeLib::BoundImportDirectory::m_vIbd
protected

Stores the individual BoundImport fields.


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