https://docs.microsoft.com/en-us/windows/desktop/shell/shell-entry
文档仅仅做记录,赚一些积分
Windows UI 给用户提供了运行应用程序、管理操作系统所需要的很大范围的对象的访问能力。其中,数量最大和最熟悉的就是我们平常所使用的驻留在电脑磁盘驱动器上的文件夹和文件夹。另外也有一些虚拟对象,允许用户执行,类似将文件发送到远程打印机,或访问回收站的任务。Shell 组织这些对象到一个分级的命名空间,并给应用程序和用户提供了一个一致和高效的方法来访问和管理这些对象。
Shell 开发指南
安全性考虑
这小节,介绍Shell 相关的安全问题,但并不涉及所有的需要知道的安全信息—相反,仅仅作为一个开头和参考。
Shell 控制了系统很多的重要的方面,包括一些如果处理不当可能造成潜在安全漏洞的部分。本主题概述了一些常见问题以及如何在应用程序中解决这些问题。安全不仅仅限制在基于Internet 的开发。在共享系统上,包括可以通过终端服务访问的系统,开发人员必须确保当前用户不会做可能伤害使用系统的其它用户的事情。
正确的安装应用程序
大部分潜在的Shell安全问题,可以通过正确安装应用程序来缓解。
1. 安装应用程序到Program Files folder
Operating System | Location |
Windows XP, Windows Server 2003, and earlier | CSIDL_PROGRAM_FILES |
Windows Vista and later | FOLDERID_ProgramFiles, FOLDERID_ProgramFilesX86, FOLDERID_ProgramFilesX64, FOLDERID_ProgramFilesCommon, FOLDERID_ProgramFilesCommonX86, or FOLDERID_ProgramFilesCommonX64. See KNOWNFOLDERID for specifics. |
2. 不要将用户数据存储到Program Files folder
将所有用户共有的数据存储在恰当的文件夹
Operating System | Location |
Windows XP, Windows Server 2003, and earlier | CSIDL_COMMON_APPDATA |
Windows Vista and later | FOLDERID_ProgramData |
将特定用户的数据存储在正确的用户数据文件夹
Operating System | Location |
Windows XP, Windows Server 2003, and earlier | CSIDL_APPDATA, CSIDL_PERSONAL, and others. |
Windows Vista and later | FOLDERID_RoamingAppData, FOLDERID_Documents, and others. |
- 如果你必须将程序安装在Program Files 文件夹之外的地方,应该使用ACL 来确保用户没有访问文件系统中不恰当的地方的权限。任何特定于某个用户的数据都应该使用ACL 来禁止其它用户的访问。
- 当你建立了文件关联,应该确保正确的指定了命令行。使用全路径,并将包含了空白的空格的路径用双引号包起来。将命令参数包装在单独的引号中。否则,可能会错误的解析该字符串。下面是两个示例:
"C:\Program Files\MyApp\MyApp.exe" "%1" "%2"
C:\MyAppDir\MyApp\MyApp.exe "%1"
注意:
不同系统上,标准安装位置的位置可能不同,Vista 后的系统,使用SHGetKnownFolderPath + 正确的KNOWNFOLDERID 值,XP 和 Server2003 或更早的系统上,SHGetFolderLocation 或 SHGetFolderPath + 正确的CSIDL 值。
Shlwapi
即Shell 轻量级API,包括一系列的字符操作API。错误的使用这些API,可能没有任何截断提示的情况下将传入的字符串截断。下面的情况下,不建议使用Shlwapi,而应该使用风险更加小的,替代API
Shlwapi Function | Alternative Function |
StringCchCat, StringCbCat and related functions | |
StringCchCopy, StringCbCopy and related functions | |
StringCchPrintf, StringCbPrintf and related functions |
对于那些返回文件路径的函数,比如PathRelativePathTo,建议传入buffer,且字符数为MAX_PATH,这样可以确保有足有的缓存。
Autocomplete
密码操作时不要使用自动填充功能???
ShellExecute,ShellExecuteEx 和 相关函数
可以用来加载应用程序的API:ShellExecute,ShellExecuteEx,WinExec,和SHCreateProcessAsUserW。
- 输入全路径
- 输入命令行,且,包含空格,使用引号包起来
移动和拷贝文件
Shell 命名空间扩展是强大、灵活的给用户展示数据的一种方式。但错误的书写将导致系统错误。需要注意下面两点:
- 不要假设数据,比如图片被正确的格式化
- 不要假设MAX_PATH 是字符所占用的字节数,它代表的是字符数
安全警告
如果错误的使用下面的函数,可能会破坏所编写的应用程序的安全性
Feature | Mitigation |
应该使用全路径,以确保我们访问的是正确的文件,防止欺骗攻击 | |
Psz1,必须足够容纳psz2 和 最后的’\0’,否则可能产生溢出,使用下面的替代函数:. StringCbCat, StringCbCatEx, StringCbCatN, StringCbCatNEx, StringCchCat, StringCchCatEx, StringCchCatN, or StringCchCatNEx. | |
最后一个字符,不确保是,null-terminated,使用替代函数:. StringCbCat, StringCbCatEx, StringCbCatN, StringCbCatNEx, StringCchCat, StringCchCatEx, StringCchCatN, or StringCchCatNEx. | |
同上,. StringCbCatEx, StringCbCatNEx, StringCchCatEx, or StringCchCatNEx. | |
同StrCat StringCbCopy, StringCbCopyEx, StringCbCopyN, StringCbCopyNEx, StringCchCopy, | |
被copy 的字符,不一定是null-terminated,. StringCbCopy, StringCbCopyEx, StringCbCopyN, StringCbCopyNEx, StringCchCopy, StringCchCopyEx, StringCchCopyN, StringCchCopyNEx. | |
StrDup assumes that lpsz is a null-terminated string. Further, the returned string is not guaranteed to be null-terminated. Use one of the following alternatives instead. StringCbCat, StringCbCopyEx, StringCbCopyN, StringCbCopyNEx, StringCchCopy, StringCchCopyEx, StringCchCopyN, or StringCchCopyNEx. | |
The first argument, pszFront, must be large enough to hold pszBackand the closing '\0', otherwise a buffer overrun might occur. Be aware that the last argument, cchMax, is the number of characters to copy into pszFront, not necessarily the size of the pszFront in bytes. Use one of the following alternatives instead. StringCbCat, StringCbCatEx, StringCbCatN, StringCbCatNEx, StringCchCat, StringCchCatEx, StringCchCatN, or StringCchCatNEx. | |
The copied string is not guaranteed to be null-terminated. Use one of the following alternatives instead. StringCbPrintf, StringCbPrintfEx, StringCbVPrintf, StringCbVPrintfEx, StringCchPrintf, StringCchPrintfEx, StringCchVPrintf, or StringCchVPrintfEx. | |
The copied string is not guaranteed to be null-terminated. Use one of the following alternatives instead. StringCbPrintf, StringCbPrintfEx, StringCbVPrintf, StringCbVPrintfEx, StringCchPrintf, StringCchPrintfEx, StringCchVPrintf, or StringCchVPrintfEx. |