-
Notifications
You must be signed in to change notification settings - Fork 102
/
qhexutils.h
66 lines (53 loc) · 1.93 KB
/
qhexutils.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
#pragma once
#include <QByteArray>
#include <QPair>
#include <QString>
#include <QVariant>
struct QHexOptions;
class QHexView;
namespace QHexFindOptions {
enum : unsigned int {
None = (1 << 0),
CaseSensitive = (1 << 1),
Int8 = (1 << 2),
Int16 = (1 << 3),
Int32 = (1 << 4),
Int64 = (1 << 5),
Float = (1 << 6),
Double = (1 << 7),
BigEndian = (1 << 11),
};
}
enum class QHexFindMode { Text, Hex, Int, Float };
enum class QHexFindDirection { All, Forward, Backward };
enum class QHexArea { Header, Address, Hex, Ascii, Extra };
struct QHexPosition {
qint64 line;
qint64 column;
static inline QHexPosition invalid() { return {-1, -1}; }
inline bool isValid() const { return line >= 0 && column >= 0; }
inline bool operator==(const QHexPosition& rhs) const {
return (line == rhs.line) && (column == rhs.column);
}
inline bool operator!=(const QHexPosition& rhs) const {
return (line != rhs.line) || (column != rhs.column);
}
};
namespace QHexUtils {
bool isHex(char ch);
QByteArray toHex(const QByteArray& ba, char sep);
QByteArray toHex(const QByteArray& ba);
qint64 positionToOffset(const QHexOptions* options, QHexPosition pos);
QHexPosition offsetToPosition(const QHexOptions* options, qint64 offset);
bool checkPattern(QString pattern);
QPair<qint64, qint64> find(const QHexView* hexview, QVariant value,
qint64 startoffset = 0,
QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward);
QPair<qint64, qint64>
replace(const QHexView* hexview, QVariant oldvalue, QVariant newvalue,
qint64 startoffset = 0, QHexFindMode mode = QHexFindMode::Text,
unsigned int options = QHexFindOptions::None,
QHexFindDirection fd = QHexFindDirection::Forward);
} // namespace QHexUtils