Hacker News new | comments | show | ask | jobs | submit login
Wildfire.py - Self-modifying Python bytecode (github.com)
66 points by adulau 1493 days ago | hide | past | web | 9 comments | favorite

Another interesting one, byteplay [1] makes bytecode-hacking childs play.

The most evil code I ever wrote [2] actually used this to modify the caller's bytecode in order to turn a log message into an exception with the correct stack trace from behind a C callback. I wouldn't recommend doing this, and I plan to excise this nasty hack at some point. Remarkably it works, even with a pretty intense multi-threaded unit test. I still don't like the idea of trusting this in production though.. You know the code in front of you must be evil if it contains a function named `re_execute_with_exception(frame, exception, traceback)`.

The problem is that the "correct" solution requires writing C/C++ code which we don't want to introduce to the project (distribution is a pain in the highly heterogeneous software environments that high energy physics has). The other correct solution is to fix upstream, which I hope will happen at some point. I look forward to the time when I can delete this code, anyway.

[1] https://code.google.com/p/byteplay/ [2] https://github.com/rootpy/rootpy/blob/master/rootpy/logger/m...

I suggest readin "5 years of bad ideas" by Armin Ronacher - https://ep2013.europython.eu/conference/talks/5-years-of-bad... (video and slides on the page). It summarizes 5 years of similar hacks.

Don't be discouraged by the first couple of hacks presented, they get more interesting as the talk goes on.

"Wildfire" is a fabulous name for a self-modifying code library. Also, I see it's GPLed, I imagine that license presents some interesting questions in the context of a self modifying program.

Maybe, but I think there is also a reasonably straightforward interpretation of self-modifications as being mere processing output and not a derivative work (since computers cannot currently hold copyright anywhere that I know of). Now, if a person ran the self-modifying code (for example, by emulating a Turing machine with a pen and paper) and distributed the output (for example, over a network, as a result of running the program), the person might have the obligations of the GPL (or be in breach of them, if he or she distributed a derivative work in violation of them as a result of interpretation), if they licensed the code under the GPL, in the same way that processing/modifying and then distributing any GPL code would, whether the tools used were GPL or not. If that person were the original copyright holder, however, they could still do whatever they want (for example, releasing the modifications without the GPL) since they have the full rights, not merely the GPL-granted ones.

The big question this raises is: on a network of devices, what constitutes the operator's computer and what is the threshold past which execution would constitute distribution. It goes without saying that IANAL.

Cool! I don't really know what the heck it does, but I like seeing weird examples of Python's other side.

I don't know much about the underworld of Python, but is this kind of stuff similar to what PyPy does?

I started working on a visualizer for Python's AST (example [0]). I think it would be really cool to blend a lot of the functions of the underbelly of Python to see what's really happening. An AST side by side with a bytecode interpretation of it (or something). I haven't done too much looking, but there doesn't seem to be as much information about the inner workings of Python, just uses of it.

[0] http://imgur.com/IKXcoAp (I use Nodebox OpenGL for graphing)

I'm always up for some crazy unsafe python tricks, but ... what is going on here? :)

would be nice to have a more descriptive description for this project

There are tons of comments in the code, it's actually pretty readable. The title here is about as descriptive as it gets, but if I were to make it better I would add 'by making a .pyc file'.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact