Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 915d344

Browse files
committed
some code refactoring
1 parent 1bdf94f commit 915d344

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

lib/core/common.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import posixpath
3535
import subprocess
3636

37+
from StringIO import StringIO
3738
from tempfile import NamedTemporaryFile
3839
from tempfile import mkstemp
40+
from xml.sax import parse
3941

4042
from extra.cloak.cloak import decloak
4143
from lib.contrib import magic
@@ -1084,4 +1086,12 @@ def getConsoleWidth(default=80):
10841086
except:
10851087
pass
10861088

1087-
return width if width else default
1089+
return width if width else default
1090+
1091+
def parseXmlFile(xmlFile, handler):
1092+
file = open(paths.GENERIC_XML)
1093+
content = file.read()
1094+
stream = StringIO(content)
1095+
parse(stream, handler)
1096+
stream.close()
1097+
file.close()

lib/parse/banner.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424

2525
import re
2626

27-
from StringIO import StringIO
28-
from xml.sax import parse
2927
from xml.sax.handler import ContentHandler
3028

3129
from lib.core.common import checkFile
30+
from lib.core.common import parseXmlFile
3231
from lib.core.common import sanitizeStr
3332
from lib.core.data import kb
3433
from lib.core.data import paths
@@ -122,11 +121,11 @@ def bannerParser(banner):
122121

123122
if kb.dbms == "Microsoft SQL Server":
124123
handler = MSSQLBannerHandler(banner, kb.bannerFp)
125-
parse(StringIO(open(xmlfile).read()), handler)
124+
parseXmlFile(xmlfile, handler)
126125

127126
handler = FingerprintHandler(banner, kb.bannerFp)
128-
parse(StringIO(open(paths.GENERIC_XML).read()), handler)
127+
parseXmlFile(paths.GENERIC_XML, handler)
129128
else:
130129
handler = FingerprintHandler(banner, kb.bannerFp)
131-
parse(StringIO(open(xmlfile).read()), handler)
132-
parse(StringIO(open(paths.GENERIC_XML).read()), handler)
130+
parseXmlFile(xmlfile, handler)
131+
parseXmlFile(paths.GENERIC_XML, handler)

lib/parse/headers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
import os
2626

27-
from StringIO import StringIO
28-
from xml.sax import parse
29-
3027
from lib.core.common import checkFile
28+
from lib.core.common import parseXmlFile
3129
from lib.core.data import kb
3230
from lib.core.data import paths
3331
from lib.parse.handler import FingerprintHandler
@@ -64,5 +62,5 @@ def headersParser(headers):
6462

6563
handler = FingerprintHandler(value, kb.headersFp)
6664

67-
parse(StringIO(open(xmlfile).read()), handler)
68-
parse(StringIO(open(paths.GENERIC_XML).read()), handler)
65+
parseXmlFile(xmlfile, handler)
66+
parseXmlFile(paths.GENERIC_XML, handler)

lib/parse/html.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424

2525
import re
2626

27-
from StringIO import StringIO
28-
from xml.sax import parse
2927
from xml.sax.handler import ContentHandler
3028

3129
from lib.core.common import checkFile
30+
from lib.core.common import parseXmlFile
3231
from lib.core.common import sanitizeStr
3332
from lib.core.data import kb
3433
from lib.core.data import paths
@@ -69,7 +68,7 @@ def htmlParser(page):
6968
checkFile(xmlfile)
7069
page = sanitizeStr(page)
7170
handler = htmlHandler(page)
72-
parse(StringIO(open(xmlfile).read()), handler)
71+
parseXmlFile(xmlfile, handler)
7372

7473
if handler.dbms and handler.dbms not in kb.htmlFp:
7574
kb.htmlFp.append(handler.dbms)

lib/parse/queriesfile.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
2424

25-
from StringIO import StringIO
26-
from xml.sax import parse
2725
from xml.sax.handler import ContentHandler
2826

2927
from lib.core.common import checkFile
28+
from lib.core.common import parseXmlFile
3029
from lib.core.common import sanitizeStr
3130
from lib.core.data import logger
3231
from lib.core.data import queries
@@ -235,4 +234,4 @@ def queriesParser():
235234

236235
checkFile(xmlfile)
237236
handler = queriesHandler()
238-
parse(StringIO(open(xmlfile).read()), handler)
237+
parseXmlFile(xmlfile, handler)

0 commit comments

Comments
 (0)