mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2026-01-27 16:49:03 +00:00
Moving binary to textual file openings
This commit is contained in:
@@ -2465,7 +2465,7 @@ def getSQLSnippet(dbms, sfile, **variables):
|
||||
|
||||
return retVal
|
||||
|
||||
def readCachedFileContent(filename, mode="rb"):
|
||||
def readCachedFileContent(filename, mode='r'):
|
||||
"""
|
||||
Cached reading of file content (avoiding multiple same file reading)
|
||||
|
||||
@@ -3609,7 +3609,7 @@ def saveConfig(conf, filename):
|
||||
|
||||
config.set(family, option, value)
|
||||
|
||||
with openFile(filename, "wb") as f:
|
||||
with openFile(filename, 'w') as f:
|
||||
try:
|
||||
config.write(f)
|
||||
except IOError as ex:
|
||||
@@ -3815,6 +3815,7 @@ def openFile(filename, mode='r', encoding=UNICODE_ENCODING, errors="reversible",
|
||||
# Reference: https://stackoverflow.com/a/37462452
|
||||
if 'b' in mode:
|
||||
buffering = 0
|
||||
encoding = None
|
||||
|
||||
if filename == STDIN_PIPE_DASH:
|
||||
if filename not in kb.cache.content:
|
||||
@@ -4022,7 +4023,7 @@ def createGithubIssue(errMsg, excMsg):
|
||||
logger.info(infoMsg)
|
||||
|
||||
try:
|
||||
with openFile(paths.GITHUB_HISTORY, "a+b") as f:
|
||||
with openFile(paths.GITHUB_HISTORY, "a+") as f:
|
||||
f.write("%s\n" % key)
|
||||
except:
|
||||
pass
|
||||
@@ -5103,7 +5104,7 @@ def resetCookieJar(cookieJar):
|
||||
os.close(handle)
|
||||
|
||||
# Reference: http://www.hashbangcode.com/blog/netscape-http-cooke-file-parser-php-584.html
|
||||
with openFile(filename, "w+b") as f:
|
||||
with openFile(filename, "w+") as f:
|
||||
f.write("%s\n" % NETSCAPE_FORMAT_HEADER_COOKIES)
|
||||
for line in lines:
|
||||
_ = line.split("\t")
|
||||
|
||||
@@ -110,7 +110,7 @@ class Dump(object):
|
||||
|
||||
self._outputFile = os.path.join(conf.outputPath, "log")
|
||||
try:
|
||||
self._outputFP = openFile(self._outputFile, "ab" if not conf.flushSession else "wb")
|
||||
self._outputFP = openFile(self._outputFile, 'a' if not conf.flushSession else 'w')
|
||||
except IOError as ex:
|
||||
errMsg = "error occurred while opening log file ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapGenericException(errMsg)
|
||||
@@ -453,7 +453,7 @@ class Dump(object):
|
||||
dumpFileName = conf.dumpFile or os.path.join(dumpDbPath, re.sub(r'[\\/]', UNSAFE_DUMP_FILEPATH_REPLACEMENT, "%s.%s" % (unsafeSQLIdentificatorNaming(table), conf.dumpFormat.lower())))
|
||||
if not checkFile(dumpFileName, False):
|
||||
try:
|
||||
openFile(dumpFileName, "w+b").close()
|
||||
openFile(dumpFileName, "w+").close()
|
||||
except SqlmapSystemException:
|
||||
raise
|
||||
except:
|
||||
@@ -481,7 +481,7 @@ class Dump(object):
|
||||
else:
|
||||
count += 1
|
||||
|
||||
dumpFP = openFile(dumpFileName, "wb" if not appendToFile else "ab", buffering=DUMP_FILE_BUFFER_SIZE)
|
||||
dumpFP = openFile(dumpFileName, 'w' if not appendToFile else 'a', buffering=DUMP_FILE_BUFFER_SIZE)
|
||||
|
||||
count = int(tableValues["__infos__"]["count"])
|
||||
if count > TRIM_STDOUT_DUMP_SIZE:
|
||||
|
||||
@@ -753,7 +753,7 @@ def _listTamperingFunctions():
|
||||
logger.info(infoMsg)
|
||||
|
||||
for script in sorted(glob.glob(os.path.join(paths.SQLMAP_TAMPER_PATH, "*.py"))):
|
||||
content = openFile(script, "rb").read()
|
||||
content = openFile(script, 'r').read()
|
||||
match = re.search(r'(?s)__priority__.+"""(.+)"""', content)
|
||||
if match:
|
||||
comment = match.group(1).strip()
|
||||
@@ -1015,8 +1015,8 @@ def _setPostprocessFunctions():
|
||||
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.PREPROCESS, suffix=".py")
|
||||
os.close(handle)
|
||||
|
||||
openFile(filename, "w+b").write("#!/usr/bin/env\n\ndef postprocess(page, headers=None, code=None):\n return page, headers, code\n")
|
||||
openFile(os.path.join(os.path.dirname(filename), "__init__.py"), "w+b").write("pass")
|
||||
openFile(filename, "w+").write("#!/usr/bin/env\n\ndef postprocess(page, headers=None, code=None):\n return page, headers, code\n")
|
||||
openFile(os.path.join(os.path.dirname(filename), "__init__.py"), "w+").write("pass")
|
||||
|
||||
errMsg = "function 'postprocess(page, headers=None, code=None)' "
|
||||
errMsg += "in postprocess script '%s' " % script
|
||||
@@ -1593,7 +1593,7 @@ def _createHomeDirectories():
|
||||
os.makedirs(directory)
|
||||
|
||||
_ = os.path.join(directory, randomStr())
|
||||
open(_, "w+b").close()
|
||||
open(_, "w+").close()
|
||||
os.remove(_)
|
||||
|
||||
if conf.get("outputDir") and context == "output":
|
||||
@@ -1623,7 +1623,7 @@ def _createTemporaryDirectory():
|
||||
|
||||
_ = os.path.join(conf.tmpDir, randomStr())
|
||||
|
||||
open(_, "w+b").close()
|
||||
open(_, "w+").close()
|
||||
os.remove(_)
|
||||
|
||||
tempfile.tempdir = conf.tmpDir
|
||||
|
||||
@@ -19,7 +19,7 @@ from lib.core.enums import OS
|
||||
from thirdparty import six
|
||||
|
||||
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
|
||||
VERSION = "1.10.1.51"
|
||||
VERSION = "1.10.1.52"
|
||||
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
|
||||
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
|
||||
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
|
||||
|
||||
@@ -64,7 +64,7 @@ def configFileParser(configFile):
|
||||
logger.debug(debugMsg)
|
||||
|
||||
checkFile(configFile)
|
||||
configFP = openFile(configFile, "rb")
|
||||
configFP = openFile(configFile, 'r')
|
||||
|
||||
try:
|
||||
config = UnicodeRawConfigParser()
|
||||
|
||||
@@ -490,7 +490,7 @@ class Connect(object):
|
||||
headers = forgeHeaders(auxHeaders, headers)
|
||||
|
||||
if kb.headersFile:
|
||||
content = openFile(kb.headersFile, "rb").read()
|
||||
content = openFile(kb.headersFile, 'r').read()
|
||||
for line in content.split("\n"):
|
||||
line = getText(line.strip())
|
||||
if ':' in line:
|
||||
|
||||
@@ -254,7 +254,7 @@ def storeResultsToFile(results):
|
||||
infoMsg = "writing crawling results to a temporary file '%s' " % filename
|
||||
logger.info(infoMsg)
|
||||
|
||||
with openFile(filename, "w+b") as f:
|
||||
with openFile(filename, "w+") as f:
|
||||
if conf.forms:
|
||||
f.write("URL,POST\n")
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ def purge(directory):
|
||||
for filepath in filepaths:
|
||||
try:
|
||||
filesize = os.path.getsize(filepath)
|
||||
with openFile(filepath, "w+b") as f:
|
||||
with openFile(filepath, "w+") as f:
|
||||
f.write("".join(_unichr(random.randint(0, 255)) for _ in xrange(filesize)))
|
||||
except:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user