Quote:
Originally Posted by Exolent[jNr]
Heh I wish I was more familiar with Python to completely understand your code. I can understand most of it though so it's okay.
|
PHP Code:
'''
Created on 21/09/2010
@author: Reuben 'Seta00' Morais
'''
import os # to use exit
import socket
from threading import Thread # high-level threading facilities
import pythoncom # access to OS info on multiple threads
import wmi # access to OS info
import ImageGrab # screenshot
from wxPython.wx import * #@UnusedWildImport # graphical interface library (wxWidgets binding to Python)
HOST = '' # accept all hosts
PORT = 41337 # port to listen to
class WorkerThread(Thread): # this is the actual server
def __init__(self, socket, logActivity):
Thread.__init__(self)
self.socket = socket
self.LogActivity = logActivity
self.shuttingDown = False
self.start()
def run(self):
pythoncom.CoInitialize() #@UndefinedVariable # allow access to OS info on this thread
self.wmiConn = wmi.WMI() # connect to the local machine
while True:
if (self.shuttingDown):
break
connection, address = self.socket.accept() # accept a new connection
data = connection.recv(256) # receive the request header
self.LogActivity('Received "' + data + '" from ' + str(address) + '.')
if data == 'SACRunningRequest': # basic request, check if the client is running
connection.send('OK')
elif data == 'SACProcRequest': # process list request
processes = self.wmiConn.Win32_Process.instances() # get running processes
retData = str([proc.Properties_('Name').Value for proc in processes]) # build list of names
connection.send(str(len(retData))) # send data length
if connection.recv(32) != None:
connection.send(retData) # send actual data
elif data == 'SACSSRequest': # sceenshot request
img = ImageGrab.grab() # take the screenshot
connection.send(repr(img.size)) # send the image size first (width x height)
if connection.recv(32) == None: # wait for confirmation
self.LogActivity("Client didn't respond to image size message.")
continue
retData = img.tostring() # convert the img to raw pixel data
connection.send(str(len(retData))) # send the data size in bytes
if connection.recv(32) == None: # wait for confirmation
self.LogActivity("Client didn't respond to data size message.")
continue
connection.send(retData) # send the actual data
pythoncom.CoUnitialize() #@UndefinedVariable # to access OS info on multiple threads
class MainFrame(wxFrame):
def __init__(self, parent, id, title): # this is the constructor in Python
# removed GUI stuff
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.bind((HOST, PORT))
except socket.error:
wxMessageBox("The address is already in use, can't start the client.")
self.Destroy()
os._exit(1)
self.socket.listen(1) # set to listen mode, wait for one connection
self.shuttingDown = False
self.thread = WorkerThread(self.socket, self.LogActivity) # create and start the server thread
def LogActivity(self, activity):
self.statusUpdater.AppendText(activity + '\n')
def OnCloseWindow(self, event):
self.LogActivity('Shutting down worker thread.')
self.thread.shuttingDown = True
self.thread.join(1.0)
self.socket.close()
self.Destroy()
class SACApp(wxApp): # GUI stuff
def OnInit(self):
frame = MainFrame(NULL, -1, 'Simple Anti-Cheat')
frame.Show(true)
self.SetTopWindow(frame)
return true
app = SACApp(NULL)
app.MainLoop()
os._exit(0)