6 printf(
"Invalid roundup unit!\n");
11 if (roundDown < size) unitsNum ++;
12 return unitsNum * unit;
18 if (buf == NULL)
return false;
41 if (buf == NULL || bufSize == 0) {
46 if (allowExceptions)
throw BufferException(
"Pointer before buffer begining!");
49 offset_t offset =
static_cast<BYTE*
>(ptr) - buf;
50 if (offset >= bufSize) {
51 if (allowExceptions)
throw BufferException(
"Pointer does not belong to buffer!");
60 if (allowExceptions)
throw BufferException(
"Invalid address requested!");
70 if (buf == NULL)
return NULL;
72 if (offset >= fileSize ) {
73 if (allowExceptions)
throw BufferException(
"Too far offset requested!");
77 if (offset + size > fileSize) {
81 BYTE *cntnt = buf + offset;
90 if (contentSize < startOffset)
return 0;
107 if (dstPtr == srcPtr)
return false;
108 if (dstPtr == NULL || srcPtr == NULL)
return false;
112 printf(
"Invalid copy destination!");
113 if (allowExceptions)
throw BufferException(
"Invalid copy destination!");
119 if (dstMaxSize < size) {
123 if (memcmp(dstPtr, srcPtr, size) == 0) {
126 if (paddingSize != 0) {
127 memset(dstPtr, 0, size);
129 memcpy(dstPtr, srcPtr, srcSize);
135 std::string newTextStr = newText.toStdString();
138 BYTE *dstPtr = this->
getContentAt(rawOffset, newTextLen + 1);
143 const char* newTextC = newTextStr.c_str();
157 return QString::fromUtf8(ptr,
static_cast<int>(asciiLen));
165 size = len * unitSize;
167 WORD* ptr = (WORD*) this->
getContentAt(rawOffset, size);
168 if (ptr == NULL)
return "";
169 return QString::fromUtf16(ptr,
static_cast<int>(len));
177 size = len * unitSize;
183 return QString::fromUtf16(ptr,
static_cast<int>(asciiLen));
189 if (area == NULL)
return false;
192 if (area[i] != 0)
return false;
202 if (buf == NULL)
return false;
204 memset(buf, filling, bufSize);
210 if (
isValid(buf) ==
false ||
isValid(
this) ==
false)
return false;
211 if (buf == NULL || buf->
getContent() == NULL)
return false;
216 if (
static_cast<offset_t>(mySize) <= rawOffset) {
218 "Too far offset requested: %llX while mySize: %lX",
219 static_cast<unsigned long long>(rawOffset),
220 static_cast<unsigned long>(mySize)
224 BYTE *target = this->
getContentAt(rawOffset, sizeToFill);
225 if (target == NULL) {
226 if (allowTrunc ==
false)
return false;
227 sizeToFill = mySize - rawOffset;
230 if (target == NULL)
return false;
231 memcpy(target, source, sizeToFill);
237 if (rawOffset ==
INVALID_ADDR || size == 0)
return false;
240 if (ptr == NULL)
return false;
247 offset_t srchdEnd = rawOffset + size;
248 if (rawOffset >= startOffset && srchdEnd <= endOffset) {
257 if (rawOffset ==
INVALID_ADDR || size == 0)
return false;
260 if (ptr == NULL)
return false;
267 offset_t srchdEnd = rawOffset + size;
268 if (rawOffset >= startOffset && rawOffset <= endOffset) {
270 "Found in bounds: %llX - %llX end: %llX",
271 static_cast<unsigned long long>(startOffset),
272 static_cast<unsigned long long>(endOffset),
273 static_cast<unsigned long long>(rawOffset)
277 if (srchdEnd >= startOffset && srchdEnd <= endOffset) {
279 "Found in bounds: %llX - %llX",
280 static_cast<unsigned long long>(startOffset),
281 static_cast<unsigned long long>(endOffset)
290 if (isOk) (*isOk) =
false;
299 if (size ==
sizeof(uint8_t)) val = *((uint8_t*) ptr);
300 else if (size ==
sizeof(uint16_t)) val = *((uint16_t*) ptr);
301 else if (size ==
sizeof(uint32_t)) val = *((uint32_t*) ptr);
302 else if (size ==
sizeof(uint64_t)) val = *((uint64_t*) ptr);
306 if (isOk) (*isOk) =
true;
316 "Cannot get Ptr at: %llX of size: %lX!",
317 static_cast<unsigned long long>(offset),
318 static_cast<unsigned long>(size)
323 if (size ==
sizeof(uint8_t)) {
324 uint8_t nVal = newVal;
325 uint8_t* valPtr = (uint8_t*) ptr;
326 if ((*valPtr) == nVal)
return false;
329 else if (size ==
sizeof(uint16_t)) {
330 uint16_t nVal = newVal;
331 uint16_t* valPtr = (uint16_t*) ptr;
332 if ((*valPtr) == nVal)
return false;
335 else if (size ==
sizeof(uint32_t)) {
336 uint32_t nVal = newVal;
337 uint32_t* valPtr = (uint32_t*) ptr;
338 if ((*valPtr) == nVal)
return false;
341 else if (size ==
sizeof(uint64_t)) {
342 uint64_t nVal = newVal;
343 uint64_t* valPtr = (uint64_t*) ptr;
344 if ((*valPtr) == nVal)
return false;
356 : parent(v_parent), offset(v_offset), size(v_size)
358 if (v_parent == NULL)
throw BufferException(
"Cannot make subBuffer for NULL buffer!");
const bufsize_t BUFSIZE_MAX
const offset_t INVALID_ADDR
virtual bufsize_t getContentSize()=0
bufsize_t getMaxSizeFromOffset(offset_t startOffset)
bool intersectsBlock(offset_t rawOffset, bufsize_t size)
virtual BYTE * getContentAtPtr(BYTE *ptr, bufsize_t size, bool allowExceptions=false)
QString getStringValue(offset_t rawOffset, bufsize_t len=BUFSIZE_MAX)
virtual BYTE * getContent()=0
bool setNumValue(offset_t offset, bufsize_t size, uint64_t newVal)
virtual bool setBufferedValue(BYTE *dstPtr, BYTE *srcPtr, bufsize_t srcSize, bufsize_t paddingSize, bool allowExceptions=false)
virtual BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
bool pasteBuffer(offset_t rawOffset, AbstractByteBuffer *buf, bool allowTrunc)
bool setStringValue(offset_t rawOffset, QString newText)
uint64_t getNumValue(offset_t offset, bufsize_t size, bool *isOk)
bool containsBlock(offset_t rawOffset, bufsize_t size)
BYTE operator[](size_t idx)
static bool isValid(AbstractByteBuffer *buf)
QString getWStringValue(offset_t rawOffset, bufsize_t len)
QString getWAsciiStringValue(offset_t rawOffset, bufsize_t len)
bool isAreaEmpty(offset_t rawOffset, bufsize_t size)
virtual offset_t getOffset(void *ptr, bool allowExceptions=false)
bool fillContent(BYTE filling)
BufferView(AbstractByteBuffer *parent, offset_t offset, bufsize_t size)
AbstractByteBuffer * parent
virtual BYTE * getContent()
virtual bufsize_t getContentSize()
bool append(dbg_level lvl, const char *format,...)
bufsize_t roundupToUnit(bufsize_t size, bufsize_t unit)
size_t getAsciiLen(const char *ptr, size_t maxCount, bool acceptNotTerminated=false)
size_t getAsciiLenW(const WORD *ptr, size_t maxCount, bool acceptNotTerminated=false)