|
CLR hosts specify which host protection categories they'd like to block using the host protection manager from the CLR hosting interfaces. The host protection manager has just one interface, ICLRHostProtectionManager. As its name indicates (following the naming convention used throughout the hosting interfaces), ICLRHostProtectionManager is implemented by the CLR, not by the host. A host obtains an ICLRHostProtectionManager interface pointer from the CLR through the standard CLR control object described in Chapter 2. Given this pointer, a host then calls its SetProtectedCategories method to specify which host protection categories to block. Here's the definition of ICLRHostProtectionManager from mscoree.idl: interface ICLRHostProtectionManager : IUnknown { HRESULT SetProtectedCategories([in] EApiCategories categories); }; The host specifies which categories to block by performing an OR operation on values from the EApiCategories enumeration. EApiCategories is the unmanaged equivalent of the System.Security.Permissions.HostProtectionResource enumerations used to specify the host protection categories in managed code: typedef enum { eNoChecks = 0, eSynchronization = 0x1, eSharedState = 0x2, eExternalProcessMgmt = 0x4, eSelfAffectingProcessMgmt = 0x8, eExternalThreading = 0x10, eSelfAffectingThreading = 0x20, eSecurityInfrastructure = 0x40, eUI = 0x80, eMayLeakOnAbort = 0x100, eAll = 0x1ff } EApiCategories; As you can see, enabling host protection is relatively straightforward. The real challenge with this feature is not in writing the code required to enable it, but rather in the analysis to determine which host protection categories should be blocked in your particular scenario. Now that I've covered the details of the host protection features, let's enable it in one of our existing example hosts. |
|