public static SafeHGlobalHandle AllocHGlobal(int cb) { if (cb < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("cb", System.IdentityModel.SR.GetString("ValueMustBeNonNegative"))); } SafeHGlobalHandle handle = new SafeHGlobalHandle(); RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { IntPtr ptr = Marshal.AllocHGlobal(cb); handle.SetHandle(ptr); } return handle; }
public static SafeHGlobalHandle AllocHGlobal(int cb) { if (cb < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("cb", System.IdentityModel.SR.GetString("ValueMustBeNonNegative"))); } SafeHGlobalHandle handle = new SafeHGlobalHandle(); RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { IntPtr ptr = Marshal.AllocHGlobal(cb); handle.SetHandle(ptr); } return(handle); }
internal static byte[] ConvertHGlobalToByteArray(SafeHGlobalHandle hGlobal) { int length = SafeNativeMethods.GlobalSize(hGlobal).ToInt32(); if (length <= 0) { return null; } byte[] destination = new byte[length]; IntPtr source = SafeNativeMethods.GlobalLock(hGlobal); if (IntPtr.Zero == source) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new OutOfMemoryException()); } try { Marshal.Copy(source, destination, 0, length); } finally { SafeNativeMethods.GlobalUnlock(hGlobal); } return destination; }
internal static extern SafeCertContextHandle CertFindCertificateInStore([In] SafeCertStoreHandle hCertStore, [In] uint dwCertEncodingType, [In] uint dwFindFlags, [In] uint dwFindType, [In] SafeHGlobalHandle pvFindPara, [In] SafeCertContextHandle pPrevCertContext);
internal static extern bool GetTokenInformation([In] IntPtr tokenHandle, [In] uint tokenInformationClass, [In] SafeHGlobalHandle tokenInformation, [In] uint tokenInformationLength, out uint returnLength);
public static SafeHGlobalHandle AllocHGlobal(int cb) { if (cb < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("cb", SR.GetString(SR.ValueMustBeNonNegative))); } SafeHGlobalHandle result = new SafeHGlobalHandle(); // CER RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { IntPtr ptr = Marshal.AllocHGlobal(cb); result.SetHandle(ptr); } return result; }
internal static extern bool GlobalUnlock(SafeHGlobalHandle hGlobal);
internal static extern IntPtr GlobalSize(SafeHGlobalHandle hGlobal);
internal static extern IntPtr GlobalLock(SafeHGlobalHandle hGlobal);
private static void WriteAuditEvent(uint auditType, uint auditId, params string[] parameters) { if (!IsSecurityAuditSupported) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new PlatformNotSupportedException(System.ServiceModel.SR.GetString("SecurityAuditPlatformNotSupported"))); } Privilege privilege = new Privilege("SeAuditPrivilege"); RuntimeHelpers.PrepareConstrainedRegions(); try { try { SafeSecurityAuditHandle handle; privilege.Enable(); if (!NativeMethods.AuthzRegisterSecurityEventSource(0, "ServiceModel 4.0.0.0", out handle)) { int error = Marshal.GetLastWin32Error(); Utility.CloseInvalidOutSafeHandle(handle); throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error)); } SafeHGlobalHandle handle2 = null; SafeHGlobalHandle[] handleArray = new SafeHGlobalHandle[parameters.Length]; try { NativeMethods.AUDIT_PARAM audit_param; NativeMethods.AUDIT_PARAMS audit_params; handle2 = SafeHGlobalHandle.AllocHGlobal((int) (parameters.Length * NativeMethods.AUDIT_PARAM.Size)); long num2 = handle2.DangerousGetHandle().ToInt64(); audit_param.Type = NativeMethods.AUDIT_PARAM_TYPE.APT_String; audit_param.Length = 0; audit_param.Flags = 0; audit_param.Data1 = IntPtr.Zero; for (int i = 0; i < parameters.Length; i++) { if (!string.IsNullOrEmpty(parameters[i])) { string s = System.ServiceModel.Diagnostics.EventLogger.NormalizeEventLogParameter(parameters[i]); handleArray[i] = SafeHGlobalHandle.AllocHGlobal(s); audit_param.Data0 = handleArray[i].DangerousGetHandle(); } else { audit_param.Data0 = IntPtr.Zero; } Marshal.StructureToPtr(audit_param, new IntPtr(num2 + (i * NativeMethods.AUDIT_PARAM.Size)), false); } audit_params.Length = 0; audit_params.Flags = auditType; audit_params.Parameters = handle2; audit_params.Count = (ushort) parameters.Length; if (!NativeMethods.AuthzReportSecurityEventFromParams(auditType, handle, auditId, null, ref audit_params)) { int num4 = Marshal.GetLastWin32Error(); throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(num4)); } } finally { for (int j = 0; j < handleArray.Length; j++) { if (handleArray[j] != null) { handleArray[j].Close(); } } if (handle2 != null) { handle2.Close(); } handle.Close(); } } finally { int num6 = -1; string message = null; try { num6 = privilege.Revert(); if (num6 != 0) { message = System.ServiceModel.SR.GetString("RevertingPrivilegeFailed", new object[] { new Win32Exception(num6) }); } } finally { if (num6 != 0) { System.ServiceModel.DiagnosticUtility.FailFast(message); } } } } catch { throw; } }