This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNDBViewer.h
299 lines (252 loc) · 8.71 KB
/
NDBViewer.h
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#pragma once
#include "ndbport.h"
#include "ltpport.h"
#define Unreferenced(_a) (_a);
struct NodeData
{
BREF bref;
NID nid;
NID nidParent;
HID hid;
CB cb;
BTKEY btkey;
ULONG ulFlags;
};
enum
{
fChildrenLoaded = 0x1,
fInfoNode = 0x2,
// open btpage inspector for bref.ib
aOpenBTPage = 0x4, // open a bt page inspector
aOpenPage = 0x8, // open a regular page inspector
// open the appropriate block inspector for bref.ib
aOpenBlock = 0x10,
aOpenXBlock = 0x20,
aOpenSBlock = 0x40,
// open a binary inspector
aOpenBinary = 0x80,
// select a specific node in one of the trees
aBrowseBBT = 0x100, // browse to bref.bid in bbt
aBrowseNBT = 0x200, // browse to nid in nbt
// try to find refs to bref.bid
aBrowseRefs = 0x400,
// open a node size dialog for nid, nidparent
aViewNodeSize = 0x800,
// open a HN inspector for nid, nidparent
aOpenHN = 0x1000,
// open an ES inspector for nid, nidparent
aOpenES = 0x2000,
// open a HID inspector for nid, nidparent, hid
aOpenHID = 0x4000,
// open a BTH inspector for nid, nidparent
aOpenBTH = 0x10000,
// open a TCV Index Root inspector for nid
aOpenTCVIR = 0x20000,
// open a PC inspector for nid, nidparent
aOpenPC = 0x40000,
// error state
errCRCFailed = 0x80000000,
};
#define feLeaf 0x01
#define feNonLeaf 0x02
#define feInvalid 0x04
#define feAllValid (feLeaf|feNonLeaf)
#define feAll (feLeaf|feNonLeaf|feInvalid)
enum {
iconNone,
iconFolder,
iconMessage,
iconCorrupt,
iconPass,
iconInternal,
iconSearchFolder,
iconAttachment,
iconLeafPage,
iconAssociatedMessage,
iconBlock,
iconPage,
iconInternalBlock,
iconWarning
};
#define iconFail iconCorrupt
#define iconInfo iconInternal
UINT const s_nidTypeToIcon[NID_TYPE_LTP+1] = {
iconNone, // NID_TYPE_NONE
iconInternal, // NID_TYPE_INTERNAL
iconFolder, //NID_TYPE_NORMAL_FOLDER
iconSearchFolder, //NID_TYPE_SEARCH_FOLDER
iconMessage, //NID_TYPE_NORMAL_MESSAGE
iconAttachment, //NID_TYPE_ATTACHMENT
iconInternal, //NID_TYPE_SEARCH_UPDATE_QUEUE
iconInternal, //NID_TYPE_SEARCH_CRITERIA_OBJECT
iconAssociatedMessage, //NID_TYPE_ASSOC_MESSAGE
iconInternal, // NID_TYPE_STORAGE
iconInternal, //NID_TYPE_CONTENTS_TABLE_INDEX
iconFolder, //NID_TYPE_RECEIVE_FOLDER_TABLE
iconFolder, //NID_TYPE_OUTGOING_QUEUE_TABLE
iconFolder, //NID_TYPE_HIERARCHY_TABLE
iconFolder, //NID_TYPE_CONTENTS_TABLE
iconFolder, //NID_TYPE_ASSOC_CONTENTS_TABLE
iconSearchFolder, //NID_TYPE_SEARCH_CONTENTS_TABLE
iconFolder, //NID_TYPE_ATTACHMENT_TABLE
iconFolder, //NID_TYPE_RECIPIENT_TABLE
iconInternal, //NID_TYPE_SEARCH_TABLE_INDEX
iconFolder, // NID_TYPE_CONTENTS_SMP
iconFolder, // NID_TYPE_ASSOC_CONTENTS_SMP
iconFolder, // NID_TYPE_CHANGE_HISTORY_TABLE
iconFolder, // NID_TYPE_TOMBSTONE_TABLE
iconFolder, // NID_TYPE_TOMBSTONE_DATE_TABLE
iconInternal, // NID_TYPE_LREP_DUPS_TABLE
iconCorrupt, // 1A
iconCorrupt, // 1B
iconCorrupt, // 1C
iconCorrupt, // 1D
iconCorrupt, // 1E
iconInternal // NID_TYPE_LTP
};
#define ICONFROMNID(x) (NIDType(x) <= NID_TYPE_LTP ? s_nidTypeToIcon[NIDType(x)] : iconCorrupt)
const WCHAR* const s_nidTypeToString[] = {
L"NID_TYPE_NONE",
L"NID_TYPE_INTERNAL",
L"NID_TYPE_NORMAL_FOLDER",
L"NID_TYPE_SEARCH_FOLDER",
L"NID_TYPE_NORMAL_MESSAGE",
L"NID_TYPE_ATTACHMENT",
L"NID_TYPE_SEARCH_UPDATE_QUEUE",
L"NID_TYPE_SEARCH_CRITERIA_OBJECT",
L"NID_TYPE_ASSOC_MESSAGE",
L"NID_TYPE_STORAGE",
L"NID_TYPE_CONTENTS_TABLE_INDEX",
L"NID_TYPE_RECEIVE_FOLDER_TABLE",
L"NID_TYPE_OUTGOING_QUEUE_TABLE",
L"NID_TYPE_HIERARCHY_TABLE",
L"NID_TYPE_CONTENTS_TABLE",
L"NID_TYPE_ASSOC_CONTENTS_TABLE",
L"NID_TYPE_SEARCH_CONTENTS_TABLE",
L"NID_TYPE_ATTACHMENT_TABLE",
L"NID_TYPE_RECIPIENT_TABLE",
L"NID_TYPE_SEARCH_TABLE_INDEX",
L"NID_TYPE_CONTENTS_SMP",
L"NID_TYPE_ASSOC_CONTENTS_SMP",
L"NID_TYPE_CHANGE_HISTORY_TABLE",
L"NID_TYPE_TOMBSTONE_TABLE",
L"NID_TYPE_TOMBSTONE_DATE_TABLE",
L"NID_TYPE_LREP_DUPS_TABLE",
L"Unknown Type 1A",
L"Unknown Type 1B",
L"Unknown Type 1C",
L"Unknown Type 1D",
L"Unknown Type 1E",
L"NID_TYPE_LTP"
};
#define TYPESTRINGFROMNID(x) (NIDType(x) <= NID_TYPE_LTP ? s_nidTypeToString[NIDType(x)] : L"Unknown")
const WCHAR* const s_cryptTypeToString[] = {
L"NDB_CRYPT_NONE",
L"NDB_CRYPT_PERMUTE",
L"NDB_CRYPT_CYCLIC"
};
#define CRYPTSTRING(x) (x <= NDB_CRYPT_CYCLIC ? s_cryptTypeToString[x] : L"Unknown")
const WCHAR* const s_btypeToString[] = {
L"btypeNB",
L"btypeXB",
L"btypeSB"
};
#define BTYPESTRING(x) (x <= btypeSB ? s_btypeToString[x] : L"Unknown")
const WCHAR* GetVersionString(WORD w);
const WCHAR* GetPlatformString(WORD w);
const WCHAR* GetClientVersionString(WORD w);
const WCHAR* GetClientMagicNumString(WORD w);
const WCHAR* GetMagicNumString(DWORD dw);
const WCHAR* GetAMapString(BYTE b);
const WCHAR* GetPTypeString(BYTE b);
ULONGLONG ULLSize(ULONGLONG ull);
const WCHAR* WSZSize(ULONGLONG ull);
// Range checking functions
UINT SBIEnt(const SBLOCK& block, UINT dataSize);
UINT SBLEnt(const SBLOCK& block, UINT dataSize);
UINT XBEnt(const XBLOCK& block, UINT dataSize);
UINT BTEnt(const BTPAGE& page);
UINT BBTEnt(const BTPAGE& page);
UINT NBTEnt(const BTPAGE& page);
UINT BBufferSize(UINT blockUnaligned); // size block data buffers using this function
class NDBViewer
{
public:
NDBViewer(LPCWSTR filename);
~NDBViewer(void);
void PopulateNBT(CTreeCtrl* ptctrl);
BOOL SelectNID(CTreeCtrl* ptctrl, NID nid);
void PopulateBBT(CTreeCtrl* ptctrl);
BOOL SelectBID(CTreeCtrl* ptctrl, BID bid);
void PopulateSBlock(CTreeCtrl *ptctrl, const BREF& bref, CB cb);
void ExpandSBlockNode(CTreeCtrl* ptctrl, HTREEITEM hItem);
void AddBTNodeChildren(CTreeCtrl* ptctrl, HTREEITEM parent);
void PopulateHeader(CTreeCtrl* ptctrl);
void ForEachBTPage(PTYPE ptype, bool (*pfn)(BTPAGE*,PAGETRAILER*,IB,void*), int btType, void* pv);
void DeleteNode(CTreeCtrl* ptctrl, HTREEITEM hItem);
void ReadPage(BYTE* pPageData, UINT cbData, PAGETRAILER* pPageTrailer, IB ib);
void ReadBlock(BYTE* pBlockData, UINT cbData, BLOCKTRAILER* pBlockTrailer, IB ib, UINT cbBlock);
void ReadData(BYTE* buffAll, UINT cbBuffAll, BYTE* buffTrailer, UINT cbBuffTrailer, IB ib, UINT cb);
void DecodeBlockInPlace(BYTE * pBlockData, UINT cbData, BID bid);
CB IsFree(IB ib);
bool LookupBID(BID b, BREF& bref, CB& cb, UINT& cRef);
bool LookupNID(NID nid, BID& data, BID& sub);
bool LookupSubnodeNID(NID nidParent, NID nidSubnode, BID& data, BID& sub);
CB NODE_ReadData(NID nidParent, NID nid, BYTE* buffAll, UINT cbBuffAll, IB ib, UINT cb);
CB NODE_GetSize(NID nidParent, NID nid);
CB XBlockRead(BID bid, BYTE* buffAll, UINT cbBuffAll, IB ib, UINT cb);
CB XBGetSize(BID bid);
HEADER GetHeader() { return m_header; }
IB GetFileEOF() { return m_ndb.GetLength(); }
bool FValidPartialCRC() { return m_fPartialCRCPass; }
bool FValidCRC() { return m_fFullCRCPass; }
bool FValidPage(IB ib, PTYPE ptype = 0);
bool FValidBlock(IB ib, CB cbUnaligned, BID bid = 0);
bool FFree(IB ib);
void CacheAMapBitmap(CBitmap * pBitmap) { m_cachedAMapBitmap = pBitmap; }
CBitmap * GetCachedAMapBitmap() { return m_cachedAMapBitmap; }
void CacheBTBitmap(CBitmap * pBitmap) { m_cachedBTBitmap = pBitmap; }
CBitmap * GetCachedBTBitmap() { return m_cachedBTBitmap; }
CFile& GetFile() { return m_ndb; }
protected:
CFile m_ndb;
// header and CRC checks
HEADER m_header;
bool m_fPartialCRCPass;
bool m_fFullCRCPass;
// File Cache
static const int c_pcMaxSize = 50;
struct CACHEINFO
{
UINT cb;
BYTE* pData;
};
CMap<IB, IB, CACHEINFO*, CACHEINFO*> m_fileCache;
CList<IB> m_fileCacheAgeList;
// Cached AMap bitmap
CBitmap * m_cachedAMapBitmap;
// Cached BT bitmap
CBitmap * m_cachedBTBitmap;
protected:
bool ReadVerifyHeader(void);
void AddSBlockChildren(CTreeCtrl* ptctrl, HTREEITEM parent);
void AddNBTLeafNodes(CTreeCtrl* ptctrl, HTREEITEM parent, const BTPAGE& btpage);
void AddBBTLeafNodes(CTreeCtrl* ptctrl, HTREEITEM parent, const BTPAGE& btpage);
void ForEachBTPageImpl(IB ib, bool (*pfn)(BTPAGE*,PAGETRAILER*,IB,void*), int btType, void* pv);
bool LookupBIDImpl(BTPAGE * pPage, BID bid, BREF& bref, CB& cb, UINT& cRef);
bool LookupNIDImpl(BTPAGE * pPage, NID nid, BID& data, BID& sub);
bool LookupSubnodeNIDImpl(SBLOCK * pSBlock, CB cbBlocksize, NID nidSubnode, BID& data, BID& sub);
};
// Helper Functions
inline void RemoveFalseChild(CTreeCtrl * ptctrl, HTREEITEM hItem)
{
HTREEITEM hFalseChild = ptctrl->GetChildItem(hItem);
ptctrl->DeleteItem(hFalseChild);
}
inline void AddFalseChild(CTreeCtrl * ptctrl, HTREEITEM hItem)
{
ptctrl->InsertItem(L"False Child", hItem);
}
CFont* GetGlobalFont();
CFont* GetGlobalFontFixedWidth();
void DestroyFonts();