import ast import inspect import types import asyncio import dis import platform import socket class InsanityInjector(ast.NodeTransformer): def visit_FunctionDef(self, node): print(f"Mutating function: {node.name}") new_node = ast.Expr( value=ast.Call( func=ast.Name(id='print', ctx=ast.Load()), args=[ast.Constant(value=f"Function {node.name} has been modified at runtime!")], keywords=[] ) ) node.body.insert(0, new_node) return node def generate_and_compile_insane_code(): source = inspect.getsource(insane_payload) tree = ast.parse(source) mutated_tree = InsanityInjector().visit(tree) ast.fix_missing_locations(mutated_tree) code = compile(mutated_tree, filename="", mode="exec") return code def insane_payload(): print("Original function running...") hostname = socket.gethostname() os_info = platform.platform() print(f"System: {os_info} | Hostname: {hostname}") async def nested_async_magic(): await asyncio.sleep(0.1) print("Async function ran inside modified function!") asyncio.run(nested_async_magic()) def disassemble_bytecode(func): print(f"\nDisassembled bytecode of {func.__name__}:") dis.dis(func) if __name__ == "__main__": print("== 🧠 Welcome to the Python Insanity Engine ==\n") # Disassemble original function disassemble_bytecode(insane_payload) # Generate, mutate, and compile function on the fly code_obj = generate_and_compile_insane_code() # Create an isolated namespace to exec insane_globals = globals().copy() insane_locals = {} exec(code_obj, insane_globals, insane_locals) # Grab the mutated function and run it mutated_func = insane_locals['insane_payload'] print("\n== 🔁 Executing mutated function ==\n") mutated_func() # Disassemble mutated function disassemble_bytecode(mutated_func)