简体   繁体   English

是否可以锁定应用程序中通用控件使用的内存?

[英]Is it possible to lock memory used by common controls in my application?

I'm writing an application that encrypts its data. 我正在编写一个对其数据进行加密的应用程序。 It can then display it unencrypted using the app's UI after a user enters password. 然后,它可以显示它在用户输入密码后,使用应用程序的UI加密。 My goal is to minimize exposure of plaintext data while in RAM. 我的目标是尽量减少,而在RAM明文数据的曝光。 For that I want to prevent swapping it to disk as much as possible. 为此,我想尽可能避免将其交换到磁盘上。

I know that I can adjust my process's working set (by calling SetProcessWorkingSetSize API) and then lock those sensitive pages in RAM (by calling VirtualLock .) That, in theory, should minimize the chances of it being written to disk. 我知道我可以调整进程的工作集(通过调用SetProcessWorkingSetSize API),然后将这些敏感页面锁定在RAM中(通过调用VirtualLock) 。从理论上讲,这应该最大程度地减少将其写入磁盘的机会。

The question I have is, can I do the same with the memory that is used by the common controls in my dialog window, namely in Edit boxes , combo boxes , and most importantly RichEdit control? 我的问题是,我可以做所使用的通用控件在我的对话框窗口,即在内存中相同的编辑框组合框 ,最重要的RichEdit控制?

PS. PS。 I'm assuming that they all use data from the heap for my process. 我假设它们都将堆中的数据用于我的进程。 Correct? 正确?

EDIT: Seeing all the comments below I need to clarify. 编辑: 看到所有的评论下面我需要澄清。 By saying "lock", I don't mean, "lock it with a padlock and key so that no one can see it." 说“锁定”,我不是这个意思,“用挂锁和钥匙锁住它,这样没有人能看到它。” I meant, lock it as with the VirtualLock API. 我的意思是,将其锁定为与VirtualLock API。

You can use EM_SETHANDLE to set a handle for an edit control's initial allocation, then respond to EN_ERRSPACE when (if) it runs out of space and needs more. 您可以使用EM_SETHANDLE设置编辑控件的初始分配的句柄,然后在(如果)空间不足并且需要更多空间时响应EN_ERRSPACE

From there, it's up to you to also use VirtualLock on that block of memory to keep it in RAM as much as possible. 从那里开始,还取决于您是否在该内存块上使用VirtualLockVirtualLock尽可能地保留在RAM中。 If you're going to do this a lot, you probably want to consider superclassing the control(s) to keep from duplicating the code everywhere. 如果您打算做很多事情,则可能要考虑对控件进行超类化,以防止在各处复制代码。

For better or worse, I don't believe there's an equivalent for rich text controls though. 不管是好是坏,我都不相信富文本控件具有等效功能。

There is actually a native windows API to help minimize the exposure of crucial items like passwords to memory scraping. 实际上,有一个本机Windows API可以帮助最大程度地减少关键内容(例如密码)对内存刮取的影响。

See CryptProtectMemory as a starting point. 请参阅CryptProtectMemory作为起点。

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

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