示例#1
0
        /// <summary>
        /// 返回ID
        /// </summary>
        /// <param name="tz">厂商</param>
        /// <param name="id">ID</param>
        /// <param name="er">错误代码</param>
        /// <returns></returns>
        public HaspStatus time(int tz, out string id, out string er)
        {
            id = string.Empty;

            er = string.Empty;

            try
            {
                string DateTime = string.Empty;
                scope = defaultScope;

                HaspFeature feature = HaspFeature.FromFeature(tz);

                hasp = new Hasp(feature);

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

                if (status != HaspStatus.StatusOk)
                {
                    er = status.ToString();
                    return(status);
                }
                er = Convert.ToString(status);
                string xlmFile = "<haspformat root=" + "\"" + "hasp_info" + "\"" + ">" +
                                 "<hasp>" +
                                 "<attribute name=" + "\"" + "id" + "\"" + "/>" +
                                 "<feature>" +
                                 "<element name=" + "\"" + "license" + "\"" + "/>" +
                                 "</feature>" +
                                 "</hasp>" +
                                 "</haspformat>";

                string info = string.Empty;

                string Time2 = hasp.GetSessionInfo(xlmFile, ref info).ToString();

                string[] sArray = info.Split(new char[2] {
                    '"', '"'
                });

                if (sArray.Length > 6)
                {
                    id = sArray[5];
                }

                //释放内存
                status = hasp.Logout();

                return(status);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(HaspStatus.SystemError);
            }
        }
示例#2
0
        /// <summary>
        ///     Uses pre-defined vendor code for validating whether the HASP software license installed on the server is valid or not
        ///     Returns the detailed hasp pass/fail message only
        /// </summary>
        /// <remarks>
        ///     The HASP dlls (hasp_net_windows.dll, hasp_windows_x64_102489.dll, haspvlib_102489.dll, and hasp_windows_102489.dll)
        ///     must be placed in the windows system directory in order for IIS to access those external dlls
        /// </remarks>
        public static string validateLicenseDetails()
        {
            // Sentinel LDK API
            HaspFeature feature = HaspFeature.FromFeature(1001);  // Using feature 1 defined in EMS-Server; Actual product should be using 1001

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(getVendorCode());

            return(status.ToString());
        }
示例#3
0
        /// <summary>
        ///     Uses pre-defined vendor code for validating whether the HASP software license installed on the server is valid or not
        /// </summary>
        /// <remarks>
        ///     The HASP dlls (hasp_net_windows.dll, hasp_windows_x64_102489.dll, haspvlib_102489.dll, and hasp_windows_102489.dll)
        ///     must be placed in the windows system directory in order for IIS to access those external dlls
        /// </remarks>
        public static bool validateLicense()
        {
            // Sentinel LDK API
            HaspFeature feature = HaspFeature.FromFeature(1001);  // Using feature 1 defined in EMS-Server; Actual product should be using 1001

            Hasp       hasp   = new Hasp(feature);
            HaspStatus status = hasp.Login(getVendorCode());

            if (HaspStatus.StatusOk != status)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#4
0
        private static void InitializeLicense()
        {
            // Must change by released program
            ProgramLicense = new NKHardLockInfo()
            {
                VendorCode = NKLicenseList.Code_YIOBI,
                Feature    = (int)NKLicenseList.Feature_YIOBI.NK_Label,
                Scope      = NKLicenseList.DefaultScope,

                HaspID        = string.Empty,
                NetCountLimit = string.Empty,
                MaxMemory     = (int)NKLicenseList.MaxMemory.SRM_PRO,
                MemoryType    = NKLicenseList.MemoryType.ePM_Ex,

                ManufacturedDate      = new DateTime(),
                ServiceExpirationDate = new DateTime(),
            };
            //

            HaspFeature feature = HaspFeature.FromFeature(ProgramLicense.Feature);

            HaspData = new Hasp(feature);
        }
示例#5
0
    //public void Init()
    //{
    //    InitDog();
    //    //InvokeRepeating("CheckOutDog",10,300);
    //}

    //加密狗初始化//
    public void  InitDog()
    {
        if (ioo.gameController.Type == InputType.Mouse)
        {
            return;
        }

        haspDemo = new HaspDemo();
        hasp     = haspDemo.LoginDemo(HaspFeature.FromFeature(FeatureID));

        if (hasp == null || !hasp.IsLoggedIn())
        {
            Application.Quit();
            Debug.Log("登录加密狗失败!!!");
            return;
        }
        //haspDemo.WriteMessageFirst(hasp, HaspFileId.ReadWrite, "");
        device = SystemInfo.deviceUniqueIdentifier;
        //每次开启游戏时随机向加密狗中写入一个数字,防止监听及共享打印机破解加密狗\\
        long index = (long)UnityEngine.Random.Range(1000000000, 99999999999999);

        checkIndex = index.ToString();

        readStrs = haspDemo.ReadToStr(hasp, HaspFileId.ReadWrite);
        if (GetDeviceStr(readStrs) == "")
        {
            writeStrs += device;
        }
        else
        {
            writeStrs += GetDeviceStr(readStrs);
        }
        writeStrs += ",";
        writeStrs += checkIndex;

        haspDemo.WriteMessageFirst(hasp, HaspFileId.ReadWrite, writeStrs);
    }
示例#6
0
        /// <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);
            }
        }
示例#7
0
        /// <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);
        }
示例#8
0
    /// <summary>
    /// Runs the API demo.
    /// </summary>
    public void RunDemo(string scope)
    {
        try
        {
            this.scope = scope;

            Header();

            // Demonstrate the different login methods
            LoginDefaultAutoDemo();
            LoginLogoutDefaultDemo();
            LoginDisposeDemo();

            // Demonstrates how to get a list of available features
            GetInfoDemo();

            // run the API demo using the default feature
            // (ALWAYS present in every key)
            Hasp hasp = LoginDefaultDemo();
            SessionInfoDemo(hasp);
            ReadWriteDemo(hasp, HaspFileId.ReadWrite);
            ReadWritePosDemo(hasp, HaspFileId.ReadWrite);
            EncryptDecryptDemo(hasp);
            RtcDemo(hasp);

            // Accessing Dynamic memory available in Sentinel HL (Driverless configuration) Key
            ReadWriteDynamicMemory(hasp, HaspDemo.dynamicMemoryFileId);

            LogoutDemo(ref hasp);

            int[] features =
            {
                HaspFeature.FromFeature(1).Feature,
                HaspFeature.FromFeature(3).Feature,
                HaspFeature.FromFeature(42).Feature,
                HaspFeature.FromFeature(101).Feature
            };

            // run the API demo using various feature ids
            for (int index = 0; index < features.Length; index++)
            {
                hasp = LoginDemo(new HaspFeature(features[index]));
                SessionInfoDemo(hasp);
                ReadWriteDemo(hasp, HaspFileId.ReadWrite);
                ReadWritePosDemo(hasp, HaspFileId.ReadWrite);
                EncryptDecryptDemo(hasp);
                RtcDemo(hasp);
                LogoutDemo(ref hasp);
            }
            Footer();
        }
        catch (Exception ex)
        {
            //if (textHistory == null)
            //    Console.WriteLine(ex.Message);
            //else
            //    System.Windows.Forms.MessageBox.Show(ex.Message,
            //                                     "Exception",
            //                                      System.Windows.Forms.MessageBoxButtons.OK);
        }
    }
示例#9
0
    public void  CheckOutDog()
    {
        if (ioo.gameController.Type == InputType.Mouse)
        {
            return;
        }

        hasp = haspDemo.LoginDemo(HaspFeature.FromFeature(FeatureID));
        if (hasp == null || !hasp.IsLoggedIn())
        {
            Application.Quit();
            Debug.Log("登录加密狗失败!!!");
            return;
        }
        readStrs = haspDemo.ReadToStr(hasp, HaspFileId.ReadWrite);
        string devicestr     = GetDeviceStr(readStrs);
        string checkindexStr = GetCheckIndexStr(readStrs);

        //每隔一段时间检验写入的数据是否是游戏一开始的数据//
        // Debug.Log(checkIndex + "  :  " + checkindexStr);
        //Debug.Log(device + "  :  " + devicestr);
        if (checkIndex != checkindexStr)
        {
            Application.Quit();
            Debug.Log("检验失败!!!");
            return;
        }
        if (device != devicestr)
        {
            Application.Quit();
            Debug.Log("检验失败!!!");
            return;
        }
        //DateTime time = DateTime.Now;
        //HaspStatus status = hasp.GetRtc(ref time);
        ////检验加密数据,总共120组,每个月随机其中的40组,3个月一个循环//
        //try
        //{
        //    int index = (UnityEngine.Random.Range(time.Month % 3 * 40, time.Month % 3 * 40 + 40));
        //    //Debug.Log(index+" : "+time.Month);
        //    string checkCode =VendorCode.DeCodeStrs[index];
        //    hasp.Decrypt(ref checkCode);
        //   // Debug.Log(checkCode + "  :  " + VendorCode.EncryptStrs[index]);
        //    if (checkCode != VendorCode.EncryptStrs[index])
        //    {
        //        Debug.Log("检验失败!!!");
        //        Application.Quit();
        //    }
        //}
        //catch
        //{
        //    int index = UnityEngine.Random.Range(0, VendorCode.DeCodeStrs.Length);
        //    string checkCode = VendorCode.DeCodeStrs[index];
        //    hasp.Decrypt(ref checkCode);
        //    Debug.Log(checkCode + "  :  " + VendorCode.EncryptStrs[index]);
        //    if (checkCode != VendorCode.EncryptStrs[index])
        //    {
        //        Debug.Log("检验失败!!!");
        //        Application.Quit();
        //    }
        //}
    }