BearParser
Portable Executable parsing library (from PE-bear)
Loading...
Searching...
No Matches
WrappedValue.cpp
Go to the documentation of this file.
1#include "WrappedValue.h"
2
4{
5 if (m_Type == INT) {
6 bool isOk = false;
7
8 qlonglong num = (qlonglong) m_Owner->getNumValue(m_Offset, m_Size, &isOk);
9 if (!isOk) return QVariant("INVALID");
10 return QVariant(num);
11 }
12 if (m_Type == STRING) {
13 char *strPtr = (char*) this->m_Owner->getContentAt(m_Offset, m_Size);
14 if (strPtr == NULL) return QVariant();
15 return QString(strPtr);
16 }
17 if (this->m_Type == WSTRING) {
18
19 bufsize_t wSize = m_Size / bufsize_t(sizeof(WORD));
20 WORD *strPtr = (WORD*) this->m_Owner->getContentAt(m_Offset, m_Size);
21 return QString::fromUtf16(strPtr, static_cast<int>(wSize));
22 }
23 return QVariant("...");
24}
25
27{
28 QString format = "%0" + QString::number(m_Size * 2) +"llX";
29 return format;
30}
31
33{
34 if (this->m_Type == NONE) return "";
35 if (this->m_Type == COMPLEX) return "...";
36
37 QVariant val = getQVariant();
38
39 if (this->m_Type == STRING || this->m_Type == WSTRING) {
40 return val.toString();
41 }
42 if (this->m_Type == INT) {
43
44 bufsize_t size = this->m_Size;
45 if (size > sizeof(uint64_t)) return "...";
46
47 bool isOk = false;
48 uint64_t num = m_Owner->getNumValue(m_Offset, m_Size, &isOk);
49 if (!isOk) return "INVALID";
50 QString out;
51#if QT_VERSION >= 0x050000
52 out = QString::asprintf(getIntFormat().toStdString().c_str(), num);
53#else
54 out.sprintf(getIntFormat().toStdString().c_str(), num);
55#endif
56 return out;
57 }
58 return getQVariant().toString();
59}
uint32_t bufsize_t
virtual BYTE * getContentAt(offset_t offset, bufsize_t size, bool allowExceptions=false)
uint64_t getNumValue(offset_t offset, bufsize_t size, bool *isOk)
QVariant getQVariant()
AbstractByteBuffer * m_Owner
offset_t m_Offset
QString toQString()
bufsize_t m_Size
virtual QString getIntFormat()
data_type m_Type