Implement a mempatch function and create a ServerProcess patch with it

This commit is contained in:
Robert MacGregor 2017-07-22 16:57:21 -04:00
parent cb9895a38e
commit da08659d72
7 changed files with 59 additions and 6 deletions

View file

@ -1,2 +1,2 @@
#v4.0:v100
Release|Win32|C:\Documents and Settings\NobodyBla\Desktop\T2AI\T2-CPP-master\|
Release|Win32|C:\Documents and Settings\NobodyBla\Desktop\T2AI\T2-CPP\|

View file

@ -57,6 +57,6 @@ namespace DX
bool SanitizeFileName(char *ret, int buffer_length);
//! Initializes all hooks for the engine.
void initializeHooks(void);
// bool memPatch(void* address, void* payload, unsigned int payloadSize);
bool memPatch(unsigned int address, void* payload, unsigned int payloadSize);
} // End NameSpace DX

View file

@ -189,8 +189,28 @@ namespace DX
return was_dirty;
}
void initializeHooks(void)
bool memPatch(void* address, void* payload, unsigned int payloadSize)
{
DWORD oldProtect;
bool success = VirtualProtect(address, payloadSize, PAGE_EXECUTE_READWRITE, &oldProtect);
if (!success)
return false;
// Come on Microsoft... why can't anything you make actually be good.
// NOTE: This memcpy invocation was crashing the linker...
//memcpy(address, payload, payloadSize);
unsigned char* destination = reinterpret_cast<unsigned char*>(address);
unsigned char* sourceData = reinterpret_cast<unsigned char*>(payload);
for (unsigned int iteration = 0; iteration < payloadSize; ++iteration)
destination[iteration] = sourceData[iteration];
return true;
}
bool memPatch(unsigned int address, void* payload, unsigned int payloadSize)
{
return memPatch(reinterpret_cast<void*>(address), payload, payloadSize);
}
}

View file

@ -1,2 +1,2 @@
#v4.0:v100
Release|Win32|C:\Documents and Settings\NobodyBla\Desktop\T2AI\T2-CPP-master\|
Release|Win32|C:\Documents and Settings\NobodyBla\Desktop\T2AI\T2-CPP\|

View file

@ -5,4 +5,5 @@
#include <LinkerAPI.h>
// Mod Loader Implementation
void serverProcessReplacement(unsigned int timeDelta);
bool conLoadMod(Linker::SimObject *obj,S32 argc, const char* argv[]);

View file

@ -23,6 +23,8 @@ void serverProcessReplacement(unsigned int timeDelta)
currentCallables->mServerProcessPointer(timeDelta);
}
Con::errorf(0, "Bla -bla blallaaa");
__asm
{
mov ecx,serverthisptr

View file

@ -63,6 +63,36 @@ const char* congetInterpreterAddr(Linker::SimObject *obj, S32 argc, const char *
sprintf(test2,"B8%08XFFE0",endian(spr));
return test2;
}
void initializeHooks()
{
// Replicates:
// memPatch("5BBBDC",getServPAddr());
// sprintf(test2,"B8 FFD089EC5DC3",endian(spr));
unsigned char serverProcessBytes[] = {
0xB8,
// Replacement processs
0x00,
0x00,
0x00,
0x00,
// Other code
0xFF,
0xD0,
0x89,
0xEC,
0x5D,
0xC3
};
// Write in the process address
unsigned int* serverProcessOffset = reinterpret_cast<unsigned int*>(&serverProcessBytes[1]);
*serverProcessOffset = reinterpret_cast<unsigned int>(*serverProcessReplacement);
DX::memPatch(0x5BBBDC, serverProcessBytes, sizeof(serverProcessBytes));
}
class CImmCompoundEffect
@ -106,7 +136,7 @@ class CImmDevice
lpinitT2DLL(); // The function was loaded, call TribesNext and move on to postTN Startup
// Initialize all engine hooks
DX::initializeHooks();
initializeHooks();
return 0;
}