-
Notifications
You must be signed in to change notification settings - Fork 1
/
valueitem.cpp
214 lines (197 loc) · 4.95 KB
/
valueitem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "valueitem.h"
#include <QDebug>
#include <QPair>
ValueItem::ValueItem(HiveItem *parent, int index,
hive_h *hive, hive_value_h value) :
HiveItem(parent, index, getValueName(hive, value)),
m_hive(hive), m_valueHandle(value)
{
loadData();
}
int ValueItem::valueType()
{
return m_valueType;
}
QString ValueItem::valueTypeDisplay()
{
switch (m_valueType)
{
case hive_t_REG_NONE:
return "REG_NONE";
case hive_t_REG_SZ:
return "REG_SZ";
case hive_t_REG_EXPAND_SZ:
return "REG_EXPAND_SZ";
case hive_t_REG_BINARY:
return "REG_BINARY";
case hive_t_REG_DWORD:
return "REG_DWORD";
case hive_t_REG_DWORD_BIG_ENDIAN:
return "REG_DWORD_BIG_ENDIAN";
case hive_t_REG_LINK:
return "REG_LINK";
case hive_t_REG_MULTI_SZ:
return "REG_MULTI_SZ";
case hive_t_REG_RESOURCE_LIST:
return "REG_RESOURCE_LIST";
case hive_t_REG_FULL_RESOURCE_DESCRIPTOR:
return "REG_FULL_RESOURCE_DESCRIPTOR";
case hive_t_REG_RESOURCE_REQUIREMENTS_LIST:
return "REG_RESOURCE_REQUIREMENTS_LIST";
case hive_t_REG_QWORD:
return "REG_QWORD";
default:
return "UNKNOWN";
}
}
QByteArray ValueItem::rawData()
{
return m_rawData;
}
bool ValueItem::isDefault() const
{
return name().isEmpty();
}
bool ValueItem::isNode() const
{
return false;
}
QVariant ValueItem::data() const
{
return m_data;
}
QPair<QString, bool> ValueItem::dataDisplay() const
{
QString str;
bool isSpecial = false;
switch (m_valueType)
{
case hive_t_REG_SZ:
case hive_t_REG_EXPAND_SZ:
case hive_t_REG_LINK:
str = m_data.toString();
if (str.isEmpty())
{
str = "(empty string)";
isSpecial = true;
}
break;
case hive_t_REG_MULTI_SZ:
str = m_data.toStringList().join(", ");
if (str.isEmpty())
{
str = "(empty string list)";
isSpecial = true;
}
break;
case hive_t_REG_DWORD:
case hive_t_REG_DWORD_BIG_ENDIAN:
str = m_data.toString();
if (m_rawData.length() != 4)
{
str = "(invalid DWORD value)";
isSpecial = true;
}
break;
case hive_t_REG_QWORD:
str = m_data.toString();
if (m_rawData.length() != 8)
{
str = "(invalid QWORD value)";
isSpecial = true;
}
break;
default:
str = m_rawData.toHex();
if (str.isEmpty())
{
str = "(empty binary data)";
isSpecial = true;
}
break;
}
return qMakePair(str, isSpecial);
}
void ValueItem::loadData()
{
size_t len;
hive_type valueType;
char *raw = hivex_value_value(m_hive, m_valueHandle, &valueType, &len);
if (!raw)
{
qCritical() << "Could not load hive data";
return;
}
m_valueType = valueType;
m_rawData = QByteArray{raw, static_cast<int>(len)};
switch (valueType)
{
case hive_t_REG_SZ:
case hive_t_REG_EXPAND_SZ:
case hive_t_REG_LINK:
{
char *str = hivex_value_string(m_hive, m_valueHandle);
if (!str)
{
m_data = QString{"<ERROR>"};
break;
}
m_data = QString::fromUtf8(str);
free(str);
break;
}
case hive_t_REG_MULTI_SZ:
{
char **strings = hivex_value_multiple_strings(m_hive, m_valueHandle);
QStringList strList;
if (!strings)
{
strList << "<ERROR>";
m_data = strList;
break;
}
for (char **str = strings; *str; str++)
{
strList << QString::fromUtf8(*str);
free(*str);
}
m_data = strList;
free(strings);
break;
}
case hive_t_REG_DWORD:
case hive_t_REG_DWORD_BIG_ENDIAN:
m_data = static_cast<qint32>(hivex_value_dword(m_hive, m_valueHandle));
break;
case hive_t_REG_QWORD:
m_data = static_cast<qint64>(hivex_value_qword(m_hive, m_valueHandle));
break;
default:
m_data = m_rawData;
break;
}
}
QString ValueItem::getValueName(hive_h *hive, hive_value_h value)
{
char *name = hivex_value_key(hive, value);
if (!name)
{
qCritical() << "Could not load value name of hive"
<< hive << "value" << value;
return "<ERROR>";
}
QString qName = QString::fromUtf8(name, hivex_value_key_len(hive, value));
qDebug() << "Name of value" << value << "in hive" << hive << "is" << qName;
free(name);
return qName;
}
QDebug operator<<(QDebug dbg, const ValueItem &value)
{
QDebugStateSaver saver{dbg};
Q_UNUSED(saver);
dbg.nospace() << "ValueItem(name: " << value.name()
<< ", hive: " << value.m_hive
<< ", handle: " << value.m_valueHandle
<< ", type: " << value.m_valueType << ")";
return dbg;
}