BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
parser
Formatter.cpp
Go to the documentation of this file.
1
#include "
Formatter.h
"
2
#include "
Util.h
"
3
4
//----------------
5
AbstractFormatter::AbstractFormatter
(
AbstractByteBuffer
*v_buf)
6
: buf(v_buf)
7
{
8
if
(v_buf == NULL)
throw
BufferException
(
"Cannot make HexFilter for NULL buffer!"
);
9
}
10
11
//---------------------------------------------------
12
const
QString
Formatter::operator[]
(std::size_t idx)
const
13
{
14
BYTE b = (*buf)[idx];
15
if
(
isHex
) {
16
return
QString::number(b, 16).leftJustified(2,
'0'
);
17
}
18
if
(
pe_util::isPrintable
(b) ==
false
) {
19
if
(
isSkipNonprintable
) {
20
return
".."
;
21
}
22
return
"\\x"
+ QString::number(b, 16).leftJustified(2,
'0'
);
23
}
24
return
QChar(b);
25
}
26
27
/*
28
29
BufferPrinter::BufferPrinter()
30
{
31
this->addFormater(int formatterId, AbstractFormatter);
32
33
}
34
35
36
bool BufferPrinter::addFormater(int formatterId, AbstractFormatter *formatter)
37
{
38
if (this->formatters[formatterId] != NULL) {
39
return false; //already exist
40
}
41
this->formatters[formatterId] = formatter;
42
return true;
43
}
44
45
bool BufferPrinter::useFormatter(int formatterId)
46
{
47
if (this->formatters[formatterId] == NULL) {
48
return false; //no such formatter
49
}
50
this->strategy = this->formatters[formatterId];
51
return true;
52
}
53
54
void BufferPrinter::clearFormatters()
55
{
56
std::map<int, AbstractFormatter*>::iterator itr;
57
for (itr = formatters.begin(); itr != formatters.end(); ++itr) {
58
AbstractFormatter* f = itr->second;
59
delete f;
60
}
61
formatters.clear();
62
}
63
*/
Formatter.h
Util.h
AbstractByteBuffer
Definition
AbstractByteBuffer.h:32
AbstractFormatter::AbstractFormatter
AbstractFormatter(AbstractByteBuffer *v_buf)
Definition
Formatter.cpp:5
BufferException
Definition
AbstractByteBuffer.h:22
Formatter::operator[]
const QString operator[](std::size_t idx) const
Definition
Formatter.cpp:12
Formatter::isHex
bool isHex
Definition
Formatter.h:32
Formatter::isSkipNonprintable
bool isSkipNonprintable
Definition
Formatter.h:33
pe_util::isPrintable
bool isPrintable(char c)
Definition
Util.h:32
Generated by
1.12.0