本文整理汇总了C#中System.Security.PermissionSet.AddPermission方法的典型用法代码示例。如果您正苦于以下问题:C# System.Security.PermissionSet.AddPermission方法的具体用法?C# System.Security.PermissionSet.AddPermission怎么用?C# System.Security.PermissionSet.AddPermission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.PermissionSet
的用法示例。
在下文中一共展示了System.Security.PermissionSet.AddPermission方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public static int Load([MarshalAs(UnmanagedType.LPWStr)]String inParam)
{
try
{
lock (_lock)
{
_injectCount++;
if (_easyHookDomain == null)
{
System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.AllFlags));
// Evidence of null means use the current appdomain evidence
_easyHookDomain = AppDomain.CreateDomain("EasyHook", null, new AppDomainSetup()
{
ApplicationBase = Path.GetDirectoryName(typeof(Loader).Assembly.Location),
// ShadowCopyFiles = "true", // copies assemblies from ApplicationBase into cache, leaving originals unlocked and updatable
}, ps);
}
}
int result = -1;
// Load the EasyHook assembly in the child AppDomain by using the proxy class
Type proxyType = typeof(LoadEasyHookProxy);
if (proxyType.Assembly != null)
{
// This is where the currentDomain.AssemblyResolve that we setup within the static
// constructor is required.
var proxy = (LoadEasyHookProxy)_easyHookDomain.CreateInstanceFrom(
proxyType.Assembly.Location,
proxyType.FullName).Unwrap();
// Loads EasyHook.dll into the AppDomain, which in turn loads the target assembly
result = proxy.Load(inParam);
}
//result = new LoadEasyHookProxy().Load(inParam);
return result;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Exception occured within Loader.Load: " + e.ToString());
}
finally
{
lock (_lock)
{
_injectCount--;
}
}
// Failed
return -1;
}
示例2: GetErasFromRegistry
[System.Security.SecuritySafeCritical] // auto-generated
private static EraInfo[] GetErasFromRegistry()
{
// Look in the registry key and see if we can find any ranges
int iFoundEras = 0;
EraInfo[] registryEraRanges = null;
#if !MONO
try
{
// Need to access registry
PermissionSet permSet = new PermissionSet(PermissionState.None);
permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
permSet.Assert();
RegistryKey key = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(c_japaneseErasHive, false);
// Abort if we didn't find anything
if (key == null) return null;
// Look up the values in our reg key
String[] valueNames = key.GetValueNames();
if (valueNames != null && valueNames.Length > 0)
{
registryEraRanges = new EraInfo[valueNames.Length];
// Loop through the registry and read in all the values
for (int i = 0; i < valueNames.Length; i++)
{
// See if the era is a valid date
EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());
// continue if not valid
if (era == null) continue;
// Remember we found one.
registryEraRanges[iFoundEras] = era;
iFoundEras++;
}
}
}
catch (System.Security.SecurityException)
{
// If we weren't allowed to read, then just ignore the error
return null;
}
catch (System.IO.IOException)
{
// If key is being deleted just ignore the error
return null;
}
catch (System.UnauthorizedAccessException)
{
// Registry access rights permissions, just ignore the error
return null;
}
//
// If we didn't have valid eras, then fail
// should have at least 4 eras
//
if (iFoundEras < 4) return null;
//
// Now we have eras, clean them up.
//
// Clean up array length
Array.Resize(ref registryEraRanges, iFoundEras);
// Sort them
Array.Sort(registryEraRanges, CompareEraRanges);
// Clean up era information
for (int i = 0; i < registryEraRanges.Length; i++)
{
// eras count backwards from length to 1 (and are 1 based indexes into string arrays)
registryEraRanges[i].era = registryEraRanges.Length - i;
// update max era year
if (i == 0)
{
// First range is 'til the end of the calendar
registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
}
else
{
// Rest are until the next era (remember most recent era is first in array)
registryEraRanges[i].maxEraYear = registryEraRanges[i-1].yearOffset + 1 - registryEraRanges[i].yearOffset;
}
}
#endif
// Return our ranges
return registryEraRanges;
}
示例3: EnlistDistributedTransactionHelper
// NOTE: This is just a private helper because OracleClient V1.1 shipped
// with a different argument name and it's a breaking change to not use
// the same argument names in V2.0 (VB Named Parameter Binding--Ick)
private void EnlistDistributedTransactionHelper(System.EnterpriseServices.ITransaction transaction) {
System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
permissionSet.AddPermission(CONNECTIONOBJECTNAME.ExecutePermission); // MDAC 81476
permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode));
permissionSet.Demand();
Bid.Trace( "<prov.DbConnectionHelper.EnlistDistributedTransactionHelper|RES|TRAN> %d#, Connection enlisting in a transaction.\n", ObjectID);
SysTx.Transaction indigoTransaction = null;
if (null != transaction) {
indigoTransaction = SysTx.TransactionInterop.GetTransactionFromDtcTransaction((SysTx.IDtcTransaction)transaction);
}
RepairInnerConnection();
// NOTE: since transaction enlistment involves round trips to the
// server, we don't want to lock here, we'll handle the race conditions
// elsewhere.
InnerConnection.EnlistTransaction(indigoTransaction);
// NOTE: If this outer connection were to be GC'd while we're
// enlisting, the pooler would attempt to reclaim the inner connection
// while we're attempting to enlist; not sure how likely that is but
// we should consider a GC.KeepAlive(this) here.
GC.KeepAlive(this);
}
示例4: GetPermissionSet
private System.Security.PermissionSet GetPermissionSet(ISecurityAttribute securityAttribute) {
var result = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
foreach (var attribute in securityAttribute.Attributes) {
var permission = this.GetPermission(securityAttribute.Action, attribute);
if (permission == null) continue; //not a trusted permission
result.AddPermission(permission);
}
return result;
}
示例5: CreateAppDomain
void CreateAppDomain()
{
System.AppDomainSetup pythonAppDomainSetup = new AppDomainSetup();
pythonAppDomainSetup.ApplicationBase = ".";
bool usePermissionTest = false;
if (usePermissionTest)
{
System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Execution));
//permissionSet.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted));
compilerAppDomain = System.AppDomain.CreateDomain("Python App Domain", null, pythonAppDomainSetup, permissionSet, null);
}
else
{
compilerAppDomain = System.AppDomain.CreateDomain("Python App Domain");
}
Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
}
示例6: Load
public static int Load([MarshalAs(UnmanagedType.LPWStr)]String inParam)
{
try
{
lock (_lock)
{
try
{
_injectCount++;
if (_easyHookDomain == null)
{
System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.AllFlags));
// Evidence of null means use the current appdomain evidence
_easyHookDomain = AppDomain.CreateDomain("EasyHook", null, new AppDomainSetup()
{
ApplicationBase = Path.GetDirectoryName(typeof(Loader).Assembly.Location),
// ShadowCopyFiles = "true", // copies assemblies from ApplicationBase into cache, leaving originals unlocked and updatable
}, ps);
}
}
catch (OutOfMemoryException ome)
{
// Creation of AppDomain failed, so fall back to using default domain (means it cannot be unloaded)
// The reason is there could be an issue with the target application's stack commit size.
// The default stack commit size must be <= 253952 (or 0x3E000) - due to bug in .NET Framework,
// this can be checked with dumpbin.exe and edited with editbin.exe.
// Load EasyHook and the target assembly
LoadEasyHookProxy lp = new LoadEasyHookProxy();
lp.Load(inParam);
return 1;
}
}
int result = -1;
// Load the EasyHook assembly in the child AppDomain by using the proxy class
Type proxyType = typeof(LoadEasyHookProxy);
if (proxyType.Assembly != null)
{
// This is where the currentDomain.AssemblyResolve that we setup within the static
// constructor is required.
var proxy = (LoadEasyHookProxy)_easyHookDomain.CreateInstanceFrom(
proxyType.Assembly.Location,
proxyType.FullName).Unwrap();
// Loads EasyHook.dll into the AppDomain, which in turn loads the target assembly
result = proxy.Load(inParam);
}
//result = new LoadEasyHookProxy().Load(inParam);
return result;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Exception occurred within Loader.Load: " + e.ToString());
}
finally
{
lock (_lock)
{
_injectCount--;
}
}
// Failed
return -1;
}