Basic Memory Read/Write Class

On lunes, 22 de noviembre de 2010 0 comentarios

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.

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; i
        if (bCompare((BYTE*)(dwdwAdd+i),bMask,szMask))  return (DWORD)(dwdwAdd+i);
    return 0;
}
Further development? Use template functions...

Usage on everything should be clear.
Code:

sprintf( szMyText, "Text: %s", ReadText(...) );
p4tr1ck/dom made FindPattern.
The rest is unique, thus no credits.
 
Here's something useful from my memory class. (commented for nubs)
PHP Code:
BOOL WriteMemoryDWORD dwAddress, const voidcpvPatchDWORD dwSize )
{
    
DWORD dwProtect;

    if( 
VirtualProtect( (void*)dwAddressdwSizePAGE_READWRITE, &dwProtect ) ) //Unprotect the memory
        
memcpy( (void*)dwAddresscpvPatchdwSize ); //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*)dwAddressdwSizedwProtect, new DWORD ); //Reprotect the memory}
BOOL WriteJumpDWORD FromDWORD 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 WriteMemoryFrombpJump);
        }
        else { 
//Backward jump
            
BYTE bpJump[2] = { 0xEB, (BYTE)(0xFF - ((From To) + 1)) }; //Calculate opcode
            
return WriteMemoryFrombpJump);
        }
    }
    else 
//Far jump
    
{
        
BYTE bpJump[5] = { 0xE90x000x000x000x00 };

        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 
WriteMemoryFrombpJump);
    }

    return 
false//If we end up here, something went horribly wrong
__________________
Moo. ‾\(º_˚ )/‾

0 comentarios:

Publicar un comentario