def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break def response_cb(dialog, response, portNum=portNum, successFunc=successFunc, programName=programName): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return if response == 0: System.kill_process(pid) startTime = time.time() while time.time() < startTime + 2: pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return time.sleep(0.1) def try_again(dialog, response, portNum=portNum, successFunc=successFunc): self.prompt_about_port(portNum, successFunc) self.show_msgbox("Failed to kill program! Try killing process yourself. pid=%s, name=%s" % (pid, programName), cb=try_again) elif response == 1: self.prompt_about_port(portNum, successFunc) self.show_msgbox("Port %s is in use by another program (%s). BitBlinder needs this port to run. \n\nWould you like to kill that program or retry the port?" % (portNum, programName), "Port Conflict!", response_cb, buttons=("Kill", 0, "Retry", 1))
def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break def response_cb(dialog, response, portNum=portNum, successFunc=successFunc, programName=programName): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return if response == 0: System.kill_process(pid) startTime = time.time() while time.time() < startTime + 2: pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return time.sleep(0.1) def try_again(dialog, response, portNum=portNum, successFunc=successFunc): self.prompt_about_port(portNum, successFunc) self.show_msgbox( "Failed to kill program! Try killing process yourself. pid=%s, name=%s" % (pid, programName), cb=try_again) elif response == 1: self.prompt_about_port(portNum, successFunc) self.show_msgbox( "Port %s is in use by another program (%s). BitBlinder needs this port to run. \n\nWould you like to kill that program or retry the port?" % (portNum, programName), "Port Conflict!", response_cb, buttons=("Kill", 0, "Retry", 1))
def set_half_open_conns(self, app, halfOpenConnections): """uses tcpz to change the number of half open connections to 218""" try: #this is a windows specific fix: if not System.IS_WINDOWS: return #also, this is only necessary if we are acting as a Tor server: if not app.torApp.settings.beRelay: return winInfo = sys.getwindowsversion() #not sure if this exists, but just in case :) if winInfo[0] > 6: return #if this is win7, we're all set: if winInfo[0] == 6 and winInfo[1] >= 1: return #if this is vista, check the service pack level: if winInfo[0] == 6 and winInfo[1] == 0: #default and SP1 need fixing: if winInfo[4] not in ('', 'Service Pack 1'): return if halfOpenConnections: #if we already did this, also return: if self.appliedHalfOpenCorrection: return self.appliedHalfOpenCorrection = True #we should only ever run one tcp-z, no going back etiher ids = System.get_process_ids() for id in ids: if id[0] == 'tcpz.exe': return #create the vbs script file to do what we need: encodedScriptFile = System.encode_for_filesystem( os.path.join(Globals.USER_DATA_DIR, "tcpz.vbs")) encodedExe = System.encode_for_filesystem( os.path.join(Globals.WINDOWS_BIN, 'tcpz.exe')) cmd = """Set oShell = WScript.CreateObject("WSCript.shell")\r\ncall oShell.run("cmd /c ""%s"" -limit:220 -autoexit", 0, false)\r\n""" % ( encodedExe) f = open(encodedScriptFile, "wb") f.write(cmd) f.close() #and execute the script: SerialProcessLauncher.get().run_app( 'cscript.exe "%s" //B //Nologo' % (encodedScriptFile)) return except Exception, e: log_ex(e, "Failed to launch tcpz.exe")
def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break #this has to go in the console as it isn't seen otherwise self.shutdown_func = "" msg = "Port %s is taken by program %s (pid=%s). Please kill the program or otherwise free the port and restart BitBlinder."% (portNum, programName, pid) log_msg(msg, 0) atexit.register(self.print_wrapper, msg) GlobalEvents.throw_event("quit_signal")
def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break #this has to go in the console as it isn't seen otherwise self.shutdown_func = "" msg = "Port %s is taken by program %s (pid=%s). Please kill the program or otherwise free the port and restart BitBlinder." % ( portNum, programName, pid) log_msg(msg, 0) atexit.register(self.print_wrapper, msg) GlobalEvents.throw_event("quit_signal")
def set_half_open_conns(self, app, halfOpenConnections): """uses tcpz to change the number of half open connections to 218""" try: #this is a windows specific fix: if not System.IS_WINDOWS: return #also, this is only necessary if we are acting as a Tor server: if not app.torApp.settings.beRelay: return winInfo = sys.getwindowsversion() #not sure if this exists, but just in case :) if winInfo [0] > 6: return #if this is win7, we're all set: if winInfo[0] == 6 and winInfo[1] >= 1: return #if this is vista, check the service pack level: if winInfo[0] == 6 and winInfo[1] == 0: #default and SP1 need fixing: if winInfo[4] not in ('', 'Service Pack 1'): return if halfOpenConnections: #if we already did this, also return: if self.appliedHalfOpenCorrection: return self.appliedHalfOpenCorrection = True #we should only ever run one tcp-z, no going back etiher ids = System.get_process_ids() for id in ids: if id[0] == 'tcpz.exe': return #create the vbs script file to do what we need: encodedScriptFile = System.encode_for_filesystem(os.path.join(Globals.USER_DATA_DIR, "tcpz.vbs")) encodedExe = System.encode_for_filesystem(os.path.join(Globals.WINDOWS_BIN,'tcpz.exe')) cmd = """Set oShell = WScript.CreateObject("WSCript.shell")\r\ncall oShell.run("cmd /c ""%s"" -limit:220 -autoexit", 0, false)\r\n""" % (encodedExe) f = open(encodedScriptFile, "wb") f.write(cmd) f.close() #and execute the script: SerialProcessLauncher.get().run_app('cscript.exe "%s" //B //Nologo' % (encodedScriptFile)) return except Exception, e: log_ex(e, "Failed to launch tcpz.exe")
def get_app_by_pid(self, originalPID): """Return the application that controls originalPID""" app = None #if this process is unknown: if not self.applicationMapping.has_key(originalPID): ids = System.get_process_ids() appName = "Unknown" for id in ids: if id[1] == originalPID: appName = id[0] break #make sure there is an app for it: if appName not in self.applications: app = BitBlinderApplication(appName, ApplicationSettings.ApplicationSettings, "", self.torApp, self.bankApp) self.add_application(app) else: app = self.applications[appName] #and finally, add the process to the app: p = Process.Process(originalPID) app.add_process(p) app = self.applicationMapping[originalPID] return app
def get_app_by_pid(self, originalPID): """Return the application that controls originalPID""" app = None #if this process is unknown: if not self.applicationMapping.has_key(originalPID): ids = System.get_process_ids() appName = "Unknown" for id in ids: if id[1] == originalPID: appName = id[0] break #make sure there is an app for it: if appName not in self.applications: app = BitBlinderApplication( appName, ApplicationSettings.ApplicationSettings, "", self.torApp, self.bankApp) self.add_application(app) else: app = self.applications[appName] #and finally, add the process to the app: p = Process.Process(originalPID) app.add_process(p) app = self.applicationMapping[originalPID] return app