BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
AbstractByteBuffer.h
Go to the documentation of this file.
1#pragma once
2
3#include "win_hdrs/win_types.h"
4#include "CustomException.h"
5#include "Util.h"
6
7#include <QtCore>
8
9#include <iostream>
10#include <stdlib.h>
11
12//------------------------------------------------
13
14typedef uint32_t bufsize_t;
16
17typedef uint64_t offset_t;
20
22{
23public:
24 BufferException(const QString info) : CustomException(info) {}
25};
26
27namespace buf_util {
29};
30
32{
33public:
34 static bool isValid(AbstractByteBuffer *buf);
35
37 virtual ~AbstractByteBuffer() { }
38
40 virtual BYTE* getContent() = 0;
41 virtual bool isTruncated() { return false; }
42 virtual bool isResized() { return false; }
43
44 BYTE operator[](size_t idx);
45
46 virtual offset_t getOffset(void *ptr, bool allowExceptions = false); // validates
47 virtual BYTE* getContentAt(offset_t offset, bufsize_t size, bool allowExceptions = false);
48 virtual BYTE* getContentAtPtr(BYTE *ptr, bufsize_t size, bool allowExceptions = false);
49
50 virtual bool setBufferedValue(BYTE *dstPtr, BYTE *srcPtr, bufsize_t srcSize, bufsize_t paddingSize, bool allowExceptions = false);
51 bool setStringValue(offset_t rawOffset, QString newText);
52
53 QString getStringValue(offset_t rawOffset, bufsize_t len = BUFSIZE_MAX, bool acceptNonTerminated = false);
54 QString getWStringValue(offset_t rawOffset, bufsize_t len);
55 QString getWAsciiStringValue(offset_t rawOffset, bufsize_t len, bool acceptNonTerminated = false);
56
59
60 bool isAreaEmpty(offset_t rawOffset, bufsize_t size);
61 bool fillContent(BYTE filling);
62 bool pasteBuffer(offset_t rawOffset, AbstractByteBuffer *buf, bool allowTrunc);
63
64 bool containsBlock(offset_t rawOffset, bufsize_t size);
65 bool intersectsBlock(offset_t rawOffset, bufsize_t size);
66
67 uint64_t getNumValue(offset_t offset, bufsize_t size, bool* isOk);
68 bool setNumValue(offset_t offset, bufsize_t size, uint64_t newVal);
69 bool setTextValue(char* textPtr, std::string newText, size_t fieldLimitLen = 0);
70
71 //TODO
72 virtual bool resize(bufsize_t newSize) { return false; }
73 offset_t substFragmentByFile(offset_t offset, bufsize_t contentSize, QFile &fIn);
74};
75
76//--------------------------------------------
77
79{
80public:
82 virtual ~BufferView() { }
83
84 virtual bufsize_t getContentSize();
85 virtual BYTE* getContent();
86
87 bufsize_t getRequestedSize() const { return size; }
88
89protected:
93};
94
const bufsize_t BUFSIZE_MAX
const offset_t OFFSET_MAX
uint32_t bufsize_t
const offset_t INVALID_ADDR
uint64_t offset_t
virtual bufsize_t getContentSize()=0
bufsize_t getMaxSizeFromOffset(offset_t startOffset)
virtual bool isTruncated()
bool intersectsBlock(offset_t rawOffset, bufsize_t size)
QString getStringValue(offset_t rawOffset, bufsize_t len=BUFSIZE_MAX, bool acceptNonTerminated=false)
virtual BYTE * getContentAtPtr(BYTE *ptr, bufsize_t size, bool allowExceptions=false)
virtual bool isResized()
virtual BYTE * getContent()=0
bool setTextValue(char *textPtr, std::string newText, size_t fieldLimitLen=0)
bufsize_t getMaxSizeFromPtr(BYTE *ptr)
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)
offset_t substFragmentByFile(offset_t offset, bufsize_t contentSize, QFile &fIn)
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)
virtual bool resize(bufsize_t newSize)
static bool isValid(AbstractByteBuffer *buf)
QString getWStringValue(offset_t rawOffset, bufsize_t len)
bool isAreaEmpty(offset_t rawOffset, bufsize_t size)
virtual offset_t getOffset(void *ptr, bool allowExceptions=false)
QString getWAsciiStringValue(offset_t rawOffset, bufsize_t len, bool acceptNonTerminated=false)
bool fillContent(BYTE filling)
BufferException(const QString info)
virtual ~BufferView()
bufsize_t getRequestedSize() const
BufferView(AbstractByteBuffer *parent, offset_t offset, bufsize_t size)
AbstractByteBuffer * parent
virtual BYTE * getContent()
virtual bufsize_t getContentSize()
bufsize_t roundupToUnit(bufsize_t size, bufsize_t unit)