sqlmap源码阅读系列检查是否满足依赖

sqlmap --dependencies 可以用来检查sqlmap需要使用的一些依赖是否满足。

通过阅读源码我们知道了,核心是__import__()函数。
异常:ImportError

__import__的好处就是,包名可以作为字符串参数传给__import__()

While writing a code, there might be a need for some specific modules. So we import those modules by using a single line code in Python.

But what if the name of the module needed is known to us only during runtime? How can we import that module? One can use the Python’s inbuilt import() function. It helps to import modules in runtime also.


def _checkDependencies():
    """
    Checks for missing dependencies.
    """

    if conf.dependencies:
    	# 关于依赖的检查的函数
        checkDependencies()

在checkDependencies()中有类似如下的代码。

    try:
        __import__("tkinter.ttk")
        debugMsg = "'tkinter.ttk' library is found"
        logger.debug(debugMsg)
    except ImportError:
        warnMsg = "sqlmap requires 'tkinter.ttk' library "
        warnMsg += "if you plan to run a GUI"
        logger.warn(warnMsg)
        missing_libraries.add('tkinter.ttk')

读了两天sqlmap源码,还是在init()函数内,说明这条路很远啊。

Guess you like

Origin blog.csdn.net/lineuman/article/details/121708464