retdec
|
#include <elf_upx_stub.h>
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) |
![]() | |
UpxStub (retdec::loader::Image *inputFile, const UpxStubData *stubData, const DynamicBuffer &stubCapturedData, std::unique_ptr< Decompressor > decompressor, const UpxMetadata &metadata) | |
UpxStubVersion | getVersion () const |
const UpxStubData * | getStubData () const |
const DynamicBuffer * | getStubCapturedData () const |
Decompressor * | getDecompressor () const |
const UpxMetadata * | getUpxMetadata () const |
virtual std::uint32_t | getRealEpAddress () const |
void | setStubData (const UpxStubData *stubData) |
void | setStubCapturedData (const DynamicBuffer &stubCapturedData) |
![]() | |
UnpackingStub (loader::Image *file) | |
virtual | ~UnpackingStub ()=default |
loader::Image * | getFile () |
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 std::shared_ptr< UpxStub > | createStub (retdec::loader::Image *file) |
static std::shared_ptr< UpxStub > | createStub (retdec::loader::Image *file, const DynamicBuffer &stubBytes) |
![]() | |
std::unique_ptr< Decompressor > | decodePackingMethod (std::uint8_t packingMethod) const |
![]() | |
void | setFile (loader::Image *file) |
![]() | |
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... | |
![]() | |
loader::Image * | _file |
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.
bits | Number of bits of the architecture. |
using retdec::unpackertool::upx::ElfUpxStub< bits >::AddressType = typename ElfUpxStubTraits<bits>::AddressType |
using retdec::unpackertool::upx::ElfUpxStub< bits >::ElfHeaderType = typename ElfUpxStubTraits<bits>::ElfHeaderType |
using retdec::unpackertool::upx::ElfUpxStub< bits >::ProgHeaderType = typename ElfUpxStubTraits<bits>::ProgHeaderType |
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.
bits | Number of bits of the architecture. |
inputFile | Packed input file. |
stubData | UpxStubData associated with this unpacking stub. |
stubCapturedData | Data captured from signature matching. |
decompressor | Associated decompressor with this unpacking stub. |
metadata | The UPX metadata associated with this unpacking stub. |
|
overridevirtual |
Performs releasing of owned resources.
bits | Number of bits of the architecture. |
Implements retdec::unpacker::UnpackingStub.
void retdec::unpackertool::upx::ElfUpxStub< bits >::decompress | ( | DynamicBuffer & | packedData, |
DynamicBuffer & | unpackedData | ||
) |
Accepts the visitor-like decompressor and runs decompression.
bits | Number of bits of the architecture. |
packedData | The packed data. |
unpackedData | Buffer where to unpack the data. |
|
private |
Finds the offset of the first block.
|
private |
Finds the gap between two following LOAD segments in the original ELF header. Headers are searched circullary starting from the specified segment.
bits | Number of bits of the architecture. |
phdrs | Program headers in the original ELF header. |
currentLoadSegmentIndex | Index of starting segment. |
void retdec::unpackertool::upx::ElfUpxStub< bits >::setupPackingMethod | ( | std::uint8_t | packingMethod | ) |
Accepts the visitor-like decompressor and runs checking of packing method.
bits | Number of bits of the architecture. |
packingMethod | The packing method to check. |
|
private |
Unfilters the unpacked block based on the packed block header.
bits | Number of bits of the architecture. |
packedBlock | The packed block which contains at least its header. |
unpackedData | Data containing unpacked block. |
|
overridevirtual |
Performs the whole process of unpacking. This is the method that is being run from UpxPlugin to start unpacking stub.
bits | Number of bits of the architecture. |
outputFile | Path to unpacked output file. |
Implements retdec::unpacker::UnpackingStub.
|
private |
Unpacks the packed block that is in the packed input file.
bits | Number of bits of the architecture. |
unpackedData | Buffer where to unpack the block. |
fileOffset | Offset in the file, where the packed block is located. |
readFromBlock | Number of bytes that equal to the size of the block together with its header. |
sizeHint | Potentional 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. |
|
private |
Unpacks the packed block that is stored in the retdec::utils::DynamicBuffer.
bits | Number of bits of the architecture. |
unpackedData | Buffer where to unpack the block. |
packedBlock | Buffer that contains packed block. |
readFromBlock | Number of bytes that equal to the size of the block together with its header. |
sizeHint | Potentional 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. |
|
private |
Checks whether the packed block is valid.
bits | Number of bits of the architecture. |
block | The buffer that contains block to be checked. |
|
private |
Associated NRV bit parser.