Skip to content

Commit 12a5ec9

Browse files
committed
more unicode refactoring
1 parent 2fb8bf3 commit 12a5ec9

16 files changed

Lines changed: 37 additions & 23 deletions

File tree

lib/controller/checks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import time
2828

2929
from lib.core.agent import agent
30+
from lib.core.common import getUnicode
3031
from lib.core.common import randomInt
3132
from lib.core.common import randomStr
3233
from lib.core.convert import md5hash
@@ -257,7 +258,7 @@ def checkDynParam(place, parameter, value):
257258
logger.info(infoMsg)
258259

259260
randInt = randomInt()
260-
payload = agent.payload(place, parameter, value, unicode(randInt))
261+
payload = agent.payload(place, parameter, value, getUnicode(randInt))
261262
dynResult1 = Request.queryPage(payload, place)
262263

263264
if True == dynResult1:
@@ -395,7 +396,7 @@ def checkConnection():
395396
conf.seqMatcher.set_seq1(page)
396397

397398
except sqlmapConnectionException, errMsg:
398-
errMsg = unicode(errMsg)
399+
errMsg = getUnicode(errMsg)
399400
raise sqlmapConnectionException, errMsg
400401

401402
return True

lib/controller/controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from lib.controller.checks import checkString
3030
from lib.controller.checks import checkRegexp
3131
from lib.controller.checks import checkConnection
32+
from lib.core.common import getUnicode
3233
from lib.core.common import paramToDict
3334
from lib.core.common import parseTargetUrl
3435
from lib.core.common import readInput
@@ -155,7 +156,7 @@ def start():
155156

156157
if not conf.dropSetCookie:
157158
for _, cookie in enumerate(conf.cj):
158-
cookie = unicode(cookie)
159+
cookie = getUnicode(cookie)
159160
index = cookie.index(" for ")
160161

161162
cookieStr += "%s;" % cookie[8:index]
@@ -267,7 +268,7 @@ def start():
267268
action()
268269

269270
except exceptionsTuple, e:
270-
e = unicode(e)
271+
e = getUnicode(e)
271272

272273
if conf.multipleTargets:
273274
e += ", skipping to next url"

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ def getCommonStart(strings=[]):
13541354

13551355
def getUnicode(value):
13561356
if isinstance(value, basestring):
1357-
return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding)
1357+
return value if isinstance(value, unicode) else unicode(value, conf.dataEncoding if 'dataEncoding' in conf else "utf-8")
13581358
else:
13591359
return unicode(value)
13601360

lib/core/progress.py

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

25+
from lib.core.common import getUnicode
2526
from lib.core.common import dataToStdout
2627
from lib.core.data import conf
2728

@@ -80,7 +81,7 @@ def update(self, newAmount=0):
8081
" " * (allFull - numHashes))
8182

8283
# Add the percentage at the beginning of the progress bar
83-
percentString = unicode(percentDone) + "%"
84+
percentString = getUnicode(percentDone) + "%"
8485
self.__progBar = "%s %s" % (percentString, self.__progBar)
8586

8687
def draw(self, eta=0):
@@ -102,4 +103,4 @@ def __str__(self):
102103
This method returns the progress bar string
103104
"""
104105

105-
return unicode(self.__progBar)
106+
return getUnicode(self.__progBar)

lib/core/update.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from subprocess import PIPE
4040
from subprocess import Popen as execute
4141

42+
from lib.core.common import getUnicode
4243
from lib.core.common import dataToStdout
4344
from lib.core.common import pollProcess
4445
from lib.core.common import readInput
@@ -215,7 +216,7 @@ def __updateSqlmap():
215216
logger.debug(debugMsg)
216217

217218
def notify(event_dict):
218-
action = unicode(event_dict['action'])
219+
action = getUnicode(event_dict['action'])
219220
index = action.find('_')
220221
prefix = action[index + 1].upper() if index != -1 else action.capitalize()
221222

@@ -225,7 +226,7 @@ def notify(event_dict):
225226
if action.find('_completed') == -1:
226227
print "%s\t%s" % (prefix, event_dict['path'])
227228
else:
228-
revision = unicode(event_dict['revision'])
229+
revision = getUnicode(event_dict['revision'])
229230
index = revision.find('number ')
230231

231232
if index != -1:

lib/request/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def decodePage(page, encoding):
9494
Decode gzip/deflate HTTP response
9595
"""
9696

97-
if unicode(encoding).lower() in ('gzip', 'x-gzip', 'deflate'):
97+
if isinstance(encoding, basestring) and encoding.lower() in ('gzip', 'x-gzip', 'deflate'):
9898
if encoding == 'deflate':
9999
# http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
100100
data = StringIO.StringIO(zlib.decompress(page, -15))

lib/request/direct.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from lib.core.agent import agent
2626
from lib.core.common import dataToSessionFile
27+
from lib.core.common import getUnicode
2728
from lib.core.convert import base64pickle
2829
from lib.core.convert import base64unpickle
2930
from lib.core.convert import utf8decode
@@ -55,7 +56,7 @@ def direct(query, content=True):
5556
output = base64unpickle(kb.resumedQueries[conf.hostname][query][:-1])
5657

5758
infoMsg = "resumed from file '%s': " % conf.sessionFile
58-
infoMsg += "%s..." % unicode(output)[:20]
59+
infoMsg += "%s..." % getUnicode(output)[:20]
5960
logger.info(infoMsg)
6061
elif select:
6162
output = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None)

lib/takeover/metasploit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from lib.core.common import dataToStdout
3737
from lib.core.common import getLocalIP
3838
from lib.core.common import getRemoteIP
39+
from lib.core.common import getUnicode
3940
from lib.core.common import normalizePath
4041
from lib.core.common import ntToPosixSlashes
4142
from lib.core.common import pollProcess
@@ -157,7 +158,7 @@ def __skeletonSelection(self, msg, lst=None, maxValue=1, default=1):
157158

158159
if not choice:
159160
if lst:
160-
choice = unicode(default)
161+
choice = getUnicode(default)
161162
else:
162163
return default
163164

lib/techniques/inband/union/use.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from lib.core.agent import agent
2929
from lib.core.common import calculateDeltaSeconds
30+
from lib.core.common import getUnicode
3031
from lib.core.common import parseUnionPage
3132
from lib.core.data import conf
3233
from lib.core.data import kb
@@ -227,7 +228,7 @@ def unionUse(expression, direct=False, unescape=True, resetCounter=False, nullCh
227228
# sql injection output
228229
startPosition = resultPage.index(temp.start)
229230
endPosition = resultPage.rindex(temp.stop) + len(temp.stop)
230-
value = unicode(resultPage[startPosition:endPosition])
231+
value = getUnicode(resultPage[startPosition:endPosition])
231232

232233
duration = calculateDeltaSeconds(start)
233234

lib/utils/google.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import socket
2828
import urllib2
2929

30+
from lib.core.common import getUnicode
3031
from lib.core.convert import urlencode
3132
from lib.core.data import conf
3233
from lib.core.data import kb
@@ -123,7 +124,7 @@ def search(self, googleDork):
123124
responseMsg = "HTTP response (%s - %d):\n" % (status, code)
124125

125126
if conf.verbose <= 4:
126-
responseMsg += unicode(responseHeaders)
127+
responseMsg += getUnicode(responseHeaders)
127128
elif conf.verbose > 4:
128129
responseMsg += "%s\n%s\n" % (responseHeaders, page)
129130

0 commit comments

Comments
 (0)