Skip to main content

EVIL PYTHON VOODOO

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyevil-0.0.9.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file pyevil-0.0.9.tar.gz.

File metadata

  • Download URL: pyevil-0.0.9.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for pyevil-0.0.9.tar.gz
Algorithm Hash digest
SHA256 8299156533037209ebf8add5d8faa40d8bc1e5777efbbcf8ce7e6c225c2cdcc1
MD5 ea4314487536f8fe8da2561ad62790b9
BLAKE2b-256 ba8385ec411e2270af2624a583b8addd24d39e8ed27583d034de14131c40465e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page