Пример #1
0
 public void GetTokenStatistics_ForCurrentProcess()
 {
     using (var token = Security.OpenProcessToken(AccessTokenRights.Read))
     {
         TokenStatistics stats = token.GetTokenStatistics();
         stats.TokenType.Should().Be(TokenType.Primary);
     }
 }
Пример #2
0
        protected override async Task DoWork()
        {
            DbContext.DetachEverything();
            var tokenList = await DbContext.Tokens.Where(x => x.IsEnabled && !x.IsDeleted).ToListAsync();

            var thisDayStart = DayStartOf(DateTime.Now);

            foreach (var token in tokenList)
            {
                var lastStat = await DbContext.TokenStatistics.LastOrDefaultAsync(x => x.TokenId == token.Id);

                var add = lastStat == null || lastStat.Date != thisDayStart;

                var price = await TronObserver.GetTokenPrice(token.FotronContractAddress);

                var buyCount = await TronObserver.GetBuyCount(token.FotronContractAddress);

                var sellCount = await TronObserver.GetSellCount(token.FotronContractAddress);

                var bonusPerShare = await TronObserver.GetBonusPerShare(token.FotronContractAddress);

                var volumeEth = await TronObserver.GetVolumeEth(token.FotronContractAddress);

                var volumeToken = await TronObserver.GetVolumeToken(token.FotronContractAddress);

                var blockNum = await TronObserver.GetLatestBlockNumber();

                if (add)
                {
                    var tokenStat = new TokenStatistics {
                        Date        = thisDayStart,
                        PriceEth    = price,
                        BuyCount    = buyCount,
                        SellCount   = sellCount,
                        ShareReward = bonusPerShare,
                        VolumeEth   = volumeEth,
                        VolumeToken = volumeToken,
                        BlockNum    = blockNum,
                        TokenId     = token.Id
                    };
                    await DbContext.TokenStatistics.AddAsync(tokenStat);
                }
                else
                {
                    lastStat.PriceEth    = price;
                    lastStat.BuyCount    = buyCount;
                    lastStat.SellCount   = sellCount;
                    lastStat.ShareReward = bonusPerShare;
                    lastStat.VolumeEth   = volumeEth;
                    lastStat.VolumeToken = volumeToken;
                    lastStat.BlockNum    = blockNum;
                }
            }

            await DbContext.SaveChangesAsync();
        }
Пример #3
0
 public void GetTokenGroupSids_ForCurrentProcess()
 {
     using (var token = Security.OpenProcessToken(AccessTokenRights.Read))
     {
         token.IsInvalid.Should().BeFalse();
         List <SidAndAttributes> groups = token.GetTokenGroupSids().ToList();
         groups.Should().NotBeEmpty();
         groups.Should().Contain((group) => group.Sid.LookupAccountSid(null).Name.Equals("Everyone"));
         TokenStatistics stats = token.GetTokenStatistics();
         groups.Count.Should().Be((int)stats.GroupCount);
     }
 }
Пример #4
0
        public void Initialize()
        {
            tokenStatistics = TokenStatistics.Instance;

            switch (TokensEngine.Pars.Type)
            {
            case TokensEngineProperties.TOKEN3x3:
                CurrentTokenType = (new Token3x3());
                break;

            case TokensEngineProperties.TOKEN4x4:
                CurrentTokenType = (new Token4x4());
                break;

            case TokensEngineProperties.TOKEN5x5:
                CurrentTokenType = (new Token5x5());
                break;
            }

            ClusterManager.Instance.Initialize();
            ClusterManager.Instance.SetClusterDistThreshold(CurrentTokenType.TokenDiagonalPX);

            if (TokensEngine.Pars.MeanSquare)
            {
                ClassComputeRefSystem = ClassComputeReferenceSystem.MeanSqure;
            }
            else
            {
                ClassComputeRefSystem = ClassComputeReferenceSystem.Regular;
            }

            ContinuousMeanSquare = TokensEngine.Pars.ContinuousMeanSquare;

            if (TokensEngine.Pars.ComputePixels == TokensEngineProperties.PIXELS)
            {
                ComputeDimension = ClassComputeDimension.Pixels;
            }
            else
            {
                ComputeDimension = ClassComputeDimension.Centimeters;
            }


            TokenUpdateTranslationThreshold = (TokensEngine.Pars.TranslationThr);
            TokenUpdateRotationThreshold    = (TokensEngine.Pars.RotationThr);

            // listen to updated cluster events
            ClusterManager.Instance.ClustersUpdateEvent += OnClustersUpdated;
        }
Пример #5
0
        private static NativeHelpers.SECURITY_LOGON_TYPE GetTokenLogonType(SafeNativeHandle hToken)
        {
            TokenStatistics stats = TokenUtil.GetTokenStatistics(hToken);

            SafeLsaMemoryBuffer sessionDataPtr;
            UInt32 res = NativeMethods.LsaGetLogonSessionData(ref stats.AuthenticationId, out sessionDataPtr);

            if (res != 0)
            {
                // Default to Network, if we weren't able to get the actual type treat it as an error and assume
                // we don't want to run a process with the token
                return(NativeHelpers.SECURITY_LOGON_TYPE.Network);
            }

            using (sessionDataPtr)
            {
                NativeHelpers.SECURITY_LOGON_SESSION_DATA sessionData = (NativeHelpers.SECURITY_LOGON_SESSION_DATA)Marshal.PtrToStructure(
                    sessionDataPtr.DangerousGetHandle(), typeof(NativeHelpers.SECURITY_LOGON_SESSION_DATA));
                return(sessionData.LogonType);
            }
        }
Пример #6
0
        private static SafeNativeHandle GetElevatedToken(SafeNativeHandle hToken)
        {
            TokenElevationType tet = TokenUtil.GetTokenElevationType(hToken);

            // We already have the best token we can get, no linked token is really available.
            if (tet != TokenElevationType.Limited)
            {
                return(null);
            }

            SafeNativeHandle linkedToken = TokenUtil.GetTokenLinkedToken(hToken);
            TokenStatistics  tokenStats  = TokenUtil.GetTokenStatistics(linkedToken);

            // We can only use a token if it's a primary one (we had the SeTcbPrivilege set)
            if (tokenStats.TokenType == TokenType.Primary)
            {
                return(linkedToken);
            }
            else
            {
                return(null);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Session Id: {0}", System.Diagnostics.Process.GetCurrentProcess().SessionId);

                IntPtr tokenInfo;
                bool   result;
                int    infoSize;

                IntPtr hToken = System.Security.Principal.WindowsIdentity.GetCurrent().Token;

                result = GetTokenInformation(hToken, TokenInformationClass.TokenStatistics, IntPtr.Zero, 0, out infoSize);
                if (!result && Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER)
                {
                    tokenInfo = Marshal.AllocHGlobal(infoSize);
                    result    = GetTokenInformation(hToken, TokenInformationClass.TokenStatistics, tokenInfo, infoSize, out infoSize);
                    if (result)
                    {
                        TokenStatistics tokenStats = (TokenStatistics)Marshal.PtrToStructure(tokenInfo, typeof(TokenStatistics));
                        Console.WriteLine("LogonId: 0x{0:X16}", tokenStats.AuthenticationId);
                    }
                    else
                    {
                        Console.Error.WriteLine("LogonId: FAILED with 0x{0:X08}", Marshal.GetLastWin32Error());
                    }
                    Marshal.FreeHGlobal(tokenInfo);
                }
                else
                {
                    Console.Error.WriteLine("LogonId: FAILED with 0x{0:X08}", Marshal.GetLastWin32Error());
                }


                tokenInfo = Marshal.AllocHGlobal(sizeof(Int32));
                result    = GetTokenInformation(hToken, TokenInformationClass.TokenSessionId, tokenInfo, sizeof(Int32), out infoSize);
                if (result)
                {
                    int tokenSessionId = Marshal.ReadInt32(tokenInfo);
                    Console.WriteLine("TokenSessionId: {0}", tokenSessionId);
                }
                else
                {
                    Console.Error.WriteLine("TokenSessionId: FAILED with 0x{0:X08}", Marshal.GetLastWin32Error());
                }

                Marshal.FreeHGlobal(tokenInfo);


                result = GetTokenInformation(hToken, TokenInformationClass.TokenOrigin, IntPtr.Zero, 0, out infoSize);
                if (!result && Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER)
                {
                    tokenInfo = Marshal.AllocHGlobal(infoSize);
                    result    = GetTokenInformation(hToken, TokenInformationClass.TokenOrigin, tokenInfo, infoSize, out infoSize);
                    if (result)
                    {
                        TokenOrigin tokenOrigin = (TokenOrigin)Marshal.PtrToStructure(tokenInfo, typeof(TokenOrigin));
                        Console.WriteLine("OriginatingSessionId: 0x{0:X16}", tokenOrigin.OriginatingLogonSession);
                    }
                    else
                    {
                        Console.WriteLine("OriginatingSessionId: FAILED with 0x{0:X08}", Marshal.GetLastWin32Error());
                    }
                    Marshal.FreeHGlobal(tokenInfo);
                }
                else
                {
                    Console.WriteLine("OriginatingSessionId: FAILED with 0x{0:X08}", Marshal.GetLastWin32Error());
                }

                Console.WriteLine("Press any key...");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Unexpected error: {0}", ex);
                Console.ReadKey();
            }
        }