Code:
#
# Project: SouLboT [SouL-Wraith]
#
# Auto Patching system
# - Copyright (C) 2013 SouLboT. All rights reserved.
#
# Python imports
import struct
import ctypes
#
# Page protection
#
PAGE_NOACCESS = 0x01
PAGE_READONLY = 0x02
PAGE_READWRITE = 0x04
PAGE_WRITECOPY = 0x08
PAGE_EXECUTE = 0x10
PAGE_EXECUTE_READ = 0x20
PAGE_EXECUTE_READWRITE = 0x40
PAGE_EXECUTE_WRITECOPY = 0x80
PAGE_GUARD = 0x100
PAGE_NOCACHE = 0x200
PAGE_WRITECOMBINE = 0x400
#
# Patch engine
#
# Write a patch to memory
def SouLPatch(address, patch):
if ( address is None ): return False
protection = ctypes.c_ulong ()
buffer = ctypes.create_string_buffer ( patch, len ( patch ) )
ctypes.windll.kernel32.VirtualProtect ( address, ctypes.sizeof ( buffer ), PAGE_EXECUTE_READWRITE, ctypes.byref ( protection ) )
ctypes.windll.kernel32.WriteProcessMemory ( ctypes.windll.kernel32.GetCurrentProcess (), address, buffer, ctypes.sizeof ( buffer ), None )
ctypes.windll.kernel32.VirtualProtect ( address, ctypes.sizeof ( buffer ), protection, ctypes.byref ( protection ) )
return True
# Querying helper class
class Query(object):
def __init__(self, *args):
self.query = b''
self.range = Offsets.Range ( args [ 0 ] ) if args else Offsets.Range ()
def reset():
self.query = b''
return self
def match(self, bytes):
self.query += struct.pack ( '<sL{0}s'.format ( len ( bytes ) ), b'=', len ( bytes ), bytes )
return self
def skip(self, count):
self.query += struct.pack ( '<sL', b'*', count )
return self
def collect(self, offset):
self.query += struct.pack ( '<sL', b'!', offset )
return self
def relative(self, offset):
self.query += struct.pack ( '<sL', b'&', offset )
return self
def at(self, offset):
self.query += struct.pack ( '<sL', b'@', offset )
return self
def execute(self):
results = Offsets.Query ( self.query, self.range )
self.query = b''
}
X_address=True:SFX;
If Name SouLBoT-> Log->Write("@BIN = %X",(PBYTE)VK-SHOCK);
}
}else{
{ALL ADDRESS CHECK}
ProjectSouL=Find(0x00000000,FFFFFFFF,(BYTE*)"\x80\xC4\x08\x??\#\@","########????######");
SouL=\75\+0x54;
#do convert Address Patch #[010] ->Write("@DAT = %X",(PBYTE)&91F);
empty[del]ff5\+0x59
}
return results
# Exception classes
class HeaderError(Exception): pass
class EntryError(Exception): pass
class VerifyError(Exception): pass
def __init__(self, data):
# Initialization
self.info = []
self.files = {}
self.data = io.BytesIO ( data )
self.__extractheader ()
self.__extractfiles ()
def __extractentry(self):
# Clear out existing scripts
def Clear(self):
files = [ os.path.join ( self.Profile, x ) for x in os.listdir ( self.Profile ) ]
files = filter ( os.path.isfile, files )
files = filter ( lambda x: x.lower ().endswith ( '.atpy' ), files )
for x in files: os.remove ( x )
# Perform the scan
def Update(self, data, overwrite = False):
package = Package ( data )
if ( not os.path.exists ( self.Profile ) ): os.makedirs ( self.Profile )
if ( overwrite ): self.Clear ()
for entry in package.getfiles ():
# Setup the path to the script file
path = os.path.join ( self.Profile, entry [ 'name' ] )
if ( os.path.exists ( path ) and not overwrite ):
Logger.Log ( Names.SouL-Patch, 'Skipping: %s' % entry [ 'name' ] ); continue
# Write out the script to the new file
file = open ( path, 'wb' )
file.write ( entry [ 'file' ] )
file.close ()
Logger.Log ( Names.SouL-Patch, 'Extracted: %s' % entry [ 'name' ] )
modulelist = [ os.path.splitext ( x ) [ 0 ] for x in os.listdir ( self.Profile ) if x.lower().endswith ( '.atpy' ) ]
modulelist = [ x for x in modulelist if x != __name__ ]
# First try to unload any previous instances of the modules
for module in modulelist: ExecuteCommand ( 'pyunload %s' % module )
# Now perform a load of every module in the package
for module in modulelist:
ExecuteCommand ( 'pyload %s' % module )
Logger.Log ( Names.SouL-Patch, 'Loading module %s... Done!' % module )






