【问题标题】:Using SetWindowText in WIN32 GDI, and securely deleting data typed in在 WIN32 GDI 中使用 SetWindowText,并安全删除输入的数据
【发布时间】:2011-05-01 04:36:29
【问题描述】:

我希望安全地删除(甚至不是内存中的痕迹)用户在文本框中键入的任何内容。我想知道将其设置为"" 是否足够安全。 SetWindowText 是 Win32 API 中的一个函数,在 user32.dll 中。

在节目中:

SetWindowText(myHandle, "Hello");
SetWindowText(myHandle, "Goodbye");

//Was the buffer containing chars "Hello" overwritten by the
//series of chars "Goodb"?

//Or was another chunk of buffer being allocated to store "Goodbye",
//hence "Hello" still exist somewhere in the memory?

SetWindowText(myHandle, "");
//What does Windows do to the buffer that used to store chars "Goodbye"?
//Does it wipe out and replace the data in the buffer to all 0s here?
//Or does "Goodbye" actually still stays in the memory?

【问题讨论】:

  • 你的意思可能是“你好”(双引号)

标签: c++ security winapi memory gdi


【解决方案1】:

这在形式上是未指定的,并且在实践中相当复杂。因此,简单的答案是“不,它不安全”

【讨论】:

    【解决方案2】:

    不,它不安全,因为 GDI 会多次复制您的字符串,例如使其成为宽字符字符串:您使用 SetWindowTextA 但它只是 SetWindowTextW 的包装器,因此 SetWindowTextA 将您的字符串复制到宽字符字符串。

    对于安全解决方案,您应该使用自定义用户输入处理(WM_KEY* 等)和自定义呈现(WM_DRAW)来实现自己的文本框。

    要检查其安全性,请在 OllyDbg 下运行您的程序并扫描整个内存以查找您的字符串(Alt-M、Ctrl-B)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-10
      • 2015-02-01
      • 2019-08-07
      • 2023-03-05
      • 2015-11-10
      • 2020-09-01
      • 2019-11-28
      • 1970-01-01
      相关资源
      最近更新 更多