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

Skip to content

Commit 094dc91

Browse files
committed
minor update (prior to some changes regarding large content retrieval)
1 parent a89140e commit 094dc91

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

lib/core/common.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
import codecs
1111
import copy
1212
import ctypes
13+
import httplib
1314
import inspect
1415
import logging
16+
import ntpath
1517
import os
18+
import pickle
19+
import posixpath
1620
import random
1721
import re
1822
import socket
1923
import string
24+
import struct
2025
import sys
2126
import time
2227
import urlparse
23-
import ntpath
24-
import posixpath
25-
import httplib
26-
import struct
2728
import unicodedata
2829

2930
from ConfigParser import DEFAULTSECT
@@ -64,6 +65,7 @@
6465
from lib.core.exception import sqlmapMissingDependence
6566
from lib.core.exception import sqlmapSyntaxException
6667
from lib.core.optiondict import optDict
68+
from lib.core.settings import BIGARRAY_CHUNK_LENGTH
6769
from lib.core.settings import INFERENCE_UNKNOWN_CHAR
6870
from lib.core.settings import UNICODE_ENCODING
6971
from lib.core.settings import DBMS_DICT
@@ -194,6 +196,40 @@ def rewind(self):
194196
self.index = 0
195197
self.adjust()
196198

199+
class BigArray(list):
200+
"""
201+
List-like object used for storing large amounts of data (disk cached)
202+
"""
203+
204+
def __init__(self):
205+
self.chunks = [[]]
206+
self.cache = None
207+
self.length = 0
208+
209+
def append(self, value):
210+
self.chunks[-1].append(value)
211+
if len(self.chunks[-1]) >= BIGARRAY_CHUNK_LENGTH:
212+
fp = tempfile.TemporaryFile()
213+
pickle.dump(self.chunks[-1], fp)
214+
del(self.chunks[-1][:])
215+
self.chunks[-1] = fp
216+
self.chunks.append([])
217+
218+
def __getitem__(self, y):
219+
index = y / BIGARRAY_CHUNK_LENGTH
220+
offset = y % BIGARRAY_CHUNK_LENGTH
221+
chunk = self.chunks[index]
222+
if isinstance(chunk, list):
223+
return chunk[offset]
224+
else:
225+
if not (self.cache and self.cache[0] == index):
226+
chunk.seek(0)
227+
self.cache = (index, pickle.load(chunk))
228+
return self.cache[1][offset]
229+
230+
def __len__(self):
231+
return len(self.chunks[-1]) if len(self.chunks) == 1 else (len(self.chunks) - 1) * BIGARRAY_CHUNK_LENGTH + len(self.chunks[-1])
232+
197233
class DynamicContentItem:
198234
"""
199235
Represents line in content page with dynamic properties (candidate

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,6 @@
382382

383383
# Used for status representation in dictionary attack phase
384384
ROTATING_CHARS = ('\\', '|', '|', '/', '-')
385+
386+
# Chunk length used in BigArray object (only last one is held in memory)
387+
BIGARRAY_CHUNK_LENGTH = 10000

0 commit comments

Comments
 (0)