'Converting a HEX user input to executable HEX and not a string

Scope: I am trying to research on a malware where a ShellCode in HEX is statically declared in a variable. I am trying to make it dynamic so it can work on the same hex but taken from user input. The desired output is that calculator.exe will pop up as the shellcode is meant to do that.

I tried: With taking user input with CIN but it doesn't work and I will show you how. Doing a static declaration like: Unsigned Char [] = "\xfc\x48\x83\xe4\xf0\xe8\xc0\x00\.................etc"; gives me a gibberish output like ----> ⁿHâΣ≡Φ└ <----- But this one works fine.

BUT

Doing:

unsigned char shcode[9096];
cout << "Enter Shellcode: " << endl;
cin >> hex >> shcode;

and giving the same shellcode, returns the exact shellcode in the screen like: output -> "\xfc\x48\x83\xe4\xf0\xe8\xc0\x00.................etc".

Question: Is there any way I am making a wrong conversion or not doing something that should be done?

Thanks for your time.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source