[ Log In | Register ]       
Resource Database Index -> Source Code -> Memory Patcher
Description // Info



Source Code

  1. void *FindMemory( void *begin, unsigned int look_size,
  2.                     unsigned char *search, unsigned int len )
  3. {
  4.      if begin == NULL || look_size == 0 || search == NULL || len == 0 )
  5.          return NULL;
  6.          
  7.      //begin search
  8.      bool isFound = false;
  9.      for( unsigned int i = 0; i < look_size; i++ )
  10.      {
  11.           if( *(unsigned char *)(begin + i ) == search[0] )
  12.           {
  13.               for( unsigned int j = 1; j < len; j++ )
  14.               {
  15.                    if( *(unsigned char *)(begin + i + j ) == search[j] )
  16.                        isFound = true;
  17.                    else
  18.                    {
  19.                        isFound = false;
  20.                        break;
  21.                    }
  22.               }
  23.           }
  24.           if( isFound == true )
  25.               return (void *)( begin + i );
  26.      }
  27.      
  28.      return NULL;
  29. }
  30.  
  31. //Takes the found addr \\\'memory\\\' and writes the \\\'patch\\\' of length \\\'patch_len\\\' with a filler if the
  32. //patch is less then the original memory contents \\\'filler\\\'
  33. int PatchMemory( void *memory, int orig_size, unsigned char *patch, int patch_len, unsigned char filler )
  34. {
  35.     if( puid == 0 || memory == NULL || orig_size == 0 || patch == NULL || patch_len == 0 )
  36.         return -1;
  37.        
  38.     if( orig_size < patch_size )
  39.         return -10;
  40.        
  41.     for( unsigned int i = 0; i < patch_len )
  42.     {
  43.          *(unsigned char *)( memory + i ) = *(unsigned char *)(patch + i );
  44.     }
  45.    
  46.     if( orig_size > patch_len )
  47.     {
  48.         orig_size -= patch_len;
  49.        
  50.         for( unsigned int i = 0; i < orig_size; i++ )
  51.         {
  52.              *(unsigned char *)( memory + patch_len + i + 1 ) = filler;
  53.         }
  54.     }
  55.    
  56.     return 0;
  57. }


Comments

You must be logged in to post comments.

 Network Access...
USER ID
PASSWORD

 Code Information
Language:
C/C++

Version:



Submitted:
2008-08-27 - 16:45:56


Author:
p4ll4t0n
E-Mail
Website

Greetz:
All real coders and hackers

[ Download | Report Issue ]

 Code Search
Search by Language
+ Assembly
+ ASP
+ ASP.NET
+ C#
+ C/C++
+ Cobol
+ Delphi
+ Java
+ Javascript
+ Pascal
+ Perl
+ PHP
+ Python
+ VB6
+ VB.NET

Advanced Search




 
 
By continuing past this page, and by your continued use of this site, you agree to be bound by and abide by the User Agreement.

© 2008 r00tsecurity network. All rights reserved.
[ About Us | Contact Us | Support Us | Legal | Advertise | User Agreement | Privacy Policy ]