public unsafe bool Check(byte[] fileimage) { if (this.TagName == "head") fixed(byte *img = &fileimage[0]) { // reset checkSumAdjustment headTable *head = (headTable *)(img + (uint)this.offset); ULONG csa = head->checkSumAdjustment; head->checkSumAdjustment = (ULONG)0; bool ret = this.CalculateTableSum(fileimage) == (uint)this.checkSum; // Check checkSumAdjustment OffsetTable * offset = (OffsetTable *)img; TableDirectoryEntry *entry = (TableDirectoryEntry *)(offset + 1); TableDirectoryEntry *end = entry + (uint)offset->numTables; uint sum = (uint)offset->Sum; for (; entry < end; entry++) { sum += entry->Sum; sum += (uint)entry->checkSum; } // restore checkSumAdjustment head->checkSumAdjustment = csa; return(ret); //&&sum==0xB1B0AFBA-(uint)csa; } return(this.CalculateTableSum(fileimage) == (uint)this.checkSum); }
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetCustomErrorObject( /* [in] */ ULONG ulRecordNum, /* [in] */ REFIID riid, /* [iid_is][out] */ IUnknown **ppObject) = 0;
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetBasicErrorInfo( /* [in] */ ULONG ulRecordNum, /* [out] */ ERRORINFO *pErrorInfo) = 0;
public BOOL Receive([In] RIO_RQ SocketQueue, [In] ref RIO_BUF pData, [In] ULONG DataBufferCount, [In] DWORD Flags, [In] PVOID RequestContext) => receive(SocketQueue, ref pData, DataBufferCount, Flags, RequestContext);
public unsafe bool Check(byte[] fileimage) { if (this.TagName == "head") fixed(byte *img = &fileimage[0]) { // reset checkSumAdjustment headTable *head = (headTable *)(img + (uint)this.offset); ULONG csa = head->checkSumAdjustment; head->checkSumAdjustment = (ULONG)0; uint csaR = 0xB1B0AFBA - (uint)csa; bool ret = this.CalculateTableSum(fileimage) == (uint)this.checkSum; // Check checkSumAdjustment OffsetTable * offset = (OffsetTable *)img; TableDirectoryEntry *entry = (TableDirectoryEntry *)(offset + 1); TableDirectoryEntry *end = entry + (uint)offset->numTables; uint sum = (uint)offset->Sum; for (; entry < end; entry++) { sum += entry->Sum; sum += (uint)entry->checkSum; } uint sum2 = this.SumEntireFont(fileimage); // restore checkSumAdjustment head->checkSumAdjustment = csa; if (sum != sum2) { System.Console.WriteLine("checkSums of all the structures and the entire file are diffrent from each other."); if (sum == csaR) { System.Console.WriteLine("checkSumAdjustment is calculated from all the structures."); } else if (sum2 == csaR) { System.Console.WriteLine("checkSumAdjustment is calculated from the entire file."); } else { System.Console.WriteLine("Neither structures nor entire file is used to calculate checkSumAdjustment: 0x{0:X8}", csaR); } } else { if (sum != csaR) { System.Console.WriteLine("checkSumAdjustment is unexpected value: 0x{0:X8}", csaR); } } System.Console.WriteLine("Σ1: 0x{0:X8}; checkSumAdjustment: 0x{1:X8}", sum, csaR); System.Console.WriteLine("Σ2: 0x{0:X8}; checkSumAdjustment: 0x{1:X8}", sum2, csaR); System.Console.WriteLine("Σ1 〜 checkSumAdjustment: 0x{0:X8} / 0x{1:X8}", csaR - sum, sum - csaR); System.Console.WriteLine("Σ2 〜 checkSumAdjustment: 0x{0:X8} / 0x{1:X8}", csaR - sum2, sum2 - csaR); return(ret); } return(this.CalculateTableSum(fileimage) == (uint)this.checkSum); }
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetCustomErrorObject( /* [in] */ ULONG ulRecordNum, /* [in] */ REFIID riid, /* [iid_is][out] */ IUnknown **ppObject) = 0;
public ULONG DequeueCompletion([In] RIO_CQ CQ, [In] IntPtr Array, [In] ULONG ArraySize) => dequeueCompletion(CQ, Array, ArraySize);
/// <summary> /// Get the native (unmanaged) representation of the list of values in /// the Microsoft.Samples.Cbac.ClaimValue instance. /// </summary> /// <param name="valueType">Type of the value(s) in this instance</param> /// <param name="values">The collection of values each in string format</param> /// <param name="valueCount">Return the count of unique values</param> /// <returns>SafeHGlobalHandle that references a native (unmanaged) /// pointer to values that can be used in the 'Values' field of the /// CLAIM_SECURITY_ATTRIBUTE_V1 structure.</returns> static SafeHGlobalHandle GetRawValues(ClaimValueType valueType, string value, out ULONG valueCount) { const int BASE_OCTAL = 8; const int BASE_DECIMAL = 10; const int BASE_HEX = 16; const string OCTAL_REGEX = "^[+]?0[0-7]+$"; const string HEX_REGEX = "^[+]?0[xX][0-9a-fA-f]+$"; var stringValues = new StringCollection(); valueCount = 1; // // As part of formulating the values in native format, verify that // we do not have duplicates. AuthzModifyClaims fails with // ERROR_ALREADY_EXISTS when duplicate values are specified. // switch (valueType) { case ClaimValueType.Integer: { long[] values = new long[1]; try { int fromBase = BASE_DECIMAL; if (Regex.Match(value, OCTAL_REGEX).Success) { fromBase = BASE_OCTAL; } else if (Regex.Match(value, HEX_REGEX).Success) { fromBase = BASE_HEX; } values[0] = Convert.ToInt64(value, fromBase); return(SafeHGlobalHandle.AllocHGlobal(values)); } catch (Exception e) { throw new BadValueException(string.Format(CultureInfo.CurrentCulture, "Invalid Int value - {0}", value), e); } } case ClaimValueType.Boolean: { long[] values = new long[1]; try { string strValue = value; if (string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0) { strValue = "1"; } else if (string.Compare(value, "false", StringComparison.OrdinalIgnoreCase) == 0) { strValue = "0"; } values[0] = Convert.ToInt64(strValue, CultureInfo.InvariantCulture); return(SafeHGlobalHandle.AllocHGlobal(values)); } catch (Exception e) { throw new BadValueException(string.Format(CultureInfo.CurrentCulture, "Invalid Boolean value - {0}", value), e); } } case ClaimValueType.MultiValuedString: { char[] bracketChars = { '[', ']' }; const string CSV_REGEX = @"# Parse CVS line. Capture next value in named group: 'val' \s* # Ignore leading whitespace. (?: # Group of value alternatives. "" # Either a double quoted string, (?<val> # Capture contents between quotes. [^""]*(""""[^""]*)* # Zero or more non-quotes, allowing ) # doubled "" quotes within string. ""\s* # Ignore whitespace following quote. | (?<val>[^,]+) # Or... One or more non-commas. ) # End value alternatives group. (?:,|$) # Match end is comma or EOS"; if (!value.StartsWith("[", StringComparison.Ordinal) || !value.EndsWith("]", StringComparison.Ordinal)) { throw new BadValueException(string.Format(CultureInfo.CurrentCulture, "Multi-valued String is not enclosed within square brackets: '{0}'", value)); } MatchCollection splitResult = Regex.Matches(value.Trim(bracketChars), CSV_REGEX, RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); if (splitResult.Count == 0) { throw new BadValueException(string.Format(CultureInfo.CurrentCulture, "Ill-formed Multi-valued String: '{0}'", value)); } else { foreach (Match literal in splitResult) { string strVal = literal.Groups["val"].Value.Trim(); if (!stringValues.Contains(strVal)) { if (!string.IsNullOrEmpty(strVal)) { stringValues.Add(strVal); } } else { Helper.ReportDuplicateValue(ClaimValueType.MultiValuedString, literal.Groups["val"].Value); } } } if (stringValues.Count == 0) { throw new BadValueException(string.Format(CultureInfo.CurrentCulture, "No non-empty strings in : '{0}'", value)); } valueCount = (ULONG)stringValues.Count; goto case ClaimValueType.String; } case ClaimValueType.String: { if (stringValues.Count == 0) { string strVal = value.Trim(); if (!string.IsNullOrEmpty(strVal)) { stringValues.Add(strVal); } } var strings = new List <SafeHGlobalHandle>(stringValues.Count); foreach (var stringValue in stringValues) { SafeHGlobalHandle nativeString = SafeHGlobalHandle.AllocHGlobal(stringValue); strings.Add(nativeString); } SafeHGlobalHandle result = SafeHGlobalHandle.AllocHGlobal( strings.Select(n => n.ToIntPtr()) .ToArray()); // // Since the native (managed) representation is an array // of pointers to strings, ensure that these pointers // are being referenced in the uber SafeHGlobalHandle // that represents the array of pointers. // result.AddSubReference(strings); valueCount = (ULONG)strings.Count; return(result); } default: { valueCount = 0; break; } } return(SafeHGlobalHandle.InvalidHandle); }
/// <summary> /// Adds or replaces claims in the specified Authz Client Context. /// </summary> /// <remarks>This method invokes AuthzModifyClaims, modifying the claims /// using AUTHZ_SECURITY_ATTRIBUTE_OPERATION_REPLACE. This ensures that /// the values of a claims that already exists are replaces and the ones /// not present are added.</remarks> /// <param name="handleClientContext">Handle to the Authz Client Context to be modified</param> /// <returns>Win32Error.ERROR_SUCCESS on success and Win32 error code otherwise.</returns> public int ApplyClaims(AUTHZ_CLIENT_CONTEXT_HANDLE handleClientContext) { NativeMethods.AuthzSecurityAttributeOperation[] claimOps = null; var claims = new List <NativeMethods.AUTHZ_SECURITY_ATTRIBUTE_V1>(this.Count); foreach (var claim in this) { // // If all of the value specified turned out invalid, ignore the claim altogether. // if (claim.Value.ValueCount == 0) { continue; } var attribute = new NativeMethods.AUTHZ_SECURITY_ATTRIBUTE_V1(); attribute.Name = claim.Key; attribute.Flags = 0; attribute.Values = claim.Value.RawValues.ToIntPtr(); attribute.ValueCount = claim.Value.ValueCount; switch (claim.Value.ValueType) { case ClaimValueType.Integer: { Debug.Assert(attribute.ValueCount == 1); attribute.Type = NativeMethods.AuthzSecurityAttributeValueType.Int; break; } case ClaimValueType.Boolean: { Debug.Assert(attribute.ValueCount == 1); attribute.Type = NativeMethods.AuthzSecurityAttributeValueType.Boolean; break; } case ClaimValueType.String: { Debug.Assert(attribute.ValueCount == 1); goto case ClaimValueType.MultiValuedString; } case ClaimValueType.MultiValuedString: { attribute.Type = NativeMethods.AuthzSecurityAttributeValueType.String; break; } } claims.Add(attribute); } var claimInfo = new NativeMethods.AUTHZ_SECURITY_ATTRIBUTES_INFORMATION(); claimInfo.Version = 1; // AUTHZ_SECURITY_ATTRIBUTES_INFORMATION_VERSION_V1 claimInfo.Reserved = 0; claimInfo.AttributeCount = (ULONG)claims.Count; SafeHGlobalHandle v1Attributes = SafeHGlobalHandle.InvalidHandle; if (claimInfo.AttributeCount != 0) { v1Attributes = SafeHGlobalHandle.AllocHGlobal(claims); claimOps = new NativeMethods.AuthzSecurityAttributeOperation[claimInfo.AttributeCount]; for (ULONG Idx = 0; Idx < claimInfo.AttributeCount; ++Idx) { claimOps[Idx] = NativeMethods.AuthzSecurityAttributeOperation.Replace; } } claimInfo.pAttributeV1 = v1Attributes.ToIntPtr(); if (!NativeMethods.AuthzModifyClaims(handleClientContext, claimDefnType == ClaimDefinitionType.User ? NativeMethods.AuthzContextInformationClass.AuthzContextInfoUserClaims : NativeMethods.AuthzContextInformationClass.AuthzContextInfoDeviceClaims, claimOps, ref claimInfo)) { return(Marshal.GetLastWin32Error()); } return(Win32Error.ERROR_SUCCESS); }
public static extern int LsaGetAppliedCAPIDs( ref LSA_UNICODE_STRING systemName, ref IntPtr CAPIDs, out ULONG CAPIDCount );
public static extern int LsaGetAppliedCAPIDs( ref LSA_UNICODE_STRING systemName, ref IntPtr CAPIDs, out ULONG CAPIDCount );
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetRecordCount( /* [out] */ ULONG *pcRecords) = 0;
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetErrorParameters( /* [in] */ ULONG ulRecordNum, /* [out] */ DISPPARAMS *pdispparams) = 0;
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetErrorInfo( /* [in] */ ULONG ulRecordNum, /* [in] */ LCID lcid, /* [out] */ IErrorInfo **ppErrorInfo) = 0;
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetErrorInfo( /* [in] */ ULONG ulRecordNum, /* [in] */ LCID lcid, /* [out] */ IErrorInfo **ppErrorInfo) = 0;
public RIO_RQ CreateRequestQueue([In] SOCKET Socket, [In] ULONG MaxOutstandingReceive, [In] ULONG MaxReceiveDataBuffers, [In] ULONG MaxOutstandingSend, [In] ULONG MaxSendDataBuffers, [In] RIO_CQ ReceiveCQ, [In] RIO_CQ SendCQ, [In] PVOID SocketContext) => createRequestQueue(Socket, MaxOutstandingReceive, MaxReceiveDataBuffers, MaxOutstandingSend, MaxSendDataBuffers, ReceiveCQ, SendCQ, SocketContext);
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetErrorParameters( /* [in] */ ULONG ulRecordNum, /* [out] */ DISPPARAMS *pdispparams) = 0;
virtual /* [local] */ HRESULT STDMETHODCALLTYPE GetBasicErrorInfo( /* [in] */ ULONG ulRecordNum, /* [out] */ ERRORINFO *pErrorInfo) = 0;