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

Skip to content

Commit 2fb8bf3

Browse files
committed
more dump/unicode cleanup
1 parent 64ad3b0 commit 2fb8bf3

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

lib/core/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,12 @@ def getCommonStart(strings=[]):
13521352

13531353
return retVal
13541354

1355+
def getUnicode(value):
1356+
if isinstance(value, basestring):
1357+
return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding)
1358+
else:
1359+
return unicode(value)
1360+
13551361
def getBruteUnicode(string):
13561362
retVal = unicode()
13571363
for char in string:

lib/core/dump.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import os
2828

2929
from lib.core.common import dataToDumpFile
30+
from lib.core.common import getUnicode
3031
from lib.core.data import conf
3132
from lib.core.data import logger
3233

@@ -54,7 +55,7 @@ def __write(self, data, n=True):
5455
conf.loggedToOut = True
5556

5657
def __formatString(self, string):
57-
string = unicode(string)
58+
string = getUnicode(string)
5859
string = string.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")
5960
string = string.replace("__START__", "").replace("__STOP__", "")
6061
string = string.replace("__DEL__", ", ")
@@ -71,7 +72,7 @@ def string(self, header, data, sort=True):
7172

7273
return
7374

74-
data = unicode(data)
75+
data = getUnicode(data)
7576

7677
if data:
7778
data = self.__formatString(data)
@@ -99,7 +100,7 @@ def lister(self, header, elements, sort=True):
99100
if isinstance(element, basestring):
100101
self.__write("[*] %s" % element)
101102
elif isinstance(element, (list, tuple, set)):
102-
self.__write("[*] " + ", ".join(unicode(e) for e in element))
103+
self.__write("[*] " + ", ".join(getUnicode(e) for e in element))
103104

104105
if elements:
105106
self.__write("")
@@ -318,7 +319,7 @@ def dbTableValues(self, tableValues):
318319
if column != "__infos__":
319320
info = tableValues[column]
320321

321-
value = unicode(info["values"][i]) if type(info["values"][i]) != unicode else info["values"][i]
322+
value = getUnicode(info["values"][i])
322323

323324
if re.search("^[\ *]*$", value):
324325
value = "NULL"

lib/core/xmldump.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import xml.sax.saxutils as saxutils
88
from xml.dom.minidom import Document
99

10+
from lib.core.common import getUnicode
1011
from lib.core.data import conf
1112
from lib.core.data import logger
1213
from lib.core.exception import sqlmapFilePathException
@@ -130,22 +131,16 @@ def __createAttribute(self,attrName,attrValue):
130131
if attrValue is None :
131132
attr.nodeValue = u''
132133
else :
133-
attr.nodeValue = self.__getUnicode(attrValue)
134+
attr.nodeValue = getUnicode(attrValue)
134135
return attr
135136

136137
def __formatString(self, string):
137-
string = self.__getUnicode(string)
138+
string = getUnicode(string)
138139
string = string.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")
139140
string = string.replace("__START__", "").replace("__STOP__", "")
140141
string = string.replace("__DEL__", ", ")
141142
return string
142143

143-
def __getUnicode(self, value):
144-
if isinstance(value, basestring):
145-
return value if isinstance(value, unicode) else unicode(value, "utf-8")
146-
else:
147-
return unicode(value)
148-
149144
def string(self, header, data, sort=True):
150145
'''
151146
Adds string element to the xml.
@@ -196,7 +191,7 @@ def lister(self, header, elements, sort=True):
196191
for e in element :
197192
memberElemStr = self.__doc.createElement(MEMBER_ELEM)
198193
memberElemStr.setAttributeNode(self.__createAttribute(TYPE_ATTR, "string"))
199-
memberElemStr.appendChild(self.__createTextNode(self.__getUnicode(e)))
194+
memberElemStr.appendChild(self.__createTextNode(getUnicode(e)))
200195
memberElem.appendChild(memberElemStr)
201196
listsElem = self.__getRootChild(LSTS_ELEM_NAME)
202197
if not(listsElem):
@@ -250,7 +245,7 @@ def dba(self,isDBA):
250245
Adds information to the xml that indicates whether the user has DBA privileges
251246
'''
252247
isDBAElem = self.__doc.createElement(IS_DBA_ELEM_NAME)
253-
isDBAElem.setAttributeNode(self.__createAttribute(VALUE_ATTR, self.__getUnicode(isDBA)))
248+
isDBAElem.setAttributeNode(self.__createAttribute(VALUE_ATTR, getUnicode(isDBA)))
254249
self.__addToRoot(isDBAElem)
255250

256251
def users(self,users):
@@ -502,21 +497,21 @@ def finish(self, resultStatus, resultMsg=""):
502497
'''
503498
if ((self.__outputFP is not None) and not(self.__outputFP.closed)):
504499
statusElem = self.__doc.createElement(STATUS_ELEM_NAME)
505-
statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR,self.__getUnicode(resultStatus)))
500+
statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR,getUnicode(resultStatus)))
506501

507502
if not(resultStatus) :
508503
errorElem = self.__doc.createElement(ERROR_ELEM_NAME)
509504

510505
if (isinstance(resultMsg, Exception)):
511506
errorElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, type(resultMsg).__name__))
512507
else :
513-
errorElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, UNHANDLED_PROBLEM_TYPE))
508+
errorElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, UNHANDLED_PROBLEM_TYPE))
514509

515-
errorElem.appendChild(self.__createTextNode(self.__getUnicode(resultMsg)))
510+
errorElem.appendChild(self.__createTextNode(getUnicode(resultMsg)))
516511
statusElem.appendChild(errorElem)
517512

518513
self.__addToRoot(statusElem)
519-
self.__write(self.__doc.toprettyxml(encoding=ENCODING))
514+
self.__write(self.__doc.toprettyxml(encoding=ENCODING))
520515
self.__outputFP.close()
521516

522517
def closeDumper(status, msg=""):

0 commit comments

Comments
 (0)