The offset-calculation technique here is exactly what tools like pwntools' cyclic() and GDB's pattern-create automate when CTF players and pentesters find the exact byte count to hijack RIP. It is also the mechanism behind decades of real exploits, from early Linux/x86 shellcode injection through today's patched CVEs in network daemons and media parsers.