Exemplo n.º 1
0
 public MainViewModel()
 {
     AddItemCommand = ActionCommand.Create(parameter =>
     {
         Items.Add(DateTime.Now.ToString());
     });
 }
Exemplo n.º 2
0
 public IgnoreTree(string directory, string pattern, Action closeAction)
     : this()
 {
     this._closeAction = closeAction;
     this.ViewModel    = new IgnoreTreeModel(directory, pattern);
     this.CloseCommand = ActionCommand.Create(this._closeAction);
     this.ToggleShowAllFilesCommand = ActionCommand.Create(() => this.ViewModel.ShowAllFiles = !this.ViewModel.ShowAllFiles);
     this.ToggleSyncCommand         = ActionCommand.Create(() => this.ViewModel.SyncToSolutionExplorer = !this.ViewModel.SyncToSolutionExplorer);
 }
Exemplo n.º 3
0
        public MainWindowViewModel(IServiceProvider provider)
        {
            var processObserver = provider.GetRequiredService <IProcessObserverService>();

            _injectorFactory = provider.GetRequiredService <ISocketHookServiceFactory>();
            _optionsService  = provider.GetRequiredService <IInjectOptionsService>();
            Processes        = processObserver.GetObservableCollection();

            Refresh  = ActionCommand.Create(processObserver.Refresh);
            Settings = ActionCommand.Create(() => provider.GetRequiredService <InjectOptionsView>());
            InjectTo = AsyncCommand.CreateWithInput <ObservedProcess>(async item =>
            {
                if (item == default)
                {
                    MessageBox.Show("You must select a process before injecting !", "Warning", MessageBoxButton.OK,
                                    MessageBoxImage.Exclamation);
                    return;
                }

                var current = _optionsService.GetCurrentOptions();
                if (current == default)
                {
                    MessageBox.Show("Couldn't find inject options, you must configure them within the settings view !",
                                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var(options, _) = current;
                var injector    = _injectorFactory.CreateWith(options);
                if (!await injector.TryInject((int)item.ProcessId))
                {
                    MessageBox.Show($"Couldn't inject to process with id:{item.ProcessId}, name:{item.FileName} !", "Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                MessageBox.Show($"Successfully injected to current {item.FileName} process !", "Success",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            });

            CreateAndInject = AsyncCommand.Create(async() =>
            {
                var dialog = new OpenFileDialog
                {
                    InitialDirectory = Directory.GetCurrentDirectory(),
                    Filter           = "EXE Files(*.exe) | *.exe",
                    DefaultExt       = ".exe",
                    Multiselect      = false
                };

                var result = dialog.ShowDialog();
                if (!result.HasValue || result == false)
                {
                    return;
                }
                var current = _optionsService.GetCurrentOptions();
                if (current == default)
                {
                    MessageBox.Show("Couldn't find inject options, you must configure them within the settings view !",
                                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var(options, _) = current;
                var injector    = _injectorFactory.CreateWith(options);
                if (!await injector.TryCreateAndInject(dialog.FileName))
                {
                    MessageBox.Show($"Couldn't create and inject to file at : {dialog.FileName} !", "Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                MessageBox.Show($"Successfully created and injected executable at {dialog.FileName} !", "Success",
                                MessageBoxButton.OK, MessageBoxImage.Information);
            });
        }