Skip to main content
deleted 36 characters in body
Source Link
ovs
  • 60.6k
  • 3
  • 47
  • 161

Python 3, pxeger

With direct memory access, nothing is really immutable. Replaces the string in the constant table of the lambda function.

import ctypes

old_constswow = f.__code__.co_consts[2].co_constsco_consts[1]
new_constshah = (None, 'hah')
ctypes.memmove(id(old_constswow), id(new_constshah), new_constshah.__sizeof__())

Attempt This Online!Attempt This Online!

Python 3, pxeger

With direct memory access, nothing is really immutable. Replaces the constant table of the lambda function.

import ctypes

old_consts = f.__code__.co_consts[2].co_consts
new_consts = (None, 'hah')
ctypes.memmove(id(old_consts), id(new_consts), new_consts.__sizeof__())

Attempt This Online!

Python 3, pxeger

With direct memory access, nothing is really immutable. Replaces the string in the constant table of the lambda function.

import ctypes

wow = f.__code__.co_consts[2].co_consts[1]
hah = 'hah'
ctypes.memmove(id(wow), id(hah), hah.__sizeof__())

Attempt This Online!

Source Link
ovs
  • 60.6k
  • 3
  • 47
  • 161

Python 3, pxeger

With direct memory access, nothing is really immutable. Replaces the constant table of the lambda function.

import ctypes

old_consts = f.__code__.co_consts[2].co_consts
new_consts = (None, 'hah')
ctypes.memmove(id(old_consts), id(new_consts), new_consts.__sizeof__())

Attempt This Online!