-
Notifications
You must be signed in to change notification settings - Fork 2
/
memytools.h
83 lines (62 loc) · 2.09 KB
/
memytools.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
#include "Psapi.h"
#pragma comment(lib, "psapi.lib")
#define MEM_READ 1
#define MEM_WRITE 2
#define MEM_EXEC 4
#elif defined (POSIX)
#include "tier0/valve_minmax_off.h"
#include "sys/mman.h"
#define MEM_READ PROT_READ
#define MEM_WRITE PROT_WRITE
#define MEM_EXEC PROT_EXEC
// Addresses must be aligned to page size for linux
#define LALIGN(addr) (void*)((uintptr_t)(addr) & ~(getpagesize() - 1))
#define LALDIF(addr) ((uintptr_t)(addr) % getpagesize())
#include "tier0/valve_minmax_on.h"
#endif
#include <cbase.h>
typedef unsigned char byte;
#ifdef PostMessage
#undef PostMessage
#endif
struct modbin
{
uintptr_t addr = NULL;
size_t size = 0;
};
// shared between client and server
extern struct modbin* engine_bin;
extern struct modbin* server_bin;
extern struct modbin* tier0_bin;
// client only
extern struct modbin* vgui_bin;
extern struct modbin* client_bin;
extern struct modbin* gameui_bin;
class memy_init : public CAutoGameSystem
{
public:
memy_init();
bool Init() override;
};
class memy
{
public:
memy();
static bool InitAllBins();
static uintptr_t FindPattern(uintptr_t startaddr, size_t searchsize, const char* pattern, size_t sigsize, size_t offset = 0);
static uintptr_t FindPattern(modbin* mbin, const char* pattern, size_t sigsize, size_t offset = 0)
{
return memy::FindPattern(mbin->addr, mbin->size, pattern, sigsize, offset);
}
static bool SetMemoryProtection(void* addr, size_t protlen, int wantprot);
#if defined (POSIX)
static int GetModuleInformation(const char* name, void** base, size_t* length);
#endif
private:
static bool InitSingleBin(const char* binname, modbin* mbin);
static inline bool comparedata(const byte* addr, const char* pattern, size_t sigsize);
};