This array can be executed with ((void(*)())code)(), which creates a void function pointer to the array and then calls that pointer.
To execute our opcode we first create an unsigned char array (the distinction between unsigned/signed char is important when working with hex) called code. The user mode technique is adapted from several examples on GitHub (unfortunately I can’t now find the original posts) and can also be implemented in Python. You can of course create a pure hex file and convert it into a binary, but that’s a nightmare if you want to code the equivalent of thousands of lines of C! I hope you find these techniques for executing machine code in user mode and kernel mode useful. I wanted to create a C program automating the testing and analysis of millions of undocumented instructions, so it had to be machine code rather than assembly as there were no mnemonics for them. When I started trying to test undocumented opcodes, I struggled to find a technique for integrating machine code into higher-level code.
This is part of a series of blog posts on undocumented opcode fuzzing.