The meaning is as follows:
- There is a temporary buffer, the usual string, it gets a password.
- I need to clear all traces of this password so that those who are especially gifted cannot find it through the disassembler for example.
For example:
int main() { std::string str = { "Hello World!" }; printf_s("%s\n%#x", str.c_str(), &str); while (true) { Sleep(1); } return 0; } Open the well-known disassembler (if you can call it that) and open our process and search the string "Hello World!", We find the following:
Then the first thing that occurred to me was to use the SecureZeroMemory function.
We try:
int main() { std::string str = { "Hello World!" }; printf_s("%s\n%#x", str.c_str(), &str); SecureZeroMemory(&str, str.capacity()); while (true) { Sleep(1); } return 0; } We repeat the manipulations with the disassembler, this is what it finds:
Already better, there are "2 findings" + one of these addresses, as I suppose the printf_s call, but the second base one did not get lost. Next, I used the fill algorithm, the result is the same.
Ultimately, I want to destroy all traces of the password so that lovers of reverse code could not find anything. Please suggest options.


stringis stored, and the buffer used by it, generally speaking, is far from there ... for example, walk the entire length of the stringstr, overwriting its characters with spaces. what you did, generally speaking, should crash the program in the end ... - HarrySecureZeroMemory(str.c_str(), str.length());? - Qwertiy ♦