Basic Memory Read/Write Class
Real basic, just going through my old hdd and releasing source that I've coded.
Probably none of the functions are orginal or anything new, so I wont take credit.
Further development? Use template functions...
Usage on everything should be clear.
p4tr1ck/dom made FindPattern.
The rest is unique, thus no credits.
Probably none of the functions are orginal or anything new, so I wont take credit.
Code:
#include "Manager.h" void BasicMemory::WriteMemory(PVOID dwAdd, void *val, int bytes) { //Raw .Code editting rite here DWORD d, ds; VirtualProtect(dwAdd, bytes, PAGE_EXECUTE_READWRITE, &d); //Shit might be protected memcpy(dwAdd, val, bytes); VirtualProtect(dwAdd,bytes,d,&ds); } void BasicMemory::WriteFloat(DWORD dwAdd,float Value) { *(float*)dwAdd = Value; } void BasicMemory::WriteInteger(DWORD dwAdd, int Value) { *(int*)dwAdd = Value; } void BasicMemory::WriteText(char *szText, DWORD dwAdd) { CHAR* Text = (CHAR*)dwAdd; *Text = (CHAR)szText; } CHAR* BasicMemory::ReadText(DWORD dwAdd) { CHAR* Text = (CHAR*)dwAdd; //reversal of WriteText... return Text; } bool bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask) { for(;*szMask;++szMask,++pData,++bMask) if(*szMask=='x' && *pData!=*bMask) return 0; return (*szMask) == NULL; } DWORD BasicMemory::FindPattern(DWORD dwdwAdd,DWORD dwLen,BYTE *bMask,char * szMask) { for(DWORD i=0; iif (bCompare((BYTE*)(dwdwAdd+i),bMask,szMask)) return (DWORD)(dwdwAdd+i); return 0; }
Usage on everything should be clear.
Code:
sprintf( szMyText, "Text: %s", ReadText(...) );
The rest is unique, thus no credits.
Here's something useful from my memory class. (commented for nubs)
__________________PHP Code:
BOOL WriteMemory( DWORD dwAddress, const void* cpvPatch, DWORD dwSize )
{
DWORD dwProtect;
if( VirtualProtect( (void*)dwAddress, dwSize, PAGE_READWRITE, &dwProtect ) ) //Unprotect the memory
memcpy( (void*)dwAddress, cpvPatch, dwSize ); //Write our patch
// for(int i = 0; i < dwSize; i++) { *(BYTE*)(dwAddress + i) = *(BYTE*)(cpvPatch + i); } //Alternative to memcpy
else
return false; //Failed to unprotect, so return false..
return VirtualProtect( (void*)dwAddress, dwSize, dwProtect, new DWORD ); //Reprotect the memory}
BOOL WriteJump( DWORD From, DWORD To )
{
if( To < From + 128 && To > From - 128 ) //Short jump
{
if(To > From) { //Forward jump
BYTE bpJump[2] = { 0xEB, (BYTE)((To - From) - 2)}; //Calculate opcode
return WriteMemory( From, bpJump, 2 );
}
else { //Backward jump
BYTE bpJump[2] = { 0xEB, (BYTE)(0xFF - ((From - To) + 1)) }; //Calculate opcode
return WriteMemory( From, bpJump, 2 );
}
}
else //Far jump
{
BYTE bpJump[5] = { 0xE9, 0x00, 0x00, 0x00, 0x00 };
if(To > From) { //Forward jump
*(DWORD*)&bpJump[1] = To - (From + 5); //Calculate jump
} else { //Backward jump
*(DWORD*)&bpJump[1] = (0xFFFFFFFF - (From + 4)) + To; //Calculate jump
}
return WriteMemory( From, bpJump, 5 );
}
return false; //If we end up here, something went horribly wrong}
Moo. ‾\(º_˚ )/‾
0 comentarios:
Publicar un comentario