private void ThemeListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            string       settings     = File.ReadAllText(Environment.CurrentDirectory + "/settings.json");
            HookSettings hookSettings = JsonConvert.DeserializeObject <HookSettings>(settings);

            hookSettings.theme = themeListBox.SelectedItem.ToString();
            File.WriteAllText(Environment.CurrentDirectory + "/settings.json", JsonConvert.SerializeObject(hookSettings));
            Program.resetForms();
        }
Example #2
0
        //挂接检测
        private void button2_Click(object sender, EventArgs e)
        {
            HookSettings hookSettings = new HookSettings(false, false);

            if (hookSettings.ShowDialog() == DialogResult.OK)
            {
                button2.Text = "已设置";
            }
        }
        private void PluginList_ItemCheck(object sender, ItemCheckedEventArgs e)
        {
            string        settings     = File.ReadAllText(Environment.CurrentDirectory + "/settings.json");
            HookSettings  hookSettings = JsonConvert.DeserializeObject <HookSettings>(settings);
            List <string> checks       = new List <string>();

            foreach (ListViewItem chkd in pluginList.CheckedItems)
            {
                checks.Add(chkd.Text);
            }
            hookSettings.enabledPlugins = checks;
            File.WriteAllText(Environment.CurrentDirectory + "/settings.json", JsonConvert.SerializeObject(hookSettings));
        }
Example #4
0
        static void Main(string[] args)
        {
            SetupConsole();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("hooksettings.json", optional: false)
                                .Build();

            var settings = new HookSettings();

            configuration.Bind(settings);

            try
            {
                _ipcServer = RemoteHooking.IpcCreateServer <HookInterface>(ref _channelName, WellKnownObjectMode.Singleton);
                RemoteHooking.CreateAndInject(
                    settings.ExePath,
                    string.Empty,
                    0x00000004,
                    InjectionOptions.DoNotRequireStrongName,
                    hookPath,
                    hookPath,
                    out var pId,
                    _channelName,
                    settings.RedirectedIps,
                    settings.RedirectionPort);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            while (true)
            {
                Thread.Sleep(1000);          // TODO: handle close request etc.
            }
        }
        private void SettingsWindow_Load(object sender, EventArgs e)
        {
            string settings  = File.ReadAllText(Environment.CurrentDirectory + "/settings.json");
            string themeName = JsonConvert.DeserializeObject <HookSettings>(settings).theme;
            string json      = File.ReadAllText(Environment.CurrentDirectory + "/Themes/" + themeName + ".json");
            Theme  theme     = JsonConvert.DeserializeObject <Theme>(json);

            this.BackColor = theme.mainColor;
            this.selectThemeLabel.ForeColor = theme.textColor;
            this.selectThemeLabel.BackColor = theme.mainColor;
            this.themeListBox.BackColor     = theme.mainColor;
            this.themeListBox.ForeColor     = theme.textColor;
            this.pluginLabel.ForeColor      = theme.textColor;
            this.pluginLabel.BackColor      = theme.mainColor;
            this.pluginList.BackColor       = theme.mainColor;
            this.pluginList.ForeColor       = theme.textColor;
            this.closeButton.BackColor      = theme.mainColor;

            HookSettings hookSettings = JsonConvert.DeserializeObject <HookSettings>(settings);

            foreach (FileInfo finfo in new DirectoryInfo(Environment.CurrentDirectory + "\\Themes").GetFiles())
            {
                this.themeListBox.Items.Add(finfo.Name.Replace(".json", ""));
            }
            foreach (FileInfo finfo in new DirectoryInfo(Environment.CurrentDirectory + "\\Plugins").GetFiles())
            {
                this.pluginList.Items.Add(finfo.Name);
            }
            foreach (ListViewItem chkd in pluginList.Items)
            {
                if (hookSettings.enabledPlugins.Contains(chkd.Text))
                {
                    chkd.Checked = true;
                }
            }
        }
 public void ConfigureHook(string gitHubHookId, string gitHubUsername, string gitHubRepo)
 {
     var config = new HookSettings();
     config.active = true;
     config.events = new[]
     {
         "push",
         "issues",
         "issue_comment",
         "commit_comment",
         "pull_request",
         "pull_request_review_comment",
         "gollum",
         "watch",
         "download",
         "fork",
         "fork_apply",
         "member",
         "public",
         "team_add",
         "status",
     };
     string json = JsonConvert.SerializeObject(config);
     var request =
         new RestRequest(string.Format("/repos/{0}/{1}/hooks/{2}", gitHubUsername, gitHubRepo, gitHubHookId),
             Method.PATCH);
     request.RequestFormat = DataFormat.Json;
     request.AddBody(config);
     IRestResponse response = _gitHubClient.Execute(request);
     if (!string.IsNullOrWhiteSpace(response.ErrorMessage) || response.StatusCode != HttpStatusCode.OK)
     {
         Console.WriteLine(string.Format("Encountered an error trying to reconfigure the hook: {0}",
             response.ErrorMessage));
         throw new Exception("Unable to reconfigure hook.");
     }
     Console.WriteLine("I have reconfigured the hook - you should get notifications for all events now.");
 }
Example #7
0
        public static void loadPlugins()
        {
            string           settings     = File.ReadAllText(Environment.CurrentDirectory + "/settings.json");
            HookSettings     hookSettings = JsonConvert.DeserializeObject <HookSettings>(settings);
            BackgroundWorker pluginWorker = new BackgroundWorker();

            pluginWorker.DoWork += (object sender, DoWorkEventArgs e) =>
            {
                string        currentDir = Environment.CurrentDirectory;
                DirectoryInfo pluginDir  = new DirectoryInfo(currentDir + "\\Plugins");
                if (!pluginDir.Exists)
                {
                    pluginDir.Create();
                }
                foreach (FileInfo file in pluginDir.GetFiles())
                {
                    if (!file.Name.Contains(".dll"))
                    {
                        Logger.Log("Skipping " + file.Name + " as it isnt a .dll");
                        continue;
                    }
                    if (!hookSettings.enabledPlugins.Contains(file.Name))
                    {
                        Logger.Log("Skipping " + file.Name + " as it isnt enabled.");
                        continue;
                    }
                    BackgroundWorker pluginLoadWorker = new BackgroundWorker();
                    pluginLoadWorker.DoWork += (object obj, DoWorkEventArgs dw) =>
                    {
                        try
                        {
                            Logger.Log("Unblocking " + file.Name);
                            FileUnblocker.Unblock(file.FullName);
                            Logger.Log("Attempting to load " + file.Name);
                            Assembly pluginAsm  = Assembly.LoadFrom(file.FullName);
                            Type     pluginType = typeof(NkPlugin);
                            foreach (Type t in pluginAsm.GetTypes())
                            {
                                //Logger.Log("Found class " + t.Name);
                                if (pluginType.IsAssignableFrom(t))
                                {
                                    Logger.Log("Found " + t.Name + " to be assignable");
                                    NkPlugin plugin = (NkPlugin)Activator.CreateInstance(t);
                                    plugin.NkLoad();
                                    Logger.Log("Loaded " + t.Name + " via NkPlugin load function");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Log("Exception while loading plugin!");
                            Logger.Log("-------------------------------");
                            Logger.Log("Message: " + ex.Message);
                            Logger.Log("Stacktrace:\n" + ex.StackTrace);
                            Logger.Log("-------------------------------");
                        }
                    };
                    pluginLoadWorker.RunWorkerAsync();
                }
                Console.Title = "NKHook5-Console";
            };
            pluginWorker.RunWorkerAsync();
        }