Results 1 to 5 of 5
  1. #1
    scimmyboy's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Location
    https://mpgh.net MPGHCash: $442,596,199
    Posts
    5,645
    Reputation
    26
    Thanks
    896
    My Mood
    Happy

    [C/C++] Memory Patcher

    Well here is a simple memory patcher, takes a block of memory and searches for a string pattern that you pass and applies a patch to it, super simple.

    Code:
    //Give a memory string 'search' of size 'len' to find in a memory block
    //of'look_size' starting at addr 'begin' returns the beggining of the memory
    //of the found memory or null on fail
    void *ELFindMemory( void *begin, unsigned int look_size,
                         unsigned char *search, unsigned int len )
    {
         if begin == NULL || look_size == 0 || search == NULL || len == 0 )
             return NULL;
            
         //begin search
         bool isFound = false;
         for( unsigned int i = 0; i < look_size; i++ )
         {
              if( *(unsigned char *)(begin + i ) == search[0] )
              {
                   for( unsigned int j = 1; j < len; j++ )
                  {
                        if( *(unsigned char *)(begin + i + j ) == search[j] )
                            isFound = true;
                        else
                            isFound = false;
                  }
               }
               if( isFound == true )
                  return (void *)( begin + i );
         }
        
         return NULL;
    }
    
    //Takes the found addr 'memory' and writes the 'patch' of length 'patch_len' with a filler if the
    //patch is less then the original memory contents 'filler'
    int ELPatchMemory( void *memory, int orig_size, unsigned char *patch, int patch_len, unsigned char filler )
    {
        if( puid == 0 || memory == NULL || orig_size == 0 || patch == NULL || patch_len == 0 )
            return -1;
            
        if( orig_size < patch_size )
            return -10;
            
        for( unsigned int i = 0; i < patch_len )
        {
             *(unsigned char *)( memory + i ) = *(unsigned char *)(patch + i );
        }
        
        if( orig_size > patch_len )
        {
            orig_size -= patch_len;
            
             for( unsigned int i = 0; i < orig_size; i++ )
            {
                  *(unsigned char *)( memory + patch_len + i + 1 ) = filler;
            }
        }
         
        return 0;
    }
    Hope this helps people learning C++ in any way!

  2. The Following User Says Thank You to scimmyboy For This Useful Post:

    why06 (01-28-2010)

  3. #2
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Very nice!

    The patch memory function reminds me exactly of WriteProcessMemory(), and good error checking by the way. There were a few syntax errors, in other words, you can't just stick this into a compiler w/o getting a few errors.

    Code:
    for( unsigned int i = 0; i < patch_len )
        {
             *(unsigned char *)( memory + i ) = *(unsigned char *)(patch + i );
        }
    This part is missing an incrementor. Unless ofcourse the incrementor is implied, I dunno all the shortcuts for for loops.

    But there was something important... oh yeh!
    Your memory searcher only checks the first and last character, and the length. Which might work, but what if you run into something like "dop" when u were lookin for "dip"?

    Oh and filler needs to be assigned a value. perhaps NOP 0x90?

    Someone correct me about anything if Im mistaken, but I assume *(unsigned char*) meant the value of a char*....

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  4. #3
    scimmyboy's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Location
    https://mpgh.net MPGHCash: $442,596,199
    Posts
    5,645
    Reputation
    26
    Thanks
    896
    My Mood
    Happy
    the incrementer is implied for this source code. thanks for the comments

  5. The Following User Says Thank You to scimmyboy For This Useful Post:

    why06 (01-28-2010)

  6. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by Justin
    for( unsigned int i = 0; i < patch_len )
    {
    *(unsigned char *)( memory + i ) = *(unsigned char *)(patch + i );
    }
    I is never incremented, so thats pretty much an infinite loop
    Ah we-a blaze the fyah, make it bun dem!

  7. #5
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Hell_Demon View Post
    I is never incremented, so thats pretty much an infinite loop
    O the incrementation isn't implied o_O?
    Is or isn't wdf? Im confused, just right out the whole for statement for clarity's sake >_>...

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

Similar Threads

  1. Steam client memory patcher.
    By Tyeabc in forum Exploits
    Replies: 4
    Last Post: 02-18-2014, 06:55 PM
  2. [Tutorial] Memory Tips
    By njdavid in forum WarRock - International Hacks
    Replies: 6
    Last Post: 09-23-2006, 10:25 AM
  3. Optimize Memory
    By 1h1a1i in forum Hardware & Software Support
    Replies: 35
    Last Post: 08-03-2006, 07:31 AM
  4. Replies: 3
    Last Post: 01-04-2006, 09:52 PM
  5. Direct Memory Access (DMA) to Static Memory Addresses
    By Dave84311 in forum Game Hacking Tutorials
    Replies: 0
    Last Post: 12-31-2005, 08:18 PM