retdec
Public Member Functions | Private Attributes | List of all members
retdec::macho_extractor::BreakMachOUniversal Class Reference

#include <break_fat.h>

Collaboration diagram for retdec::macho_extractor::BreakMachOUniversal:
Collaboration graph
[legend]

Public Member Functions

 BreakMachOUniversal (const std::string &path)
 
bool isValid ()
 Information methods. More...
 
bool isStaticLibrary ()
 
bool listArchitectures (std::ostream &output, bool withObjects=false)
 
bool listArchitecturesJson (std::ostream &output, bool withObjects=false)
 
bool extractAllArchives ()
 Extracting methods. More...
 
bool extractBestArchive (const std::string &outPath)
 
bool extractArchiveWithIndex (unsigned index, const std::string &outPath)
 
bool extractArchiveForFamily (const std::string &familyName, const std::string &outPath)
 
bool extractArchiveForArchitecture (const std::string &machoArchName, const std::string &outPath)
 

Private Member Functions

bool isArchive ()
 Auxiliary methods. More...
 
const char * getFileBufferStart ()
 
bool getByArchFamily (std::uint32_t cpuType, llvm::object::MachOUniversalBinary::object_iterator &res)
 
bool extract (llvm::object::MachOUniversalBinary::object_iterator &object, const std::string &outPath)
 
bool getObjectNamesForArchive (std::uintptr_t archOffset, std::size_t archSize, std::vector< std::string > &result)
 

Private Attributes

bool valid = false
 
bool isStatic = false
 
std::string path
 
std::unique_ptr< llvm::object::MachOUniversalBinary > file
 
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > buffer
 

Constructor & Destructor Documentation

◆ BreakMachOUniversal()

retdec::macho_extractor::BreakMachOUniversal::BreakMachOUniversal ( const std::string &  filePath)

BreakMachOUniversal constructor

Parameters
filePathpath to input file

Verify success with isValid() function.

Member Function Documentation

◆ extract()

bool retdec::macho_extractor::BreakMachOUniversal::extract ( llvm::object::MachOUniversalBinary::object_iterator &  it,
const std::string &  outPath 
)
private

Extract object by iterator

Parameters
itobject iterator
outPathoutput file path
Returns
true if object was created successfully, false otherwise

◆ extractAllArchives()

bool retdec::macho_extractor::BreakMachOUniversal::extractAllArchives ( )

Extracting methods.

Extract all archives, simulates ar x behavior

Returns
true if extraction was successful, false otherwise

◆ extractArchiveForArchitecture()

bool retdec::macho_extractor::BreakMachOUniversal::extractArchiveForArchitecture ( const std::string &  machoArchName,
const std::string &  outPath 
)

Extract archive by architecture

Parameters
machoArchNameMach-O specific architecture string
outPathpath to output file
Returns
true if extraction was successful, false otherwise

◆ extractArchiveForFamily()

bool retdec::macho_extractor::BreakMachOUniversal::extractArchiveForFamily ( const std::string &  familyName,
const std::string &  outPath 
)

Extract archive by architecture family

Parameters
familyNamefamily name
outPathpath to output file
Returns
true if extraction was successful, false otherwise

◆ extractArchiveWithIndex()

bool retdec::macho_extractor::BreakMachOUniversal::extractArchiveWithIndex ( unsigned  index,
const std::string &  outPath 
)

Extract archive with selected index

Parameters
indexindex of archive to extract
outPathoutput file path
Returns
true if extraction was successful, false otherwise

◆ extractBestArchive()

bool retdec::macho_extractor::BreakMachOUniversal::extractBestArchive ( const std::string &  outPath)

Extract archive with best architecture for decompilation

Parameters
outPathoutput file path
Returns
true if extraction was successful, false otherwise

◆ getByArchFamily()

bool retdec::macho_extractor::BreakMachOUniversal::getByArchFamily ( std::uint32_t  cpuType,
llvm::object::MachOUniversalBinary::object_iterator &  res 
)
private

Get Mach-O Universal object iterator by architecture

Parameters
cpuTypeMach-O specific CPU type constant
resreference for storing result
Returns
true if object with cpuType was found, false otherwise

◆ getFileBufferStart()

const char * retdec::macho_extractor::BreakMachOUniversal::getFileBufferStart ( )
private

Get file memory buffer start

Returns
pointer to file memory buffer start

◆ getObjectNamesForArchive()

bool retdec::macho_extractor::BreakMachOUniversal::getObjectNamesForArchive ( std::uintptr_t  archOffset,
std::size_t  archSize,
std::vector< std::string > &  result 
)
private

Get file names of objects stored in archive

Parameters
archOffsetstart of archive in Mach-O Universal Binary
archSizesize of archive in Mach-O Universal Binary
resultvector with names
Returns
true if names were retrieved successfully, false otherwise

Actual LLVM implementation is problematic but changed a lot in newer versions, so in future, it may be possible to remove this function and use getAsArchive function and llvm::Archive interface instead.

Function is fit only for Apple OS (BSD) archive variant used in Mach-O.

◆ isArchive()

bool retdec::macho_extractor::BreakMachOUniversal::isArchive ( )
private

Auxiliary methods.

Check if input binary contains static libraries

Returns
true if file contains static libraries, false otherwise

◆ isStaticLibrary()

bool retdec::macho_extractor::BreakMachOUniversal::isStaticLibrary ( )

Check if input binary contains static library

Returns
true if file is fat Mach-O static library, false otherwise

◆ isValid()

bool retdec::macho_extractor::BreakMachOUniversal::isValid ( )

Information methods.

Verify state of instance after construction

Returns
true if file was read successfully, false otherwise

◆ listArchitectures()

bool retdec::macho_extractor::BreakMachOUniversal::listArchitectures ( std::ostream &  output,
bool  withObjects = false 
)

List all architectures contained in fat Mach-O

Parameters
outputstream to print result to
withObjectstrue when archive content is to be included
Returns
true if all actions were successful, false otherwise

◆ listArchitecturesJson()

bool retdec::macho_extractor::BreakMachOUniversal::listArchitecturesJson ( std::ostream &  output,
bool  withObjects = false 
)

List all architectures contained in fat Mach-O in JSON format

Parameters
outputstream to print result to
withObjectstrue when archive content is to be included
Returns
true if all actions were successful, false otherwise

Member Data Documentation

◆ buffer

llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer> > retdec::macho_extractor::BreakMachOUniversal::buffer
private

◆ file

std::unique_ptr<llvm::object::MachOUniversalBinary> retdec::macho_extractor::BreakMachOUniversal::file
private

◆ isStatic

bool retdec::macho_extractor::BreakMachOUniversal::isStatic = false
private

◆ path

std::string retdec::macho_extractor::BreakMachOUniversal::path
private

◆ valid

bool retdec::macho_extractor::BreakMachOUniversal::valid = false
private

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