MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / ReadSLEB128

Method ReadSLEB128

view/sharedcache/core/VirtualMemory.cpp:210–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210int64_t VirtualMemoryReader::ReadSLEB128(size_t cursorLimit)
211{
212 constexpr size_t BYTE_SIZE = 7; // Number of bits in each SLEB128 byte
213 constexpr size_t INT64_BITS = 64; // Total number of bits in an int64_t
214
215 int64_t value = 0;
216 size_t shift = 0;
217 uint64_t offset;
218
219 // Retrieve associated memory region and the file buffer
220 auto mapping = m_memory->GetRegionAtAddress(m_cursor, offset);
221 auto fileLimit = offset + (cursorLimit - m_cursor);
222 auto fileAccessor = mapping->fileAccessor.lock();
223 auto* fileBuffer = static_cast<uint8_t*>(fileAccessor->Data());
224
225 // Loop through the SLEB128 encoded bytes
226 while (offset < fileLimit)
227 {
228 uint8_t currentByte = fileBuffer[offset++];
229 value |= (static_cast<int64_t>(currentByte & 0x7F) << shift);
230 shift += BYTE_SIZE;
231
232 if ((currentByte & 0x80) == 0) // If MSB is not set, we're done
233 break;
234 }
235
236 // Properly sign-extend the value according to its size
237 value = (value << (INT64_BITS - shift)) >> (INT64_BITS - shift);
238
239 // TODO: There has got to be a better way to prevent this...
240 // Prevent deallocation of the fileAccessor
241 fileAccessor->Data();
242
243 return value;
244}
245
246uint64_t VirtualMemoryReader::ReadPointer()
247{

Callers

nothing calls this directly

Calls 3

GetRegionAtAddressMethod · 0.80
DataMethod · 0.80
lockMethod · 0.45

Tested by

no test coverage detected