Loosely related: I recall using raw Python bytecode manipulation to deal with obfuscated malware, as described here: https://www.mandiant.com/resources/deobfuscating-python
I did this a while back. It is not as detailed as this post, but implemented in pyodide. So you can explore online.
Happy to answer questions or hear your feedback!
I think that the link to Skybison is broken.
Have you looked at PyPy’s translation process? The RPython toolchain also builds a collection of basic blocks from bytecode.
Thanks for the tip! Fixing it now. I’ll take a look at PyPy…
EDIT: Oh, very neat. I should add a link to that somewhere.