unknowncheats uc-forum.com ucdownloads ucdownloads.com

Go Back   UC-Tutorials - Multiplayer Game Hacking and Cheat Tutorials > Programming > C and C++

- Sponsored Advertisement -
http://www.myfpscheats.com/


Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2007, 03:24 PM
t10101 t10101 is offline
Junior Member
 
Join Date: Sep 2007
Posts: 21
Default [source] Memory Editing Class

by Cyclone

Hi guys

this a simple memory editing class, you can use it in your hacks or whateva.
Code:
struct MEMPATCH {
char *name[MAX_PATH];
int offset;
vector<BYTE> orig;
vector<BYTE> patch;
int size;
BOOL inited;
BOOL enabled;
}

class MemoryEditing
{
public:
      MemoryEditing();
      ~MemoryEditing();
public:
      void Add(MEMPATCH memory);
      BOOL Modify(char *cheat, BOOL modify);
private:
     vector<MEMPATCH> m_vCheats;
};

MemoryEditing::MemoryEditing()
{
        m_vCheats.clear();
}

MemoryEditing::~MemoryEditing()
{
        m_vCheats.clear();
}

void MemoryEditing::Add(MEMPATCH memory)
{
        m_vCheats.push_back(memory);
}

BOOL MemoryEditing::Modify(char *cheat, BOOL modify)
{
        for(vector<MEMPATCH>::iterator it = m_vCheats.begin(); it != m_vCheats.end(); ++it)
       {
               if(strcmp(it->name, cheat) == 0) {
                       if(it->enabled == modify) return FALSE;
                       if(!it->inited) {
                              DWORD oldprot;
                              VirtualProtect(it->offset, it->size, PAGE_READWRITE, oldprot);
                              BYTE tmp[it->size] = {0};
                              memcpy(tmp, it->offset, sizeof(tmp));
                              for(int i = 0; i <= it->size; i++)
                                     orig.push_back(tmp[i]);
                              VirtualProtect(it->offset, it->size, oldprot, &1);
                              it->inited = TRUE;
                       }

                       DWORD oldprot;
                       VirtualProtect(it->offset, it->size, PAGE_READWRITE, oldprot);
                       BYTE tmp[it->size] = {0};
                       if(modify)  {
                            for(int i =0; i <= sizeof(tmp); i++)
                                 tmp[i] = it->patch[i];
                       }
                       else  {
                            for(int i =0; i <= sizeof(tmp); i++)
                                 tmp[i] = it->orig[i];
                       }
                       memcpy(tmp, it->offset, sizeof(tmp));
                        VirtualProtect(it->offset, it->size, oldprot, &1);
                        it->enabled = modify;
               }
       }
       return TRUE;
}
Usage:

Code:
MemoryEditing memeditor;

void SomeFunction()
{
           MEMPATCH mem;
           strcpy(mem.name, "Minimap");
           offset = (int)GetModuleHandle("RendDx9.dll") + OFFSET;
           size = 1;
           patch.push_back(0x90);
           inited = FALSE;
           enabled = FALSE;
           memeditor.Add(mem);
}
I wrote this code in UC's "New Topic" page which unfortunately doesnt include a c++ compiler, so i havnt tested it, if you get errors when trying to compile this, post them in here. I will try to continue work on this class as its really the most important class in a hack.

There are a lot of improvements that you can make to this class, this is just a basic sample.

Some things you can try doing:
- Turn MEMPATCH into a class and let it control all the patching, MemoryEditing class shoud only tell the MEMPATCH what to do.
- Add internal(by MemoryEditing class) module base adding to main offset.

Hope someone finds this useful!
Reply With Quote
Reply

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit

Tags
class, editing, memory, source

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 08:21 AM.