@@ -902,6 +902,25 @@ public static CachedSigningLevel GetCachedSigningLevel(SafeKernelObjectHandle ha
902902 return new CachedSigningLevel ( flags , signing_level , thumb_print , thumb_print_algo ) ;
903903 }
904904
905+ /// <summary>
906+ /// Get the cached signing level for a file.
907+ /// </summary>
908+ /// <param name="handle">The handle to the file to query.</param>
909+ /// <param name="throw_on_error">True to throw on error.</param>
910+ /// <returns>The cached signing level.</returns>
911+ public static NtResult < CachedSigningLevel > GetCachedSigningLevel ( SafeKernelObjectHandle handle , bool throw_on_error )
912+ {
913+ byte [ ] thumb_print = new byte [ 0x68 ] ;
914+ int thumb_print_size = thumb_print . Length ;
915+
916+ return NtSystemCalls . NtGetCachedSigningLevel ( handle , out int flags ,
917+ out SigningLevel signing_level , thumb_print , ref thumb_print_size , out HashAlgorithm thumb_print_algo ) . CreateResult ( throw_on_error , ( ) =>
918+ {
919+ Array . Resize ( ref thumb_print , thumb_print_size ) ;
920+ return new CachedSigningLevel ( flags , signing_level , thumb_print , thumb_print_algo ) ;
921+ } ) ;
922+ }
923+
905924 /// <summary>
906925 /// Get the cached singing level from the raw EA buffer.
907926 /// </summary>
@@ -944,20 +963,50 @@ public static void SetCachedSigningLevel(SafeKernelObjectHandle handle,
944963 int flags , SigningLevel signing_level ,
945964 IEnumerable < SafeKernelObjectHandle > source_files ,
946965 string catalog_path )
966+ {
967+ SetCachedSigningLevel ( handle , flags , signing_level , source_files , catalog_path , true ) ;
968+ }
969+
970+ /// <summary>
971+ /// Set the cached signing level for a file.
972+ /// </summary>
973+ /// <param name="handle">The handle to the file to set the cache on.</param>
974+ /// <param name="flags">Flags to set for the cache.</param>
975+ /// <param name="signing_level">The signing level to cache</param>
976+ /// <param name="source_files">A list of source file for the cache.</param>
977+ /// <param name="catalog_path">Optional directory path to look for catalog files.</param>
978+ /// <param name="throw_on_error">True to throw on error.</param>
979+ public static NtStatus SetCachedSigningLevel ( SafeKernelObjectHandle handle ,
980+ int flags , SigningLevel signing_level ,
981+ IEnumerable < SafeKernelObjectHandle > source_files ,
982+ string catalog_path , bool throw_on_error )
947983 {
948984 IntPtr [ ] handles = source_files ? . Select ( f => f . DangerousGetHandle ( ) ) . ToArray ( ) ;
949985 int handles_count = handles == null ? 0 : handles . Length ;
950986 if ( catalog_path != null )
951987 {
952988 CachedSigningLevelInformation info = new CachedSigningLevelInformation ( catalog_path ) ;
953- NtSystemCalls . NtSetCachedSigningLevel2 ( flags , signing_level , handles , handles_count , handle , info ) . ToNtException ( ) ;
989+ return NtSystemCalls . NtSetCachedSigningLevel2 ( flags , signing_level , handles ,
990+ handles_count , handle , info ) . ToNtException ( throw_on_error ) ;
954991 }
955992 else
956993 {
957- NtSystemCalls . NtSetCachedSigningLevel ( flags , signing_level , handles , handles_count , handle ) . ToNtException ( ) ;
994+ return NtSystemCalls . NtSetCachedSigningLevel ( flags , signing_level , handles ,
995+ handles_count , handle ) . ToNtException ( throw_on_error ) ;
958996 }
959997 }
960998
999+ /// <summary>
1000+ /// Compare two signing levels.
1001+ /// </summary>
1002+ /// <param name="current_level">The current level.</param>
1003+ /// <param name="signing_level">The signing level to compare against.</param>
1004+ /// <returns>True if the current level is above or equal to the signing level.</returns>
1005+ public static bool CompareSigningLevel ( SigningLevel current_level , SigningLevel signing_level )
1006+ {
1007+ return NtSystemCalls . NtCompareSigningLevel ( current_level , signing_level ) . IsSuccess ( ) ;
1008+ }
1009+
9611010 /// <summary>
9621011 /// Get readable name for a SID, if known. This covers sources of names such as LSASS lookup, capability names and package names.
9631012 /// </summary>
0 commit comments