retdec
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::unpackertool::upx::ElfUpxStub< bits > Class Template Reference

#include <elf_upx_stub.h>

Inheritance diagram for retdec::unpackertool::upx::ElfUpxStub< bits >:
Inheritance graph
[legend]
Collaboration diagram for retdec::unpackertool::upx::ElfUpxStub< bits >:
Collaboration graph
[legend]

Public Types

using AddressType = typename ElfUpxStubTraits< bits >::AddressType
 
using ElfHeaderType = typename ElfUpxStubTraits< bits >::ElfHeaderType
 
using ProgHeaderType = typename ElfUpxStubTraits< bits >::ProgHeaderType
 

Public Member Functions

 ElfUpxStub (retdec::loader::Image *inputFile, const UpxStubData *stubData, const DynamicBuffer &stubCapturedData, std::unique_ptr< Decompressor > decompressor, const UpxMetadata &metadata)
 
virtual void unpack (const std::string &outputFile) override
 
virtual void cleanup () override
 
void setupPackingMethod (std::uint8_t packingMethod)
 
void decompress (DynamicBuffer &packedData, DynamicBuffer &unpackedData)
 
- Public Member Functions inherited from retdec::unpackertool::upx::UpxStub
 UpxStub (retdec::loader::Image *inputFile, const UpxStubData *stubData, const DynamicBuffer &stubCapturedData, std::unique_ptr< Decompressor > decompressor, const UpxMetadata &metadata)
 
UpxStubVersion getVersion () const
 
const UpxStubDatagetStubData () const
 
const DynamicBuffergetStubCapturedData () const
 
DecompressorgetDecompressor () const
 
const UpxMetadatagetUpxMetadata () const
 
virtual std::uint32_t getRealEpAddress () const
 
void setStubData (const UpxStubData *stubData)
 
void setStubCapturedData (const DynamicBuffer &stubCapturedData)
 
- Public Member Functions inherited from retdec::unpacker::UnpackingStub
 UnpackingStub (loader::Image *file)
 
virtual ~UnpackingStub ()=default
 
loader::ImagegetFile ()
 

Private Member Functions

std::uint32_t getFirstBlockOffset ()
 
bool validBlock (const DynamicBuffer &block)
 
void unpackBlock (DynamicBuffer &unpackedData, AddressType fileOffset, AddressType &readFromBuffer, std::uint32_t sizeHint=0)
 
void unpackBlock (DynamicBuffer &unpackedData, DynamicBuffer &packedBlock, AddressType &readFromBuffer, std::uint32_t sizeHint=0)
 
AddressType nextLoadSegmentGap (const std::vector< ProgHeaderType > &phdrs, std::uint32_t currentLoadSegmentIndex)
 
void unfilterBlock (const DynamicBuffer &packedBlock, DynamicBuffer &unpackedData)
 

Private Attributes

retdec::unpacker::BitParser_bitParser
 Associated NRV bit parser. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from retdec::unpackertool::upx::UpxStub
static std::shared_ptr< UpxStubcreateStub (retdec::loader::Image *file)
 
static std::shared_ptr< UpxStubcreateStub (retdec::loader::Image *file, const DynamicBuffer &stubBytes)
 
- Protected Member Functions inherited from retdec::unpackertool::upx::UpxStub
std::unique_ptr< DecompressordecodePackingMethod (std::uint8_t packingMethod) const
 
- Protected Member Functions inherited from retdec::unpacker::UnpackingStub
void setFile (loader::Image *file)
 
- Protected Attributes inherited from retdec::unpackertool::upx::UpxStub
const UpxStubData_stubData
 Additional stub information. More...
 
DynamicBuffer _stubCapturedData
 Data captured while matching signature of this stub. More...
 
std::unique_ptr< Decompressor_decompressor
 Decompressor associated with stub. More...
 
UpxMetadata _metadata
 UPX metadata aka packheader. More...
 
- Protected Attributes inherited from retdec::unpacker::UnpackingStub
loader::Image_file
 

Detailed Description

template<int bits>
class retdec::unpackertool::upx::ElfUpxStub< bits >

Base class for ELF unpacking stubs. It doesn't implement decompress method from UpxStub as it is left to subclasses which should implement decompression based on the used compression.

Template Parameters
bitsNumber of bits of the architecture.

Member Typedef Documentation

◆ AddressType

template<int bits>
using retdec::unpackertool::upx::ElfUpxStub< bits >::AddressType = typename ElfUpxStubTraits<bits>::AddressType

◆ ElfHeaderType

template<int bits>
using retdec::unpackertool::upx::ElfUpxStub< bits >::ElfHeaderType = typename ElfUpxStubTraits<bits>::ElfHeaderType

◆ ProgHeaderType

template<int bits>
using retdec::unpackertool::upx::ElfUpxStub< bits >::ProgHeaderType = typename ElfUpxStubTraits<bits>::ProgHeaderType

Constructor & Destructor Documentation

◆ ElfUpxStub()

template<int bits>
retdec::unpackertool::upx::ElfUpxStub< bits >::ElfUpxStub ( retdec::loader::Image inputFile,
const UpxStubData stubData,
const DynamicBuffer stubCapturedData,
std::unique_ptr< Decompressor decompressor,
const UpxMetadata metadata 
)

Constructor.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
inputFilePacked input file.
stubDataUpxStubData associated with this unpacking stub.
stubCapturedDataData captured from signature matching.
decompressorAssociated decompressor with this unpacking stub.
metadataThe UPX metadata associated with this unpacking stub.

Member Function Documentation

◆ cleanup()

template<int bits>
void retdec::unpackertool::upx::ElfUpxStub< bits >::cleanup
overridevirtual

Performs releasing of owned resources.

Template Parameters
bitsNumber of bits of the architecture.

Implements retdec::unpacker::UnpackingStub.

◆ decompress()

template<int bits>
void retdec::unpackertool::upx::ElfUpxStub< bits >::decompress ( DynamicBuffer packedData,
DynamicBuffer unpackedData 
)

Accepts the visitor-like decompressor and runs decompression.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
packedDataThe packed data.
unpackedDataBuffer where to unpack the data.

◆ getFirstBlockOffset()

template<int bits>
std::uint32_t retdec::unpackertool::upx::ElfUpxStub< bits >::getFirstBlockOffset
private

Finds the offset of the first block.

Returns
Offset of the first block.

◆ nextLoadSegmentGap()

template<int bits>
ElfUpxStub< bits >::AddressType retdec::unpackertool::upx::ElfUpxStub< bits >::nextLoadSegmentGap ( const std::vector< ProgHeaderType > &  phdrs,
std::uint32_t  currentLoadSegmentIndex 
)
private

Finds the gap between two following LOAD segments in the original ELF header. Headers are searched circullary starting from the specified segment.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
phdrsProgram headers in the original ELF header.
currentLoadSegmentIndexIndex of starting segment.
Returns
The size of the gap. 0 if no gap is available. Maximal integer value for invalid gap.

◆ setupPackingMethod()

template<int bits>
void retdec::unpackertool::upx::ElfUpxStub< bits >::setupPackingMethod ( std::uint8_t  packingMethod)

Accepts the visitor-like decompressor and runs checking of packing method.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
packingMethodThe packing method to check.

◆ unfilterBlock()

template<int bits>
void retdec::unpackertool::upx::ElfUpxStub< bits >::unfilterBlock ( const DynamicBuffer packedBlock,
DynamicBuffer unpackedData 
)
private

Unfilters the unpacked block based on the packed block header.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
packedBlockThe packed block which contains at least its header.
unpackedDataData containing unpacked block.

◆ unpack()

template<int bits>
void retdec::unpackertool::upx::ElfUpxStub< bits >::unpack ( const std::string &  outputFile)
overridevirtual

Performs the whole process of unpacking. This is the method that is being run from UpxPlugin to start unpacking stub.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
outputFilePath to unpacked output file.

Implements retdec::unpacker::UnpackingStub.

◆ unpackBlock() [1/2]

template<int bits>
void retdec::unpackertool::upx::ElfUpxStub< bits >::unpackBlock ( DynamicBuffer unpackedData,
AddressType  fileOffset,
AddressType readFromBlock,
std::uint32_t  sizeHint = 0 
)
private

Unpacks the packed block that is in the packed input file.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
unpackedDataBuffer where to unpack the block.
fileOffsetOffset in the file, where the packed block is located.
readFromBlockNumber of bytes that equal to the size of the block together with its header.
sizeHintPotentional size of the unpacked data. The size of unpacked data is determinted by comparing this value with the data written in packed block header. Higher value is chosen.

◆ unpackBlock() [2/2]

template<int bits>
void retdec::unpackertool::upx::ElfUpxStub< bits >::unpackBlock ( DynamicBuffer unpackedData,
DynamicBuffer packedBlock,
AddressType readFromBlock,
std::uint32_t  sizeHint = 0 
)
private

Unpacks the packed block that is stored in the retdec::utils::DynamicBuffer.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
unpackedDataBuffer where to unpack the block.
packedBlockBuffer that contains packed block.
readFromBlockNumber of bytes that equal to the size of the block together with its header.
sizeHintPotentional size of the unpacked data. The size of unpacked data is determinted by comparing this value with the data written in packed block header. Higher value is chosen.

◆ validBlock()

template<int bits>
bool retdec::unpackertool::upx::ElfUpxStub< bits >::validBlock ( const DynamicBuffer block)
private

Checks whether the packed block is valid.

Template Parameters
bitsNumber of bits of the architecture.
Parameters
blockThe buffer that contains block to be checked.
Returns
True if the block is valid, otherwise false.

Member Data Documentation

◆ _bitParser

template<int bits>
retdec::unpacker::BitParser* retdec::unpackertool::upx::ElfUpxStub< bits >::_bitParser
private

Associated NRV bit parser.


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