简体   繁体   English

如何从进程内存中删除字符串?

[英]How to remove string from process memory?

I have an application which takes a string from the Windows Forms text box and passes it to an API which uses a string as the parameter. 我有一个应用程序,该应用程序从Windows窗体文本框中获取字符串,并将其传递给使用字符串作为参数的API。 I see that the string can still be queried from the process memory after the task is complete. 我看到任务完成后,仍然可以从进程内存中查询字符串。 I have come across suggestions to use SecureString for string memory management capabilities. 我遇到了一些建议,可以将SecureString用于字符串内存管理功能。 But, if I understand correctly, the purpose of the string is defeated if the secure string is built from a string or the value of the secure string is ultimately stored in a string. 但是,如果我理解正确,那么,如果安全字符串是根据字符串构建的,或者最终将安全字符串的值存储在字符串中,那么字符串的目的就无法实现。

Please suggest what is the best possible solution. 请提出最佳解决方案。

SecureString is not considered secure. SecureString不被认为是安全的。 If you need to do this, you can either use a char[] and overwrite the data once done, or you can use unsafe code to overwrite a string when done (just... hope it wasn't interned or a shared reference); 如果需要执行此操作,则可以使用char[]并在完成后覆盖数据,也可以在完成后使用unsafe代码来覆盖string (只是...希望它没有被检查或共享引用)。 ; note that this applies everywhere in the call stack. 注意,这适用于无处不在的调用堆栈。 Note that the OS may have copied the page for various reasons and it may even be on disk (swap file) if the memory wasn't very carefully allocated. 请注意,操作系统可能出于各种原因复制了该页面,如果内存分配不是仔细,它甚至可能位于磁盘(交换文件)上。

However, by the time memory analysis tools are a factor in a winforms app, it would be easier to use a key logger, or just take a wrench and threaten someone for the password: 但是,当内存分析工具成为winforms应用程序中的一个因素时,使用按键记录器或仅用扳手威胁他人输入密码会更容易:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM