pyptrs


Namepyptrs JSON
Version 1.0.0.post5 PyPI version JSON
download
home_pageNone
SummaryReal pointers and some memory utilities for python
upload_time2025-09-04 11:21:41
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords memory pointers ptrs
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyptrs
This library provides real pointers (as in languages like C) and some memory access utilites.

# Installation
```pip install pyptrs```

# Creating A Pointer
You should never create pointers directly. Instead, use the functions below:

pyptrs.**pointer_to_object**(obj, c_object = False)

Return a pointer to _obj_. _c_object_ specifies whether to treat the obj as a python object or a C object.
If _c_object_ is True, obj must be an instance of a ctypes C data type. 
You can learn more information about these data types from [here](https://docs.python.org/3/library/ctypes.html#fundamental-data-types), [here](https://docs.python.org/3/library/ctypes.html#arrays) and [here](https://docs.python.org/3/library/ctypes.html#structures-and-unions)

pyptrs.**pointer_to_address**(address, ctype = None)

Return a pointer that points to the given _address_. If _ctype_ is None, a python object is assumed to be living in that address. 
Otherwise, _ctype_ must be the ctypes C data type corresponding to the type of the object living in _address_.
You can learn more information about these data types from [here](https://docs.python.org/3/library/ctypes.html#fundamental-data-types), [here](https://docs.python.org/3/library/ctypes.html#arrays) and [here](https://docs.python.org/3/library/ctypes.html#structures-and-unions)

# Pointer Objects
Pointer.**get_size**()

Return the number of bytes occupied by the pointed object in memory.

Pointer.**get_mem**()

Return a bytes object representing the pointed object.

Pointer.**temp_value**(value, force_write = False)

Return a context manager that dereferences and assigns _value_ to the pointed object at \_\_enter__ and reverts this assignment at \_\_exit__.
If size of _value_ is bigger than the pointed object, a MemoryError will be raised. In order to prevent this, pass True to _force_write_.

# Simulated Operators

pyptrs.**dereference**(pointer, *value, force_write = False)

If _value_ is not given, it just dereferences the _pointer_. 
If _value_ is given, it must be a single argument and it dereferences the pointed object and assigns _value_ to it then returns a _backup_id_ that can be passed to pyptrs.mem_restore(). 
If size of _value_ is bigger than the pointed object, a MemoryError will be raised. In order to prevent this, pass True to _force_write_.
Type of _value_ can be anything if the pointed object is a python object.
If the type of the pointed object is a C type, type of _value_ must be the corresponding ctypes C data type.

pyptrs.**address_of**(obj, c_object = False)

Return address of the _obj_. If _c_object_ is True type of _obj_ must be a ctypes C data type. 
You can learn more information about these data types from [here](https://docs.python.org/3/library/ctypes.html#fundamental-data-types), [here](https://docs.python.org/3/library/ctypes.html#arrays) and [here](https://docs.python.org/3/library/ctypes.html#structures-and-unions).
If _c_object_ is True, address of the actual C object is returned, not the address of its ctypes wrapper.

# Utils
pyptrs.**mem_read**(address, amount = 1)

Read _amount_ bytes starting from _address_ and return them as a bytes object.

pyptrs.**mem_write**(address, data = b"")

Write the bytes represented by _data_ to _address_ and return a _backup_id_ that can be passed to pyptrs.mem_restore().

pyptrs.**mem_restore**(backup_id)

Revert the changes done to memory by the function that returned _backup_id_.

pyptrs.**mem_restore_last**()

Revert the last change done to memory either by pyptrs.dereference() or pyptrs.mem_write().

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyptrs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "memory, pointers, ptrs",
    "author": null,
    "author_email": "pyhacks <enginyildirim111@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1a/19/dfb21a84393037cdb4081149bd91f3da2199f00c604924ac89b5d794b242/pyptrs-1.0.0.post5.tar.gz",
    "platform": null,
    "description": "# pyptrs\nThis library provides real pointers (as in languages like C) and some memory access utilites.\n\n# Installation\n```pip install pyptrs```\n\n# Creating A Pointer\nYou should never create pointers directly. Instead, use the functions below:\n\npyptrs.**pointer_to_object**(obj, c_object = False)\n\nReturn a pointer to _obj_. _c_object_ specifies whether to treat the obj as a python object or a C object.\nIf _c_object_ is True, obj must be an instance of a ctypes C data type. \nYou can learn more information about these data types from [here](https://docs.python.org/3/library/ctypes.html#fundamental-data-types), [here](https://docs.python.org/3/library/ctypes.html#arrays) and [here](https://docs.python.org/3/library/ctypes.html#structures-and-unions)\n\npyptrs.**pointer_to_address**(address, ctype = None)\n\nReturn a pointer that points to the given _address_. If _ctype_ is None, a python object is assumed to be living in that address. \nOtherwise, _ctype_ must be the ctypes C data type corresponding to the type of the object living in _address_.\nYou can learn more information about these data types from [here](https://docs.python.org/3/library/ctypes.html#fundamental-data-types), [here](https://docs.python.org/3/library/ctypes.html#arrays) and [here](https://docs.python.org/3/library/ctypes.html#structures-and-unions)\n\n# Pointer Objects\nPointer.**get_size**()\n\nReturn the number of bytes occupied by the pointed object in memory.\n\nPointer.**get_mem**()\n\nReturn a bytes object representing the pointed object.\n\nPointer.**temp_value**(value, force_write = False)\n\nReturn a context manager that dereferences and assigns _value_ to the pointed object at \\_\\_enter__ and reverts this assignment at \\_\\_exit__.\nIf size of _value_ is bigger than the pointed object, a MemoryError will be raised. In order to prevent this, pass True to _force_write_.\n\n# Simulated Operators\n\npyptrs.**dereference**(pointer, *value, force_write = False)\n\nIf _value_ is not given, it just dereferences the _pointer_. \nIf _value_ is given, it must be a single argument and it dereferences the pointed object and assigns _value_ to it then returns a _backup_id_ that can be passed to pyptrs.mem_restore(). \nIf size of _value_ is bigger than the pointed object, a MemoryError will be raised. In order to prevent this, pass True to _force_write_.\nType of _value_ can be anything if the pointed object is a python object.\nIf the type of the pointed object is a C type, type of _value_ must be the corresponding ctypes C data type.\n\npyptrs.**address_of**(obj, c_object = False)\n\nReturn address of the _obj_. If _c_object_ is True type of _obj_ must be a ctypes C data type. \nYou can learn more information about these data types from [here](https://docs.python.org/3/library/ctypes.html#fundamental-data-types), [here](https://docs.python.org/3/library/ctypes.html#arrays) and [here](https://docs.python.org/3/library/ctypes.html#structures-and-unions).\nIf _c_object_ is True, address of the actual C object is returned, not the address of its ctypes wrapper.\n\n# Utils\npyptrs.**mem_read**(address, amount = 1)\n\nRead _amount_ bytes starting from _address_ and return them as a bytes object.\n\npyptrs.**mem_write**(address, data = b\"\")\n\nWrite the bytes represented by _data_ to _address_ and return a _backup_id_ that can be passed to pyptrs.mem_restore().\n\npyptrs.**mem_restore**(backup_id)\n\nRevert the changes done to memory by the function that returned _backup_id_.\n\npyptrs.**mem_restore_last**()\n\nRevert the last change done to memory either by pyptrs.dereference() or pyptrs.mem_write().\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Real pointers and some memory utilities for python",
    "version": "1.0.0.post5",
    "project_urls": {
        "Homepage": "https://github.com/pyhacks/pyptrs"
    },
    "split_keywords": [
        "memory",
        " pointers",
        " ptrs"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7b2e84bc601d257a919177ba42221a8697d04790c6520d52dbfda11a841f8c45",
                "md5": "1203f4b7d17466836794b9ec6671dad9",
                "sha256": "904ff02db9e1625b9aa6b2991c2046bfc6e9abfa2d15fc12a1716db437ec9e48"
            },
            "downloads": -1,
            "filename": "pyptrs-1.0.0.post5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1203f4b7d17466836794b9ec6671dad9",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4655,
            "upload_time": "2025-09-04T11:21:40",
            "upload_time_iso_8601": "2025-09-04T11:21:40.668159Z",
            "url": "https://files.pythonhosted.org/packages/7b/2e/84bc601d257a919177ba42221a8697d04790c6520d52dbfda11a841f8c45/pyptrs-1.0.0.post5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1a19dfb21a84393037cdb4081149bd91f3da2199f00c604924ac89b5d794b242",
                "md5": "7edaf474dd104ea4ca5e7708b3fdac09",
                "sha256": "60b1beba855c5cbabdb9784659ce8f5dba52edf976d569a67f1eaf83c10b46e8"
            },
            "downloads": -1,
            "filename": "pyptrs-1.0.0.post5.tar.gz",
            "has_sig": false,
            "md5_digest": "7edaf474dd104ea4ca5e7708b3fdac09",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4923,
            "upload_time": "2025-09-04T11:21:41",
            "upload_time_iso_8601": "2025-09-04T11:21:41.529002Z",
            "url": "https://files.pythonhosted.org/packages/1a/19/dfb21a84393037cdb4081149bd91f3da2199f00c604924ac89b5d794b242/pyptrs-1.0.0.post5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-04 11:21:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pyhacks",
    "github_project": "pyptrs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyptrs"
}
        
Elapsed time: 1.91199s