Пример #1
0
def tree_parent_process(grph, proc_obj, pids_seen_set):
    try:
        the_pid = proc_obj.pid
        if the_pid == 0 or the_pid == 1:
            return

        # A circular processes hierarchy can happen on Windows.
        if the_pid in pids_seen_set:
            WARNING("Circular pids tree:%d", the_pid)
            return
        pids_seen_set.add(the_pid)

        # Strange, but apparently it can happen.
        the_ppid = CIM_Process.PsutilProcToPPid(proc_obj)
        if the_ppid == 0:
            return

        if lib_common.is_useless_process(proc_obj):
            return

        node_process = lib_common.gUriGen.PidUri(the_pid)
        node_pprocess = lib_common.gUriGen.PidUri(the_ppid)
        grph.add((node_pprocess, pc.property_ppid, node_process))
        CIM_Process.AddInfo(grph, node_pprocess, [str(the_ppid)])

        AddExtraInformationtoProcess(grph, node_process, proc_obj)

        parent_proc_obj = CIM_Process.PsutilGetProcObjNoThrow(int(the_ppid))
        tree_parent_process(grph, parent_proc_obj, pids_seen_set)
    # This exception depends on the version of psutil.
    except CIM_Process.NoSuchProcess:
        # Maybe a process has suddenly disappeared. It does not matter.
        return
Пример #2
0
def tree_parent_process(grph, proc_obj):
    try:
        the_pid = proc_obj.pid
        if the_pid == 0 or the_pid == 1:
            return
        # Strange, but apparently it can happen.
        the_ppid = CIM_Process.PsutilProcToPPid(proc_obj)
        if the_ppid == 0:
            return

        if lib_common.UselessProc(proc_obj):
            return

        node_process = lib_common.gUriGen.PidUri(the_pid)
        node_pprocess = lib_common.gUriGen.PidUri(the_ppid)
        grph.add((node_pprocess, pc.property_ppid, node_process))
        CIM_Process.AddInfo(grph, node_pprocess, [str(the_ppid)])

        AddExtraInformationtoProcess(grph, node_process, proc_obj)

        parent_proc_obj = CIM_Process.PsutilGetProcObjNoThrow(int(the_ppid))
        tree_parent_process(grph, parent_proc_obj)
    # This exception depends on the version of psutil.
    except CIM_Process.NoSuchProcess:
        # Maybe a process has suddenly disappeared. It does not matter.
        return
Пример #3
0
def Usable(entity_type, entity_ids_arr):
    """MS-Dos Batch processes"""

    isWindows = lib_util.UsableWindows(entity_type, entity_ids_arr)
    if not isWindows:
        return False

    pidProc = entity_ids_arr[0]
    try:
        # Any error, no display.
        proc_obj = CIM_Process.PsutilGetProcObjNoThrow(int(pidProc))
    except:
        return False

    # The command line can be something like:
    # C:\windows\system32\cmd.exe /c ""C:\Users\rchateau\Developpement\ReverseEngineeringApps\StartCgiServer.cmd" "
    # "cmd.exe" /s /k pushd "C:\Users\rchateau\Developpement\ReverseEngineeringApps\PythonStyle\Tests"
    # cmd  /help
    # "C:\windows\system32\cmd.exe"
    #
    # cmd_line = CIM_Process.PsutilProcToCmdline(proc_obj)
    # cmdlinSplit = cmd_line.split(" ")
    # execNam = cmdlinSplit[0]

    # For all of these command lines, the path is always: "C:\Windows\System32\cmd.exe"
    procName = CIM_Process.PsutilProcToName(proc_obj)

    return procName == "cmd.exe"
Пример #4
0
def Usable(entity_type, entity_ids_arr):
    """Python processes"""

    pidProc = entity_ids_arr[0]
    try:
        # Any error, no display.
        proc_obj = CIM_Process.PsutilGetProcObjNoThrow(int(pidProc))
    except:
        return False

    cmd_line = CIM_Process.PsutilProcToCmdline(proc_obj)

    cmdlinSplit = cmd_line.split(" ")
    execNam = cmdlinSplit[0]
    basNam = os.path.basename(execNam)

    # This is a python process because of the executable.
    return basNam.startswith("python")