Hack Forums
[C] C++ convert function to unsigned char array - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] C++ convert function to unsigned char array (/showthread.php?tid=5896792)



C++ convert function to unsigned char array - eyehollow - Oct 19, 2018

How to convert function to unsigned char array (*void pointer)
I'm sorry if I do not understand correctly what is *void pointer
For example i have functions like this

Example 1
Code
void test(){
 std::cout << "Hello" << std::endl;
}

Example 2
Code
void test2(int a){
 std::cout << "Hello" << std::endl;
 std::cout << std::to_string(a) << std::endl;
}

Example 3
Code
int test3(int a){
 return a;
}

In short i need univesal method to convert any method(function) to raw data.
I need to save this functions as array or vector of unsigned char.

Someone can help me?
Thank you so much.


RE: C++ convert function to unsigned char array - Auriana - Oct 19, 2018

Code
unsigned char* function = (unsigned char*)test;
//remove page protection
unsigned char functioncopy[SIZE_OF_FUNCTION] = {0};
memcpy(functioncopy,function,SIZE_OF_FUNCTION);
//restore page protection