BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
FileBuffer.h
Go to the documentation of this file.
1#pragma once
2#include <QtCore>
3
4#include "ByteBuffer.h"
5
7const bufsize_t FILEVIEW_MAXSIZE = (1024*1024*400); //419mb
8
10{
11public:
12 FileBufferException(const QString info) : BufferException(info) {}
13};
14
15
17public:
18 static ByteBuffer* read(QString &file, bufsize_t minBufSize, const bool allowTruncate); //throws exceptions
19 static bufsize_t getReadableSize(QFile &fIn);
20
21 static bufsize_t getReadableSize(const QString &path);
22 static bufsize_t dump(const QString &fileName, AbstractByteBuffer &buf, bool allowExceptions = false);
23 QString getFileName() { return this->fileName; }
24
25protected:
26 static ByteBuffer* read(QFile &fIn, bufsize_t minBufSize, const bool allowTruncate); //throws exceptions
27
28 AbstractFileBuffer(QString v_fileName) :fileName(v_fileName) {}
29
30 QString fileName;
31 qint64 fileSize; // real size of the file
32};
33
34
36{
37public:
38 static bufsize_t getMappableSize(QFile &fIn);
39
40 FileView(QString &fileName, bufsize_t maxSize = FILE_MAXSIZE); //throws exceptions
41 virtual ~FileView();
42
43 virtual bufsize_t getContentSize() { return mappedSize; }
44 virtual BYTE* getContent() { return mappedContent; }
46 virtual bool isTruncated() { return fIn.size() > mappedSize; }
47
48protected:
51 QFile fIn;
52};
53
54
56{
57public:
58 FileBuffer(QString &fileName, bufsize_t minSize, bool allowTruncate) //throws exceptions
60 {
61 QFile fIn(fileName);
62 if (fIn.open(QFile::ReadOnly) == false) {
63 throw FileBufferException("Cannot open the file: " + fileName);
64 }
65 fileSize = fIn.size();
66 this->m_Buf = read(fIn, minSize, allowTruncate);//throws exceptions
67 fIn.close();
68 }
69
70 virtual ~FileBuffer() { delete m_Buf; }
71
72 virtual bufsize_t getContentSize() { return (m_Buf == NULL) ? 0 : m_Buf->getContentSize(); }
73 virtual BYTE* getContent() { return (m_Buf == NULL) ? NULL : m_Buf->getContent(); }
74 offset_t getFileSize() { return static_cast<offset_t>(fileSize); }
75 bool resize(bufsize_t newSize) { return m_Buf->resize(newSize); }
76
77 virtual bool isResized() { return m_Buf ? m_Buf->isResized() : false; }
78
79 virtual bool isTruncated()
80 {
81 if (!m_Buf) return false;
82 return fileSize > this->m_Buf->getContentSize();
83 }
84
85protected:
87};
const bufsize_t BUFSIZE_MAX
uint32_t bufsize_t
uint64_t offset_t
const bufsize_t FILEVIEW_MAXSIZE
Definition FileBuffer.h:7
const bufsize_t FILE_MAXSIZE
Definition FileBuffer.h:6
static bufsize_t getReadableSize(QFile &fIn)
QString getFileName()
Definition FileBuffer.h:23
static bufsize_t dump(const QString &fileName, AbstractByteBuffer &buf, bool allowExceptions=false)
static ByteBuffer * read(QString &file, bufsize_t minBufSize, const bool allowTruncate)
AbstractFileBuffer(QString v_fileName)
Definition FileBuffer.h:28
virtual BYTE * getContent()
Definition ByteBuffer.h:16
virtual bufsize_t getContentSize()
Definition ByteBuffer.h:15
virtual bool isResized()
Definition ByteBuffer.h:19
virtual bool resize(bufsize_t newSize)
FileBufferException(const QString info)
Definition FileBuffer.h:12
virtual ~FileBuffer()
Definition FileBuffer.h:70
virtual bool isResized()
Definition FileBuffer.h:77
ByteBuffer * m_Buf
Definition FileBuffer.h:86
FileBuffer(QString &fileName, bufsize_t minSize, bool allowTruncate)
Definition FileBuffer.h:58
virtual bufsize_t getContentSize()
Definition FileBuffer.h:72
virtual BYTE * getContent()
Definition FileBuffer.h:73
bool resize(bufsize_t newSize)
Definition FileBuffer.h:75
virtual bool isTruncated()
Definition FileBuffer.h:79
offset_t getFileSize()
Definition FileBuffer.h:74
virtual ~FileView()
virtual bool isTruncated()
Definition FileBuffer.h:46
virtual BYTE * getContent()
Definition FileBuffer.h:44
bufsize_t mappedSize
Definition FileBuffer.h:50
QFile fIn
Definition FileBuffer.h:51
bufsize_t getMappableSize()
Definition FileBuffer.h:45
virtual bufsize_t getContentSize()
Definition FileBuffer.h:43
FileView(QString &fileName, bufsize_t maxSize=FILE_MAXSIZE)
Definition FileBuffer.cpp:4
BYTE * mappedContent
Definition FileBuffer.h:49