MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / _setPostprocessFunctions

Function _setPostprocessFunctions

lib/core/option.py:952–1025  ·  view source on GitHub ↗

Loads postprocess function(s) from given script(s)

()

Source from the content-addressed store, hash-verified

950 raise SqlmapGenericException(errMsg)
951
952def _setPostprocessFunctions():
953 """
954 Loads postprocess function(s) from given script(s)
955 """
956
957 if conf.postprocess:
958 for script in re.split(PARAMETER_SPLITTING_REGEX, conf.postprocess):
959 found = False
960 function = None
961
962 script = safeFilepathEncode(script.strip())
963
964 try:
965 if not script:
966 continue
967
968 if not os.path.exists(script):
969 errMsg = "postprocess script '%s' does not exist" % script
970 raise SqlmapFilePathException(errMsg)
971
972 elif not script.endswith(".py"):
973 errMsg = "postprocess script '%s' should have an extension '.py'" % script
974 raise SqlmapSyntaxException(errMsg)
975 except UnicodeDecodeError:
976 errMsg = "invalid character provided in option '--postprocess'"
977 raise SqlmapSyntaxException(errMsg)
978
979 dirname, filename = os.path.split(script)
980 dirname = os.path.abspath(dirname)
981
982 infoMsg = "loading postprocess module '%s'" % filename[:-3]
983 logger.info(infoMsg)
984
985 if not os.path.exists(os.path.join(dirname, "__init__.py")):
986 errMsg = "make sure that there is an empty file '__init__.py' "
987 errMsg += "inside of postprocess scripts directory '%s'" % dirname
988 raise SqlmapGenericException(errMsg)
989
990 if dirname not in sys.path:
991 sys.path.insert(0, dirname)
992
993 try:
994 module = __import__(safeFilepathEncode(filename[:-3]))
995 except Exception as ex:
996 raise SqlmapSyntaxException("cannot import postprocess module '%s' (%s)" % (getUnicode(filename[:-3]), getSafeExString(ex)))
997
998 for name, function in inspect.getmembers(module, inspect.isfunction):
999 if name == "postprocess" and inspect.getargspec(function).args and all(_ in inspect.getargspec(function).args for _ in ("page", "headers", "code")):
1000 found = True
1001
1002 kb.postprocessFunctions.append(function)
1003 function.__name__ = module.__name__
1004
1005 break
1006
1007 if not found:
1008 errMsg = "missing function 'postprocess(page, headers=None, code=None)' "
1009 errMsg += "in postprocess script '%s'" % script

Callers 1

initFunction · 0.85

Calls 12

safeFilepathEncodeFunction · 0.90
getUnicodeFunction · 0.90
getSafeExStringFunction · 0.90
openFileFunction · 0.90
infoMethod · 0.80
insertMethod · 0.45
appendMethod · 0.45
closeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…