-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFile.cpp
80 lines (65 loc) · 1.46 KB
/
File.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
#include "File.h"
#define BXML_BUFFER_SIZE 65536
namespace Evtx {
File::File(char* filename)
{
stream = fopen(filename, "rb");
header = new Header(stream);
nextChunkIndex = 0;
currentChunk = NULL;
}
File::~File(void)
{
fclose(stream);
delete header;
if (currentChunk != NULL) {
delete currentChunk;
}
}
bool File::isDirty(void) {
return header->isDirty();
}
bool File::isFull(void) {
return header->isFull();
}
uint16 File::getChunkCount(void) {
return header->ChunkCount;
}
bool File::CRCPass(void) {
return header->hasValidCRC();
}
uint16 File::getMajorVersion(void) {
return header->MajorVersion;
}
uint16 File::getMinorVersion(void) {
return header->MinorVersion;
}
int64 File::getCurrentChunkNum(void) {
return header->CurrentChunkNum;
}
int64 File::getNextRecordNum(void) {
return header->NextRecordNum;
}
void File::dumpTo(char* filename, uint32 mode) {
// TODO: write dump code
FILE* dumpStream = fopen(filename, "w");
nextChunkIndex = 0;
wchar_t* buffer = new wchar_t[BXML_BUFFER_SIZE];
while (loadNextChunk()) {
while (currentChunk->getNextRecordXml(buffer, BXML_BUFFER_SIZE)) {
fprintf(dumpStream, "%s", buffer);
}
}
}
bool File::loadNextChunk(void) {
if (nextChunkIndex < getChunkCount()) {
if (currentChunk != NULL) {
delete currentChunk;
}
currentChunk = new Chunk(stream, nextChunkIndex);
nextChunkIndex++;
return true;
}
return false;
}
}