Metadata-Version: 2.4
Name: pyevil
Version: 0.0.10
Summary: EVIL PYTHON VOODOO
Author-email: Adam Jenca <jenca.adam@gmail.com>
Maintainer-email: Adam Jenca <jenca.adam@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Adam Jenča
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/jenca-adam/pyevil
Project-URL: Bug Reports, https://github.com/jenca-adam/pyevil/issues
Project-URL: Source, https://github.com/jenca-adam/pyevil
Keywords: c,evil,voodoo,unsafe
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: C
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Intended Audience :: Developers
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# `pyevil`

A python module that groups together a bunch of voodoo c black magic functions that can be useful when dealing with stuff at the very lowest of low levels of Python programming.

## A disclaimer

Almost every function in this module is **dangerous** and can cause **SEGFAULTS** or **MEMORY LEAKS**.
**NEVER** use this in production.

## Installation
1. git clone this repo
2. python -m pip install .
## Functions

### `dereference()`

Converts an address to a Python object.

Note that despite the misleading name, this function is **not guaranteed** to restore the object if it was garbage collected.
Also this relies on the implementation of `id()` - (i.e. it will only do what's advertised if you're using CPython)
### `addrof()`

Converts a Python object to an address.

Coincidentally, this does the same thing as `id()` in CPython, but it actually returns the address of the object regardless of the implementation of `id()`.

### `rawdump()`

Gets the raw memory representation of a Python object.

Can be used together with `rawload()` to create a super-rudimentary **unsafe**, **never-use-this** version of `pickle`.
If the object itself or any object it points to was GC'd or had their address changed, `rawload()` will fail to return a well-formed object.
As a result, you **won't** get the same result when `rawload()` is called in another Python instance.

### `rawload()`

Creates a Python object from its raw memory representation

See the note about `rawdump()`

### `getrefcount()`

Returns the reference count of a Python object.

Does the same as `sys.getrefcount()`

### `setrefcount()`

Sets the reference count of a Python object.

Using this can cause memory leaks if you increase the reference count or segmentation faults if you decrease it.
Use with care.

### `mk_immortal()`

Sets the reference count of a Python object to `_Py_IMMORTAL_REFCNT`

### `eternize()`

Makes the object and all its items (if it's a container) immortal.

### `settype()`

Sets the `ob_type` of an object without any conversion being done whatsoever.

Using this will likely create a malformed object.

### `getsize()`

Gets the `ob_size` of an object.

Returns bogus values on objects that don't have sizes.

### `setsize()`

Sets the `ob_size` of an object.

Decreasing will likely cause memory leaks, increasing will likely cause segfaults.

Setting the size of an object that doesn't have a size will create a malformed object.

### `forceset()`

Directly sets the value of an object to the value of another object.
To avoid data being overwritten, both objects must have the same size.

**CAN CRASH THE PYTHON SHELL!**

### `settupleitem()`

Sets a `tuple`'s item.

### `setbytesitem()`

Sets a `bytes`'s item.

Note that this **doesn't** change the hash.

### `untrack()`

Calls `PyObject_GC_UnTrack()` on the argument. 
 
