ctypesprocstuff


Namectypesprocstuff JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/ctypesprocstuff
SummaryRestarts process (Windows only)
upload_time2024-04-13 22:09:56
maintainerNone
docs_urlNone
authorJohannes Fischer
requires_pythonNone
licenseMIT
keywords ctypes windows
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Some ctypes stuff for processes

## pip install randomandroidphone

### Tested against Windows 10 / Python 3.11 / Anaconda

```py

    from ctypesprocstuff import (
        get_kids_dict,
        get_all_procs_with_children,
        iter_process,
        wmic_process_active,
        is_process_user_an_admin,
        kill_process_and_children,
        suspend_subprocess,
        resume_subprocess,
    )
    import subprocess
    import time

    qq = get_kids_dict(pid=23336, bi_rl_lr="lr")
    print(qq)

    allprocschild = get_all_procs_with_children()
    for i in iter_process():
        di = wmic_process_active(i.th32ProcessID)
        try:
            print(is_process_user_an_admin(i.th32ProcessID))
        except Exception as e:
            print(e)
        if di.get("Caption", "") == "uc_driver.exe":
            print(i.th32ProcessID)
            kill_process_and_children(i.th32ProcessID, taskkillargs=("/f",))
        print(di)


    p = subprocess.Popen("notepad.exe")
    time.sleep(5)
    suspend_subprocess(p)
    time.sleep(15)
    resume_subprocess(p)

    # kill_process_and_children(pid=15300, taskkillargs=("/f",))


    get_all_procs_with_children() -> 'list[dict]'
        A function to get all processes with their children.
        Returns a list of dictionaries containing information about processes and their children (except pid 0 and pid 4).

    get_kids_dict(pid: 'int', bi_rl_lr: "Literal['rl', 'lr', 'bi']" = 'lr') -> 'dict'
        A function that constructs a dictionary of processes and their children based on the provided process ID.

        Args:
            pid (int): The process ID for which to build the dictionary.
            bi_rl_lr (Literal["rl", "lr", "bi"], optional): The direction of the process hierarchy. Defaults to "lr" (left to right).

        Returns:
            dict: A dictionary mapping the processes and their children along with module information.

    is_process_user_an_admin(pid: 'int') -> 'bool'
        Checks if the process user identified by the given process ID is an administrator.

        Args:
            pid (int): The process ID to check for administrator privileges.

        Returns:
            bool: True if the process user is an administrator, False otherwise.

    iter_module(pid: 'int') -> 'Generator'
        A function that iterates over the modules of a specified process.

        Args:
            pid (int): The process ID for which to iterate over the modules.

        Yields:
            Generator: Yields the module information obtained from the snapshot.

    iter_process() -> 'Generator'
        A function that iterates over the processes from a snapshot and yields them.

    iter_threads() -> 'Generator'
        A function that iterates over the threads from a snapshot and yields them.

    kill_process_and_children(pid: 'int', taskkillargs: 'tuple' = ('/f',)) -> 'list[list[bytes, bytes, int]]'
        A function to kill a process and its children based on the given process ID (starting from the deepest child).
        Args:
            pid (int): The process ID of the parent process to be killed.
            taskkillargs (tuple, optional): Additional arguments for the taskkill command. Defaults to ("/f",).

        Returns:
            list[list[bytes, bytes, int]]: A list containing information about the executed kill process and its children after termination.

    resume_subprocess(proc: 'subprocess.Popen') -> 'None'
        Resumes a subprocess based on the given process handle.

        Args:
            proc (subprocess.Popen): The subprocess to be resumed.

        Returns:
            None

    suspend_subprocess(proc: 'subprocess.Popen') -> 'None'
        Suspend a subprocess by calling NtSuspendProcess with the handle of the provided subprocess.

        Parameters:
            proc (subprocess.Popen): The subprocess to be suspended.

        Returns:
            None

    wmic_process_active(pid: 'int') -> 'dict'
        Retrieves information about an active process based on the provided process ID.
        Args:
            pid (int): The process ID for which to retrieve information.

        Returns:
            dict: A dictionary containing information about the active process, including CommandLine, Caption, and ProcessId.
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/ctypesprocstuff",
    "name": "ctypesprocstuff",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "ctypes, windows",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fd/02/a60ea7e0729ba80cd4832fadcd70662d909fbca52adf83f6a4c4ead29871/ctypesprocstuff-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Some ctypes stuff for processes\r\n\r\n## pip install randomandroidphone\r\n\r\n### Tested against Windows 10 / Python 3.11 / Anaconda\r\n\r\n```py\r\n\r\n    from ctypesprocstuff import (\r\n        get_kids_dict,\r\n        get_all_procs_with_children,\r\n        iter_process,\r\n        wmic_process_active,\r\n        is_process_user_an_admin,\r\n        kill_process_and_children,\r\n        suspend_subprocess,\r\n        resume_subprocess,\r\n    )\r\n    import subprocess\r\n    import time\r\n\r\n    qq = get_kids_dict(pid=23336, bi_rl_lr=\"lr\")\r\n    print(qq)\r\n\r\n    allprocschild = get_all_procs_with_children()\r\n    for i in iter_process():\r\n        di = wmic_process_active(i.th32ProcessID)\r\n        try:\r\n            print(is_process_user_an_admin(i.th32ProcessID))\r\n        except Exception as e:\r\n            print(e)\r\n        if di.get(\"Caption\", \"\") == \"uc_driver.exe\":\r\n            print(i.th32ProcessID)\r\n            kill_process_and_children(i.th32ProcessID, taskkillargs=(\"/f\",))\r\n        print(di)\r\n\r\n\r\n    p = subprocess.Popen(\"notepad.exe\")\r\n    time.sleep(5)\r\n    suspend_subprocess(p)\r\n    time.sleep(15)\r\n    resume_subprocess(p)\r\n\r\n    # kill_process_and_children(pid=15300, taskkillargs=(\"/f\",))\r\n\r\n\r\n    get_all_procs_with_children() -> 'list[dict]'\r\n        A function to get all processes with their children.\r\n        Returns a list of dictionaries containing information about processes and their children (except pid 0 and pid 4).\r\n\r\n    get_kids_dict(pid: 'int', bi_rl_lr: \"Literal['rl', 'lr', 'bi']\" = 'lr') -> 'dict'\r\n        A function that constructs a dictionary of processes and their children based on the provided process ID.\r\n\r\n        Args:\r\n            pid (int): The process ID for which to build the dictionary.\r\n            bi_rl_lr (Literal[\"rl\", \"lr\", \"bi\"], optional): The direction of the process hierarchy. Defaults to \"lr\" (left to right).\r\n\r\n        Returns:\r\n            dict: A dictionary mapping the processes and their children along with module information.\r\n\r\n    is_process_user_an_admin(pid: 'int') -> 'bool'\r\n        Checks if the process user identified by the given process ID is an administrator.\r\n\r\n        Args:\r\n            pid (int): The process ID to check for administrator privileges.\r\n\r\n        Returns:\r\n            bool: True if the process user is an administrator, False otherwise.\r\n\r\n    iter_module(pid: 'int') -> 'Generator'\r\n        A function that iterates over the modules of a specified process.\r\n\r\n        Args:\r\n            pid (int): The process ID for which to iterate over the modules.\r\n\r\n        Yields:\r\n            Generator: Yields the module information obtained from the snapshot.\r\n\r\n    iter_process() -> 'Generator'\r\n        A function that iterates over the processes from a snapshot and yields them.\r\n\r\n    iter_threads() -> 'Generator'\r\n        A function that iterates over the threads from a snapshot and yields them.\r\n\r\n    kill_process_and_children(pid: 'int', taskkillargs: 'tuple' = ('/f',)) -> 'list[list[bytes, bytes, int]]'\r\n        A function to kill a process and its children based on the given process ID (starting from the deepest child).\r\n        Args:\r\n            pid (int): The process ID of the parent process to be killed.\r\n            taskkillargs (tuple, optional): Additional arguments for the taskkill command. Defaults to (\"/f\",).\r\n\r\n        Returns:\r\n            list[list[bytes, bytes, int]]: A list containing information about the executed kill process and its children after termination.\r\n\r\n    resume_subprocess(proc: 'subprocess.Popen') -> 'None'\r\n        Resumes a subprocess based on the given process handle.\r\n\r\n        Args:\r\n            proc (subprocess.Popen): The subprocess to be resumed.\r\n\r\n        Returns:\r\n            None\r\n\r\n    suspend_subprocess(proc: 'subprocess.Popen') -> 'None'\r\n        Suspend a subprocess by calling NtSuspendProcess with the handle of the provided subprocess.\r\n\r\n        Parameters:\r\n            proc (subprocess.Popen): The subprocess to be suspended.\r\n\r\n        Returns:\r\n            None\r\n\r\n    wmic_process_active(pid: 'int') -> 'dict'\r\n        Retrieves information about an active process based on the provided process ID.\r\n        Args:\r\n            pid (int): The process ID for which to retrieve information.\r\n\r\n        Returns:\r\n            dict: A dictionary containing information about the active process, including CommandLine, Caption, and ProcessId.\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Restarts process (Windows only)",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/ctypesprocstuff"
    },
    "split_keywords": [
        "ctypes",
        " windows"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f2a70396df688fe48f241292dee102a48065cf20ff765b1627b6283a6bbcf6d",
                "md5": "b1a2a40324f92dcfabfa49311b111cdc",
                "sha256": "4c1efffd9fc04938eb1fc027365518d90868a71098d466d56bd2e50faee6ebb8"
            },
            "downloads": -1,
            "filename": "ctypesprocstuff-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b1a2a40324f92dcfabfa49311b111cdc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 14411,
            "upload_time": "2024-04-13T22:09:54",
            "upload_time_iso_8601": "2024-04-13T22:09:54.494485Z",
            "url": "https://files.pythonhosted.org/packages/8f/2a/70396df688fe48f241292dee102a48065cf20ff765b1627b6283a6bbcf6d/ctypesprocstuff-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd02a60ea7e0729ba80cd4832fadcd70662d909fbca52adf83f6a4c4ead29871",
                "md5": "b5f11fdeef4bf7dea425cf31e5ce7429",
                "sha256": "84c6acc6ede0fc38f0146f7d03b8c19e9e1aacf259781c1be30355f8043278f7"
            },
            "downloads": -1,
            "filename": "ctypesprocstuff-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "b5f11fdeef4bf7dea425cf31e5ce7429",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13601,
            "upload_time": "2024-04-13T22:09:56",
            "upload_time_iso_8601": "2024-04-13T22:09:56.469722Z",
            "url": "https://files.pythonhosted.org/packages/fd/02/a60ea7e0729ba80cd4832fadcd70662d909fbca52adf83f6a4c4ead29871/ctypesprocstuff-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-13 22:09:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "ctypesprocstuff",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "ctypesprocstuff"
}
        
Elapsed time: 0.22510s