forked from gijsgroenewegen/CWSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcwsdk.cpp
68 lines (52 loc) · 1.63 KB
/
cwsdk.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
66
67
68
#define MOD_MAJOR_VERSION 7
#define MOD_MINOR_VERSION 5
#include "cwsdk.h"
#include <windows.h>
void* moduleBase;
void* CWBase(){
return moduleBase;
}
void* CWOffset(size_t offset) {
return (void*)((char*)moduleBase + offset);
}
EXPORT void ModPreInitialize(){
moduleBase = GetModuleHandle(NULL);
}
EXPORT int ModMajorVersion(){
return MOD_MAJOR_VERSION;
}
EXPORT int ModMinorVersion(){
return MOD_MINOR_VERSION;
}
void WriteByte(void* location, char val){
DWORD dwOldProtection;
VirtualProtect(location, 1, PAGE_EXECUTE_READWRITE, &dwOldProtection);
*(char*)location = val;
VirtualProtect(location, 1, dwOldProtection, &dwOldProtection);
}
/*
#ifndef MODLOADER
void WriteFarJMP(void* source, void* destination) {
DWORD dwOldProtection;
VirtualProtect(source, 14, PAGE_EXECUTE_READWRITE, &dwOldProtection);
char* location = (char*)source;
// Far jump
*((UINT16*)&location[0]) = 0x25FF;
// mode
*((UINT32*)&location[2]) = 0x00000000;
*((UINT64*)&location[6]) = (UINT64)destination;
VirtualProtect(location, 14, dwOldProtection, &dwOldProtection);
}
__declspec(noinline) void* operator new(size_t size) {
return ((void* (*)(size_t))CWOffset(0x392BAC))(size);
}
__declspec(noinline) void* operator new[](size_t size) {
return ((void* (*)(size_t))CWOffset(0x392BAC))(size);
}
__declspec(noinline) void operator delete(void* ptr) noexcept {
((void(*)(void*))CWOffset(0x392BE8))(ptr);
}
__declspec(noinline) void operator delete[](void* ptr) noexcept {
((void(*)(void*))CWOffset(0x392BE8))(ptr);
}
#endif*/