class DataExtractor

Declaration

class DataExtractor { /* full declaration omitted */ };

Declared at: llvm/include/llvm/Support/DataExtractor.h:41

Method Overview

  • public DataExtractor(ArrayRef<uint8_t> Data, bool IsLittleEndian, uint8_t AddressSize)
  • public DataExtractor(llvm::StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
  • public bool eof(const llvm::DataExtractor::Cursor & C) const
  • public uint64_t getAddress(llvm::DataExtractor::Cursor & C) const
  • public uint64_t getAddress(uint64_t * offset_ptr) const
  • public uint8_t getAddressSize() const
  • public const char * getCStr(uint64_t * offset_ptr) const
  • public llvm::StringRef getCStrRef(uint64_t * offset_ptr) const
  • public llvm::StringRef getData() const
  • protected static llvm::Error & getError(llvm::DataExtractor::Cursor & C)
  • protected static uint64_t & getOffset(llvm::DataExtractor::Cursor & C)
  • public int64_t getSLEB128(uint64_t * offset_ptr) const
  • public int64_t getSigned(uint64_t * offset_ptr, uint32_t size) const
  • public uint16_t * getU16(uint64_t * offset_ptr, uint16_t * dst, uint32_t count) const
  • public uint16_t getU16(llvm::DataExtractor::Cursor & C) const
  • public uint16_t getU16(uint64_t * offset_ptr, llvm::Error * Err = nullptr) const
  • public uint32_t getU24(uint64_t * offset_ptr) const
  • public uint32_t getU32(uint64_t * offset_ptr, llvm::Error * Err = nullptr) const
  • public uint32_t getU32(llvm::DataExtractor::Cursor & C) const
  • public uint32_t * getU32(uint64_t * offset_ptr, uint32_t * dst, uint32_t count) const
  • public uint64_t getU64(uint64_t * offset_ptr, llvm::Error * Err = nullptr) const
  • public uint64_t getU64(llvm::DataExtractor::Cursor & C) const
  • public uint64_t * getU64(uint64_t * offset_ptr, uint64_t * dst, uint32_t count) const
  • public uint8_t * getU8(llvm::DataExtractor::Cursor & C, uint8_t * Dst, uint32_t Count) const
  • public void getU8(llvm::DataExtractor::Cursor & C, SmallVectorImpl<uint8_t> & Dst, uint32_t Count) const
  • public uint8_t * getU8(uint64_t * offset_ptr, uint8_t * dst, uint32_t count) const
  • public uint8_t getU8(llvm::DataExtractor::Cursor & C) const
  • public uint8_t getU8(uint64_t * offset_ptr, llvm::Error * Err = nullptr) const
  • public uint64_t getULEB128(uint64_t * offset_ptr, llvm::Error * Err = nullptr) const
  • public uint64_t getULEB128(llvm::DataExtractor::Cursor & C) const
  • public uint64_t getUnsigned(llvm::DataExtractor::Cursor & C, uint32_t Size) const
  • public uint64_t getUnsigned(uint64_t * offset_ptr, uint32_t byte_size, llvm::Error * Err = nullptr) const
  • public bool isLittleEndian() const
  • public bool isValidOffset(uint64_t offset) const
  • public bool isValidOffsetForAddress(uint64_t offset) const
  • public bool isValidOffsetForDataOfSize(uint64_t offset, uint64_t length) const
  • public void setAddressSize(uint8_t Size)
  • public size_t size() const
  • public void skip(llvm::DataExtractor::Cursor & C, uint64_t Length) const

Methods

DataExtractor(ArrayRef<uint8_t> Data,
              bool IsLittleEndian,
              uint8_t AddressSize)

Declared at: llvm/include/llvm/Support/DataExtractor.h:85

Parameters

ArrayRef<uint8_t> Data
bool IsLittleEndian
uint8_t AddressSize

DataExtractor(llvm::StringRef Data,
              bool IsLittleEndian,
              uint8_t AddressSize)

Description

Construct with a buffer that is owned by the caller. This constructor allows us to use data that is owned by the caller. The data must stay around as long as this object is valid.

Declared at: llvm/include/llvm/Support/DataExtractor.h:83

Parameters

llvm::StringRef Data
bool IsLittleEndian
uint8_t AddressSize

bool eof(
    const llvm::DataExtractor::Cursor& C) const

Description

Return true iff the cursor is at the end of the buffer, regardless of the error state of the cursor. The only way both eof and error states can be true is if one attempts a read while the cursor is at the very end of the data buffer.

Declared at: llvm/include/llvm/Support/DataExtractor.h:537

Parameters

const llvm::DataExtractor::Cursor& C

uint64_t getAddress(
    llvm::DataExtractor::Cursor& C) const

Description

Extract a pointer-sized unsigned integer from the location given by the cursor. In case of an extraction error, or if the cursor is already in an error state, zero is returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:233

Parameters

llvm::DataExtractor::Cursor& C

uint64_t getAddress(uint64_t* offset_ptr) const

Description

Extract an pointer from \a *offset_ptr. Extract a single pointer from the data and update the offset pointed to by \a offset_ptr. The size of the extracted pointer is \a getAddressSize(), so the address size has to be set correctly prior to extracting any pointer values.

Declared at: llvm/include/llvm/Support/DataExtractor.h:226

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.

Returns

The extracted pointer value as a 64 integer.

uint8_t getAddressSize() const

Description

Get the address size for this extractor.

Declared at: llvm/include/llvm/Support/DataExtractor.h:96

const char* getCStr(uint64_t* offset_ptr) const

Description

Extract a C string from \a *offset_ptr. Returns a pointer to a C String from the data at the offset pointed to by \a offset_ptr. A variable length NULL terminated C string will be extracted and the \a offset_ptr will be updated with the offset of the byte that follows the NULL terminator byte.

Declared at: llvm/include/llvm/Support/DataExtractor.h:120

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.

Returns

A pointer to the C string value in the data. If the offset pointed to by \a offset_ptr is out of bounds, or if the offset plus the length of the C string is out of bounds, NULL will be returned.

llvm::StringRef getCStrRef(
    uint64_t* offset_ptr) const

Description

Extract a C string from \a *offset_ptr. Returns a StringRef for the C String from the data at the offset pointed to by \a offset_ptr. A variable length NULL terminated C string will be extracted and the \a offset_ptr will be updated with the offset of the byte that follows the NULL terminator byte.

Declared at: llvm/include/llvm/Support/DataExtractor.h:142

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.

Returns

A StringRef for the C string value in the data. If the offset pointed to by \a offset_ptr is out of bounds, or if the offset plus the length of the C string is out of bounds, a default-initialized StringRef will be returned.

llvm::StringRef getData() const

Description

Get the data pointed to by this extractor.

Declared at: llvm/include/llvm/Support/DataExtractor.h:92

static llvm::Error& getError(
    llvm::DataExtractor::Cursor& C)

Declared at: llvm/include/llvm/Support/DataExtractor.h:573

Parameters

llvm::DataExtractor::Cursor& C

static uint64_t& getOffset(
    llvm::DataExtractor::Cursor& C)

Declared at: llvm/include/llvm/Support/DataExtractor.h:572

Parameters

llvm::DataExtractor::Cursor& C

int64_t getSLEB128(uint64_t* offset_ptr) const

Description

Extract a signed LEB128 value from \a *offset_ptr. Extracts an signed LEB128 number from this object's data starting at the offset pointed to by \a offset_ptr. The offset pointed to by \a offset_ptr will be updated with the offset of the byte following the last extracted byte.

Declared at: llvm/include/llvm/Support/DataExtractor.h:498

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.

Returns

The extracted signed integer value.

int64_t getSigned(uint64_t* offset_ptr,
                  uint32_t size) const

Description

Extract an signed integer of size \a byte_size from \a *offset_ptr. Extract a single signed integer value (sign extending if required) and update the offset pointed to by \a offset_ptr. The size of the extracted integer is specified by the \a byte_size argument.\a byte_size should have a value greater than or equal to one and less than or equal to eight since the return value is 64 bits wide. Any \a byte_size values less than 1 or greater than 8 will result in nothing being extracted, and zero being returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:207

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
uint32_t size
The size in bytes of the integer to extract.

Returns

The sign extended signed integer value that was extracted, or zero on failure.

uint16_t* getU16(uint64_t* offset_ptr,
                 uint16_t* dst,
                 uint32_t count) const

Description

Extract \a count uint16_t values from \a *offset_ptr. Extract \a count uint16_t values from the binary data at the offset pointed to by \a offset_ptr, and advance the offset on success. The extracted values are copied into \a dst.

Declared at: llvm/include/llvm/Support/DataExtractor.h:359

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
uint16_t* dst
A buffer to copy \a count uint16_t values into. \a dst must be large enough to hold all requested data.
uint32_t count
The number of uint16_t values to extract.

Returns

\a dst if all values were properly extracted and copied, NULL otherise.

uint16_t getU16(
    llvm::DataExtractor::Cursor& C) const

Description

Extract a single uint16_t value from the location given by the cursor. In case of an extraction error, or if the cursor is already in an error state, zero is returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:334

Parameters

llvm::DataExtractor::Cursor& C

uint16_t getU16(uint64_t* offset_ptr,
                llvm::Error* Err = nullptr) const

Description

Extract a uint16_t value from \a *offset_ptr. Extract a single uint16_t from the binary data at the offset pointed to by \a offset_ptr, and update the offset on success.

Declared at: llvm/include/llvm/Support/DataExtractor.h:329

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
llvm::Error* Err = nullptr
A pointer to an Error object. Upon return the Error object is set to indicate the result (success/failure) of the function. If the Error object is already set when calling this function, no extraction is performed.

Returns

The extracted uint16_t value.

uint32_t getU24(uint64_t* offset_ptr) const

Description

Extract a 24-bit unsigned value from \a *offset_ptr and return it in a uint32_t. Extract 3 bytes from the binary data at the offset pointed to by\a offset_ptr, construct a uint32_t from them and update the offset on success.

Declared at: llvm/include/llvm/Support/DataExtractor.h:376

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the 3 bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.

Returns

The extracted 24-bit value represented in a uint32_t.

uint32_t getU32(uint64_t* offset_ptr,
                llvm::Error* Err = nullptr) const

Description

Extract a uint32_t value from \a *offset_ptr. Extract a single uint32_t from the binary data at the offset pointed to by \a offset_ptr, and update the offset on success.

Declared at: llvm/include/llvm/Support/DataExtractor.h:398

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
llvm::Error* Err = nullptr
A pointer to an Error object. Upon return the Error object is set to indicate the result (success/failure) of the function. If the Error object is already set when calling this function, no extraction is performed.

Returns

The extracted uint32_t value.

uint32_t getU32(
    llvm::DataExtractor::Cursor& C) const

Description

Extract a single uint32_t value from the location given by the cursor. In case of an extraction error, or if the cursor is already in an error state, zero is returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:403

Parameters

llvm::DataExtractor::Cursor& C

uint32_t* getU32(uint64_t* offset_ptr,
                 uint32_t* dst,
                 uint32_t count) const

Description

Extract \a count uint32_t values from \a *offset_ptr. Extract \a count uint32_t values from the binary data at the offset pointed to by \a offset_ptr, and advance the offset on success. The extracted values are copied into \a dst.

Declared at: llvm/include/llvm/Support/DataExtractor.h:428

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
uint32_t* dst
A buffer to copy \a count uint32_t values into. \a dst must be large enough to hold all requested data.
uint32_t count
The number of uint32_t values to extract.

Returns

\a dst if all values were properly extracted and copied, NULL otherise.

uint64_t getU64(uint64_t* offset_ptr,
                llvm::Error* Err = nullptr) const

Description

Extract a uint64_t value from \a *offset_ptr. Extract a single uint64_t from the binary data at the offset pointed to by \a offset_ptr, and update the offset on success.

Declared at: llvm/include/llvm/Support/DataExtractor.h:450

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
llvm::Error* Err = nullptr
A pointer to an Error object. Upon return the Error object is set to indicate the result (success/failure) of the function. If the Error object is already set when calling this function, no extraction is performed.

Returns

The extracted uint64_t value.

uint64_t getU64(
    llvm::DataExtractor::Cursor& C) const

Description

Extract a single uint64_t value from the location given by the cursor. In case of an extraction error, or if the cursor is already in an error state, zero is returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:455

Parameters

llvm::DataExtractor::Cursor& C

uint64_t* getU64(uint64_t* offset_ptr,
                 uint64_t* dst,
                 uint32_t count) const

Description

Extract \a count uint64_t values from \a *offset_ptr. Extract \a count uint64_t values from the binary data at the offset pointed to by \a offset_ptr, and advance the offset on success. The extracted values are copied into \a dst.

Declared at: llvm/include/llvm/Support/DataExtractor.h:480

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
uint64_t* dst
A buffer to copy \a count uint64_t values into. \a dst must be large enough to hold all requested data.
uint32_t count
The number of uint64_t values to extract.

Returns

\a dst if all values were properly extracted and copied, NULL otherise.

uint8_t* getU8(llvm::DataExtractor::Cursor& C,
               uint8_t* Dst,
               uint32_t Count) const

Description

Extract \a Count uint8_t values from the location given by the cursor and store them into the destination buffer. In case of an extraction error, or if the cursor is already in an error state, a nullptr is returned and the destination buffer is left unchanged.

Declared at: llvm/include/llvm/Support/DataExtractor.h:291

Parameters

llvm::DataExtractor::Cursor& C
uint8_t* Dst
uint32_t Count

void getU8(llvm::DataExtractor::Cursor& C,
           SmallVectorImpl<uint8_t>& Dst,
           uint32_t Count) const

Description

Extract \a Count uint8_t values from the location given by the cursor and store them into the destination vector. The vector is resized to fit the extracted data. In case of an extraction error, or if the cursor is already in an error state, the destination vector is left unchanged and cursor is placed into an error state.

Declared at: llvm/include/llvm/Support/DataExtractor.h:298

Parameters

llvm::DataExtractor::Cursor& C
SmallVectorImpl<uint8_t>& Dst
uint32_t Count

uint8_t* getU8(uint64_t* offset_ptr,
               uint8_t* dst,
               uint32_t count) const

Description

Extract \a count uint8_t values from \a *offset_ptr. Extract \a count uint8_t values from the binary data at the offset pointed to by \a offset_ptr, and advance the offset on success. The extracted values are copied into \a dst.

Declared at: llvm/include/llvm/Support/DataExtractor.h:285

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
uint8_t* dst
A buffer to copy \a count uint8_t values into. \a dst must be large enough to hold all requested data.
uint32_t count
The number of uint8_t values to extract.

Returns

\a dst if all values were properly extracted and copied, NULL otherise.

uint8_t getU8(
    llvm::DataExtractor::Cursor& C) const

Description

Extract a single uint8_t value from the location given by the cursor. In case of an extraction error, or if the cursor is already in an error state, zero is returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:260

Parameters

llvm::DataExtractor::Cursor& C

uint8_t getU8(uint64_t* offset_ptr,
              llvm::Error* Err = nullptr) const

Description

Extract a uint8_t value from \a *offset_ptr. Extract a single uint8_t from the binary data at the offset pointed to by \a offset_ptr, and advance the offset on success.

Declared at: llvm/include/llvm/Support/DataExtractor.h:255

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
llvm::Error* Err = nullptr
A pointer to an Error object. Upon return the Error object is set to indicate the result (success/failure) of the function. If the Error object is already set when calling this function, no extraction is performed.

Returns

The extracted uint8_t value.

uint64_t getULEB128(
    uint64_t* offset_ptr,
    llvm::Error* Err = nullptr) const

Description

Extract a unsigned LEB128 value from \a *offset_ptr. Extracts an unsigned LEB128 number from this object's data starting at the offset pointed to by \a offset_ptr. The offset pointed to by \a offset_ptr will be updated with the offset of the byte following the last extracted byte.

Declared at: llvm/include/llvm/Support/DataExtractor.h:522

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
llvm::Error* Err = nullptr
A pointer to an Error object. Upon return the Error object is set to indicate the result (success/failure) of the function. If the Error object is already set when calling this function, no extraction is performed.

Returns

The extracted unsigned integer value.

uint64_t getULEB128(
    llvm::DataExtractor::Cursor& C) const

Description

Extract an unsigned ULEB128 value from the location given by the cursor. In case of an extraction error, or if the cursor is already in an error state, zero is returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:527

Parameters

llvm::DataExtractor::Cursor& C

uint64_t getUnsigned(
    llvm::DataExtractor::Cursor& C,
    uint32_t Size) const

Description

Extract an unsigned integer of the given size from the location given by the cursor. In case of an extraction error, or if the cursor is already in an error state, zero is returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:180

Parameters

llvm::DataExtractor::Cursor& C
uint32_t Size

uint64_t getUnsigned(
    uint64_t* offset_ptr,
    uint32_t byte_size,
    llvm::Error* Err = nullptr) const

Description

Extract an unsigned integer of size \a byte_size from \a *offset_ptr. Extract a single unsigned integer value and update the offset pointed to by \a offset_ptr. The size of the extracted integer is specified by the \a byte_size argument. \a byte_size should have a value greater than or equal to one and less than or equal to eight since the return value is 64 bits wide. Any\a byte_size values less than 1 or greater than 8 will result in nothing being extracted, and zero being returned.

Declared at: llvm/include/llvm/Support/DataExtractor.h:174

Parameters

uint64_t* offset_ptr
A pointer to an offset within the data that will be advanced by the appropriate number of bytes if the value is extracted correctly. If the offset is out of bounds or there are not enough bytes to extract this value, the offset will be left unmodified.
uint32_t byte_size
The size in byte of the integer to extract.
llvm::Error* Err = nullptr
A pointer to an Error object. Upon return the Error object is set to indicate the result (success/failure) of the function. If the Error object is already set when calling this function, no extraction is performed.

Returns

The unsigned integer value that was extracted, or zero on failure.

bool isLittleEndian() const

Description

Get the endianness for this extractor.

Declared at: llvm/include/llvm/Support/DataExtractor.h:94

bool isValidOffset(uint64_t offset) const

Description

Test the validity of \a offset.

Declared at: llvm/include/llvm/Support/DataExtractor.h:544

Parameters

uint64_t offset

Returns

\b true if \a offset is a valid offset into the data in this object, \b false otherwise.

bool isValidOffsetForAddress(
    uint64_t offset) const

Description

Test the availability of enough bytes of data for a pointer from\a offset. The size of a pointer is \a getAddressSize().

Declared at: llvm/include/llvm/Support/DataExtractor.h:562

Parameters

uint64_t offset

Returns

\b true if \a offset is a valid offset and there are enough bytes for a pointer available at that offset, \b false otherwise.

bool isValidOffsetForDataOfSize(
    uint64_t offset,
    uint64_t length) const

Description

Test the availability of \a length bytes of data from \a offset.

Declared at: llvm/include/llvm/Support/DataExtractor.h:551

Parameters

uint64_t offset
uint64_t length

Returns

\b true if \a offset is a valid offset and there are \a length bytes available at that offset, \b false otherwise.

void setAddressSize(uint8_t Size)

Description

Set the address size for this extractor.

Declared at: llvm/include/llvm/Support/DataExtractor.h:98

Parameters

uint8_t Size

size_t size() const

Description

Return the number of bytes in the underlying buffer.

Declared at: llvm/include/llvm/Support/DataExtractor.h:567

void skip(llvm::DataExtractor::Cursor& C,
          uint64_t Length) const

Description

Advance the Cursor position by the given number of bytes. No-op if the cursor is in an error state.

Declared at: llvm/include/llvm/Support/DataExtractor.h:531

Parameters

llvm::DataExtractor::Cursor& C
uint64_t Length