-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.h
69 lines (51 loc) · 1.46 KB
/
patch.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
#ifndef _SENDVAREDIT_PATCH_H_
#define _SENDVAREDIT_PATCH_H_
#include <vector>
#include <string>
// doesn't compile without these two in this order when including sp::MacroAssembler and I'm clueless as to why
#include "extension.h"
// #include <memory>
#include <platform.h>
#include <asm/asm.h>
#include <macro-assembler-x86.h>
class PatchMask
{
public:
enum MaskEntry {
EIGNORE = -0x10000,
ENOP = -0x20000,
};
private:
std::vector<int> mask;
public:
PatchMask() {}
// Space delimited string. 'n' = replace with NOP, 'i' to ignore a byte, string integer to shift a byte over to make space.
PatchMask(const std::string &mask_string);
// Index into the mask
inline int operator[](size_t index) const { return *&mask[index]; }
// Number of bytes the mask ranges over
inline size_t MaskSize() const { return mask.size(); }
// If parsing didn't fail
inline bool Valid() const { return !mask.empty(); }
// Get how many bytes will be writable with this mask
size_t WritableSize() const;
};
class Patcher
{
private:
void* base = nullptr;
PatchMask mask;
bool writable = false;
bool patched = false;
char* original = nullptr;
public:
Patcher() {}
Patcher(void* base, PatchMask mask);
~Patcher();
inline bool Valid() const { return original != nullptr; }
bool Patch(sp::MacroAssembler &masm);
void UnPatch();
private:
bool ApplyMask();
};
#endif // _SENDVAREDIT_PATCH_H_