public ThreadEntry(NativeHandle handle)
 {
     Handle = handle;
     SecurityDescriptor = NativeBridge.GetSecurityDescriptorForHandle(handle);
     StringSecurityDescriptor = NativeBridge.GetStringSecurityDescriptor(SecurityDescriptor);
     Tid = NativeBridge.GetTidForThread(handle);
     NativeHandle token = NativeBridge.OpenThreadToken(handle);
     if (token != null)
     {
         Token = new TokenEntry(token);
     }
 }
Exemplo n.º 2
0
 private static string CalculateToken(TokenEntry token, params TokensSet[] tokens)
 {
     foreach (var tokens_set in tokens)
         if (tokens_set.Contains(token.Name))
         {
             var token_ = tokens_set[token.Name];
             return token_.GetValue(
                 Process(
                     token_.Prepare(token.Body, Process, tokens),
                     tokens));
         }
     throw new Exception(string.Format("Token {0} not found in data", token.Name));
 }
            public ProcessEntry(NativeHandle handle)
            {
                Handle = handle;
                Pid = NativeBridge.GetPidForProcess(handle);
                Threads = NativeBridge.GetThreadsForProcess(handle).Select(h => new ThreadEntry(h)).ToArray();
                Array.Sort(Threads, (a, b) => a.Tid - b.Tid);

                SecurityDescriptor = NativeBridge.GetSecurityDescriptorForHandle(handle);
                StringSecurityDescriptor = NativeBridge.GetStringSecurityDescriptor(SecurityDescriptor);

                ImagePath = String.Empty;
                if (Pid == 0)
                {
                    Name = "Idle";
                }
                else if (Pid == 4)
                {
                    Name = "System";
                }
                else
                {
                    ImagePath = NativeBridge.GetProcessPath(handle);
                    Name = Path.GetFileNameWithoutExtension(ImagePath);
                }

                NativeHandle token = NativeBridge.OpenProcessToken(handle);
                if (token != null)
                {
                    Token = new TokenEntry(token);
                }
            }
        internal static void PopulateProviderCredentials(TokenEntry tokenEntry, ProviderCredentials credentials)
        {
            if (tokenEntry.UserClaims != null)
            {
                credentials.Claims = new Dictionary <string, string>();
                Collection <Claim> userClaims = new Collection <Claim>();
                foreach (ClaimSlim claim in tokenEntry.UserClaims)
                {
                    credentials.Claims[claim.Type] = claim.Value;
                    userClaims.Add(new Claim(claim.Type, claim.Value));
                }
                credentials.UserClaims = userClaims;
            }

            FacebookCredentials facebookCredentials = credentials as FacebookCredentials;

            if (facebookCredentials != null)
            {
                facebookCredentials.AccessToken = tokenEntry.AccessToken;
                facebookCredentials.UserId      = tokenEntry.UserId;
                return;
            }

            GoogleCredentials googleCredentials = credentials as GoogleCredentials;

            if (googleCredentials != null)
            {
                googleCredentials.AccessToken           = tokenEntry.AccessToken;
                googleCredentials.RefreshToken          = tokenEntry.RefreshToken;
                googleCredentials.UserId                = tokenEntry.UserId;
                googleCredentials.AccessTokenExpiration = tokenEntry.ExpiresOn;

                return;
            }

            AzureActiveDirectoryCredentials aadCredentials = credentials as AzureActiveDirectoryCredentials;

            if (aadCredentials != null)
            {
                aadCredentials.AccessToken = tokenEntry.IdToken;
                Claim objectIdClaim = credentials.UserClaims.FirstOrDefault(c => string.Equals(c.Type, ObjectIdentifierClaimType, StringComparison.OrdinalIgnoreCase));
                if (objectIdClaim != null)
                {
                    aadCredentials.ObjectId = objectIdClaim.Value;
                }
                Claim tenantIdClaim = credentials.UserClaims.FirstOrDefault(c => string.Equals(c.Type, TenantIdClaimType, StringComparison.OrdinalIgnoreCase));
                if (tenantIdClaim != null)
                {
                    aadCredentials.TenantId = tenantIdClaim.Value;
                }
                aadCredentials.UserId = tokenEntry.UserId;
                return;
            }

            MicrosoftAccountCredentials microsoftAccountCredentials = credentials as MicrosoftAccountCredentials;

            if (microsoftAccountCredentials != null)
            {
                microsoftAccountCredentials.AccessToken           = tokenEntry.AccessToken;
                microsoftAccountCredentials.RefreshToken          = tokenEntry.RefreshToken;
                microsoftAccountCredentials.UserId                = tokenEntry.UserId;
                microsoftAccountCredentials.AccessTokenExpiration = tokenEntry.ExpiresOn;

                return;
            }

            TwitterCredentials twitterCredentials = credentials as TwitterCredentials;

            if (twitterCredentials != null)
            {
                twitterCredentials.AccessToken       = tokenEntry.AccessToken;
                twitterCredentials.AccessTokenSecret = tokenEntry.AccessTokenSecret;
                twitterCredentials.UserId            = tokenEntry.UserId;

                return;
            }
        }