在gcc中,这个很好用。代码大致如下:
但是当将此代码放入Visual C++中时,会提示以下错误信息:
有人知道为什么会这样吗?
unsigned char b[50] = "\xda\xd1 ... \x0"; //some shellcode with terminating \x0
( (void(*)())b )(); //cast b to function pointer from void to void, then run it
但是当将此代码放入Visual C++中时,会提示以下错误信息:
1>..\test.cpp(132): error C2440: 'type cast' : cannot convert from 'unsigned char [50]' to 'void (__cdecl *)(void)'
1> There is no context in which this conversion is possible
有人知道为什么会这样吗?
reinterpret_cast<void(*)()>(static_cast<char*>(b))()
。 - Kerrek SB@NiklasB. (*(void(*)())&b[0])()
在运行时崩溃。 首先,&b[0]与b相同。 其次,开头的额外*对函数指针进行了解引用; 我认为它然后尝试将shellcode解释为地址。 - jcai***********************************fun_ptr
示例的来源。 - R. Martinho Fernandes