开发者

Is it possible to Invoke an exported "private" method in c++

Is it possible to invoke a private method of a class exported from a DLL?

Will it be hidden from people who would like to use it but are not supposed 开发者_如何学编程to?

thanks :)


Yes, it's possible, but you need to use dirty casting tricks or rely on semi-undefined behaviour, but for certainty you can call an exported function, no matter it's private/public status.

The language does not provide security against malicious attackers. It will help everyone play by the rules, but it will not guard against those who try to break the system.

For instance:

  • use GetProcAddress() to get the function's address, cast it to the right member function type, and call it.
  • create a modified header file of the class, declaring everything as public (or just add a static function, void crowbar() ), compile against that. (Undefined behaviour, since you're violating the One Defintion Rule, but it will probably work...)

Do not rely on C++ private keyword for security.


If it appears in the DLL's export table, it can be invoked by using GetProcAddress and calling the returned function pointer. There are some technical hurdles to get the right calling convention, but it is possible (most likely some assembly language will be required).

Strictly speaking, any function for which the compiler generates an out-of-line instance can be called by any native code. Being exported by a DLL just makes it far easier to find the address of the code for the function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜