【问题标题】:C++ #define that gets a string获取字符串的 C++ #define
【发布时间】:2017-11-02 15:33:11
【问题描述】:

我想创建一个非常基本的混淆方法,基本上我只想xor每个字符串都这样调用

printf("%s\n", OBF("Test"));

会产生类似的东西

printf("%s\n", unxor("\x65\x54\x42\x45"));

在这种情况下,我用1 对字符串进行了异或运算

【问题讨论】:

标签: c++ obfuscation xor pre-compilation


【解决方案1】:

使用现代 C++,你可以不用任何宏来编写它:

#include <iostream>
#include <array>
#include <utility>
#include <cstddef>

constexpr const char key_byte{'1'};

template<::std::size_t VArrayItemsCount, ::std::size_t... Is> constexpr auto
obf_impl
(
    ::std::index_sequence<Is...>
,   char const ( & sz_text )[VArrayItemsCount]
)
-> ::std::array<char, VArrayItemsCount>
{
    return(::std::array<char, VArrayItemsCount>{static_cast<char>(sz_text[Is] ^ key_byte)..., '\0'});
}

template<::std::size_t VArrayItemsCount> constexpr auto
obf
(
    char const ( & sz_text )[VArrayItemsCount]
)
-> ::std::array<char, VArrayItemsCount>
{
    return
    (
        obf_impl<VArrayItemsCount>
        (
            ::std::make_index_sequence<VArrayItemsCount - ::std::size_t{1}>()
        ,   sz_text
        )
    );
}

int main()
{
    constexpr const auto hello{obf("hello")};
    ::std::cout << hello.data() << ::std::endl;
    return 0;
}

Run this code in online compiler

【讨论】:

    猜你喜欢
    • 2017-08-27
    • 2017-03-07
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2011-05-25
    相关资源
    最近更新 更多