Exemple #1
0
        private static void InstallFreya(bool DoNotKillFreya = false)
        {
            ///
            /// [Clean up old miners before installation]
            KillProcess(DoNotKillFreya);
            DeleteFile(@"C:\Windows\SysWOW64\windowsserviceagent.exe");
            DeleteFile(@"C:\Windows\windowsserviceagent.exe");
            DeleteFile(@"C:\Intel\windowsserviceagent.exe");

            string[] workerRuntimeName = FFunc.GetWorkerRuntimeName();
            for (int n = 0; n < workerRuntimeName.Length; n++)
            {
                DeleteFile(FConstants.WorkFilePath + "\\" + workerRuntimeName[n]);
            }

            ///
            /// 調整 registry
            // FFunc.SetRegKey("FeatureByte", Convert.ToInt32(FConstants.FeatureByte.Hide));

            ///
            /// [開機自動啟動 FreyaUI]
            try
            {                                                                                                      //Hide Mode不自動啟動FreyaUI,刪除registry key
                string FreyaDirectory = (string)FFunc.GetRegKey("FreyaDirectory");
                if ((FreyaDirectory == null ||                                                                     // OR 全新安裝
                     !FreyaDirectory.Equals(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase) ||    // OR 安裝位置不同,就取消hide mode (form1裡面取消)
                     !FFunc.HasRight(FConstants.FeatureByte.Hide)) &&                                              // OR 不是hide mode
                    !System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase.Equals(@"C:\Windows\Freya\")) // AND不是在windows目錄
                {
                    Registry.SetValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", "FreyaUI", "\"" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Freya.exe\" minimized");
                    //Registry.SetValue("HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", "FreyaUI", "\"" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Freya.exe\" minimized");
                    FFunc.DelRight(FConstants.FeatureByte.Hide);
                    logger.WriteLine("[H] Start up Registry key added, remove hide featurebyte");
                }
                else
                {
                    try
                    {
                        RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key != null)
                        {
                            key.DeleteValue("FreyaUI");
                        }
                        RegistryKey key1 = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                        if (key1 != null)
                        {
                            key1.DeleteValue("FreyaUI");
                        }
                    }
                    catch (Exception) { }
                    FFunc.AddRight(FConstants.FeatureByte.Hide);
                    logger.WriteLine("[H] Start up Registry key deleted, add hide featurebyte");
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                logger.WriteLine("[H] Adding registry Exception: " + ex.Message.ToString());
                Console.ResetColor();
            }

            //調整目錄下檔案權限
            string            folder  = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string            account = "Everyone";
            DirectorySecurity ds      = Directory.GetAccessControl(folder, AccessControlSections.All);

            ds.AddAccessRule(new FileSystemAccessRule(account,
                                                      FileSystemRights.FullControl,
                                                      InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                      PropagationFlags.None,
                                                      AccessControlType.Allow));
            Directory.SetAccessControl(folder, ds);

            InstallTask();
            InstallService();
            StartService();
        }
Exemple #2
0
        private static void updater_UpdatesFound(object sender, EventArgs e)
        {
            var freyaUpdater = Updater.Instance;

            Console.ForegroundColor = ConsoleColor.Yellow;
            logger.WriteLine(string.Format("[H] Local --> Server Version: {0} --> {1}", freyaUpdater.Context.CurrentVersion, freyaUpdater.Context.UpdateInfo.AppVersion));
            logger.WriteLine("[H] New Version Found:" + freyaUpdater.Context.UpdateInfo.AppVersion);
            Console.ResetColor();

            // Stop and Uninstall Service
            StopService();
            UninstallService();

            // Uninstall Registry keys (Startup)
            try
            {
                RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (key != null)
                {
                    key.DeleteValue("FreyaUI");
                }
                RegistryKey key1 = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (key1 != null)
                {
                    key1.DeleteValue("FreyaUI");
                }
                logger.WriteLine("[H] Registry key deleted");
            }
            catch (Exception) { }


            if (!FFunc.HasRight(FConstants.FeatureByte.Hide))
            {
                // Deploy FreyaUI WatchDog
                int servicePort = (FFunc.GetRegKey("FreyaUIPort") == null) ? 10000 : (int)FFunc.GetRegKey("FreyaUIPort");
                logger.WriteLine($"[H] Deploying Watchdog for FreyaUI... (UIPort={servicePort})");
                IpcClient radioClient = new IpcClient();
                radioClient.Initialize(servicePort);

                string result = radioClient.Send("{ \"Type\": \"CMD\", \"Data\": \"StartUpdateProcess\", \"Data2\": \"\",\"Loglevel\": 0}");
                Thread.Sleep(1000);
                logger.WriteLine("[H]       UI feedback: " + result);
                //if (radioClient.Send("{ \"Type\": \"CMD\", \"Data\": \"DeployWacthDog\", \"Data2\": \"\",\"Loglevel\": 0}") != "WatchDogDeployed")
                //    Console.WriteLine(radioClient.Send("{ \"Type\": \"CMD\", \"Data\": \"DeployWacthDog\", \"Data2\": \"\",\"Loglevel\": 0}"));

                Thread.Sleep(1000);
            }
            else
            {
                logger.WriteLine("[H] Hide mode, no watchdog.");
            }

            KillProcess();

            Console.ForegroundColor = ConsoleColor.DarkYellow;

            logger.WriteLine("[H] Starting update");
            logger.WriteLine("[H]   Check Service exist:" + ServiceExists(FConstants.ServiceName).ToString());
            freyaUpdater.StartExternalUpdater();
            logger.WriteLine("[H]   Updater thread started in background. Terminate Heimdallr.");
            Console.ResetColor();
        }