retdec
|
Class that handles import directories. More...
#include <ImportDirectory.h>
Public Member Functions | |
ImportDirectory () | |
Constructor. More... | |
int | addFunction (const std::string &strFilename, std::uint16_t wHint) |
Add a function to the import directory. More... | |
int | addFunction (const std::string &strFilename, const std::string &strFuncname) |
Add a function to the import directory. More... | |
unsigned int | getFileIndex (const std::string &strFilename, currdir cdDir) const |
Get the ID of a file through it's name. More... | |
unsigned int | getFunctionIndex (const std::string &strFilename, const std::string &strFuncname, currdir cdDir) const |
Get the ID of a function through it's name. More... | |
std::string | getFileName (std::uint32_t dwFilenr, currdir cdDir) const |
Get the name of an imported file. More... | |
void | setFileName (std::uint32_t filenr, currdir cdDir, const std::string &name) |
LoaderError | loaderError () const |
Retrieve the loader error. More... | |
void | setLoaderError (LoaderError ldrError) |
std::uint16_t | getFunctionHint (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const |
Get the hint of an imported function. More... | |
void | setFunctionHint (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir, std::uint16_t value) |
std::string | getFunctionName (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const |
Get the name of an imported function. More... | |
void | setFunctionName (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir, const std::string &functionName) |
std::uint32_t | getNumberOfFiles (currdir cdDir) const |
Get the number of files which are imported. More... | |
std::uint32_t | getNumberOfFunctions (std::uint32_t dwFilenr, currdir cdDir) const |
Get the number of fucntions which are imported by a specific file. More... | |
int | read (ImageLoader &imageLoader) |
Read a file's import directory. More... | |
void | writePointer (OutputBuffer &obBuffer, std::uint64_t pointerValue) |
Writes pointer to the buffer (32-bit or 64-bit) More... | |
void | rebuild (std::vector< std::uint8_t > &vBuffer, std::uint32_t dwRva, bool fixEntries=true) |
Rebuild the import directory. More... | |
int | removeFile (const std::string &strFilename) |
Remove a file from the import directory. More... | |
int | removeFunction (const std::string &strFilename, const std::string &strFuncname) |
Remove a function from the import directory. More... | |
int | removeFunction (const std::string &strFilename, std::uint16_t wHint) |
Remove a function from the import directory. More... | |
unsigned int | calculateSize (std::uint32_t pointerSize) const |
Returns the size of the current import directory. More... | |
int | write (const std::string &strFilename, std::uint32_t uiOffset, std::uint32_t uiRva, std::uint32_t pointerSize) |
Writes the import directory to a file. More... | |
void | setPointerSize (std::uint32_t pointerSize) |
Updates the pointer size for the import directory. More... | |
std::uint32_t | getFirstThunk (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const |
Returns the FirstThunk value of a function. More... | |
void | setFirstThunk (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir, std::uint32_t value) |
std::uint32_t | getOriginalFirstThunk (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const |
Returns the OriginalFirstThunk value of a function. More... | |
void | setOriginalFirstThunk (std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir, std::uint32_t value) |
std::uint32_t | getFirstThunk (const std::string &strFilename, currdir cdDir) const |
Returns the FirstThunk value of a file. More... | |
std::uint32_t | getOriginalFirstThunk (const std::string &strFilename, currdir cdDir) const |
Returns the OriginalFirstThunk value of a file. More... | |
std::uint32_t | getForwarderChain (const std::string &strFilename, currdir cdDir) const |
Returns the ForwarderChain value of a file. More... | |
std::uint32_t | getRvaOfName (const std::string &strFilename, currdir cdDir) const |
std::uint32_t | getTimeDateStamp (const std::string &strFilename, currdir cdDir) const |
Returns the TimeDateStamp value of a file. More... | |
std::uint32_t | getFirstThunk (std::uint32_t dwFilenr, currdir cdDir) const |
Returns the FirstThunk value of a file. More... | |
void | setFirstThunk (std::uint32_t dwFilenr, currdir cdDir, std::uint32_t value) |
std::uint32_t | getOriginalFirstThunk (std::uint32_t dwFilenr, currdir cdDir) const |
Returns the OriginalFirstThunk value of a file. More... | |
void | setOriginalFirstThunk (std::uint32_t dwFilenr, currdir cdDir, std::uint32_t value) |
std::uint32_t | getForwarderChain (std::uint32_t dwFilenr, currdir cdDir) const |
Returns the ForwarderChain value of a file. More... | |
void | setForwarderChain (std::uint32_t dwFilenr, currdir cdDir, std::uint32_t value) |
std::uint32_t | getRvaOfName (std::uint32_t dwFilenr, currdir cdDir) const |
void | setRvaOfName (std::uint32_t dwFilenr, currdir cdDir, std::uint32_t value) |
std::uint32_t | getTimeDateStamp (std::uint32_t dwFilenr, currdir cdDir) const |
Returns the TimeDateStamp value of a file. More... | |
void | setTimeDateStamp (std::uint32_t dwFilenr, currdir cdDir, std::uint32_t value) |
const std::vector< std::pair< unsigned int, unsigned int > > & | getOccupiedAddresses () const |
Private Types | |
typedef std::vector< PELIB_IMAGE_IMPORT_DIRECTORY >::iterator | ImpDirFileIterator |
typedef std::vector< PELIB_IMAGE_IMPORT_DIRECTORY >::const_iterator | ConstImpDirFileIterator |
Private Member Functions | |
template<typename T > | |
bool | hasFunction (std::string strFilename, T value, bool(PELIB_THUNK_DATA::*comp)(T) const) const |
Tests if a certain function is imported. More... | |
Private Attributes | |
std::vector< PELIB_IMAGE_IMPORT_DIRECTORY > | m_vOldiid |
Stores information about already imported DLLs. More... | |
std::vector< PELIB_IMAGE_IMPORT_DIRECTORY > | m_vNewiid |
Stores information about imported DLLs which will be added. More... | |
std::vector< std::pair< unsigned int, unsigned int > > | m_occupiedAddresses |
Stores RVAs which are occupied by this import directory. More... | |
std::uint64_t | m_ordinalMask |
Mask for file ordinal. More... | |
LoaderError | m_ldrError |
Error detected by the import table parser. More... | |
std::size_t | m_thunkSize |
size of single thunk item More... | |
Class that handles import directories.
This class can read import directories from existing PE files or start completely from scratch. Modifying import directories and writing them to files is also possible. It's worthy to note that many functions require an extra parameter of type currdir because the structure of import directories make it necessary that the OLDDIR import directory must be preserved. That's why some functions (like adding and removing) imported functions only exist for the new import directory, not for the one which is already written to the file.
Adding functions by ordinal doesn't work yet (rebuild needs to be changed).
Somehow store the rvas of the chunks in the file.
|
private |
|
private |
|
inline |
Constructor.
|
inline |
Add a function to the import directory.
Add a function to the Import Directory.
strFilename | Name of the file which will be imported |
strFuncname | Name of the function which will be imported. |
|
inline |
Add a function to the import directory.
Add another import (by Ordinal) to the current file. Note that the import table is not automatically updated. The new imported functions will be added when you recalculate the import table as it's necessary to specify the address the import table will have in the file.
strFilename | The name of a DLL. |
wHint | The ordinal of the function in the DLL. |
|
inline |
Returns the size of the current import directory.
Calculates size of import directory that would be written to a PE file.
|
inline |
Get the ID of a file through it's name.
Searches through the import directory and returns the number of the import directory entry which belongs to the given filename.
strFilename | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Get the name of an imported file.
Get the name of an imported file.
dwFilenr | Identifies which file should be checked. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the FirstThunk value of a file.
strFilename | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the FirstThunk value of a file.
dwFilenr | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the FirstThunk value of a function.
dwFilenr | ID of the imported file. |
dwFuncnr | ID of the imported function. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the ForwarderChain value of a file.
strFilename | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the ForwarderChain value of a file.
dwFilenr | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Get the hint of an imported function.
Get the hint of an imported function.
dwFilenr | Identifies which file should be checked. |
dwFuncnr | Identifies which function should be checked. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Get the ID of a function through it's name.
Searches through an imported file for a specific function.
strFilename | Name of the imported file. |
strFuncname | Name of the imported function. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Get the name of an imported function.
Get the name of an imported function.
dwFilenr | Identifies which file should be checked. |
dwFuncnr | Identifies which function should be checked. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Get the number of files which are imported.
Get the number of files which are currently being imported.
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Get the number of fucntions which are imported by a specific file.
Get the number of functions which are currently being imported from a specific file.
dwFilenr | Identifies which file should be checked. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
|
inline |
Returns the OriginalFirstThunk value of a file.
strFilename | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the OriginalFirstThunk value of a file.
dwFilenr | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the OriginalFirstThunk value of a function.
dwFilenr | ID of the imported file. |
dwFuncnr | ID of the imported function. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
|
inline |
|
inline |
Returns the TimeDateStamp value of a file.
strFilename | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inline |
Returns the TimeDateStamp value of a file.
dwFilenr | Name of the imported file. |
cdDir | Flag to decide if the OLDDIR or new import directory is used. |
|
inlineprivate |
Tests if a certain function is imported.
|
inline |
Retrieve the loader error.
Get the error that was detected during import table parsing
|
inline |
Read a file's import directory.
Read an import directory from a file.
imageLoader | A valid PE loader. |
|
inline |
Rebuild the import directory.
Rebuilds the import directory.
vBuffer | Buffer the rebuilt import directory will be written to. |
dwRva | The RVA of the ImportDirectory in the file. |
fixEntries | Boolean flag. |
|
inline |
Remove a file from the import directory.
Removes a specific file and all functions of it from the import directory.
strFilename | Name of the file which will be removed. |
|
inline |
Remove a function from the import directory.
Removes a specific function from the import directory.
strFilename | Name of the file which exports the function. |
strFuncname | Name of the imported function. |
|
inline |
Remove a function from the import directory.
Removes a specific function from the import directory.
strFilename | Name of the file which exports the function. |
wHint | The hint of the function. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Updates the pointer size for the import directory.
Updates pointer size for import directory
pointerSize | Size of the pointer (4 or 8 bytes). |
|
inline |
|
inline |
|
inline |
Writes the import directory to a file.
Writes the current import directory to a file.
strFilename | Name of the file. |
uiOffset | File Offset of the new import directory. |
uiRva | RVA which belongs to that file offset. |
pointerSize | Size of the pointer (4 bytes or 8 bytes) |
|
inline |
Writes pointer to the buffer (32-bit or 64-bit)
|
private |
Error detected by the import table parser.
|
private |
Stores RVAs which are occupied by this import directory.
|
private |
Mask for file ordinal.
|
private |
size of single thunk item
|
private |
Stores information about imported DLLs which will be added.
|
private |
Stores information about already imported DLLs.