I am attempting to encrypt a string at compile-time, but the string seems to still be present in the data of my executable.
I disabled all optimizations, but yet it is still there
class str {
public:
template<unsigned int Size>
constexpr str(wchar_t(&String)[Size], wchar_t KeyCharacter)
: m_Buffer{}, m_Key{}, m_Size{} {
this->m_Size = Size;
this->m_Key = KeyCharacter;
this->SetString(String);
}
~str() {
}
template<unsigned int Size>
constexpr void SetString(wchar_t(&String)[Size]) {
for(unsigned int i{}; i < this->m_Size; ++i) {
this->m_Buffer[i] = String[i] ^ this->m_Key;
String[i] = L'\0';
}
this->m_Buffer[this->m_Size] = L'\0';
}
constexpr wchar_t* GetString() {
return this->m_Buffer;
}
wchar_t m_Buffer[250];
wchar_t m_Key;
unsigned int m_Size;
};
int main() {
wchar_t unstr[] = { L"Hello, world!" };
str s(unstr, L'a');
getchar();
return 0;
}
BTW, the code does not evaluate into a memcpy call, that's just the pseudocode's interpretation
As you can see, the hello world text is still there, but in the SetString function I empty it out. It is empty at run-time, but it still appears in the binary.
What is going on here? Why is the string still there? How can I fix it?