Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[FREE][C++] Simple anti-modification

Junior Spellweaver
Joined
Aug 1, 2011
Messages
126
Reaction score
90
Here is the code for one of my simple security modules. You can use it to protect your classes, methods and functions against hooking, and variables against unauthorized modifications.
You can implement this regardless of having an anticheat system (like LiveGuard, MHP or other) as an additional security measure.

C++ Code:
Code:
class AC {
protected:
	unsigned long a, l, s, k1, k2 = 0;
	unsigned long S() {
		if (a == 0) return -1; unsigned long c = k1;
		for (unsigned long i = 0; i < l; i++, c = (c ^ ((unsigned char*)a)[i]) * k2) { }
		return c;
	}
	unsigned long A() {
		__asm { rdtsc; xor eax, edx; xor edx, eax 
		}
	}
public:
	AC(unsigned long x, unsigned long y) : a(x), l(y) { k1 = A(); k2 = A(); s = S(); }
	void U() { k1 = A(); k2 = A(); s = S(); }
	bool C() { return s == S(); }
};


Example usage:

-- Attached file Main.cpp

Proof of concept:

Compile this program and run it. Open Cheat Engine and inject it into the process.

- Set scan type to "Bigger than" 2222 and press First Scan.
- Set scan type to "Increased value" and press Next Scan. You will see the score variable; change it.

Next, you can enable speedhack and check if it's detected.

[EXTRA CODE] You can also protect whole ".text" memory section.
Code:
    HMODULE moduleHandle = GetModuleHandle(nullptr);
    IMAGE_DOS_HEADER* dosHeader = (IMAGE_DOS_HEADER*)moduleHandle;
    IMAGE_NT_HEADERS* ntHeaders = (IMAGE_NT_HEADERS*)((DWORD)dosHeader + dosHeader->e_lfanew);
    PIMAGE_SECTION_HEADER sectionHeader = IMAGE_FIRST_SECTION(ntHeaders);
    bool isTextSectionFound = false;
    DWORD textBaseAddress = 0;
    DWORD textSize = 0;


        for (int i = 0; i < ntHeaders->FileHeader.NumberOfSections; ++i) {
            if (std::strcmp(".text", (char*)sectionHeader[i].Name) == 0) {
                isTextSectionFound = true;
                textBaseAddress = DWORD((BYTE*)moduleHandle + sectionHeader[i].VirtualAddress);
                textSize = sectionHeader[i].SizeOfRawData;
 
                if (textBaseAddress == 0) {
                    textBaseAddress = (DWORD)moduleHandle;
                }
                if (textSize == 0) {
                    textSize = 1024 * 1024;
                }
            }
        }

       if(isTextSectionFound)
       {
/// ... now you can use textBaseAddress, textSize in AC() ...
       }
 

Attachments

You must be registered for see attachments list
Last edited:
Back
Top