BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
Formatter.cpp
Go to the documentation of this file.
1#include "Formatter.h"
2#include "Util.h"
3
4//----------------
6 : buf(v_buf)
7{
8 if (v_buf == NULL) throw BufferException("Cannot make HexFilter for NULL buffer!");
9}
10
11//---------------------------------------------------
12const 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) {
20 return "..";
21 }
22 return "\\x"+ QString::number(b, 16).leftJustified(2,'0');
23 }
24 return QChar(b);
25}
26
27/*
28
29BufferPrinter::BufferPrinter()
30{
31 this->addFormater(int formatterId, AbstractFormatter);
32
33}
34
35
36bool 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
45bool 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
54void 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*/
AbstractFormatter(AbstractByteBuffer *v_buf)
Definition Formatter.cpp:5
const QString operator[](std::size_t idx) const
Definition Formatter.cpp:12
bool isHex
Definition Formatter.h:32
bool isSkipNonprintable
Definition Formatter.h:33
bool isPrintable(char c)
Definition Util.h:32