From 446d95579f00a03943df71a7c4c3685a661db7a6 Mon Sep 17 00:00:00 2001 From: beichen <43266206+BeichenDream@users.noreply.github.com> Date: Sat, 25 Nov 2023 01:15:26 +0800 Subject: [PATCH] update sharp token --- .gitignore | 4 +++- GodPotato.csproj | 5 ++++- NativeAPI/NativeMethods.cs | 4 ++++ SharpToken.cs | 32 ++++++++++++++++++++++++-------- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5b84798..7f1f225 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /.vs/ /bin/ -/obj/ \ No newline at end of file +/obj/ +GodPotato.csproj.user +app.config \ No newline at end of file diff --git a/GodPotato.csproj b/GodPotato.csproj index 538f79e..07871fa 100644 --- a/GodPotato.csproj +++ b/GodPotato.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {2AE886C3-3272-40BE-8D3C-EBAEDE9E61E1} - Exe + Library GodPotato GodPotato v2.0 @@ -32,6 +32,9 @@ prompt 4 + + + diff --git a/NativeAPI/NativeMethods.cs b/NativeAPI/NativeMethods.cs index 5d7962d..276a601 100644 --- a/NativeAPI/NativeMethods.cs +++ b/NativeAPI/NativeMethods.cs @@ -158,6 +158,10 @@ namespace GodPotato.NativeAPI public IntPtr /* PMIDL_SYNTAX_INFO */ pSyntaxInfo; } + void aa() { + + } + [DllImport("kernel32.dll", SetLastError = true)] public static extern bool VirtualProtect([In] IntPtr pBlock,[In] uint size,[In] uint newProtect,[Out] out uint oldProtect); diff --git a/SharpToken.cs b/SharpToken.cs index 0fdc80e..cb85b3c 100644 --- a/SharpToken.cs +++ b/SharpToken.cs @@ -693,6 +693,8 @@ namespace SharpToken public bool IsClose { get; private set; } + private static readonly List blackGroupSid = new List(); + private ProcessToken() { @@ -813,15 +815,29 @@ namespace SharpToken for (int i = 0; i < groupCount; i++) { - try + lock (blackGroupSid) { - securityIdentifier = new SecurityIdentifier(Marshal.ReadIntPtr(new IntPtr(tokenUserPtr.ToInt64() + offset))); - offset += Marshal.SizeOf(typeof(SID_AND_ATTRIBUTES)); - goups.Add(securityIdentifier.Translate(typeof(NTAccount)).Value); - } - catch (Exception e) - { - continue; + try + { + securityIdentifier = new SecurityIdentifier(Marshal.ReadIntPtr(new IntPtr(tokenUserPtr.ToInt64() + offset))); + offset += Marshal.SizeOf(typeof(SID_AND_ATTRIBUTES)); + + if (blackGroupSid.Contains(securityIdentifier.Value)) + { + continue; + } + + goups.Add(securityIdentifier.Translate(typeof(NTAccount)).Value); + } + catch (Exception e) + { + if (securityIdentifier != null) + { + blackGroupSid.Add(securityIdentifier.Value); + } + + continue; + } } } Marshal.FreeHGlobal(tokenUserPtr);