forked from Xplatforms/CFFFlashFileTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcffutils.cpp
65 lines (52 loc) · 1.46 KB
/
cffutils.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
#include "defs.h"
CFFUtils::CFFUtils(QObject *parent) : QObject(parent)
{
}
bool CFFUtils::CheckAndAdvanceBitflag(ulong & bitFlag)
{
bool flagIsSet = (bitFlag & 1) > 0;
bitFlag >>= 1;
return flagIsSet;
}
QString CFFUtils::ReadString(QFile * cff)
{
// read out a string, stopping at the first null terminator
QByteArray writer;
while (true)
{
char nextByte = 0;
cff->read(&nextByte, 1);
if (nextByte == 0)
{
auto stringRaw = QString(writer);
return stringRaw;
}
else
{
writer.append(nextByte);
}
}
return QString(writer);
}
QString CFFUtils::ReadBitflagString(ulong & bitFlags, QFile * cff, long virtualBase)
{
if (CheckAndAdvanceBitflag(bitFlags))
{
// read the string's offset relative to our current block
int stringOffset = 0;
cff->read((char*)&stringOffset, sizeof(int32_t)); //sizeof = 4
// save our reading cursor
long readerPosition = cff->pos();
// seek to the specified offset, then read out the string
cff->seek(stringOffset + virtualBase);
auto result = CFFUtils::ReadString(cff);
// restore our reading cursor
cff->seek(readerPosition);
return result;
}
else
{
// Console.WriteLine("Bitflag was off for string");
return "(flag disabled)";
}
}