#esoteric-python

1 messages ยท Page 123 of 1

pure dew
#

it what

#

huh

floral meteor
#

different exception code

pure dew
#

you are on windows, yes?

#

oh yea

floral meteor
#

and another one

pure dew
#

hrm

floral meteor
pure dew
#

how did you get the advanced debug details?

floral meteor
#

control panel > System and Security > Security and Maintenance > reliablity report

#

you can see blue-screens through here as well

pure dew
#

cool

#

i wonder what the handling looks like for the oserror tho

#

that seems strange

#

definitely surprised me

floral meteor
pure dew
#

oh yes... "hardware problems"

#

i really hate windows for anything beyond gaming

floral meteor
#

some system apps segfaulting :/

pure dew
#

hmm

floral meteor
#

more dead python

pure dew
#

i wonder if this is a python feature and if its recent

#

i feel like i remember getting a real "segfault" on windows

#

but that could have been WSL too

floral meteor
#

in pycharm you can get process finished with exit code (0xc0000005)

#

negative a billion and something

pure dew
#

i dont use pycharm

floral meteor
pure dew
#

why so many application failures

glass coyote
#

!projects

night quarryBOT
#

Kindling Projects

The Kindling projects page on Ned Batchelder's website contains a list of projects and ideas programmers can tackle to build their skills and knowledge.

snow beacon
woven bridge
#

assuming theres even a straightforward way to detect quickening

#

The only way that users will be able to detect the presence of the new interpreter is through timing execution, the use of debugging tools, or measuring memory use.
hope the part about the use of debugging tools implies there'll be some implementation details exposed

crystal urchin
#

anyone help me please ```python

e = globals()
p = 95
h = 116
u = 101
y = 108
a = e[chr(u)]
q = 97
l = [p,p,98,117,105,108,h]
l = l + e["".join([chr(i) for i in l]) + "\x69\x6e\x73\x5f\x5f"].list([105,110,115,p,p])
e = e["".join([chr(i) for i in l])]
k = getattr(a[chr(q)][chr(u)],"".join([chr(i) for i in [ 103,u,h,q,h,h,114] ]))
l = [98,68,69,67,79,68,69,70,85,83,67,65,84,79,82,56,49,54,50,51,54,55,56,48,57]
a[e.chr(97)]["".join([chr(i) for i in (l + [54])])] = a["k"]
a["".join([chr(i) for i in (a["l"] + [57,49,53])])] = a[chr(u)]
l = str()
bDECODEFUSCATOR81623678096(bDECODEFUSCATOR8162367809915,"".join(chr(i) for i in [112,114]) + "".join(chr(i) for i in ([105]+ [110,116])) )((chr(a[e.chr(97)]["y"]) + chr(int("1"*3)) + chr(a[chr(121)] )))

#

idk how this works

#

my friend sent me

#

it prints lol

gritty mesa
#

Anything in particular? Because I mean, it's really just a big mess that can't exactly be explained well

crystal urchin
#

but like

cloud fossil
#

i like how there is pp

crystal urchin
#

how can i make it into readable form

gritty mesa
#

You don't

#

Or rather, shouldn't

#

No matter what you do here it's still going to be a mess

#

Well actually

#

heh

acoustic gust
gritty mesa
#

print("lol") technically

eager sphinx
#

Make it into readable form print("lol")

#

Jack this is literally the second time in a row

gritty mesa
#

lol

eager sphinx
#

You're stealing my thunder here lemon_angrysad

gritty mesa
#

!e

e = globals()
p = 95
h = 116
u = 101
y = 108
a = e[chr(u)]
q = 97
l = [p,p,98,117,105,108,h]
l = l + e["".join([chr(i) for i in l]) + "\x69\x6e\x73\x5f\x5f"].list([105,110,115,p,p])
e = e["".join([chr(i) for i in l])]
k = getattr(a[chr(q)][chr(u)],"".join([chr(i) for i in [ 103,u,h,q,h,h,114] ]))
l = [98,68,69,67,79,68,69,70,85,83,67,65,84,79,82,56,49,54,50,51,54,55,56,48,57]
a[e.chr(97)]["".join([chr(i) for i in (l + [54])])] = a["k"]
a["".join([chr(i) for i in (a["l"] + [57,49,53])])] = a[chr(u)]
l = str()
bDECODEFUSCATOR81623678096(bDECODEFUSCATOR8162367809915,"".join(chr(i) for i in [112,114]) + "".join(chr(i) for i in ([105]+ [110,116])) )((chr(a[e.chr(97)]["y"]) + chr(int("1"*3)) + chr(a[chr(121)] )))
night quarryBOT
#

@gritty mesa :white_check_mark: Your eval job has completed with return code 0.

lol
crystal urchin
#

e

#

but how did he do this

#

did u use like an obfuscator

#

he*

gritty mesa
#

You can make anything into a mess if you try hard enough

crystal urchin
#

uhmm

gritty mesa
#

You don't need an obfuscator, just a need to torture yourself

acoustic gust
crystal urchin
#

i was meant to say

#

:lol:

#

but my nitro ran off

gritty mesa
#

Take for example

#

!e

(lambda _, __, ___, ____, _____, ______, _______, ________:
    getattr(
        __import__(True.__class__.__name__[_] + [].__class__.__name__[__]),
        ().__class__.__eq__.__class__.__name__[:__] +
        ().__iter__().__class__.__name__[_____:________]
    )(
        _, (lambda _, __, ___: _(_, __, ___))(
            lambda _, __, ___:
                chr(___ % __) + _(_, __, ___ // __) if ___ else
                (lambda: _).func_code.co_lnotab,
            _ << ________,
            (((_____ << ____) + _) << ((___ << _____) - ___)) + (((((___ << __)
            - _) << ___) + _) << ((_____ << ____) + (_ << _))) + (((_______ <<
            __) - _) << (((((_ << ___) + _)) << ___) + (_ << _))) + (((_______
            << ___) + _) << ((_ << ______) + _)) + (((_______ << ____) - _) <<
            ((_______ << ___))) + (((_ << ____) - _) << ((((___ << __) + _) <<
            __) - _)) - (_______ << ((((___ << __) - _) << __) + _)) + (_______
            << (((((_ << ___) + _)) << __))) - ((((((_ << ___) + _)) << __) +
            _) << ((((___ << __) + _) << _))) + (((_______ << __) - _) <<
            (((((_ << ___) + _)) << _))) + (((___ << ___) + _) << ((_____ <<
            _))) + (_____ << ______) + (_ << ___)
        )
    )
)(
    *(lambda _, __, ___: _(_, __, ___))(
        (lambda _, __, ___:
            [__(___[(lambda: _).func_code.co_nlocals])] +
            _(_, __, ___[(lambda _: _).func_code.co_nlocals:]) if ___ else []
        ),
        lambda _: _.func_code.co_argcount,
        (
            lambda _: _,
            lambda _, __: _,
            lambda _, __, ___: _,
            lambda _, __, ___, ____: _,
            lambda _, __, ___, ____, _____: _,
            lambda _, __, ___, ____, _____, ______: _,
            lambda _, __, ___, ____, _____, ______, _______: _,
            lambda _, __, ___, ____, _____, ______, _______, ________: _
        )
    )
)
night quarryBOT
#

@gritty mesa :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 25, in <module>
003 |   File "<string>", line 25, in <lambda>
004 |   File "<string>", line 27, in <lambda>
005 | AttributeError: 'function' object has no attribute 'func_code'
gritty mesa
#

nice

crystal urchin
#

lol

crystal urchin
#

like my friend

acoustic gust
#

There's a 10000 lines code to just print hello world

gritty mesa
crystal urchin
#

he said it's an obfuscator but alr i see i see

paper bloom
#

omg

crystal urchin
#

so hes lying

gritty mesa
#

That's possible

paper bloom
#

I was watching the bot logs since we just merged a change to the help channels

gritty mesa
#

But unlikely

paper bloom
#

and I see this pop up

gritty mesa
#

lmao

#

!e

class _(metaclass=(type("__", (type,), {"__init__": lambda cls, name, bases, dct: print(f"""a{setattr(cls, '__del__', lambda self: print(f"hello world {type(self)()}"[0:11]))}{cls()}"""[0].replace('a', ''), end="")}))):...
night quarryBOT
#

@gritty mesa :x: Your eval job has completed with return code 143 (SIGTERM).

001 | hello world
002 | hello world
003 | hello world
004 | hello world
005 | hello world
006 | hello world
007 | hello world
008 | hello world
009 | hello world
010 | hello world
011 | hello world
... (truncated - too many lines)

Full output: too long to upload

gritty mesa
#

enjoy

gritty mesa
#

!e

from __future__ import annotations


@lambda c:c()
class __annotations__:
    def __setitem__(self, name, value):
        globals()[value] = globals()[name]


class Number:
    def __init__(self, value):
        self.value = value

    def __pos__(self):
        self.value += 0.5
        return self
    
    def __str__(self):
        return str(self.value)


let: i = Number(5)

++i
print(i)
night quarryBOT
#

@gritty mesa :white_check_mark: Your eval job has completed with return code 0.

6.0
gritty mesa
#

This is the channel where nightmares come from

crystal urchin
#

like try to understand how it works

acoustic gust
#

!e

if 1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1 : print("Hello world")
night quarryBOT
#

@acoustic gust :white_check_mark: Your eval job has completed with return code 0.

Hello world
gritty mesa
#

I mean, you basically just try your hardest to add as many unnecessary steps as possible

#

And make it an absolute mess

#

One sec lemme get an example

crystal urchin
#

uhmm but like

#

i dont see any print functions in the code

gritty mesa
#
class While:
    def __init__(self, condition, code):
        self.condition = condition
        self.code = code

    def __del__(self):
        if eval(self.condition):
            exec(self.code)
            globals().update(locals())
            type(self)(self.condition, self.code)

x = 3

While("x < 50", "x += 3")
print(x)
```For example, this is already cursed, but somewhat readable
tropic night
crystal urchin
#

so how does it prints then?

tropic night
#
e = globals()
p = 95
h = 116
u = 101
y = 108
a = e[chr(u)]
q = 97
l = [p,p,98,117,105,108,h]
l = l + e["".join([chr(i) for i in l]) + "\x69\x6e\x73\x5f\x5f"].list([105,110,115,p,p])
e = e["".join([chr(i) for i in l])]
k = getattr(a[chr(q)][chr(u)],"".join([chr(i) for i in [ 103,u,h,q,h,h,114] ]))
l = [98,68,69,67,79,68,69,70,85,83,67,65,84,79,82,56,49,54,50,51,54,55,56,48,57]
a[e.chr(97)]["".join([chr(i) for i in (l + [54])])] = a["k"]
a["".join([chr(i) for i in (a["l"] + [57,49,53])])] = a[chr(u)]
l = str()

getattr(builtins, "print")('lol')
gritty mesa
#
class While:
    ___ = lambda self: ((exec(self.__), globals().update(locals()), 
          type(self)(self.___, self.__)
        ) if eval(self.___) else ...)
    def __init__(self, __, ___):
      self.___ = __; self.__ = ___

      ((_ := globals()['__builtins__'].setattr), (
          x := getattr(self.__class__, 
         (_(self.__class__, (t := "__del__"), lambda ________: (...,...)), 
       t)[1]), _(x, "__code__", While.___.__code__)))
tropic night
#

i changed the last line into what it really is

gritty mesa
#

Or you could do that

#

Same thing, make it a mess

crystal urchin
tropic night
#

getattr(builtins, "print")('lol') -> print('lol')

crystal urchin
#

thanks

tropic night
#

bDECODEFUSCATOR81623678096(bDECODEFUSCATOR8162367809915,"".join(chr(i) for i in [112,114]) + "".join(chr(i) for i in ([105]+ [110,116])) )((chr(a[e.chr(97)]["y"]) + chr(int("1"*3)) + chr(a[chr(121)] ))) is just convoluted for the sake of being so

#

it does not take many seconds to decode

crystal urchin
#

oh xd

#

so bDECODEFUSCATOR81623678096 = getattr?

#

uhmm

tropic night
crystal urchin
#

i dont really understnad why is that so

#

like

#

i dont see the declaration of it

#

maybe it's hidden somewhere?

gritty mesa
#

It is

crystal urchin
#

oh

tropic night
crystal urchin
#

oh

#

is there a way to find it?

#

uhm it's kinda hard is it?

#

idk either

gritty mesa
#

It's meant to be

#

The whole purpose is to be as hard to read as possible

crystal urchin
#

hmm

gritty mesa
#

a["".join([chr(i) for i in (a["l"] + [57,49,53])])] = a[chr(u)] seems to be doign that

crystal urchin
#

oh?

gritty mesa
#

Defining the variables that is, and the line above that

#

a = e[chr(u)]

#

chr(u) -> chr(101) -> e -> the globals object

crystal urchin
#

oh

gritty mesa
#

So he's writing to globals

crystal urchin
#

uhmm so that's a way to register a variable

gritty mesa
#

!e

globals()["var"] = 5

print(var)
night quarryBOT
#

@gritty mesa :white_check_mark: Your eval job has completed with return code 0.

5
gritty mesa
#

yep

crystal urchin
#

do you know how this work? ```python
"".join([chr(i) for i in (a["l"] + [57,49,53])])

#

it's kinda

#

messy i think

gritty mesa
#

It's just making a bunch of characters

crystal urchin
#

uhmm

gritty mesa
#
l = [97,97,98,117,105,108,116]

print("".join([chr(i) for i in (l + [57,49,53])]))
#

!e

l = [97,97,98,117,105,108,116]

print("".join([chr(i) for i in (l + [57,49,53])]))
night quarryBOT
#

@gritty mesa :white_check_mark: Your eval job has completed with return code 0.

aabuilt915
crystal urchin
#

oh?

gritty mesa
#

Ah wait it's re-defined

#

!e

l = [98,68,69,67,79,68,69,70,85,83,67,65,84,79,82,56,49,54,50,51,54,55,56,48,57]

print("".join([chr(i) for i in (l + [57,49,53])]))
night quarryBOT
#

@gritty mesa :white_check_mark: Your eval job has completed with return code 0.

bDECODEFUSCATOR8162367809915
gritty mesa
#

So there's that

crystal urchin
#

ohh

#

idk how did u even know how to do this

#

lol

#

but really cool

#

!e ```python
e = globals()
p = 95
h = 116
u = 101
y = 108
a = e[chr(u)]
q = 97
l = [p,p,98,117,105,108,h]
l = l + e["".join([chr(i) for i in l]) + "\x69\x6e\x73\x5f\x5f"].list([105,110,115,p,p])
e = e["".join([chr(i) for i in l])]
k = getattr(a[chr(q)][chr(u)],"".join([chr(i) for i in [ 103,u,h,q,h,h,114] ]))
l = [98,68,69,67,79,68,69,70,85,83,67,65,84,79,82,56,49,54,50,51,54,55,56,48,57]
a[e.chr(97)]["".join([chr(i) for i in (l + [54])])] = a["k"]
a["".join([chr(i) for i in (a["l"] + [57,49,53])])] = a[chr(u)]
l = str()
bDECODEFUSCATOR81623678096(bDECODEFUSCATOR8162367809915,"".join(chr(i) for i in [112,114]) + "".join(chr(i) for i in ([105]+ [110,116])) )((chr(a[e.chr(97)]["y"]) + chr(int("1"*3)) + chr(a[chr(121)] )))

night quarryBOT
#

@crystal urchin :white_check_mark: Your eval job has completed with return code 0.

lol
crystal urchin
#

wow it actually works

tropic night
midnight maple
#

Here's a funny thing I discovered

#

You can use multiple nots in a statement

#

It's hard to make code blocks on mobile but

if not not not not not not not True:
     print("something")```
#

Pretty good for obfuscating

outer dust
#

!e

from typing import Callable, Union
class if_:
    def __init__(self, condition: bool):
        self.condition = condition
        self.done = False
    def do(self, action: Callable):
        if self.condition:
            self.done = True
            action()
class elif_:
    def __init__(self, parent: Union[if_, 'elif_'], condition: bool):
        self.parent = parent
        self.condition = condition
    def do(self, action: Callable):
        if self.condition and not self.parent.condition and not self.parent.done:
            self.parent.done = True
            action()
class else_:
    def __init__(self, parent: if_):
        self.parent = parent
    def do(self, action: Callable):
        if not self.parent.condition and not self.parent.done:
            self.parent.done = True
            action()
i = 7
a = if_((i == 5))
a.do(lambda: print("equals five"))
b = elif_(a, (i < 3))
b.do(lambda: print("is less than three"))
b = elif_(a, (i > 7))
b.do(lambda: print("is over seven"))
else_(a).do(lambda: print("didn't pass"))
night quarryBOT
#

@outer dust :white_check_mark: Your eval job has completed with return code 0.

didn't pass
terse mortar
sick hound
#

hello

formal sandal
wanton kite
sick hound
#

!e ```python
print( "".join( [chr(i) for i in [105, 32, 108, 111, 118, 101, 32, 121, 111, 117]]))

night quarryBOT
#

@sick hound :white_check_mark: Your eval job has completed with return code 0.

i love you
sick hound
#

yea me too

frail token
midnight maple
#

oh cool

golden finch
#

This channel is nightmare fuel.

golden finch
#

How can I learn the ctypes nightmare fuel?

rugged sparrow
#

experiment with stuff

golden finch
#

Any advice on what to experiment with or where?

rugged sparrow
#

start with some of the code you see in here

#

and try to mess with it

#

and ask questions

golden finch
#

alright I'll search for ctypes

#

!e

import ctypes;ctypes.string_at(0)
#

interesting

#

!e

__import__('ctypes').string_at(5000)
#

!e

__import__('ctypes').string_at(id(1))
#

Interesting!

#

!e

print(__import__('ctypes').string_at(id(1)))
night quarryBOT
#

@golden finch :white_check_mark: Your eval job has completed with return code 0.

b'x'
golden finch
#

Okay - where does the x come from?

#

Or am I just reading random chunks of memory?

#

Furthermore, it gives different strings on different machines!

#

!e

print([__import__('ctypes').string_at(id(i))for i in range(10)])
night quarryBOT
#

@golden finch :white_check_mark: Your eval job has completed with return code 0.

[b'\xf9', b'v', b'Z', b'!', b'/', b' ', b'\x0f', b'\x0e', b'\x1f', b'\r']
golden finch
#

I think I'm reading random memory

#

this could be a good rng

#

@rugged sparrow What does any of this do?

tribal moon
#

You're reading some weird stuff in memory

golden finch
#

I was under the impression it should be reading 1

#

Or is it reading a PyObjectsomething

woven bridge
#

not random, the address at id(i) is the start of the memory for the int object i.

tribal moon
#

!e ```py
import ctypes
import sys

some_string_that_is_going_to_be_in_memory = "string"
size = sys.getsizeof(some_string_that_is_going_to_be_in_memory)
original_spot = id(some_string_that_is_going_to_be_in_memory)
length = len(some_string_that_is_going_to_be_in_memory)

for i in range(original_spot+size, original_spot+size-length, -1):
print(ctypes.string_at(i-2), hex(i-2))```

woven bridge
#

!e

import ctypes

for i in range(10):
    array = (ctypes.c_byte * i.__sizeof__()).from_address(id(i))
    print(list(bytes(array))[-4:])
night quarryBOT
#

@woven bridge :white_check_mark: Your eval job has completed with return code 0.

001 | [0, 0, 0, 0]
002 | [1, 0, 0, 0]
003 | [2, 0, 0, 0]
004 | [3, 0, 0, 0]
005 | [4, 0, 0, 0]
006 | [5, 0, 0, 0]
007 | [6, 0, 0, 0]
008 | [7, 0, 0, 0]
009 | [8, 0, 0, 0]
010 | [9, 0, 0, 0]
#

@tribal moon :white_check_mark: Your eval job has completed with return code 0.

001 | b'g' 0x7f8fc0633f25
002 | b'ng' 0x7f8fc0633f24
003 | b'ing' 0x7f8fc0633f23
004 | b'ring' 0x7f8fc0633f22
005 | b'tring' 0x7f8fc0633f21
006 | b'string' 0x7f8fc0633f20
tribal moon
#

also now that you're here

#

about the operator thing

#

any luck?

woven bridge
#

ive been busy with other things but its still in the works. i think it's definitely doable with a smart enough injector like gdb but dunno if itll be possibleworthwhile to do it with ctypes alone.

#

and it would likely break for any new python version since the injection addresses would likely need to be hard coded

tribal moon
#

I still think it can be done with just ctypes

woven bridge
#

right, think we had this discussion before

#

possible for sure but perhaps difficult and brittle beyond the point of being worthwhile

tribal moon
#

What did you learn though?

woven bridge
#

like overall? hmm.. learned more about the internal structure of the cpython parser, a good bit about injection, how it's done on different OS's, learned about some interesting pyhon injection projects like pyrasite. also had never heard of code caves before.

#

i mean i'm still going though, but dont hold your breath.

white verge
#

what is esoteric python

cloud fossil
#

Golfing, Python VM languages, obfuscation, code gore and other general Python weirdness

(lambda: "esoteric python")()

pastel ibex
#

What exactly is code gore?

earnest wing
#

really ugly code

sick hound
#

ugly in being hard to read or just a mess but somehow works?

tribal moon
#

hard to read and ugly

#

for example look at JSON source code: ```py
#json.py

if (not skipkeys and ensure_ascii and
check_circular and allow_nan and
cls is None and indent is None and separators is None and
default is None and not sort_keys and not kw):
iterable = _default_encoder.iterencode(obj)
else:
if cls is None:
cls = JSONEncoder
iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
separators=separators,
default=default, sort_keys=sort_keys, **kw).iterencode(obj)```

pure dew
#

thats not really codegore tho

#

code gore is more like cursed code imo

floral meteor
snow beacon
#

Have you ever wondered why only mathematicians read mathematical research?

floral meteor
#

Cos most current education systems are a joke, except where the mathematicians study

#

ยฏ\_(ใƒ„)_/ยฏ

#

I'm still trying to find the integral of x^x

floral meteor
#

And in order to study mathematics, you need to write a lot of equations, and that's more paper friendly with single symbol operations and references

#

I use python like a mathematical language

#

It has the right notation for sets, it sorta has matrices

#

Tuple pairs

#

Arithmetic

#

Integrals and other symbolic mathematics takes a bit more work

heavy ermine
#

trivia: what will cause a fatal error?
1: while True: time.sleep(1)
2: def foo(): while True: print('hi') threading. Thread(target=foo).start() foo()
3: print('idk')

floral meteor
#

Pls code block the code

heavy ermine
#

1: ```py
while True:
print('hi')

#

2: ```py
def foo():
while True:
print('hi')
threading.Thread(target=foo).start()
foo

#

3: ```py
print('idk')

#

what will cause fatal error

floral meteor
#

And neither, if you want a fatal error you do this:

from threading import Thread as T
def morte():
  try:morte()
  except BaseException:morte()
while 1:T(target=morte, daemon=True).start()
heavy ermine
#

lel

slim sonnet
#

): formatting is bad

heavy ermine
#

๐Ÿ”ก

#

โฌ…๏ธ

snow beacon
heavy ermine
#

๐Ÿ”ข ๐Ÿ‘Ž 0123 ๐Ÿ‘

#

finally my bot lagged

floral meteor
#

!e And if you want to fatally not raise an error on Windows,

Death = lambda*a:type(*a)()
class Obitus(metaclass=Death):
  def __del__(self):
    try:[Death(self) for _ in range(13)]
    except:self.__class__()

print("memento mori")
night quarryBOT
#

@floral meteor :x: Your eval job timed out or ran out of memory.

memento mori
heavy ermine
#

bro why does this server have 3 PATRON ROLES? !!?

#

!e ```py
for i in range(40):
print('a' * i)

#

!e ```py
for i in range(100000):
print('a' * i)

last locust
heavy ermine
#

!e ```py
for i in range(100):
print('a' * i)

floral meteor
#

Try obfuscating the process

heavy ermine
#

!e
for i in range(100):
print('a' * i-1+2-3+2-1+3-2)

#

!e ```py
for i in range(100):
print('a' * (i-1+2-3+2-1+3-2))

gusty island
#

what you trying to do?

heavy ermine
#

!e
for i in range(100):
print('a' * (i-1+2-3+2-1+3-2))

night quarryBOT
#

@heavy ermine :white_check_mark: Your eval job has completed with return code 0.

001 | 
002 | a
003 | aa
004 | aaa
005 | aaaa
006 | aaaaa
007 | aaaaaa
008 | aaaaaaa
009 | aaaaaaaa
010 | aaaaaaaaa
011 | aaaaaaaaaa
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/mayeganaya.txt?noredirect

heavy ermine
#

a mountain if a

floral meteor
#

!e ```py
def p(a, *b):
if b:
h = b.pop(0)
if b:x, y, (z,) = a, h, b
else:x,(y,),z = a,b,1
else:x,y,z = 0,a,1
while x < y:
yield x
x += z
def q(a): return'a' *a
r=(1<<7)-28
for i in p(r):
print (q(i))

night quarryBOT
#

@floral meteor :white_check_mark: Your eval job has completed with return code 0.

001 | 
002 | a
003 | aa
004 | aaa
005 | aaaa
006 | aaaaa
007 | aaaaaa
008 | aaaaaaa
009 | aaaaaaaa
010 | aaaaaaaaa
011 | aaaaaaaaaa
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/uboyevibis.txt?noredirect

floral meteor
#

It needs to be valid python syntax

#

Newlines between statements

#

Or run it through a proper onelinerizor

gusty island
#

!e

from threading import Thread as T
def morte():
  try:morte()
  except BaseException:morte()
while 1:T(target=morte, daemon=True).start()
night quarryBOT
#

@gusty island :x: Your eval job has completed with return code 139 (SIGSEGV).

001 | Fatal Python error: _Py_CheckRecursiveCall: Cannot recover from stack overflow.
002 | Python runtime state: initialized
003 | 
004 | Current thread 0x00007facc5eb8700 (most recent call first):
005 |   File "<string>", line 3 in morte
006 |   File "<string>", line 3 in morte
007 |   File "<string>", line 3 in morte
008 |   File "<string>", line 3 in morte
009 |   File "<string>", line 3 in morte
010 |   File "<string>", line 3 in morte
011 |   File "<string>", line 3 in morte
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/vebufehuye.txt?noredirect

gusty island
#

!e```

#

!e

Death = lambda*a:type(*a)()
class Obitus(metaclass=Death):
  def __del__(self):
    try:[Death(self) for _ in range(13)]
    except:self.__class__()

print("memento mori")
night quarryBOT
#

@gusty island :x: Your eval job timed out or ran out of memory.

memento mori
fickle scarab
gusty island
#

not too surprizing

floral meteor
#

Try running it on windows

#

it'll take about 10 minutes

#

depending on the system

#

something small will blue screen

#

your graphics drivers are usually the first to go

#

not recommended on your personal or work pc

#

completely useless on Unix systems

pure dew
floral meteor
#

I'm still working on a kernel-panic-induction-protocol as a Linux version of blue-screen-induction-protocol

#

it's a bit harder to whack linux, as unlike windows it's actually an alright OS

fickle scarab
tribal moon
#

!e print((lambda i,c:c({~0XBis(0o2)&0xFfFfor(0b01, ):-0.9j,0:i@9.7e+1} [0.e+0jand(0o00)])+c({~0XBis(0o2)&0xFfFfor(0b01, ):-0.9j,0:i@9.7e+1} [0.e+0jand(0o00)] -(0x02<<0x04))+c(~(~((0x42<<i@42.e-24) &{.2:0b0is{0.e-1j:...}}[2e-1]) <<( 0x06&0o06)>>1)*3 +0b101)+c(~(~((0x42<<i@42.e-24) &{.2:0b0is{0.e-1j:...}}[2e-1]) <<( 0x06&0o06)>>1)*3 +0b101 -(0x02<<0x04)))(type("",(object,),{"__matmul__":lambda _,__:int(__)})(),chr)) make a full on obfuscator with this design

night quarryBOT
#

@tribal moon :white_check_mark: Your eval job has completed with return code 0.

001 | <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
002 | <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
003 | <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
004 | <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
005 | aAbB
tribal moon
#

ignore the stupid warnings

fickle scarab
#

christ

pure dew
night quarryBOT
heavy ermine
#

!e
for i in range(100):
print('a' * (i-1+2-3+2-1+3-2))

night quarryBOT
#

@heavy ermine :white_check_mark: Your eval job has completed with return code 0.

001 | 
002 | a
003 | aa
004 | aaa
005 | aaaa
006 | aaaaa
007 | aaaaaa
008 | aaaaaaa
009 | aaaaaaaa
010 | aaaaaaaaa
011 | aaaaaaaaaa
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/ucosilaror.txt?noredirect

heavy ermine
#

!e
for i in range(1000):
print('a' * (i-1+2-3+2-1+3-2))

night quarryBOT
#

@heavy ermine :white_check_mark: Your eval job has completed with return code 0.

001 | 
002 | a
003 | aa
004 | aaa
005 | aaaa
006 | aaaaa
007 | aaaaaa
008 | aaaaaaa
009 | aaaaaaaa
010 | aaaaaaaaa
011 | aaaaaaaaaa
... (truncated - too many lines)

Full output: too long to upload

heavy ermine
#

!e
for i in range(999):
print('a' * (i-1+2-3+2-1+3-2))

night quarryBOT
#

@heavy ermine :white_check_mark: Your eval job has completed with return code 0.

001 | 
002 | a
003 | aa
004 | aaa
005 | aaaa
006 | aaaaa
007 | aaaaaa
008 | aaaaaaa
009 | aaaaaaaa
010 | aaaaaaaaa
011 | aaaaaaaaaa
... (truncated - too many lines)

Full output: too long to upload

slim sonnet
#

!e

globals()[''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x5f', 16), int('0x5f', 16), int('0x62', 16), int('0x75', 16), int('0x69', 16), int('0x6c', 16), int('0x74', 16), int('0x69', 16), int('0x6e', 16), int('0x73', 16), int('0x5f', 16), int('0x5f', 16)]])].__dict__[''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x70', 16), int('0x72', 16), int('0x69', 16), int('0x6e', 16), int('0x74', 16)]])](''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x68', 16), int('0x65', 16), int('0x6c', 16), int('0x6c', 16), int('0x6f', 16), int('0x20', 16), int('0x77', 16), int('0x6f', 16), int('0x72', 16), int('0x6c', 16), int('0x64', 16)]]))
night quarryBOT
#

@slim sonnet :white_check_mark: Your eval job has completed with return code 0.

hello world
slim sonnet
#

!e

getattr(globals()[''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x5f', 16), int('0x5f', 16), int('0x62', 16), int('0x75', 16), int('0x69', 16), int('0x6c', 16), int('0x74', 16), int('0x69', 16), int('0x6e', 16), int('0x73', 16), int('0x5f', 16), int('0x5f', 16)]])].__dict__[''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x70', 16), int('0x72', 16), int('0x69', 16), int('0x6e', 16), int('0x74', 16)]])], ''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x5f', 16), int('0x5f', 16), int('0x63', 16), int('0x61', 16), int('0x6c', 16), int('0x6c', 16), int('0x5f', 16), int('0x5f', 16)]]))(getattr(getattr(__import__, ''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x5f', 16), int('0x5f', 16), int('0x63', 16), int('0x61', 16), int('0x6c', 16), int('0x6c', 16), int('0x5f', 16), int('0x5f', 16)]]))(''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x73', 16), int('0x79', 16), int('0x73', 16)]])), ''.join([chr(x) for x in []]).join([chr(x) for x in [int('0x70', 16), int('0x61', 16), int('0x74', 16), int('0x68', 16)]])))
night quarryBOT
#

@slim sonnet :white_check_mark: Your eval job has completed with return code 0.

['', '/snekbox/user_base/lib/python3.9/site-packages', '/usr/local/lib/python39.zip', '/usr/local/lib/python3.9', '/usr/local/lib/python3.9/lib-dynload']
slim sonnet
#

hastebin wouldn't fit it

fickle scarab
#

and how is it done for Ellipsis? or is it an interpreter / runtime env thing

floral meteor
#

!e print(....new(type(...))is...)

night quarryBOT
#

@floral meteor :white_check_mark: Your eval job has completed with return code 0.

True
floral meteor
#

returns the already existing...

night quarryBOT
#

@floral meteor :white_check_mark: Your eval job has completed with return code 0.

001 | None
002 | <class 'NoneType'> Ellipsis
floral meteor
#

!e ```py
class Cell:
_reg = {}
_PyObject = import('ctypes').py_object
def new(cls, victim):
if id(victim)in cls._reg:return cls._reg[id(victim)]
else:return super().new(cls)
def init(self, prisoner):
type(self)._reg |= {id(prisoner):self}
self.cell_contents = prisoner
self._content_type = self._PyObject.from_address(id(prisoner)+8).value
def hack(self, new:type):
victim = self._PyObject.from_address(id(self.cell_contents)+8)
old, victim.value = victim.value, new
return old
def del(self):
self.hack(self._content_type)
del self._reg[id(self.cell_contents)]
def repr(self):
return f"<cell({self.cell_contents!r}) at {hex(id(self.cell_contents))}>"
def hash(self):return id(self.cell_contents)

EllipsisType = Cell(...).hack(type(None))
print(...)
NoneType = Cell(...).hack(EllipsisType)
print(NoneType, ...)
print(Cell(...) is Cell(...), Cell(True)is Cell(False))
T, O = Cell(True), Cell(1)
O.hack(T.hack(int))
if 1: print(1 == True, 1)

night quarryBOT
#

@floral meteor :white_check_mark: Your eval job has completed with return code 0.

001 | None
002 | <class 'NoneType'> Ellipsis
003 | True False
004 | 1 False
floral meteor
#

why tf is 1 look like False but is still truthy?

#

this is confusing af

gusty island
#

e! import subprocess

floral meteor
#

~

gusty island
#

e!

bashCommand = "ls"
import subprocess
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
tribal moon
floral meteor
#

attempting to break the bot is allowed in #bot-commands

#

not here

#

here we break python itself

#

!e ```py
_0='echo 69';
from subprocess import Popen as _1;
from subprocess import PIPE as _2;
_3 = _1(_0, stdout=_2);
_4 = _3.communicate()
print(*_4)

tribal moon
#

It doesn't allow that

floral meteor
#

stripped terminal?

tribal moon
#

Can't access the terminal in any way I think

floral meteor
#

!e ```py
_0='/usr/local/lib/python3.9';
from subprocess import Popen as _1;
from subprocess import PIPE as _2;
_3 = _1(_0, stdout=_2);
_4 = _3.communicate()
print(*_4)

night quarryBOT
#

@floral meteor :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 4, in <module>
003 |   File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
004 |     self._execute_child(args, executable, preexec_fn, close_fds,
005 |   File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
006 |     raise child_exception_type(errno_num, err_msg, err_filename)
007 | PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.9'
gusty island
#

!e

import subprocess
subprocess.call('python')
floral meteor
#

bruh you have the ! and the e the wrong way around

#

and it will error 2

#

32512

tribal moon
#

alright then

floral meteor
#

im going to use that to obfuscate something aha

gusty island
#

!e

import subprocess
subprocess.call('python')
floral meteor
#

error 2

#

!e ```py
import('os').abort()

night quarryBOT
#

@floral meteor :warning: Your eval job has completed with return code 139 (SIGSEGV).

[No output]
gusty island
#

!e

floral meteor
#

!e ```py
from signal import*
from os import abort
for i in range(2,22):
try:signal(i, lambda*a:print(*a)or 0)
except Exception:pass
abort()

night quarryBOT
#

@floral meteor :warning: Your eval job timed out or ran out of memory.

[No output]
dawn kayak
#

!e ```py
(s := lambda: import('sys').setrecursionlimit(2**24) or s())()

night quarryBOT
#

@dawn kayak :warning: Your eval job has completed with return code 139 (SIGSEGV).

[No output]
gusty island
#

!e

import weakref
ref = None
class Target:
  def __del__(self):
    global ref
    ref = weakref.ref(self)

def g():
  w = Target()
  w = None
  print(ref)

g()
night quarryBOT
#

@gusty island :white_check_mark: Your eval job has completed with return code 0.

<weakref at 0x7f7195d8e3b0; dead>
floral meteor
#

that's a large id

#

I'm still trying to makes sense of the opcodes for just an annotation

#

!e not e!

#

okay the LOAD_CONST is actually two lines after

#

damn stack based bytecode

night quarryBOT
#

@gusty island :warning: Your eval job has completed with return code 0.

[No output]
floral meteor
#

!e ```py
def Mortis():
try:Decessus
except:Mortis()
Mortis()

night quarryBOT
#

@floral meteor :x: Your eval job has completed with return code 139 (SIGSEGV).

001 | Fatal Python error: _Py_CheckRecursiveCall: Cannot recover from stack overflow.
002 | Python runtime state: initialized
003 | 
004 | Current thread 0x00007f90cfc28740 (most recent call first):
005 |   File "<string>", line 2 in Mortis
006 |   File "<string>", line 3 in Mortis
007 |   File "<string>", line 3 in Mortis
008 |   File "<string>", line 3 in Mortis
009 |   File "<string>", line 3 in Mortis
010 |   File "<string>", line 3 in Mortis
011 |   File "<string>", line 3 in Mortis
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/jepijomizo.txt?noredirect

floral meteor
#

that's how you death it

gusty island
#

@floral meteor would there be a way to lock a resource that the python interpreter needs to access and then kill the program with the lock still in place?

#

!e

import os
os.system('ping kekex.cc')
night quarryBOT
#

@gusty island :warning: Your eval job has completed with return code 0.

[No output]
golden finch
gusty island
#

!e

import os
while True:
    os.system('ping kekex.cc')
night quarryBOT
#

@gusty island :warning: Your eval job timed out or ran out of memory.

[No output]
golden finch
gusty island
#

๐Ÿ˜ญ

golden finch
#

It was made by those who are Dead, and the Dead keep it, until the time comes. The box is sealed.

gusty island
#

there must be a way

floral meteor
#

print the return code

#

oh and it will be -1

gusty island
#

!e

import os
while True:
    os.system('ping 27.0.0.1')
golden finch
golden finch
gusty island
#

it must have some network device

#

maybe it's sealed but maybe it can be crashed

golden finch
#

I've had some experience breaking into and out of boxes before. I did not succeed.

#

I learnt that generally the only way to get data in is via the way it inputs code, and the only way out is how it outputs output.

#

I haven't looked into snekbox, but I'm guessing it's a virtual machine.

gusty island
#

well, I guess I will continue hacking the box before I make another atempt

golden finch
#

suggestion: track network traffic and see if anything goes in/out

gusty island
#

i just did that

#

but I guess that's too easy

rugged sparrow
#

it has no network

#

you also cannot start new processes (so os.system fails immediately)

gusty island
#

no sockets no os.system?

rugged sparrow
#

correct

gusty island
#

well, kinda makes sense to disable those

rugged sparrow
#

you can use os.execv however

#

because that does not call fork()

tribal moon
#

You can't escape the isolated environment or do anything really bad

#

I think Google made it and tested it

gusty island
#

thonk
there must be a better way

golden finch
#

I really doubt there's a way out.

tribal moon
#

There's always a way out

golden finch
#

Yes, there is a way out. However, it probably involves incredible amounts of voodoo and access to the source of the box and the host os.

#

Read: Unless you're a nation-state, it's impossible

rugged sparrow
#

Even if you root the box you'd need an 0day to get out of the vm

golden finch
#

that's my point

#

wait, if the box is rooted would it still filter ingoing/outgoing net requests/

#

my guess is yes

rugged sparrow
#

The box has no network connection at all

#

afaik

golden finch
#

I don't doubt you. How is input/output sent?

#

could you explain?

#

anyone know how to use __build_class__?

pine edge
#

lmao how long ago was that

#

uhh ping me again tomorrow i'm going to sleep

golden finch
#

sure

#

when is tomorrow for you?

#

I got a spicy error

#

better than a segfault imo

pine edge
#

let's say 13 hours

golden finch
#

okay - that's about the same time as tomorrow for me

#

What are the dunders:

__class__
__base__
__subclasses__
__name__
__module__
__builtins__

?

#

Specifically, the code is this:

(([x for x in (1).__class__.__base__.__subclasses__() if x.__name__ == 'catch_warnings'][0]()._module.__builtins__))['__import__']('os').system('ls -la')
#

I can't find documentation on object

#

seems to just list subclasses or smth

#

so then we get a catch_warnings thing

earnest wing
#

looks like a "missing __builtins__" escape

#

fetches the catch_warnings object, recovers __builtins__ from its _module, then does standard sandbox escape stuff

golden finch
#

yeah it is

#

but what is object?

earnest wing
#

It's just a plain featureless type.

#

The ancestor of every* object.

golden finch
#

so just type('',(),{})?

earnest wing
#

No.

golden finch
#

Or am I misunderstanding ancestor?

earnest wing
#

That would create a subclass of object.

golden finch
#

okay

#

so all objects inherit from object

earnest wing
#

yeah

golden finch
#

ok

#

and then subclasses just lists all objects

golden finch
earnest wing
#

You can manually alter the mro and __class__

golden finch
#

mro? that's method resolution order, but I don't know what that means

#

and class is just what it was an instance of, right?

earnest wing
#

yes and yes

golden finch
#

so what does mro do?

earnest wing
#

method resolution order
the order that methods are resolved

golden finch
#

do you have a quick demo?

earnest wing
#

which class's methods are resolved first

#

in the bases

golden finch
#

bases are those things in class x(bases): which it inherits from right

earnest wing
#

no I don't have a memo I'd like to post something else in fact but it's a bit inconvenient right now

golden finch
#

but I'm guessing resolve has a definition I don't know

earnest wing
#

Unrelated, here's a challenge:
It's possible to perform a sandbox escape with the following conditions:

  • Your code will be passed to exec with __builtins__ set to {}
  • Your code cannot contain the " or ' characters
    What's the shortest possible program to spawn a shell and execute ls? (Assuming the latest 3.9 version)
golden finch
#

just use [*map(chr,[array of ints])]

earnest wing
#

Map and chr are missing with no builtins.

golden finch
#

oh

#

oh

#

that is not fun

#

!e

print((1).__class__.__base__.__subclasses__())
#

!e

print(len((1).__class__.__base__.__subclasses__()))
night quarryBOT
#

@golden finch :white_check_mark: Your eval job has completed with return code 0.

114
golden finch
#

hmm

rugged sparrow
earnest wing
#

Yeah that's pretty much as expected

#

I wonder if it's possible to force obtaining the str class through other means (||repr(), doc||, etc))

rugged sparrow
#

a full __builtins__ rebuild is also fun

#

i mean getting str is fairly easy

earnest wing
#

Another idea would be to restrict what kinds of literals are allowed :>

#

like, ellipsis only

#

I'm sure you could enforce that, too

rugged sparrow
#

parse it with ast

earnest wing
#

just visiting the ast nodes- yeah

rugged sparrow
#
_del = delattr
_imp = __import__
for i in dir(__builtins__):
    _del(__builtins__, i)

sys = _imp('sys')
del _del, _imp
sys.meta_path.clear()
sys.modules.clear()``` write some code to recover from this
earnest wing
#

well step 1 is to define __builtins__ lol

#

oh that was just repl

#

inconvenient

golden finch
#

How can I change readonly attributes? I'm sick of Python telling me I can't break things

golden finch
golden finch
rugged sparrow
#

_frozen_importlib.BuiltinImporter

glass coyote
#

new logo

#

nive

#

nice*

golden finch
#

this is impressive algorithmically too

#
>>> s_assign('a',0,'b')
>>> x='a'
>>> x
'b'

however it opens the path for significantly more voodoo than I expected

woven bridge
#

strings use different internal layouts depending on their contents. e.g. 'uh oh: \U0002a6a5'

golden finch
#
>>> s_assign('foo',0,'bar')
>>> 'foo'
'foo'
>>> x='foo'
>>> x
'foo'
#

:(

#

How can I change builtin methods of int as a class?

woven bridge
golden finch
#

so how does it work?

#

oh lord

#

bit too much

rugged sparrow
#

@golden finch try fishhook it's more stable

#

!pypi fishhook

night quarryBOT
golden finch
#

what if I want to write my own?

rugged sparrow
#

Go for it

#

I wrote fishhook the same way

#

But fishhook can handle exceptions in hooks while forbiddenfruit crashes

golden finch
#

alr

rugged sparrow
#

Feel free to ping me with questions

golden finch
#

I have no idea where to start @rugged sparrow .

rugged sparrow
#

So generate_slotmap does the dynamic work of figuring out where each dunders slot is

#

Start there

golden finch
#

okay

#

also

#
[exec('from '+i+' import *',globals())for i in[*__import__('sys').modules]]

for no reason

#

oh lord it's all one file

#

@rugged sparrow what's a slotmap?

rugged sparrow
#

It's a mapping that says where different slot pointers need to go

#

Slot pointers are where c functions for Dunders go

golden finch
#

What's a mapping, and how can you make a dunder point to a c function?

#

oh wait

#

Is mapping similar to in math?

rugged sparrow
#

Oh it's just a dictionary, dunder names to locations

golden finch
#

locations being memory addresses of c functions?

rugged sparrow
#

The way that fishhook works is it takes the slot functions that exist on normal python classes and sticks them into builtin classes

#

Well data that can be used calculate the memory address

golden finch
#

okay

#

wait - normal python classes have slot functins?

rugged sparrow
#

Yea

#

All they do is look up the corresponding python function and call it

#

So by placing them in a builtin class, you can just place a python function in the class dictionary and it works

golden finch
#

so if I have the class

class foo:
  def bar(self,x):
    return x+1
#

what is the slotmap?

#

@rugged sparrow ?

rugged sparrow
#

The slot map isn't dependent on the class

#

It's based on how type objects look in memory

golden finch
#

type objects?

#

@rugged sparrow ?

#

Do you mean subclasses of type?

#

or things like int, str, etc (are those the same thing though)

rugged sparrow
#

So all classes are type objects (including type itself)

golden finch
#

okay

#

so type objects are things those metaclass is type?

#

do you have an example slotmap?

rugged sparrow
#

Slotmap shows every dunder name to its location

#

It's kinda big

golden finch
#

could you paste it?

#

(furthermore, how do you access it?)

#

@rugged sparrow you there?

rugged sparrow
#

You can import generate_slotmap from fishhook and call it

golden finch
#

returns a thing

#

looks like a dict of 3-item tuples keyed with method names

rugged sparrow
#

Yea that's the slot map

#

It's size of struct, base offset and secondary offset

golden finch
#

alright time to learn a bit more c

#

structs are just grouped variables, right?

#

like "classes" without methods

rugged sparrow
#

It's a set of values arranged specifically in memory

golden finch
#

it's a variable that holds several data items?

rugged sparrow
#

Yes

#

Sortof

#

But that description works for understanding fishhook

golden finch
#

ok

#

now base offset

tribal moon
#

It's a thing that holds some variables in some part in memory that you have to set later on, and all those variables can be accessed through the name of the structure variable you defined

golden finch
#

alright how do you set it later on?

tribal moon
#

You define it, and then set it by name, you could also set it like an array too

golden finch
#

Do you have an example?

tribal moon
#
struct Points {
  int x;
  int y;
}
struct Points points;

points.x = 4;
points.y = 3;``` something like that
golden finch
#

Okay - looks a lot like a methodless class.

tribal moon
#

in Python there's also ctypes.Structure that you can use

#

and I think it works if you pass it into an actual function that requires a struct

golden finch
#

ok

#

How would you set it like an array?

tribal moon
#
struct Points points = {4, 3};```
#

you could also initialize it all to 0 by just putting a 0 inside the curly braces

golden finch
#

okay

#

could the type of x and y differ?

rugged sparrow
#

Yes

golden finch
#

any restrictions?

rugged sparrow
#

No

golden finch
#

ok

#

so now what are base and secondary offsets?

rugged sparrow
#

Base specifies the offset of the struct on the type object struct, secondary specifies the location of the slot pointer on that base struct

golden finch
#

the what

#

offset being distance in memory

#

code examples might be useful if you have some

#

?

#

@rugged sparrow

rugged sparrow
#

Yea offset is distance in memory

#

Sorry I don't haven't code examples rn I don't have my computer

tribal moon
#

Read up on a stackoverflow article or something it explains it really well

#

things are usually referenced by an offset

#

Like for example local variable and function arguments are referenced by offset

#

they're referenced relative to the base pointer

golden finch
#

base pointer being?

#

the address of the first byte?

rugged sparrow
#

Yes

golden finch
#

So base offset is?

rugged sparrow
#

The base pointer + offset is an address inside the struct of a specific value

golden finch
#

I'm not sure what you're referencing

#

my c knowledge is - variables and structs exist, and pointers

#

code examples would really help if you could give any

tribal moon
#

Okay wait just a second

#

if you have something like ```c
#include <stdio.h>

struct Points {
int x;
int y;
};

int main() {
struct Points points;

points.x = 4;
points.y = 3;

printf("Address of `points`: %p, size of `points`: %d, value of `points`: %d\n", &points, sizeof(points), points);
printf("Address of `points.x` %p, size of `points.x`: %d, value of `points.x`: %d\n", &points.x, sizeof(points.x), points.x);
printf("Address of `points.x` %p, size of `points.x`: %d, value of `points.y`: %d\n", &points.y, sizeof(points.y), points.y);

}and run this this will output:
Address of points: 000000000061FE18, size of points: 8, value of points: 4
Address of points.x 000000000061FE18, size of points.x: 4, value of points.x: 4
Address of points.x 000000000061FE1C, size of points.x: 4, value of points.y: 3``` notice the addresses? See how the address of points is 0x000000000061FE18, and the value of it itself is x, that's because it points to the first starting value of the struct, where x is stored. Since x is an int, the size of it is 4 bytes, so if you wanted to access y for example, you'd go to base address which is 0x000000000061FE18, add the offset to it 000000000061FE1C (0x000000000061FE18 + 0x4) and then deference it to get the actual value. This is a really bad and rough explanation cause I'm eating right now but I'm sure you can find a better one on youtube or something

golden finch
#

reading now

golden finch
#

alright I think that makes sense

#

understood

golden finch
#

@rugged sparrow slotmaps?

golden finch
rugged sparrow
golden finch
#

okay

#

and so it is pointers to structs

#

maybe addr, size, val?

pine edge
#

i THINK

#

i was referring to how, using the gc module, you can get all the referrers to an object

golden finch
#

referrers? things that reference an object, right?

pine edge
#

yeah

#

so if you and your buddy share a secret object (or constant, since the parser makes all literal constants in the same block of code the same)

golden finch
#

okay

pine edge
#

then you can use gc to find your buddy and then call methods on it

#

that was probably it

#

so hypothetically if you write two things that use the literal constant 12353823672

#

in the same source file

#

one can find the other

golden finch
#

ah

#

okay

#

gc.get_referers or something

pine edge
#

(assuming nothing has changed about the cpython's treatment of literal constants since the original post)

#

yeah

golden finch
#

my knowledge of gc is rusty

pine edge
#

i once did some fucked up shit where the gc module formed part of my program's logic

#

nobody told me weak references existed

#

so i like

#

made them from scratch

golden finch
#

weak references?

pine edge
#

yeah, uh, things don't get cleaned up until their reference count drops to zero OR they're in a cycle that can't be accessed from globals()/locals()/etc scopes

golden finch
#

okay

pine edge
#

so what if you want to hold a reference to something, but you want it to get deallocated if you're the only thing holding a reference

#

you can make a "weak reference" that doesn't count

golden finch
#

Okay - why would you need that?

pine edge
#

i was implementing something SORT OF like a language

#

and that language needed something like a garbage collector

golden finch
#

rebuilding a lang inside python?

pine edge
#

but why should i implement a garbage collector when python can garbage collect for me

#

so by using weakrefs when appropriate python can clean up some of my messes automatically

golden finch
#

oh no

#

oh no

pine edge
#

but yeah i can't think of a good reason to use them except "i need python to free up some resources for performance reasons but i also need to know if it's still getting used"

golden finch
#

print_exception threw an exception and crashed
the cache died with it
print_exception somehow crashed again
and again
and then when calling exit() exit crashed
and then it segfaulted

#

we need a thread for spicy errors

golden finch
floral meteor
#

I use [*{*some_massive_string}] and pop a character when it's needed

golden finch
#

I knew I wasn't the only one to use [*{*}]!

golden finch
floral meteor
#

Importless random

#

But it's like a runtime hash

#

It's random between runtimes, it's consistent in the same code block

golden finch
#

ah

#

that is truly awful

floral meteor
#

I guess you could probably find the seed or figure out the seeding algorithm using this

golden finch
#

Myself, I read id() or random memory

floral meteor
#

id(1) also works

#

But the nested stars is a convenient, short, obfuscated shuffle

#

But some days I prefer to boogie rather than shuffle ;)

golden finch
#

"shuffle"

#

Furthermore, isn't there a limited amount?

thin trout
#

I am looking for a way to remove every attribute from new classes, because that's funny IG. I thought about using type.__prepare__ = lambda *_: {} but you can't assign to type. Any idea?

dawn kayak
#

how evil of you? how evil of you that you separate attribute from their classes? what happens to their feelings?

#

offended feelings intensify

woven bridge
thin trout
#

What is this function for?

#

!e

print(__builtins__.__build_class__.__doc__)
#

Umh

last locust
#

It's help() but it's not directly accessible

#

You have to monkeypatch it

thin trout
#

that's very embarrassing

#

Yeah, I need to manually load the site module

night quarryBOT
#

@thin trout :white_check_mark: Your eval job has completed with return code 0.

001 | __build_class__(func, name, /, *bases, [metaclass], **kwds) -> class
002 | 
003 | Internal helper function used by the class statement.
thin trout
#

.<

#

!e

from dis import dis

dis(__builtins__.__build_class__)โ€Š```
night quarryBOT
#

@thin trout :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 3, in <module>
003 |   File "/usr/local/lib/python3.9/dis.py", line 85, in dis
004 |     raise TypeError("don't know how to disassemble %s objects" %
005 | TypeError: don't know how to disassemble builtin_function_or_method objects
woven bridge
#

iirc it basically takes care of setting up a class' namespace by executing its body as a function with the locals set to the class' __dict__

#

the approach could then be this: you implement a new build class and pass an empty function instead of the actual function thats supposed to be used for its body

#

!e

build_class = __builtins__.__build_class__


def new_build_class(func, *args, **kwargs):
    return build_class(lambda *args, **kwargs: None, *args, **kwargs)

__builtins__.__build_class__ = new_build_class


class A:
    a = 1

print(A().a)
night quarryBOT
#

@woven bridge :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 13, in <module>
003 | AttributeError: 'A' object has no attribute 'a'
woven bridge
#

@thin trout

thin trout
#

Haha niiiice

floral meteor
golden finch
#

It seems fairly simple

#

the basic idea is

old=__builtins__.__build_class__
__builtins__.__build_class__=lambda args:(out:=o(args),type(something with out))
thin trout
golden finch
#

@thin trout
this might work for some arcane reason

__builtins__.__build_class__=lambda*a,**b:type(a[1],(),{})
thin trout
#

That's interesting too!

golden finch
#

ah, not yet

#

just need to make it support kwargs

#
>>> __builtins__.__build_class__=lambda*a,**b:type(a[1],(),{})
>>> class a(int,foo='bar'):
    n=2
    def f(self,x):
        print(x)
        return 3

    
>>> a.n
Traceback (most recent call last):
  File "<pyshell#28>", line 1, in <module>
    a.n
AttributeError: type object 'a' has no attribute 'n'
>>> a.f(1,2)
Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
    a.f(1,2)
AttributeError: type object 'a' has no attribute 'f'

yeah it works

#

sometimes the solution without ctypes is the good solution

#

@thin trout

thin trout
#

Noice

golden finch
#
o=__builtins__.__build_class__;__builtins__.__build_class__=lambda f,n,*bases,**kwargs:(globals().update(_=o(f,n,*bases)),type(n,bases,{i:getattr(_,i)if i[:2]=='__'else lambda*_:exec((lambda:0).__code__.replace(co_consts=()))for i in dir(_)}))[1]

class a(int,foo='bar'):
  def f(self,x):
    print(x)
    return 3

print('test')

a.f(1,2)

stdout:

test
[SIGSEGV]
golden finch
woven bridge
thin trout
#

Nah we don't have any

#

I guess a certificate of some mental illness could work

#

Definitely not going insane after reading this channel too much

#

What is this code doing though haha

golden finch
golden finch
rugged sparrow
#

@golden finch do you know why it segfaults?

golden finch
rugged sparrow
#

Yea but you should try to figure out why that segfaults

golden finch
#

It tries to get an element from co_consts that doesn't exist

#

which I presume is the source of the segfault

#

I stole it from codegolf stack exchange

night quarryBOT
rugged sparrow
golden finch
#
o=__builtins__.__build_class__
__builtins__.__build_class__=lambda a,b,*c,**d:(_:=o(a,b,*c,**d),type(b,c,{i:getattr(_,i)for i in dir(_)}|_._))[1]

I'm liking this new trick

golden finch
#

(I haven't looked into the cpython source)

rugged sparrow
#

look at Python/ceval.c

#

In the cpython source

golden finch
#

it's massive

golden finch
#

i.e

#

!e

o=__builtins__.__build_class__
__builtins__.__build_class__=lambda a,b,*c,**d:(_:=o(a,b,*c,**d),type(b,c,{i:getattr(_,i)for i in dir(_)}|_._))[1]

class foo:
  def __init__(self,value):
    self.value=value
  _={'__repr__':lambda self:self.value}

x=foo('potato')
print(x)
night quarryBOT
#

@golden finch :white_check_mark: Your eval job has completed with return code 0.

potato
golden finch
#

it's purely to make your code harder to debug

#

I am making the father of all undebuggable programs

pastel ibex
#

huh thats actually really cool

golden finch
#

I might make it segfault if you try to declare another class without it

#

no idea where to look in ceval.c

#

it's big

rugged sparrow
#

Do a find in file for TARGET(LOAD_CONST

golden finch
#
TARGET(LOAD_CONST): {
            PREDICTED(LOAD_CONST);
            PyObject *value = GETITEM(consts, oparg);
            Py_INCREF(value);
            PUSH(value);
            DISPATCH();
        }
#

I've been reading that bit

#

and looking at defs

rugged sparrow
#

Yea now look at GETITEM

golden finch
#
#ifndef Py_DEBUG
#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
#else
#define GETITEM(v, i) PyTuple_GetItem((v), (i))
#endif

so

#define GETITEM(v, i) PyTuple_GetItem((v), (i))
#

now to PyTuple_GetItem

#

where is that defined?

#

some other file

rugged sparrow
#

Nope, Py_DEBUG isn't defined

golden finch
#

ah

#

๐Ÿง 

#

ndef

#

missed the n

rugged sparrow
#

So you're looking for PyTuple_GET_ITEM

golden finch
#

can't find the definition either

night quarryBOT
#

Include/cpython/tupleobject.h line 23

#define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])```
night quarryBOT
#

Include/cpython/tupleobject.h line 23

#define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])```
golden finch
#

that was almost simultaneous

rugged sparrow
#

So now we know what LOAD_CONST actually runs on the C side

golden finch
#

so now what does that c mean?

#

from my java background I'm guessing it's a typecast

rugged sparrow
#

It's indexing the tuples array

golden finch
#

is a tuple an array internally?

rugged sparrow
#

It has a an array inside Its struct

golden finch
#

okay

rugged sparrow
#

But the important thing is that there isn't any bounds checking happening

golden finch
#

like checking that i is in a valid range?

rugged sparrow
#

Yes

golden finch
#

mhm

rugged sparrow
#

That's why it segfaults

#

Because it's trying to load whatever memory is there as a python object

golden finch
#

okay - makes sense so far

#

now what's the cool thing?

rugged sparrow
#

It's possible to make sure the memory it tries to load is a valid python object

golden finch
#

how?

rugged sparrow
#

By altering the argument to LOAD_CONST

#

I challenge you to try to figure out how to do that

golden finch
#

(which is the index it takes?)

#

I know almost no c

rugged sparrow
#

Yes

golden finch
#

I can change the argument, sure

rugged sparrow
#

You can change the argument to a max of 255 (there are ways to get larger but I'll explain that later)

golden finch
#

I have no clue what to do, but I can change the argument

rugged sparrow
#

I can show you an example implementation with comments

golden finch
#
(lambda:0).__code__.replace(co_code='\x64\0x01')

for example

rugged sparrow
golden finch
#

no clue how to implement it myself

rugged sparrow
#

Download my implementation and mess around with it

golden finch
#

okay makes sense

#

so you can load_const arbitrary memory

rugged sparrow
#

Yes

#

Once you have figured out how this works, LOAD_FAST has the same kind of bug, try to implement this there

golden finch
#

(within the context of python's memory?)

rugged sparrow
#

Yea the os limits us to pythons address space

golden finch
#

just change the 0x64 to 0x7c, right?

rugged sparrow
#

Not quite, LOAD_FAST Is related to a different object, not the consts tuple

#

So look at how LOAD_FAST is implemented and try to reason what object you need to work with

golden finch
#
TARGET(LOAD_FAST): {
            PyObject *value = GETLOCAL(oparg);
            if (value == NULL) {
                format_exc_check_arg(tstate, PyExc_UnboundLocalError,
                                     UNBOUNDLOCAL_ERROR_MSG,
                                     PyTuple_GetItem(co->co_localsplusnames,
                                                     oparg));
                goto error;
            }
            Py_INCREF(value);
            PUSH(value);
            DISPATCH();
        }
#

uh

#

ยฏ_(ใƒ„)_/ยฏ

rugged sparrow
#

We have an oparg getting passed to a #define again

#

So follow it

golden finch
#

can't find getlocal

#
#define GETLOCAL(i)     (localsplus[i])
rugged sparrow
#

Yup

#

Now find where localsplus is set

golden finch
#
PyObject **localsplus = _PyFrame_GetLocalsArray(frame);
rugged sparrow
#

We need to know where that array comes from so we get the right offset (i) from it

#

@golden finch I gtg for a bit, but try to figure out where localsplus is stored (and what the struct of that object looks like)

golden finch
#

okay

pastel ibex
#

I just wanna say you people are geniuses

golden finch
#

We're insane

#

I'm actually new here - it's fairly easy to learn

pastel ibex
#

holy cow youre new?!

golden finch
#

yeah I've only been here for maybe a week and a half

#

you have more messages than me in this server

pastel ibex
#

geez although im guessing you had pretty good knowledge of lower level stuff even before you joined

#

well i help alot in the help channels

golden finch
#

All I knew was a little bit of bytecode

#

I don't think anyone who spends time in #esoteric-python should touch the help channels

#

My bad - I've been here for ~28 days

#

and now I'm lost to the dark side

golden finch
pastel ibex
#

although the massive amount of insanity may be a bit overwhelming for the people wanting help

golden finch
#
o=__builtins__.__build_class__
__builtins__.__build_class__=lambda a,b,*c,**d:(_:=o(a,b,*c,**d),type(b,c,{i:getattr(_,i)if'_'in dir(_)and type(_._)==dict else exec((lambda:0).__code__.replace(co_consts=()))for i in dir(_)}|_._))[1]
#

yeah just ping us if any of the help channels ask for something truly awful ig

pastel ibex
#

How did you start learning this stuff if you dont mind me asking?

golden finch
#

I really just fiddled with dir() until I found __code__, then I read the documentation and some blogs on it, and I arrived here

#

yeah @rugged sparrow can't find it

rugged sparrow
#

localsplus can be found on frameobjects

golden finch
#

where?

rugged sparrow
#

Inside their c struct

#

Look in Include/cpython/frameobject.h

golden finch
tribal moon
#

Look into the implementation

#

not the header file

golden finch
#

where?

rugged sparrow
#

Make sure you're looking at 3.9

golden finch
#

I have no clue

rugged sparrow
#

I can help in an hour

golden finch
#

okay

golden finch
#

@rugged sparrow

rugged sparrow
#

sorry i got swept into looking at 3.10 optimizations

golden finch
#

all good I worked on a personal project

#

so @rugged sparrow where is the struct?

rugged sparrow
#

the struct definition is in that file you sent a link for

#

but im still looking at 3.10, prob all night

#

i can help tomorrow

golden finch
#

ok

#

can't do tmrw

rugged sparrow
#

later then

inner vector
#

hi

golden finch
river idol
#

Hello @inner vector Just wondering why you have posted 'hi' in a dozen different channels?

river idol
#

Ah. Please don't spam to get there.

inner vector
#

oh

river idol
#

If you join VC, people do read the messages in the associated text channels.

inner vector
#

ok

#

thx

golden finch
#

@rugged sparrow you free now?

rugged sparrow
#

I'm about to go to bed

golden finch
#

damn

floral meteor
#

I'm not free, I am enslaved by the need to torture python until it reveals all it's secrets, and 2+2 evaluates to 5

golden finch
#
>>> ctypes.cast(id(4),ctypes.POINTER(ctypes.c_int))[6]=5
>>> 2+2
5
floral meteor
#

Make it a bit more inherently evaluate to 5 rather than a substitution

#

Make python love big brother, not just pretend to

golden finch
#

What do you mean then? Change int.__add__ somehow?

floral meteor
#

Gimme a sec I'm on phone

#

.

#

Hmm

#

!e ```py
class Cell:
_reg = {}
_PyObject = import('ctypes').py_object
def new(cls, victim):
if id(victim)in cls._reg:return cls._reg[id(victim)]
else:return super().new(cls)
def init(self, prisoner):
type(self)._reg |= {id(prisoner):self}
self.cell_contents = prisoner
self._content_type = self._PyObject.from_address(id(prisoner)+8).value
def hack(self, new:type):
victim = self._PyObject.from_address(id(self.cell_contents)+8)
old, victim.value = victim.value, new
return old
def del(self):
self.hack(self._content_type)
del self._reg[id(self.cell_contents)]
def repr(self):
return f"<cell({self.cell_contents!r}) at {hex(id(self.cell_contents))}>"
def hash(self):return id(self.cell_contents)

class BigBrother(int):
def add(self, other):
a=super().add
return a(a(other))-1
two = 2
Cell(two).hack(BigBrother)
print ( two + two )
Cell(two).hack(int)

night quarryBOT
#

@floral meteor :white_check_mark: Your eval job has completed with return code 0.

5
golden finch
#

what the hell

#

so confused what that even does

#

also why do you name your variables like so

snow beacon
golden finch
#

True, but I don't recall 'hack' being mentioned anywhere in 1984. I've got a copy on my shelf, and I'm planning on rereading it, but I don't think I'll do it by hand.

#

Yeah, the string hack doesn't occur anywhere in the book.

snow beacon
#

I guess it's mixing its references.

#

No pun intended.

golden finch
#

challenge:

#your code here
try:
  raise
except:
  pass
else:
  print('Foo')

Make this code print Foo, by putting something at the top. The last line must be executed.

snow beacon
#

I'm not very good at ctypes, but the RuntimeError from having nothing to raise might be editable, or something could use the exception to hook into frames.

sick hound
#

i wonder why bare excepts are okay but bare raises arent

woven bridge
#

!e

try:
  raise Exception()
except Exception:
  raise # propagates the exception
night quarryBOT
#

@woven bridge :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 2, in <module>
003 | Exception
golden finch
#

but why?

woven bridge
#

sometimes you might need to do a little work after an exception occurs without making any prescriptions about what should be done with the exception

#

so the responsibility is passed on through propagation

golden finch
#

excellent loophole

#

alright you can only use official pure-python versions

woven bridge
#

!e

import dis
import sys
import ctypes

def mutable_bytes(instance: bytes):
  return memoryview(
    (ctypes.c_uint8 * len(instance)).from_address(
      id(instance) + bytes.__basicsize__ - 1
    )
  ).cast('B')

code = mutable_bytes(sys._getframe().f_code.co_code)

for i in range(0, len(code), 2):
  instruction = code[i]
  if instruction == dis.opmap['RAISE_VARARGS']:
    code[i] = dis.opmap['NOP']
      
try:
  raise
except:
  pass
else:
  print('Foo')
night quarryBOT
#

@woven bridge :white_check_mark: Your eval job has completed with return code 0.

Foo
golden finch
#

wow

#

consider me impressed

#

that's exactly the sort of voodoo I was looking for

#

how does it work?

#

(like, you're getting the frame and editing the codeObject, but how does mutable_bytes work?)

woven bridge
#

accesses the bytecode for the module frame and rewrites the instruction for the raise to one that does nothing, aka a no op

golden finch
#

how does mutable_bytes work?

#

it looks like it's an iterable of references

woven bridge
#

oh, mutable_bytes

  1. is taking the memory address of the bytes object, adding the boilerplate size for the bytes struct to it to get to the content memory id(instance) + bytes.__basicsize__ - 1
  2. using this new address to create an array of uint8 (unsigned bytes)
  3. wrapping it up in a memoryview for some extra functionality e.g. being able to slice the memory without copying
  4. and finally casting the memoryview to B (unsigned 8bit int with no prescribed endianness) because otherwise you might get complaints regarding endianness when trying to assign values to its indexes.
golden finch
#

mhm

#

voodoo

woven bridge
night quarryBOT
#

@sick hound :white_check_mark: Your eval job has completed with return code 0.

Foo
golden finch
#

you could mess that up a lot more

golden finch
#

okay

#

that's horrible syntax

#

list or array?

woven bridge
#

the right hand side is supposed to be an int, e.g. len(code) not code itself.

golden finch
#

yes, I got that

woven bridge
#

!e

import ctypes
print(ctypes.c_uint8 * 20)
night quarryBOT
#

@woven bridge :white_check_mark: Your eval job has completed with return code 0.

<class '__main__.c_ubyte_Array_20'>
golden finch
#

so it's actually an array not a list

woven bridge
#

its a class that is used to represent a fixed size c array

golden finch
#

ok

#

so now what happens if you call that class's from_address on a... byteobject's memory location?

woven bridge
# golden finch ok

from_address is a classmethod, so it returns an instance of the class which, using usual subscript syntax, can be used to access individual items of the array starting from the given address. the class also implements the buffer protocol which is why it can be passed into memoryview.

#

!e

import ctypes

data = b'\x01\x02\x03\04'

array_1 = (ctypes.c_uint8 * len(data)).from_address(id(data) + bytes.__basicsize__ -1)
print(array_1[0])
print(bytes(array_1))

array_2 = (ctypes.c_uint16 * (len(data)//2)).from_address(id(data) + bytes.__basicsize__ -1)
print(array_2[0])
print(bytes(array_2))
night quarryBOT
#

@woven bridge :white_check_mark: Your eval job has completed with return code 0.

001 | 1
002 | b'\x01\x02\x03\x04'
003 | 513
004 | b'\x01\x02\x03\x04'
woven bridge
#

and another thing is, since theyre both sharing the same underlying memory, changes in one will apply to the other

#

!e

import ctypes

data = b'\x01\x02\x03\04'

array_1 = (ctypes.c_uint8 * len(data)).from_address(id(data) + bytes.__basicsize__ -1)
array_2 = (ctypes.c_uint16 * (len(data)//2)).from_address(id(data) + bytes.__basicsize__ -1)
print(data)
print(array_2[0])

array_1[0] = 255
print(data)
print(array_2[0])

array_2[0] = 0
print(data)
print(array_1[1])
night quarryBOT
#

@woven bridge :white_check_mark: Your eval job has completed with return code 0.

001 | b'\x01\x02\x03\x04'
002 | 513
003 | b'\xff\x02\x03\x04'
004 | 767
005 | b'\x00\x00\x03\x04'
006 | 0
woven bridge
#

it's bit more involved than that

#

theyre closely related so its a description of both

#

The basic size includes the fields in the instance declared by the macro PyObject_HEAD or PyObject_VAR_HEAD (whichever is used to declare the instance struct) and this in turn includes the _ob_prev and _ob_next fields if they are present.

#

to try and summarize, the object's struct has some fields at the start that are always there in every instance (though strings are an exception to this). basicsize is the combined size of these always present fields

#

the stuff afterwards is the variable length data of the instance, each item of which takes up itemsize bytes of space

deep heart
#

hi

woven bridge
gusty island
#

people when they find this

pastel ibex
#

i might be wrong since im very new to this but it seems to be so they dont actually have to call the class

dire yew
#

nevermind, i get it now

#

so it basically creates the class

#

then initiates a class object

#

and discards the old class

#
@lambda _:_()
class A:
    pass
```is equivalent to```py
class A:
    pass
A = A()
golden finch
#

yes

dire yew
#

and of course, since it's esoteric, they have to use the underscore variable ๐Ÿ˜”

golden finch
#

Speaking of that - https://repl.it doesn't support decorators such as @lambda _:_)( - you've got to do ```py
c=lambda :()
class A:
pass

golden finch
#

"it works on my machine"

woven bridge
#

it's a python version thing. decorator syntax was relaxed significantly in 3.9. replit only uses 3.8 at the latest iirc

#

if you try to use a lambda decorator in any python version below 3.9 it wont work, replit or not.

#

!pep 614

night quarryBOT
#
**PEP 614 - Relaxing Grammar Restrictions On Decorators**
Status

Final

Python-Version

3.9

Created

10-Feb-2020

Type

Standards Track

golden finch
#

huh - thanks for the @eval("lambda _:_()") loophole!

proper vault
#

I used @getattr(0, '', lambda x:x())

pastel ibex
#

wait so why does it discard the class?

#

oh wait nvm i see now

#

what would be an actual use of this tho?

snow beacon
snow beacon
#

If you want to make a particular object, and don't care about needing its class again, then you might define the class and use the decorator on it.

pastel ibex
#

is there a way you can use the object tho from that?

snow beacon
#

The object gets stored in a variable with the name of the class.

#

!e ```py
@lambda :()
class x:
def add(self, other):
print(other)
x + "Hello, world!"

night quarryBOT
#

@snow beacon :white_check_mark: Your eval job has completed with return code 0.

Hello, world!
pastel ibex
#

ohhhh

#

thats actually kinda cool

floral meteor
#

!e i usually end up trying to make a mutable int by using

n:0 = [0]
def mutate(a):
  n [0] += a
mutate(4)
print (n [0])
night quarryBOT
#

@floral meteor :white_check_mark: Your eval job has completed with return code 0.

4
snow beacon
#

That's not very object-oriented.

floral meteor
#

I end up making a Cell that once it holds a value, it has heightened mutability

tribal moon
#

@woven bridge Any discoveries yet?

floral meteor
#

so i know that in memory an object is an array of memory starting at its id.
So far all I know about it is the 8th position after that id is a reference to it's class.
What are the other values?
i.e. 2, 4, 16, 24, 32, etc...

rugged sparrow
#

The first 8 bytes are the reference count of the object

#

Second set is the class

#

After that depends on the object

unique heath
#

!e

night quarryBOT
#
Command Help

!eval [code]
Can also use: e

*Run Python code and get the results.

This command supports multiple lines of code, including code wrapped inside a formatted code
block. Code can be re-evaluated by editing the original message within 10 seconds and
clicking the reaction that subsequently appears.

We've done our best to make this sandboxed, but do let us know if you manage to find an
issue with it!*

unique heath
#

!e

import os

print(os.getcwd())
night quarryBOT
#

@unique heath :white_check_mark: Your eval job has completed with return code 0.

/snekbox
unique heath
#

rIP

#

/snekbox

#

they were 10 steps ahead

#
import logging

logging.error('test')
woven bridge
floral meteor
#
SOME_CONSTANT = int(''.join(['0b',*{*'0123456789abcdef'*32}]),16)

a great start for a script, i guess?

pastel ibex
snow beacon
#

Sets have random-ish order. the *{*...} unpacks the string into a set, then unpacks the set into the list containing it.

pastel ibex
#

so when you unpack something into a set the order becomes random?

#

thats pretty interesting makes no sense to me but interesting

short crag
#

How to call a function with >>? So like: my_func >> "a arg".

#

I seen someone do it