This code is written in C:
int main(){
char Demoshellcode[] ="\xEB\x5D\x5F\x8B\xF7\x80\x3F";
void* addr=0;
addr=&Demoshellcode[0];
__asm call addr
return 0;
}
Can we consider it also as a standardC++ code? If not, What modifications are needed to make it as a standardC++code?
I’ll take ‘standard’ to exclude extensions but not implementation defined behavior (which is pretty much impossible to avoid anyway) or conditionally supported features.
No, the example is not standard because
__asmis an extension. You’d have to use the standardasm(...)(with implementation defined behavior) but VC++ does not supportasm().You could also convert the pointer to a function pointer (which is conditionally supported in C++11 with implementation defined behavior) and call that.
I don’t actually know if the above behaves as desired on any implementation. On modern systems you’ll have to deal with the NX bit (which allows memory to be marked such that instructions stored in that memory cannot be executed).
(Converting an object pointer to a function pointer was an extension over C++03, but C++11 added it as a conditionally supported feature.)