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

Skip to content

Commit a5a3092

Browse files
committed
Fix for an Issue #339
1 parent e835a2a commit a5a3092

2 files changed

Lines changed: 79 additions & 3 deletions

File tree

lib/techniques/blind/inference.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from lib.core.threads import runThreads
4949
from lib.core.unescaper import unescaper
5050
from lib.request.connect import Connect as Request
51+
from lib.utils.xrange import xrange
5152

5253
def bisection(payload, expression, length=None, charsetType=None, firstChar=None, lastChar=None, dump=False):
5354
"""
@@ -197,9 +198,9 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
197198
return result
198199

199200
if charTbl is None:
200-
charTbl = list(asciiTbl)
201+
charTbl = type(asciiTbl)(asciiTbl)
201202

202-
originalTbl = list(charTbl)
203+
originalTbl = type(asciiTbl)(charTbl)
203204

204205
if continuousOrder and shiftTable is None:
205206
# Used for gradual expanding into unicode charspace
@@ -269,7 +270,7 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
269270
# list
270271
if expand and shiftTable:
271272
charTbl = xrange(maxChar + 1, (maxChar + 1) << shiftTable.pop())
272-
originalTbl = list(charTbl)
273+
originalTbl = xrange(charTbl)
273274
maxChar = maxValue = charTbl[-1]
274275
minChar = minValue = charTbl[0]
275276
else:

lib/utils/xrange.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
class xrange(object):
2+
"""
3+
Advanced implementation of xrange (supports slice/copy/etc.)
4+
Reference: http://code.activestate.com/recipes/521885-a-pythonic-implementation-of-xrange/
5+
"""
6+
7+
__slots__ = ['_slice']
8+
9+
def __init__(self, *args):
10+
if args and isinstance(args[0], xrange):
11+
self._slice = slice(args[0].start, args[0].stop, args[0].step)
12+
else:
13+
self._slice = slice(*args)
14+
if self._slice.stop is None:
15+
# slice(*args) will never put None in stop unless it was
16+
# given as None explicitly.
17+
raise TypeError("xrange stop must not be None")
18+
19+
@property
20+
def start(self):
21+
if self._slice.start is not None:
22+
return self._slice.start
23+
return 0
24+
25+
@property
26+
def stop(self):
27+
return self._slice.stop
28+
29+
@property
30+
def step(self):
31+
if self._slice.step is not None:
32+
return self._slice.step
33+
return 1
34+
35+
def __hash__(self):
36+
return hash(self._slice)
37+
38+
def __cmp__(self, other):
39+
return (cmp(type(self), type(other)) or
40+
cmp(self._slice, other._slice))
41+
42+
def __repr__(self):
43+
return '%s(%r, %r, %r)' % (self.__class__.__name__,
44+
self.start, self.stop, self.step)
45+
46+
def __len__(self):
47+
return self._len()
48+
49+
def _len(self):
50+
try:
51+
return max(0, int((self.stop - self.start) / self.step))
52+
except Exception, ex:
53+
import pdb
54+
pdb.set_trace()
55+
56+
def __getitem__(self, index):
57+
if isinstance(index, slice):
58+
start, stop, step = index.indices(self._len())
59+
return xrange(self._index(start),
60+
self._index(stop), step*self.step)
61+
elif isinstance(index, (int, long)):
62+
if index < 0:
63+
fixed_index = index + self._len()
64+
else:
65+
fixed_index = index
66+
67+
if not 0 <= fixed_index < self._len():
68+
raise IndexError("Index %d out of %r" % (index, self))
69+
70+
return self._index(fixed_index)
71+
else:
72+
raise TypeError("xrange indices must be slices or integers")
73+
74+
def _index(self, i):
75+
return self.start + self.step * i

0 commit comments

Comments
 (0)