KittyMemoryEx 1.0.0
Dedicated library for runtime code patching, memory scanning, tracing, injection and some more useful memory utilities. works for both Android and Linux
Loading...
Searching...
No Matches
MemoryPatch.hpp
1#pragma once
2
3#include "KittyUtils.hpp"
4#include "KittyMemoryEx.hpp"
5#include "KittyMemOp.hpp"
6
10enum MP_ASM_ARCH
11{
12 MP_ASM_ARM32 = 0,
13 MP_ASM_ARM64,
14 MP_ASM_x86,
15 MP_ASM_x86_64,
16};
17
30class MemoryPatch
31{
32 friend class MemoryPatchMgr;
33
34private:
35 IKittyMemOp *_pMem;
36
37 uintptr_t _address;
38 size_t _size;
39
40 std::vector<uint8_t> _orig_code;
41 std::vector<uint8_t> _patch_code;
42
43public:
44 MemoryPatch();
45 ~MemoryPatch();
46
47 MemoryPatch(IKittyMemOp *pMem, uintptr_t absolute_address, const void *patch_code, size_t patch_size);
48
52 bool isValid() const;
53
57 size_t get_PatchSize() const;
58
62 uintptr_t get_TargetAddress() const;
63
67 bool Restore();
68
72 bool Modify();
73
77 std::string get_CurrBytes() const;
78
82 std::string get_OrigBytes() const;
83
87 std::string get_PatchBytes() const;
88};
89
93class MemoryPatchMgr
94{
95private:
96 IKittyMemOp *_pMem;
97
98public:
99 MemoryPatchMgr() : _pMem(nullptr)
100 {
101 }
102
107 MemoryPatchMgr(IKittyMemOp *pMem) : _pMem(pMem)
108 {
109 }
110
118 MemoryPatch createWithBytes(uintptr_t absolute_address, const void *patch_code, size_t patch_size);
119
126 MemoryPatch createWithHex(uintptr_t absolute_address, std::string hex);
127
128#ifndef kNO_KEYSTONE
138 MemoryPatch createWithAsm(uintptr_t absolute_address,
139 MP_ASM_ARCH asm_arch,
140 const std::string &asm_code,
141 uintptr_t asm_address = 0);
142#endif
143};
Interface class for memory operations.
Definition KittyMemOp.hpp:46
MemoryPatch createWithAsm(uintptr_t absolute_address, MP_ASM_ARCH asm_arch, const std::string &asm_code, uintptr_t asm_address=0)
Creates a memory patch with assembly code using keystone assembler.
MemoryPatch createWithHex(uintptr_t absolute_address, std::string hex)
Creates a memory patch with hexadecimal string data.
MemoryPatch createWithBytes(uintptr_t absolute_address, const void *patch_code, size_t patch_size)
Creates a memory patch with byte data.
MemoryPatchMgr(IKittyMemOp *pMem)
Constructor for MemoryPatchMgr.
Definition MemoryPatch.hpp:107
The MemoryPatch class represents a memory patch for applying modifications to a memory address.
Definition MemoryPatch.hpp:31
bool Modify()
Applies patch modifications to the target address.
size_t get_PatchSize() const
Returns the size of the memory patch.
bool isValid() const
Checks if the MemoryPatch object is valid.
uintptr_t get_TargetAddress() const
Returns the target address of the memory patch.
std::string get_OrigBytes() const
Returns hex string of the original bytes.
std::string get_PatchBytes() const
Returns hex string of the patch bytes.
bool Restore()
Restores the patch to its original value.
std::string get_CurrBytes() const
Returns hex string of the current target address bytes.