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 >
Wrap
Text File
|
1995-06-24
|
845b
|
48 lines
#include "Patch.h"
#include <resources.h>
#include <memory.h>
Patch::Patch( short resource )
: start( 0 ),
length( 0 )
{
Handle handle = GetResource( 'patc', resource );
if ( handle == 0 )
return;
length = GetHandleSize( handle );
start = NewPtrSys( length );
BlockMoveData( *handle, start, length );
}
Patch::~Patch()
{
FlushDataCache();
FlushInstructionCache();
}
Ptr Patch::Find( unsigned long pattern )
{
for ( Ptr p = start;
p + sizeof( long ) <= start + length;
p += 2 )
if ( *(unsigned long *)p == pattern )
return p;
return 0;
}
void Patch::Replace( unsigned long pattern, unsigned long replacement )
{
for ( Ptr p = start;
p + sizeof( long ) <= start + length;
p += 2 )
if ( *(unsigned long *)p == pattern )
{
*(unsigned long *)p = replacement;
p += 2;
}
}