retdec
Public Member Functions | Private Attributes | List of all members
retdec::ar_extractor::ArchiveWrapper Class Reference

#include <archive_wrapper.h>

Inheritance diagram for retdec::ar_extractor::ArchiveWrapper:
Inheritance graph
[legend]
Collaboration diagram for retdec::ar_extractor::ArchiveWrapper:
Collaboration graph
[legend]

Public Member Functions

 ArchiveWrapper (const std::string &archivePath, bool &succes, std::string &errorMessage)
 
std::size_t getNumberOfObjects () const
 Getters. More...
 
bool isThinArchive () const
 Query methods. More...
 
bool isEmptyArchive () const
 
bool getPlainTextList (std::string &result, std::string &errorMessage, bool niceNames=false, bool numbers=true) const
 Display methods. More...
 
bool getJsonList (std::string &result, std::string &errorMessage, bool niceNames=false, bool numbers=true) const
 
bool extract (std::string &errorMessage, const std::string &directory="") const
 Extraction methods. More...
 
bool extractByName (const std::string &name, std::string &errorMessage, const std::string &outputPath="") const
 
bool extractByIndex (const std::size_t index, std::string &errorMessage, const std::string &outputPath="") const
 

Private Member Functions

bool getNames (std::vector< std::string > &result, std::string &errorMessage) const
 Auxiliary methods. More...
 
bool getCount (std::size_t &count, std::string &errorMessage) const
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

std::unique_ptr< llvm::object::Archive > archive
 LLVM archive parser. More...
 
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > buffer
 Buffer storing content of whole archive. More...
 
std::size_t objectCount = 0
 Number of object files in archive. More...
 

Detailed Description

Class for reading archives using llvm::Archive.

Constructor & Destructor Documentation

◆ ArchiveWrapper()

retdec::ar_extractor::ArchiveWrapper::ArchiveWrapper ( const std::string &  archivePath,
bool &  succes,
std::string &  errorMessage 
)

Constructor.

Parameters
archivePathpath to input archive
succesresult of object construction
errorMessagepossible error message if success is set to false

Member Function Documentation

◆ extract()

bool retdec::ar_extractor::ArchiveWrapper::extract ( std::string &  errorMessage,
const std::string &  directory = "" 
) const

Extraction methods.

Extract all object files.

If directory is not specified, current directory is used. If multiple files have same name, they are decorated with their index suffix.

Parameters
errorMessagepossible error message if false is returned
directoryoptional target directory
Returns
true if no errors occurred, false otherwise
Todo:
In writeFile function call, separator is added to path, this may or may not work on Windows OS.

◆ extractByIndex()

bool retdec::ar_extractor::ArchiveWrapper::extractByIndex ( const std::size_t  index,
std::string &  errorMessage,
const std::string &  outputPath = "" 
) const

Extract object file by its index.

If output path is not given, object name and current directory is used. If name cannot be retrieved, name 'invalid_name' is used.

Parameters
indextarget index
errorMessagepossible error message if false is returned
outputPathoptional output path
Returns
true if no errors occurred, false otherwise

◆ extractByName()

bool retdec::ar_extractor::ArchiveWrapper::extractByName ( const std::string &  name,
std::string &  errorMessage,
const std::string &  outputPath = "" 
) const

Extract object file by its name.

If output path is not given, object name and current directory is used. If multiple files with the same name are present, only first one is extracted.

Parameters
nametarget name
errorMessagepossible error message if false is returned
outputPathoptional output path
Returns
true if no errors occurred, false otherwise

◆ getCount()

bool retdec::ar_extractor::ArchiveWrapper::getCount ( std::size_t &  count,
std::string &  errorMessage 
) const
private

Get object count.

Parameters
countresult
errorMessagepossible error message if false is returned
Returns
true if no errors occurred, false otherwise

◆ getJsonList()

bool retdec::ar_extractor::ArchiveWrapper::getJsonList ( std::string &  result,
std::string &  errorMessage,
bool  niceNames = false,
bool  numbers = true 
) const

Get list of object file names in JSON format.

Parameters
resultstring with complete list in JSON format
errorMessagepossible error message if false is returned
niceNamesnames will be made nicer if true
numberslist will be numbered if true
Returns
true if no errors occurred, false otherwise

◆ getNames()

bool retdec::ar_extractor::ArchiveWrapper::getNames ( std::vector< std::string > &  result,
std::string &  errorMessage 
) const
private

Auxiliary methods.

Get names of all object files in archive.

If name of object could not be read from input archive, name 'invalid_name' is used.

Parameters
resultcontainer where names will be added
errorMessagepossible error message if false is returned
Returns
true if no errors occurred, false otherwise

◆ getNumberOfObjects()

std::size_t retdec::ar_extractor::ArchiveWrapper::getNumberOfObjects ( ) const

Getters.

Get number of objects.

Returns
number of objects in file.

◆ getPlainTextList()

bool retdec::ar_extractor::ArchiveWrapper::getPlainTextList ( std::string &  result,
std::string &  errorMessage,
bool  niceNames = false,
bool  numbers = true 
) const

Display methods.

Get list of object file names in plain-text.

Parameters
resultstring with complete list in plain-text
errorMessagepossible error message if false is returned
niceNamesnames will be made nicer if true
numberslist will be numbered if true
Returns
true if no errors occurred, false otherwise

◆ isEmptyArchive()

bool retdec::ar_extractor::ArchiveWrapper::isEmptyArchive ( ) const

Check whether archive is empty.

Returns
true if archive is empty, false otherwise

◆ isThinArchive()

bool retdec::ar_extractor::ArchiveWrapper::isThinArchive ( ) const

Query methods.

Check whether archive is thin archive.

Returns
true if archive is thin, false otherwise

Member Data Documentation

◆ archive

std::unique_ptr<llvm::object::Archive> retdec::ar_extractor::ArchiveWrapper::archive
private

LLVM archive parser.

◆ buffer

llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer> > retdec::ar_extractor::ArchiveWrapper::buffer
private

Buffer storing content of whole archive.

◆ objectCount

std::size_t retdec::ar_extractor::ArchiveWrapper::objectCount = 0
private

Number of object files in archive.


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