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.10.tar.gz (5.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pyevil-0.0.10.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pyevil-0.0.10.tar.gz
Algorithm Hash digest
SHA256 e6f0e7741196ba73598c0c810c874aaada896d6fd0f75ec6a4c5f6b0cd9a8424
MD5 7eb0cb91251c3a7b4321166c603d50c0
BLAKE2b-256 484e035c99a996fa7ab61f3e62d919529cb108030aecb7df201456a26b4018bc

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