是否可以调用导出的“私有”文件? C ++中的方法 [英] Is it possible to Invoke an exported "private" method in c++

查看:81
本文介绍了是否可以调用导出的“私有”文件? C ++中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以调用从DLL导出的类的私有方法?

它会被那些想使用它但不应该使用的人隐藏吗?

谢谢:)

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.

例如:


  • 使用 GetProcAddress()来获取函数的地址,将其转换为正确的成员函数类型,然后调用它。 / li>
  • 创建该类的修改后的头文件,将所有内容声明为公共(或仅添加静态函数, void crowbar()),对此进行编译。 (未定义的行为,因为您违反了一个定义规则,但它可能会起作用...)

  • 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...)

不依靠C ++私有关键字来保证安全性。

这篇关于是否可以调用导出的“私有”文件? C ++中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆