|
24 | 24 | import string |
25 | 25 | import struct |
26 | 26 | import sys |
27 | | -import tempfile |
28 | 27 | import time |
29 | 28 | import types |
30 | 29 | import urllib |
|
50 | 49 | from extra.cloak.cloak import decloak |
51 | 50 | from extra.magic import magic |
52 | 51 | from extra.odict.odict import OrderedDict |
| 52 | +from lib.core.bigarray import BigArray |
53 | 53 | from lib.core.data import conf |
54 | 54 | from lib.core.data import kb |
55 | 55 | from lib.core.data import logger |
|
76 | 76 | from lib.core.exception import sqlmapSilentQuitException |
77 | 77 | from lib.core.exception import sqlmapSyntaxException |
78 | 78 | from lib.core.optiondict import optDict |
79 | | -from lib.core.settings import BIGARRAY_CHUNK_LENGTH |
80 | 79 | from lib.core.settings import DEFAULT_COOKIE_DELIMITER |
81 | 80 | from lib.core.settings import DEFAULT_GET_POST_DELIMITER |
82 | 81 | from lib.core.settings import DUMMY_USER_INJECTION |
@@ -156,153 +155,6 @@ def write(self, fp): |
156 | 155 |
|
157 | 156 | fp.write("\n") |
158 | 157 |
|
159 | | -class Wordlist: |
160 | | - """ |
161 | | - Iterator for looping over a large dictionaries |
162 | | - """ |
163 | | - |
164 | | - def __init__(self, filenames): |
165 | | - self.filenames = filenames |
166 | | - self.fp = None |
167 | | - self.index = 0 |
168 | | - self.iter = None |
169 | | - self.custom = [] |
170 | | - self.adjust() |
171 | | - self.lock = None |
172 | | - |
173 | | - def __iter__(self): |
174 | | - return self |
175 | | - |
176 | | - def adjust(self): |
177 | | - self.closeFP() |
178 | | - if self.index > len(self.filenames): |
179 | | - raise StopIteration |
180 | | - elif self.index == len(self.filenames): |
181 | | - if self.custom: |
182 | | - self.iter = iter(self.custom) |
183 | | - else: |
184 | | - raise StopIteration |
185 | | - else: |
186 | | - current = self.filenames[self.index] |
187 | | - infoMsg = "loading dictionary from '%s'" % current |
188 | | - singleTimeLogMessage(infoMsg) |
189 | | - self.fp = open(current, "r") |
190 | | - self.iter = iter(self.fp) |
191 | | - |
192 | | - self.index += 1 |
193 | | - |
194 | | - def append(self, value): |
195 | | - self.custom.append(value) |
196 | | - |
197 | | - def closeFP(self): |
198 | | - if self.fp: |
199 | | - self.fp.close() |
200 | | - self.fp = None |
201 | | - |
202 | | - def next(self): |
203 | | - retVal = None |
204 | | - if self.lock: |
205 | | - self.lock.acquire() |
206 | | - try: |
207 | | - retVal = self.iter.next().rstrip() |
208 | | - except StopIteration: |
209 | | - self.adjust() |
210 | | - retVal = self.iter.next().rstrip() |
211 | | - finally: |
212 | | - if self.lock: |
213 | | - self.lock.release() |
214 | | - return retVal |
215 | | - |
216 | | - def rewind(self): |
217 | | - self.index = 0 |
218 | | - self.adjust() |
219 | | - |
220 | | -class BigArray(list): |
221 | | - """ |
222 | | - List-like object used for storing large amounts of data (disk cached) |
223 | | - """ |
224 | | - |
225 | | - def __init__(self): |
226 | | - self.chunks = [[]] |
227 | | - self.cache = None |
228 | | - self.length = 0 |
229 | | - self.filenames = set() |
230 | | - |
231 | | - def append(self, value): |
232 | | - self.chunks[-1].append(value) |
233 | | - if len(self.chunks[-1]) >= BIGARRAY_CHUNK_LENGTH: |
234 | | - filename = self._dump(self.chunks[-1]) |
235 | | - del(self.chunks[-1][:]) |
236 | | - self.chunks[-1] = filename |
237 | | - self.chunks.append([]) |
238 | | - |
239 | | - def pop(self): |
240 | | - if len(self.chunks[-1]) < 1: |
241 | | - self.chunks.pop() |
242 | | - with open(self.chunks[-1], 'rb') as fp: |
243 | | - self.chunks[-1] = pickle.load(fp) |
244 | | - return self.chunks[-1].pop() |
245 | | - |
246 | | - def index(self, value): |
247 | | - for index in xrange(len(self)): |
248 | | - if self[index] == value: |
249 | | - return index |
250 | | - return ValueError, "%s is not in list" % value |
251 | | - |
252 | | - def _dump(self, value): |
253 | | - handle, filename = tempfile.mkstemp() |
254 | | - self.filenames.add(filename) |
255 | | - os.close(handle) |
256 | | - with open(filename, 'w+b') as fp: |
257 | | - pickle.dump(value, fp) |
258 | | - return filename |
259 | | - |
260 | | - def _checkcache(self, index): |
261 | | - if (self.cache and self.cache[0] != index and self.cache[2]): |
262 | | - filename = self._dump(self.cache[1]) |
263 | | - self.chunks[self.cache[0]] = filename |
264 | | - if not (self.cache and self.cache[0] == index): |
265 | | - with open(self.chunks[index], 'rb') as fp: |
266 | | - self.cache = (index, pickle.load(fp), False) |
267 | | - |
268 | | - def __getitem__(self, y): |
269 | | - index = y / BIGARRAY_CHUNK_LENGTH |
270 | | - offset = y % BIGARRAY_CHUNK_LENGTH |
271 | | - chunk = self.chunks[index] |
272 | | - if isinstance(chunk, list): |
273 | | - return chunk[offset] |
274 | | - else: |
275 | | - self._checkcache(index) |
276 | | - return self.cache[1][offset] |
277 | | - |
278 | | - def __setitem__(self, y, value): |
279 | | - index = y / BIGARRAY_CHUNK_LENGTH |
280 | | - offset = y % BIGARRAY_CHUNK_LENGTH |
281 | | - chunk = self.chunks[index] |
282 | | - if isinstance(chunk, list): |
283 | | - chunk[offset] = value |
284 | | - else: |
285 | | - self._checkcache(index) |
286 | | - self.cache[1][offset] = value |
287 | | - self.cache[2] = True # dirty flag |
288 | | - |
289 | | - def __repr__(self): |
290 | | - return "%s%s" % ("..." if len(self.chunks) > 1 else "", self.chunks[-1].__repr__()) |
291 | | - |
292 | | - def __iter__(self): |
293 | | - for i in xrange(len(self)): |
294 | | - yield self[i] |
295 | | - |
296 | | - def __len__(self): |
297 | | - return len(self.chunks[-1]) if len(self.chunks) == 1 else (len(self.chunks) - 1) * BIGARRAY_CHUNK_LENGTH + len(self.chunks[-1]) |
298 | | - |
299 | | - def __del__(self): |
300 | | - for filename in self.filenames: |
301 | | - try: |
302 | | - os.remove(filename) |
303 | | - except OSError: |
304 | | - pass |
305 | | - |
306 | 158 | class DynamicContentItem: |
307 | 159 | """ |
308 | 160 | Represents line in content page with dynamic properties (candidate |
|
0 commit comments