pywinmemscanner


Namepywinmemscanner JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/Srinath-N-Gudi/pywinmemscanner
SummaryA library for scanning memory of other processes
upload_time2024-10-30 10:40:32
maintainerNone
docs_urlNone
authorSrinath Gudi
requires_python>=3.6
licenseNone
keywords python library pywinmemscanner memory scanner memory scanner
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyWinMemScanner

**PyWinMemScanner** is a powerful Python library designed for scanning and manipulating the memory of external processes on Windows systems. It provides an intuitive interface for developers looking to interact with the memory space of other applications, enabling advanced memory search, modification, and monitoring capabilities.

With **PyWinMemScanner**, you can easily access and scan a target process’s memory to locate specific values or addresses, manipulate these values, or monitor changes in real-time. This is particularly useful for tasks like reverse engineering, debugging, and hacking tools. By leveraging Windows APIs through the use of a DLL and Python's `ctypes`, this library offers direct access to the internal workings of processes.

## Key Features

- **Process Memory Scanning**: Scan the memory of target processes to find specific values or data patterns.
- **Memory Value Manipulation**: Modify memory values of the target process directly, with built-in support for various data types like integers, floats, and more.
- **Memory Monitoring**: Continuously monitor memory regions of a process and react to changes.
- **Intuitive API**: Provides an easy-to-use Python API for interfacing with low-level system functions.
- **Cross-compatibility**: Designed to work seamlessly with Python, making it accessible for all Python developers interested in system-level programming.

## Installation

You can easily install **PyWinMemScanner** using PyPI with the following command:

```bash
pip install pywinmemscanner
```
```python
from pywinmemscanner import MemoryScanner

# Initialize the scanner with the target process
pid = MemoryScanner.get_process_id_by_name(input('Enter process name :')) # Returns int
ms = memscan.MemoryScanner(pid) # PID can be direcly passed in integer format

# Scan for a value in memory
mss = ms.new_scan(your_value)

# Printing the addresses found
print(mss) # Give's the list in string format
# To obtain the actual list
print(mss.address_list)
print(len(mss.address_list))

# If the len(mss.address_list) is too high, it can be reduced by changing value in real process and passing that value in mss.next_scan(updated_value)
mss.next_scan(updated_value)
print(mss) # prints the updated memory addresses list

#Once the len(mss.address_list) is low enough (e.g. under 10) write_address_list(your_target_data) to write into the memory of entire address_list at once.
mss.write_address_list(target_data)

# This should update the value in the process. 
```

### Example: Memory Manipulation Tool (Inspired by Tools like Cheat Engine)
```python

import argparse as ap
from pywinmemscanner import MemoryScanner # Importing the Library.
import sys
FILENAME = None
PID = None

NOFADD = 10 # min_addresses_to_exit_monitor parameter
INTERVAL = 10 # interval parameter

## Parsing for arugments passed
parser = ap.ArgumentParser(description="Quick Memory Manipulation Tool")

parser.add_argument("-fn", "--filename",action='store', type=str, help="Name of the file to process")
parser.add_argument("-p", "--pid", action='store', type=int, help="PID of the Process")
parser.add_argument("-m", "--monitor", action='store_true', help="Automatically monitors changes in memory")
parser.add_argument("-s", "--scan", action='store', help="A value to perform first memory scan")
parser.add_argument("-i", "--int", action='store_true', help="Set the value of scan datatype to be int")
parser.add_argument("-f", "--float", action='store_true', help="Set the value of scan datatype to be float")
parser.add_argument("-d", "--double", action='store_true', help="Set the value of scan datatype to be double")
parser.add_argument('-n', '--nofadd', action='store', type=int, help="Number of min address before exiting monitor mode")
parser.add_argument('-t', '--interval', action='store', type=int, help='Inteveral between each scan')

args = parser.parse_args()

if args.filename == None and args.pid == None:
    print("Please provide either a filename or a PID.")
    sys.exit(1)

if args.int == False and args.float == False and args.double == False :
    print("Please specify the data type to scan for.")
    sys.exit(1)

if (args.int and args.float) or (args.float and args.double) or (args.int and args.double):
    print("Please select only one data type to scan for.")
    sys.exit(1)

if args.scan == None:
    print("Please provide a value to scan for.")
    sys.exit(1)

if args.filename:
    FILENAME = args.filename
    PID = MemoryScanner.get_process_id_by_name(FILENAME)
    if PID == 0:
        print(f"Process '{FILENAME}' not found.")
        sys.exit(1)

elif args.pid:
    PID = args.pid


def on_change(res, counter): # Calls made by pywinmemscanner.MemoryNextScan class
    """
    Handle memory change detection and user interaction.

    When a change is detected during the memory scan, this function prompts 
    the user to confirm if the change was intentional (The memory can be changed by the software themselves to work properly | Which was not changd by the user). If so, it allows the user 
    to select which value was changed.

    Args:
    - res (list): The result is nothing but mss.address_list or the address_list stored.
    - counter (collections.Counter): A Counter object of all the values read from the memory (with frequency).

    Returns:
    tuple:
        - (bool): True if the user confirms the change was intentional, False otherwise. (If the len(mss.address_list) < min_addresses_to_exit_monitor => Exits Monitoring)
        - (any): The selected value that was changed by the user, or None if no change was confirmed.

    Example:
    If a change is detected, the user is asked if they caused it. If yes, the user 
    selects from a list of values to identify which one was changed.
    """

    yn = input("Change in memory detected!. Was it changed by you ? ")
    if yn == 'y':
        print("Which one of these was it changed to ? ")
        for value, key in enumerate(counter.keys()):
            print(f"{value+1}. {key}")
        try: 
            choice = int(input())
        except:
            print("Excepted a number shows in above table ? Exiting...")
            sys.exit(1)
        return True, list(counter.keys())[choice-1]

    else:
        return False, None

ms = MemoryScanner(PID)
mss = None
try: 
    if args.int: 
        mss = ms.new_scan(int(args.scan))
    if args.float: 
        mss = ms.new_scan(float(args.scan))
    if args.double: 
        mss = ms.new_scan(float(args.scan), isdouble=True)
except Exception as e:
    print(f"Error occured : {e}")
    mss.close() ### Free dynamically allocated memory by backend of pywinmemscanner.
    

if args.nofadd:
    NOFADD = args.nofadd
if args.interval:
    INTERVAL = args.interval
if args.monitor:
    print("Monitoring changes in memory...")
    try:
        mss.monitor_scan(on_change=on_change, min_addresses_to_exit_monitor=NOFADD, interval=INTERVAL)
    except Exception as e:
        print(f"Error occured : {e}")
        mss.close() ### Free dynamically allocated memory by backend of pywinmemscanner. 
        

        
if (len(mss.address_list) == 0):
    print("No such value found in memory!")
    mss.close()
    sys.exit(0)
while 1:
    value = input("Enter the value you want to write  : ")
    if value.lower() == 'exit' or value.lower() == 'q' or value.lower() == 'quit':
        break
    try: 
        if args.int: 
            mss.write_address_list(int(value))
        elif args.float: 
            mss.write_address_list(float(value))
        elif args.double: 
            mss.write_address_list(float(value))
    except Exception as e:
        print(f"Error occured : {e}")
        mss.close() ### Free dynamically allocated memory by backend of pywinmemscanner.



mss.close() #Important to free the memory


"""
mss.monitor_scan(on_change=on_change, min_addresses_to_exit_monitor=10, interval=10)

The above monitor_scan function can be used to monitor changes in memory, on_change function will be triggered once there were changes.
pywinmemscanner requires the on_change function to return a tuple of (BOOL, TARGET), BOOL: If the address list should be updated.(If False, you can return None for the second one)(If True, Target is required i.e. which value to scan_next(value) for it will automatically update the address_list if True is returned and the monitor_scan() function will stop when the len(mss.address_list) < min_address_to_exit_monitor) (Interval is the rest time between each scan).
"""

```



## Compatibility

This library is Windows-specific and requires access to the target process’s memory. Ensure that your Python environment has appropriate permissions and that you are running your script with sufficient privileges (e.g., Administrator).

## Why PyWinMemScanner?

- **Efficient Memory Scanning**: The library allows you to quickly locate values in large memory regions without needing to write complicated, low-level code.
- **Built-in Support for Various Data Types**: It includes handling for common data types like integers, floats and double making memory interaction seamless.
- **Real-time Memory Monitoring**: For applications like game mods or cheat engines, real-time memory monitoring can be essential, and this library handles it with ease.
- **Extendable and Open-Source**: The codebase is written in Python with an underlying C/C++ DLL, and users can easily extend its functionality for their specific needs.

**PyWinMemScanner** simplifies memory scanning tasks for developers, providing the tools to interact with a process's memory easily. This library is perfect for both beginners and experienced developers working on system-level applications or reverse engineering projects.

### ⚠️ Important Disclaimer

This tool is intended for **educational** and **ethical purposes only**. By using this software, you agree to abide by all relevant laws and regulations. The author is **not responsible** for any illegal activity, misuse, or violation of terms of service that may result from using this tool. Please ensure that you have proper authorization before manipulating any software or process.

Use responsibly and ethically.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Srinath-N-Gudi/pywinmemscanner",
    "name": "pywinmemscanner",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "python, library, pywinmemscanner, memory, scanner, memory scanner",
    "author": "Srinath Gudi",
    "author_email": "srinathngudi11@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c3/0a/4c8129b55b40fc939ab7db257cfc4ed914921fed09dfa7fdf05d45e9dd0e/pywinmemscanner-0.1.5.tar.gz",
    "platform": null,
    "description": "# PyWinMemScanner\r\n\r\n**PyWinMemScanner** is a powerful Python library designed for scanning and manipulating the memory of external processes on Windows systems. It provides an intuitive interface for developers looking to interact with the memory space of other applications, enabling advanced memory search, modification, and monitoring capabilities.\r\n\r\nWith **PyWinMemScanner**, you can easily access and scan a target process\u2019s memory to locate specific values or addresses, manipulate these values, or monitor changes in real-time. This is particularly useful for tasks like reverse engineering, debugging, and hacking tools. By leveraging Windows APIs through the use of a DLL and Python's `ctypes`, this library offers direct access to the internal workings of processes.\r\n\r\n## Key Features\r\n\r\n- **Process Memory Scanning**: Scan the memory of target processes to find specific values or data patterns.\r\n- **Memory Value Manipulation**: Modify memory values of the target process directly, with built-in support for various data types like integers, floats, and more.\r\n- **Memory Monitoring**: Continuously monitor memory regions of a process and react to changes.\r\n- **Intuitive API**: Provides an easy-to-use Python API for interfacing with low-level system functions.\r\n- **Cross-compatibility**: Designed to work seamlessly with Python, making it accessible for all Python developers interested in system-level programming.\r\n\r\n## Installation\r\n\r\nYou can easily install **PyWinMemScanner** using PyPI with the following command:\r\n\r\n```bash\r\npip install pywinmemscanner\r\n```\r\n```python\r\nfrom pywinmemscanner import MemoryScanner\r\n\r\n# Initialize the scanner with the target process\r\npid = MemoryScanner.get_process_id_by_name(input('Enter process name :')) # Returns int\r\nms = memscan.MemoryScanner(pid) # PID can be direcly passed in integer format\r\n\r\n# Scan for a value in memory\r\nmss = ms.new_scan(your_value)\r\n\r\n# Printing the addresses found\r\nprint(mss) # Give's the list in string format\r\n# To obtain the actual list\r\nprint(mss.address_list)\r\nprint(len(mss.address_list))\r\n\r\n# If the len(mss.address_list) is too high, it can be reduced by changing value in real process and passing that value in mss.next_scan(updated_value)\r\nmss.next_scan(updated_value)\r\nprint(mss) # prints the updated memory addresses list\r\n\r\n#Once the len(mss.address_list) is low enough (e.g. under 10) write_address_list(your_target_data) to write into the memory of entire address_list at once.\r\nmss.write_address_list(target_data)\r\n\r\n# This should update the value in the process. \r\n```\r\n\r\n### Example: Memory Manipulation Tool (Inspired by Tools like Cheat Engine)\r\n```python\r\n\r\nimport argparse as ap\r\nfrom pywinmemscanner import MemoryScanner # Importing the Library.\r\nimport sys\r\nFILENAME = None\r\nPID = None\r\n\r\nNOFADD = 10 # min_addresses_to_exit_monitor parameter\r\nINTERVAL = 10 # interval parameter\r\n\r\n## Parsing for arugments passed\r\nparser = ap.ArgumentParser(description=\"Quick Memory Manipulation Tool\")\r\n\r\nparser.add_argument(\"-fn\", \"--filename\",action='store', type=str, help=\"Name of the file to process\")\r\nparser.add_argument(\"-p\", \"--pid\", action='store', type=int, help=\"PID of the Process\")\r\nparser.add_argument(\"-m\", \"--monitor\", action='store_true', help=\"Automatically monitors changes in memory\")\r\nparser.add_argument(\"-s\", \"--scan\", action='store', help=\"A value to perform first memory scan\")\r\nparser.add_argument(\"-i\", \"--int\", action='store_true', help=\"Set the value of scan datatype to be int\")\r\nparser.add_argument(\"-f\", \"--float\", action='store_true', help=\"Set the value of scan datatype to be float\")\r\nparser.add_argument(\"-d\", \"--double\", action='store_true', help=\"Set the value of scan datatype to be double\")\r\nparser.add_argument('-n', '--nofadd', action='store', type=int, help=\"Number of min address before exiting monitor mode\")\r\nparser.add_argument('-t', '--interval', action='store', type=int, help='Inteveral between each scan')\r\n\r\nargs = parser.parse_args()\r\n\r\nif args.filename == None and args.pid == None:\r\n    print(\"Please provide either a filename or a PID.\")\r\n    sys.exit(1)\r\n\r\nif args.int == False and args.float == False and args.double == False :\r\n    print(\"Please specify the data type to scan for.\")\r\n    sys.exit(1)\r\n\r\nif (args.int and args.float) or (args.float and args.double) or (args.int and args.double):\r\n    print(\"Please select only one data type to scan for.\")\r\n    sys.exit(1)\r\n\r\nif args.scan == None:\r\n    print(\"Please provide a value to scan for.\")\r\n    sys.exit(1)\r\n\r\nif args.filename:\r\n    FILENAME = args.filename\r\n    PID = MemoryScanner.get_process_id_by_name(FILENAME)\r\n    if PID == 0:\r\n        print(f\"Process '{FILENAME}' not found.\")\r\n        sys.exit(1)\r\n\r\nelif args.pid:\r\n    PID = args.pid\r\n\r\n\r\ndef on_change(res, counter): # Calls made by pywinmemscanner.MemoryNextScan class\r\n    \"\"\"\r\n    Handle memory change detection and user interaction.\r\n\r\n    When a change is detected during the memory scan, this function prompts \r\n    the user to confirm if the change was intentional (The memory can be changed by the software themselves to work properly | Which was not changd by the user). If so, it allows the user \r\n    to select which value was changed.\r\n\r\n    Args:\r\n    - res (list): The result is nothing but mss.address_list or the address_list stored.\r\n    - counter (collections.Counter): A Counter object of all the values read from the memory (with frequency).\r\n\r\n    Returns:\r\n    tuple:\r\n        - (bool): True if the user confirms the change was intentional, False otherwise. (If the len(mss.address_list) < min_addresses_to_exit_monitor => Exits Monitoring)\r\n        - (any): The selected value that was changed by the user, or None if no change was confirmed.\r\n\r\n    Example:\r\n    If a change is detected, the user is asked if they caused it. If yes, the user \r\n    selects from a list of values to identify which one was changed.\r\n    \"\"\"\r\n\r\n    yn = input(\"Change in memory detected!. Was it changed by you ? \")\r\n    if yn == 'y':\r\n        print(\"Which one of these was it changed to ? \")\r\n        for value, key in enumerate(counter.keys()):\r\n            print(f\"{value+1}. {key}\")\r\n        try: \r\n            choice = int(input())\r\n        except:\r\n            print(\"Excepted a number shows in above table ? Exiting...\")\r\n            sys.exit(1)\r\n        return True, list(counter.keys())[choice-1]\r\n\r\n    else:\r\n        return False, None\r\n\r\nms = MemoryScanner(PID)\r\nmss = None\r\ntry: \r\n    if args.int: \r\n        mss = ms.new_scan(int(args.scan))\r\n    if args.float: \r\n        mss = ms.new_scan(float(args.scan))\r\n    if args.double: \r\n        mss = ms.new_scan(float(args.scan), isdouble=True)\r\nexcept Exception as e:\r\n    print(f\"Error occured : {e}\")\r\n    mss.close() ### Free dynamically allocated memory by backend of pywinmemscanner.\r\n    \r\n\r\nif args.nofadd:\r\n    NOFADD = args.nofadd\r\nif args.interval:\r\n    INTERVAL = args.interval\r\nif args.monitor:\r\n    print(\"Monitoring changes in memory...\")\r\n    try:\r\n        mss.monitor_scan(on_change=on_change, min_addresses_to_exit_monitor=NOFADD, interval=INTERVAL)\r\n    except Exception as e:\r\n        print(f\"Error occured : {e}\")\r\n        mss.close() ### Free dynamically allocated memory by backend of pywinmemscanner. \r\n        \r\n\r\n        \r\nif (len(mss.address_list) == 0):\r\n    print(\"No such value found in memory!\")\r\n    mss.close()\r\n    sys.exit(0)\r\nwhile 1:\r\n    value = input(\"Enter the value you want to write  : \")\r\n    if value.lower() == 'exit' or value.lower() == 'q' or value.lower() == 'quit':\r\n        break\r\n    try: \r\n        if args.int: \r\n            mss.write_address_list(int(value))\r\n        elif args.float: \r\n            mss.write_address_list(float(value))\r\n        elif args.double: \r\n            mss.write_address_list(float(value))\r\n    except Exception as e:\r\n        print(f\"Error occured : {e}\")\r\n        mss.close() ### Free dynamically allocated memory by backend of pywinmemscanner.\r\n\r\n\r\n\r\nmss.close() #Important to free the memory\r\n\r\n\r\n\"\"\"\r\nmss.monitor_scan(on_change=on_change, min_addresses_to_exit_monitor=10, interval=10)\r\n\r\nThe above monitor_scan function can be used to monitor changes in memory, on_change function will be triggered once there were changes.\r\npywinmemscanner requires the on_change function to return a tuple of (BOOL, TARGET), BOOL: If the address list should be updated.(If False, you can return None for the second one)(If True, Target is required i.e. which value to scan_next(value) for it will automatically update the address_list if True is returned and the monitor_scan() function will stop when the len(mss.address_list) < min_address_to_exit_monitor) (Interval is the rest time between each scan).\r\n\"\"\"\r\n\r\n```\r\n\r\n\r\n\r\n## Compatibility\r\n\r\nThis library is Windows-specific and requires access to the target process\u2019s memory. Ensure that your Python environment has appropriate permissions and that you are running your script with sufficient privileges (e.g., Administrator).\r\n\r\n## Why PyWinMemScanner?\r\n\r\n- **Efficient Memory Scanning**: The library allows you to quickly locate values in large memory regions without needing to write complicated, low-level code.\r\n- **Built-in Support for Various Data Types**: It includes handling for common data types like integers, floats and double making memory interaction seamless.\r\n- **Real-time Memory Monitoring**: For applications like game mods or cheat engines, real-time memory monitoring can be essential, and this library handles it with ease.\r\n- **Extendable and Open-Source**: The codebase is written in Python with an underlying C/C++ DLL, and users can easily extend its functionality for their specific needs.\r\n\r\n**PyWinMemScanner** simplifies memory scanning tasks for developers, providing the tools to interact with a process's memory easily. This library is perfect for both beginners and experienced developers working on system-level applications or reverse engineering projects.\r\n\r\n### \u26a0\ufe0f Important Disclaimer\r\n\r\nThis tool is intended for **educational** and **ethical purposes only**. By using this software, you agree to abide by all relevant laws and regulations. The author is **not responsible** for any illegal activity, misuse, or violation of terms of service that may result from using this tool. Please ensure that you have proper authorization before manipulating any software or process.\r\n\r\nUse responsibly and ethically.\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A library for scanning memory of other processes",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/Srinath-N-Gudi/pywinmemscanner"
    },
    "split_keywords": [
        "python",
        " library",
        " pywinmemscanner",
        " memory",
        " scanner",
        " memory scanner"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45b304207ec55b88e657c714f8aad9d25c8d60b8c97a0d7095be303d1da6beec",
                "md5": "fa354013a4879c6c1d05030beaddbe2d",
                "sha256": "d228f3c6f4630393b27225999b532b6fd10355f061a184284df219d651a78116"
            },
            "downloads": -1,
            "filename": "pywinmemscanner-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fa354013a4879c6c1d05030beaddbe2d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 20608,
            "upload_time": "2024-10-30T10:40:30",
            "upload_time_iso_8601": "2024-10-30T10:40:30.077022Z",
            "url": "https://files.pythonhosted.org/packages/45/b3/04207ec55b88e657c714f8aad9d25c8d60b8c97a0d7095be303d1da6beec/pywinmemscanner-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c30a4c8129b55b40fc939ab7db257cfc4ed914921fed09dfa7fdf05d45e9dd0e",
                "md5": "022d53c4e1be6391c1eff59e770691c8",
                "sha256": "3051c462f6fcead23ca8e597403854fa9ffd8957cab2ecfa42e7c70aac54e947"
            },
            "downloads": -1,
            "filename": "pywinmemscanner-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "022d53c4e1be6391c1eff59e770691c8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 24512,
            "upload_time": "2024-10-30T10:40:32",
            "upload_time_iso_8601": "2024-10-30T10:40:32.190017Z",
            "url": "https://files.pythonhosted.org/packages/c3/0a/4c8129b55b40fc939ab7db257cfc4ed914921fed09dfa7fdf05d45e9dd0e/pywinmemscanner-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-30 10:40:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Srinath-N-Gudi",
    "github_project": "pywinmemscanner",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pywinmemscanner"
}
        
Elapsed time: 0.40943s