コード例 #1
0
ファイル: HaspDemo.cs プロジェクト: 737871854/FireMen2
    /// <summary>
    /// Demonstrates how to get the real time clock of
    /// a key when available.
    /// </summary>
    public void RtcDemo(Hasp hasp)
    {
        // sanity check
        if ((null == hasp) || !hasp.IsLoggedIn())
        {
            return;
        }

        Verbose("Reading the Real Time Clock Demo");

        DateTime   time   = DateTime.Now;
        HaspStatus status = hasp.GetRtc(ref time);

        ReportStatus(status);

        if (HaspStatus.StatusOk == status)
        {
            Verbose("Real Time Clock is " + time.ToString());
        }

        Verbose("");
    }
コード例 #2
0
ファイル: CSentinel.cs プロジェクト: GJSoftware/Tool
        /// <summary>
        /// 打开加密狗
        /// </summary>
        /// <param name="tz">厂商</param>
        /// <param name="pwr">天数</param>
        /// <param name="er">错误代码</param>
        /// <returns></returns>
        public HaspStatus ClassCS(int tz, out int leftDays, out int er)
        {
            leftDays = -1;

            er = -1;

            try
            {
                string pwr = string.Empty;

                scope = defaultScope;

                HaspFeature feature = HaspFeature.FromFeature(tz);

                hasp = new Hasp(feature);

                HaspStatus status = hasp.Login(strVendorCode, scope);

                if (status != HaspStatus.StatusOk)
                {
                    pwr = "0";

                    er = (int)status;

                    return(status);
                }

                DateTime time3 = new DateTime();


                hasp.GetRtc(ref time3);
                int      len   = 10;
                byte[]   bytes = new byte[len];
                HaspFile file  = hasp.GetFile(HaspFileId.ReadWrite);
                status = file.Read(bytes, 0, bytes.Length);
                pwr    = System.Text.Encoding.UTF8.GetString(bytes);
                pwr    = pwr.Replace("\0", "");

                DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long     lTime   = long.Parse(pwr);

                TimeSpan toNow    = new TimeSpan(lTime);
                DateTime dtResult = dtStart.Add(toNow);

                int dayTime = (int)(Convert.ToInt32(pwr) / 3600 / 24);

                DateTime time4 = dtResult.AddDays(dayTime);

                TimeSpan sp = time4.Subtract(time3);

                leftDays = sp.Days;

                er = (int)status;

                return(status);
            }
            catch (Exception)
            {
                return(HaspStatus.SystemError);
            }
        }
コード例 #3
0
ファイル: CSentinel.cs プロジェクト: GJSoftware/Tool
        /// <summary>
        /// 返回天数
        /// </summary>
        /// <param name="tz">厂商</param>
        /// <param name="pwr">激活码</param>
        /// <param name="day">天数</param>
        /// <returns></returns>
        public HaspStatus ActivationTime(int tz, string pwr, out int day)
        {
            scope = defaultScope;

            HaspFeature feature = HaspFeature.FromFeature(tz);

            hasp = new Hasp(feature);

            HaspStatus status = hasp.Login(strVendorCode, scope);

            if (pwr.Length != 16)
            {
                status = HaspStatus.TimeError;
                day    = 0;
                return(status);
            }
            if (status != HaspStatus.StatusOk)
            {
                day = 0;
                return(status);
            }

            DateTime time = new DateTime();

            hasp.GetRtc(ref time);

            HaspFile file = hasp.GetFile(HaspFileId.ReadWrite);

            byte[] _bytes = new byte[16];

            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));

            if (pwr.Contains("6216"))
            {
                String[] arr   = new String[5];
                byte[]   bytes = new byte[80];
                file.FilePos = 16;
                status       = file.Read(bytes, 0, bytes.Length);
                string _pwr = System.Text.Encoding.UTF8.GetString(bytes);

                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = _pwr.Substring(i * 16, 16);
                    if (pwr.Equals(arr[i]))
                    {
                        file.FilePos = (16 * i) + 16;
                        Thread.Sleep(10);
                        status = file.Write(_bytes, 0, _bytes.Length);

                        DateTime time3 = time.AddDays(30);

                        long time2 = (long)(time3 - dtStart).TotalSeconds;

                        string _time = time2.ToString();

                        byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time);

                        file.FilePos = 0;

                        status = file.Write(decoded, 0, decoded.Length);

                        day = 30;

                        return(status);
                    }
                }
            }
            else if (pwr.Contains("6217"))
            {
                byte[] bytes = new byte[80];
                file.FilePos = 96;
                status       = file.Read(bytes, 0, bytes.Length);
                string _pwr = System.Text.Encoding.UTF8.GetString(bytes);


                String[] arr = new String[5];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = _pwr.Substring(i * 16, 16);

                    if (pwr.Equals(arr[i]))
                    {
                        file.FilePos = (16 * i) + 96;
                        Thread.Sleep(10);
                        status = file.Write(_bytes, 0, _bytes.Length);

                        DateTime time3 = time.AddDays(60);

                        long time2 = (long)(time3 - dtStart).TotalSeconds;

                        string _time = time2.ToString();

                        byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time);

                        file.FilePos = 0;

                        status = file.Write(decoded, 0, decoded.Length);

                        day = 60;

                        return(status);
                    }
                }
            }
            else if (pwr.Contains("6218"))
            {
                byte[] bytes = new byte[80];
                file.FilePos = 176;
                status       = file.Read(bytes, 0, bytes.Length);

                string _pwr = System.Text.Encoding.UTF8.GetString(bytes);


                String[] arr = new String[8];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = _pwr.Substring(i * 16, 16);

                    if (pwr.Equals(arr[i]))
                    {
                        file.FilePos = (16 * i) + 176;
                        Thread.Sleep(10);
                        status = file.Write(_bytes, 0, _bytes.Length);

                        DateTime time3 = time.AddDays(90);

                        long time2 = (long)(time3 - dtStart).TotalSeconds;

                        string _time = time2.ToString();

                        byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time);

                        file.FilePos = 0;
                        status       = file.Write(decoded, 0, decoded.Length);

                        day = 90;

                        return(status);
                    }
                }
            }
            else if (pwr.Contains("6219"))
            {
                byte[] bytes = new byte[16];
                file.FilePos = 256;
                status       = file.Read(bytes, 0, bytes.Length);

                string _pwr = System.Text.Encoding.UTF8.GetString(bytes);


                String[] arr = new String[1];
                for (int i = 0; i < arr.Length; i++)
                {
                    arr[i] = _pwr.Substring(i * 16, 16);

                    if (pwr.Equals(arr[i]))
                    {
                        DateTime time3 = time.AddDays(999);

                        long time2 = (long)(time3 - dtStart).TotalSeconds;

                        string _time = time2.ToString();

                        byte[] decoded = System.Text.Encoding.UTF8.GetBytes(_time);

                        file.FilePos = 0;
                        status       = file.Write(decoded, 0, decoded.Length);

                        day = 999;

                        return(status);
                    }
                }
            }
            else
            {
                status = HaspStatus.TimeError;
                day    = 0;
                return(status);
            }

            status = HaspStatus.SystemError;
            day    = 0;
            return(status);
        }
コード例 #4
0
        private void GetGeneralInfo()
        {
            // date time first
            // get size of


            DateTime hasptime = DateTime.Now;

            status = hasp.GetRtc(ref hasptime);
            if (status == HaspStatus.NoTime)
            {
                hasptime = DateTime.Now;
            }
            // create
            mDate = DaysSince2000FromSystemTime(hasptime);

            /*
             *
             *  if (hasp_hasptime_to_datetime(theTime, &theDay, &theMonth, &theYear, &theHour, &theMinute, &theSecond) == HASP_STATUS_OK)
             * {
             *  SYSTEMTIME theSystemTime;
             *  theSystemTime.wYear = theYear;
             *  theSystemTime.wMonth = theMonth;
             *  theSystemTime.wDay = theDay;
             *  theSystemTime.wHour = 0;
             *  theSystemTime.wMinute = 0;
             *  theSystemTime.wSecond = 0;
             *  theSystemTime.wMilliseconds = 0;
             *  mDate = DaysSince2000FromSystemTime(theSystemTime);
             * }
             */

            byte[] signaturebytes = null;
            byte[] clientbytes    = null;
            byte[] licensesbytes  = null;
            signaturebytes = new byte[4];
            clientbytes    = new byte[2];
            licensesbytes  = new byte[2];
            // read from Memory

            file = hasp.GetFile(HaspFiles.Main);

            uint signature;

            file.FilePos = 0;
            file.Read(signaturebytes, 0, 4);
            signature = BitConverter.ToUInt32(signaturebytes, 0);

            if (signature != 1400456047)
            {
                mLicenseCount = 0;
            }
            else
            {
                file.FilePos = 4;
                // check how many licenses we have
                file.Read(clientbytes, 0, 2);
                //mClient = BitConverter.ToUInt16(clientbytes, 0);

                file.FilePos = 6;
                // and the number of licenses
                file.Read(licensesbytes, 0, 2);
                mLicenseCount = BitConverter.ToUInt16(licensesbytes, 0);
            }
        }