~ Is it possible to read the bytes of a function, put them into an array, create a function pointer to the beginning address of the array and then execute the function pointer
So obviously there are a lot of things that would need to be done, the best method I have currently for getting the bytes in a function is to create a pointer, and iterate through each memory address until I hit the RET (0xc3) instruction. I've managed to Frankenstein together some code, but no matter what happens I get an access violation, which leads me to my question, is this even possible, is there a procedure that needs to be followed to allow this to happen.
Rough Example:
void function() {
//do something
return;
}
int main() {
size_t size = sizeofFunc(function); //uses method listed earlier
unsigned char* bytes = new unsigned char[size];
// for each memory address from 'function' to 'function + size' put contents into 'bytes'
void(*vFuncPtr)(void) = (void(*)(void))bytes;
vFuncPtr(); // Access Violation, is this even possible???
}