From b3b2c3864af6712847850084f7ec94b1b6856519 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Fri, 29 Oct 2010 10:51:09 +0000 Subject: [PATCH] Minor code refactoring --- lib/core/common.py | 17 ----------------- lib/core/subprocessng.py | 18 ++++++++++++++++++ lib/core/update.py | 2 +- lib/takeover/metasploit.py | 2 +- lib/takeover/upx.py | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index b10b21cb8..c20c16034 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -949,23 +949,6 @@ def getFileType(filePath): else: return "binary" -def pollProcess(process): - while True: - dataToStdout(".") - time.sleep(1) - - returncode = process.poll() - - if returncode is not None: - if returncode == 0: - dataToStdout(" done\n") - elif returncode < 0: - dataToStdout(" process terminated by signal %d\n" % returncode) - elif returncode > 0: - dataToStdout(" quit unexpectedly with return code %d\n" % returncode) - - break - def getCharset(charsetType=None): asciiTbl = [] diff --git a/lib/core/subprocessng.py b/lib/core/subprocessng.py index 5018a125f..09b8aaa7e 100644 --- a/lib/core/subprocessng.py +++ b/lib/core/subprocessng.py @@ -12,6 +12,7 @@ import os import sys import time +from lib.core.common import dataToStdout from lib.core.settings import IS_WIN if not IS_WIN: @@ -71,3 +72,20 @@ def setNonBlocking(fd): flags = fcntl.fcntl(fd, FCNTL.F_GETFL) flags = flags | os.O_NONBLOCK fcntl.fcntl(fd, FCNTL.F_SETFL, flags) + +def pollProcess(process): + while True: + dataToStdout(".") + time.sleep(1) + + returncode = process.poll() + + if returncode is not None: + if returncode == 0: + dataToStdout(" done\n") + elif returncode < 0: + dataToStdout(" process terminated by signal %d\n" % returncode) + elif returncode > 0: + dataToStdout(" quit unexpectedly with return code %d\n" % returncode) + + break diff --git a/lib/core/update.py b/lib/core/update.py index 5d130c898..21fbdf311 100644 --- a/lib/core/update.py +++ b/lib/core/update.py @@ -26,7 +26,6 @@ from subprocess import Popen as execute from lib.core.common import dataToStdout from lib.core.common import getUnicode -from lib.core.common import pollProcess from lib.core.common import readInput from lib.core.data import conf from lib.core.data import logger @@ -34,6 +33,7 @@ from lib.core.data import paths from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapFilePathException from lib.core.settings import MSSQL_VERSIONS_URL +from lib.core.subprocessng import pollProcess from lib.request.connect import Connect as Request def __updateMSSQLXML(): diff --git a/lib/takeover/metasploit.py b/lib/takeover/metasploit.py index b0f33ddd2..f5f9be229 100644 --- a/lib/takeover/metasploit.py +++ b/lib/takeover/metasploit.py @@ -24,7 +24,6 @@ from lib.core.common import getRemoteIP from lib.core.common import getUnicode from lib.core.common import normalizePath from lib.core.common import ntToPosixSlashes -from lib.core.common import pollProcess from lib.core.common import randomRange from lib.core.common import randomStr from lib.core.common import readInput @@ -35,6 +34,7 @@ from lib.core.exception import sqlmapDataException from lib.core.exception import sqlmapFilePathException from lib.core.subprocessng import blockingReadFromFD from lib.core.subprocessng import blockingWriteToFD +from lib.core.subprocessng import pollProcess from lib.core.subprocessng import setNonBlocking from lib.request.connect import Connect as Request from lib.takeover.upx import upx diff --git a/lib/takeover/upx.py b/lib/takeover/upx.py index 465a6ca80..282e3a626 100644 --- a/lib/takeover/upx.py +++ b/lib/takeover/upx.py @@ -17,10 +17,10 @@ from subprocess import Popen as execute from lib.core.common import dataToStdout from lib.core.common import decloakToMkstemp -from lib.core.common import pollProcess from lib.core.data import logger from lib.core.data import paths from lib.core.settings import PLATFORM +from lib.core.subprocessng import pollProcess class UPX: """