home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks95 / MultiInstall.sit / MultiInstall / Source / Patch.cp < prev    next >
Text File  |  1995-06-24  |  845b  |  48 lines

  1. #include "Patch.h"
  2. #include <resources.h>
  3. #include <memory.h>
  4.  
  5. Patch::Patch( short resource )
  6.   : start( 0 ),
  7.     length( 0 )
  8.   {
  9.     Handle handle = GetResource( 'patc', resource );
  10.     
  11.     if ( handle == 0 )
  12.         return;
  13.     
  14.     length = GetHandleSize( handle );
  15.     start = NewPtrSys( length );
  16.     
  17.     BlockMoveData( *handle, start, length );
  18.   }
  19.  
  20. Patch::~Patch()
  21.   {
  22.     FlushDataCache();
  23.     FlushInstructionCache();
  24.   }
  25.  
  26. Ptr Patch::Find( unsigned long pattern )
  27.   {
  28.     for ( Ptr p = start;
  29.             p + sizeof( long ) <= start + length;
  30.             p += 2 )
  31.         if ( *(unsigned long *)p == pattern )
  32.             return p;
  33.     
  34.     return 0;
  35.   }
  36.  
  37. void Patch::Replace( unsigned long pattern, unsigned long replacement )
  38.   {
  39.     for ( Ptr p = start;
  40.             p + sizeof( long ) <= start + length;
  41.             p += 2 )
  42.         if ( *(unsigned long *)p == pattern )
  43.           {
  44.             *(unsigned long *)p = replacement;
  45.             p += 2;
  46.           }
  47.   }
  48.