gpt4 book ai didi

c++ - 想看懂这篇使用模板的论文

转载 作者:太空宇宙 更新时间:2023-11-04 11:35:48 24 4
gpt4 key购买 nike

我在搜索有关 C++ 模板元编程的链接时发现了这篇论文。我对 C++ 中的安全性和模板都不熟悉,希望有人能给我指出正确的方向。我无缘无故地要求它激起我的兴趣,而且我想了解更多信息。

这是论文:https://www.cisuc.uc.pt/publication/showfile?fn=1357250736_metaobfv3.pdf

或者只搜索名称:Binary code obfuscation through C++ template metaprogramming

我似乎无法弄清楚程序员会如何使用它。他们是通过模板创建类型然后在原始代码本身中使用这些类型吗?这是使用的一些代码:

struct uint32 {
unsigned int x_;
uint32(unsigned int x) : x_(x) {}
uint32(const uint32 &oth) : x_(oth.x_) {}
uint32 &operator=(const uint32 &oth) { x_ = oth.x_; return *this; }
operator unsigned int() const { return x_; }
};

static inline uint32 operator+(const uint32 &a, const uint32 &b) {
return uint32(ObfuscatedAdder<unsigned int>::eval(a.x_, b.x_));
}

这是第 6 页的一小部分。我正在尝试弄清楚使用他们的技术的程序员将如何着手创建……让我们说一个算法……然后混淆它。

这将是我假设的附加混淆。我将如何接受这样的声明:

unsigned int foo = 5 + 7;

在代码中并使用模板将其混淆成更复杂的身份?

最佳答案

unsigned int foo = 5 + 7; 不会被混淆,因为它属于 constant folding。并将在编译时简单地替换为 unsigned int foo = 12;

该技术对于像这样的表达式特别有用。

uint32 a = 5;
uint32 b = 7;
unsigned int foo = a + b;

关于c++ - 想看懂这篇使用模板的论文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23101823/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com