2010-10-27 30 views
0

中輸入的數據我希望安全地刪除(甚至是內存中的跟蹤)任何用戶輸入到文本框中的數據。我想知道是否將它設置爲""足夠安全。 SetWindowText是Win32 API中的函數,位於user32.dll在WIN32 GDI中使用SetWindowText,並安全地刪除在

在節目:

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? 
+0

你可能意思是「你好」(雙引號) – MSalters 2010-10-27 08:58:32

回答

1

不,它是不安全的,因爲GDI多次複製您的字符串,例如,使它廣泛字符串:您使用SetWindowTextA,但它只是一個包裝SetWindowTextW,因此SetWindowTextA將您的字符串複製到寬字符字符串。

對於安全的解決方案,您應該使用自定義用戶輸入處理(WM_KEY *等)和自定義渲染(WM_DRAW)來實現自己的文本框。

要檢查其安全性,請在OllyDbg下運行程序,並掃描整個內存以查找字符串(Alt-M,Ctrl-B)。

2

這是正式指定,並在實踐中非常複雜。因此,簡單的答案是「不,它不安全」