Пример #1
0
        /// <summary>
        /// Gets or sets the graphics interface shared between client and hook
        /// </summary>
        // private IGraphicsInterface GraphicsInterface { get; set; }

        /// <summary>
        /// Gets or sets the speedhack interface shared between client and hook
        /// </summary>
        //  private ISpeedHackInterface SpeedHackInterface { get; set; }

        /// <summary>
        /// Injects the hook into the specified process
        /// </summary>
        /// <param name="process">The process to inject into</param>
        public override void Inject(Int32 processId)
        {
            String channelName = null;

            // Initialize the IPC server, giving the server access to the interfaces defined here
            IChannel server = EasyHook.RemoteHooking.IpcCreateServer <HookClient>(ref channelName, WellKnownObjectMode.Singleton, this);

            try
            {
                // Inject DLL into target process
                EasyHook.RemoteHooking.Inject(
                    processId,
                    EasyHook.InjectionOptions.Default,
                    typeof(HookServer).Assembly.Location,
                    typeof(HookServer).Assembly.Location,
                    channelName);
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to Hook Process, some features may not be available", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
            }

            // this.GraphicsInterface = GraphicsFactory.GetGraphicsInterface(projectDirectory);
            // this.SpeedHackInterface = new SpeedHackInterface();
        }
Пример #2
0
        /// <summary>
        /// Starts a proxy service
        /// </summary>
        /// <param name="executableName">The executable name of the service to start</param>
        /// <param name="channelServerName">The channel name for IPC</param>
        /// <returns>The proxy service that is created</returns>
        private IProxyService StartProxyService(String executableName, String channelServerName)
        {
            try
            {
                // Start the proxy service
                EventWaitHandle  processStartEvent = new EventWaitHandle(false, EventResetMode.ManualReset, ProxyCommunicator.WaitEventName);
                ProcessStartInfo processInfo       = new ProcessStartInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), executableName));
                processInfo.Arguments       = Process.GetCurrentProcess().Id.ToString() + " " + channelServerName + " " + ProxyCommunicator.WaitEventName;
                processInfo.UseShellExecute = false;
                processInfo.CreateNoWindow  = true;
                Process.Start(processInfo);
                processStartEvent.WaitOne();

                // Create connection
                NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                binding.ReceiveTimeout         = TimeSpan.MaxValue;
                binding.MaxReceivedMessageSize = Int32.MaxValue;
                binding.MaxBufferSize          = Int32.MaxValue;

                EndpointAddress endpoint     = new EndpointAddress(channelServerName);
                IProxyService   proxyService = ChannelFactory <IProxyService> .CreateChannel(binding, endpoint);

                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Started proxy service: " + executableName + " over channel " + channelServerName);

                return(proxyService);
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, "Failed to start proxy service: " + executableName + ". This may impact Scripts and .NET explorer", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Invoked when the browser is about to navigate to a new page.
        /// </summary>
        /// <param name="sender">Sending object.</param>
        /// <param name="e">Cancel event args.</param>
        private void BrowserNavigating(Object sender, NavigatingCancelEventArgs e)
        {
            if (e == null || e.Uri == null || e.Uri.AbsoluteUri == null)
            {
                return;
            }

            try
            {
                if (e.Uri.AbsoluteUri.StartsWith(TwitchLoginViewModel.LoginCallbackUrl))
                {
                    NameValueCollection queries = HttpUtility.ParseQueryString(e.Uri.Query);
                    String code = queries["code"];
                    e.Cancel = true;

                    // Pass the code from the query string to the view model command to fetch the oauth codes
                    this.TwitchLoginViewModel.PerformLoginCommand.Execute(code);

                    this.DialogResult = true;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error handling web request", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.TwitchLogin, ex);
            }
        }
Пример #4
0
        /// <summary>
        /// Runs the activation function in the script.
        /// </summary>
        /// <param name="scriptItem">The script to run.</param>
        /// <returns>Returns true if the function successfully ran, otherwise false.</returns>
        public Boolean RunActivationFunction(ScriptItem scriptItem)
        {
            try
            {
                Assembly assembly = Assembly.Load(Compression.Decompress(Convert.FromBase64String(scriptItem.CompiledScript)));

                this.ScriptObject = assembly.CreateObject("*");

                // Bind the deactivation function such that scripts can deactivate themselves
                this.ScriptObject.Deactivate = new Action(() => scriptItem.IsActivated = false);

                // Call OnActivate function in the script
                this.ScriptObject.OnActivate();

                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Script activated: " + scriptItem.Name?.ToString());
            }
            catch (SecurityException ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Invalid operation in sandbox environment", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return(false);
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to activate script", ex);
                return(false);
            }

            return(true);
        }
Пример #5
0
        /// <summary>
        /// Starts useful services that run in the background to assist in various operations.
        /// </summary>
        private void StartBackgroundServices()
        {
            DotNetObjectCollector.GetInstance().Start();
            AddressResolver.GetInstance().Start();
            AnalyticsService.GetInstance().Start();

            AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, "Start");
            OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Background services started");
        }
Пример #6
0
        /// <summary>
        /// Gets all modules in the opened process.
        /// </summary>
        /// <returns>A collection of modules in the process.</returns>
        public IEnumerable <NormalizedModule> GetModules()
        {
            // Query all modules in the target process
            IntPtr[] modulePointers = new IntPtr[0];
            Int32    bytesNeeded    = 0;

            List <NormalizedModule> modules = new List <NormalizedModule>();

            if (this.SystemProcess == null)
            {
                return(modules);
            }

            try
            {
                // Determine number of modules
                if (!NativeMethods.EnumProcessModulesEx(this.SystemProcess.Handle, modulePointers, 0, out bytesNeeded, (UInt32)Enumerations.ModuleFilter.ListModulesAll))
                {
                    return(modules);
                }

                Int32 totalNumberofModules = bytesNeeded / IntPtr.Size;
                modulePointers = new IntPtr[totalNumberofModules];

                if (NativeMethods.EnumProcessModulesEx(this.SystemProcess.Handle, modulePointers, bytesNeeded, out bytesNeeded, (UInt32)Enumerations.ModuleFilter.ListModulesAll))
                {
                    for (Int32 index = 0; index < totalNumberofModules; index++)
                    {
                        StringBuilder moduleFilePath = new StringBuilder(1024);
                        NativeMethods.GetModuleFileNameEx(this.SystemProcess.Handle, modulePointers[index], moduleFilePath, (UInt32)moduleFilePath.Capacity);

                        String            moduleName        = Path.GetFileName(moduleFilePath.ToString());
                        ModuleInformation moduleInformation = new ModuleInformation();
                        NativeMethods.GetModuleInformation(this.SystemProcess.Handle, modulePointers[index], out moduleInformation, (UInt32)(IntPtr.Size * modulePointers.Length));

                        // Ignore modules in 64-bit address space for WoW64 processes
                        if (EngineCore.GetInstance().Processes.IsOpenedProcess32Bit() && moduleInformation.ModuleBase.ToUInt64() > Int32.MaxValue)
                        {
                            continue;
                        }

                        // Convert to a normalized module and add it to our list
                        NormalizedModule module = new NormalizedModule(moduleName, moduleInformation.ModuleBase, (Int32)moduleInformation.SizeOfImage);
                        modules.Add(module);
                    }
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to fetch modules from selected process", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
            }

            return(modules);
        }
Пример #7
0
        /// <summary>
        /// Export a project to separate files.
        /// </summary>
        public void ExportProject()
        {
            Task.Run(() =>
            {
                // Export the project items to thier own individual files
                try
                {
                    if (String.IsNullOrEmpty(this.ProjectFilePath) || !Directory.Exists(Path.GetDirectoryName(this.ProjectFilePath)))
                    {
                        OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Please save the project before exporting");
                        return;
                    }

                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Project export starting");

                    String folderPath = Path.Combine(Path.GetDirectoryName(this.ProjectFilePath), "Export");
                    Directory.CreateDirectory(folderPath);

                    Parallel.ForEach(
                        ProjectExplorerViewModel.GetInstance().ProjectItems,
                        SettingsViewModel.GetInstance().ParallelSettingsFast,
                        (projectItem) =>
                    {
                        ProjectItem targetProjectItem = projectItem;

                        if (targetProjectItem == null)
                        {
                            return;
                        }

                        String filePath = Path.Combine(folderPath, targetProjectItem.Name + ProjectItemStorage.ProjectFileExtension);

                        using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                        {
                            List <ProjectItem> newProjectRoot = new List <ProjectItem>();
                            newProjectRoot.Add(targetProjectItem);

                            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                            serializer.WriteObject(fileStream, newProjectRoot.ToArray());
                        }
                    });
                }
                catch (Exception ex)
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, "Unable to complete export project", ex);
                    AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                    return;
                }

                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Project export complete");
            });
        }
Пример #8
0
        /// <summary>
        /// Save a project to disk.
        /// </summary>
        public void SaveProject()
        {
            // Save the project file
            try
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter           = ProjectExplorerViewModel.ProjectExtensionFilter;
                saveFileDialog.Title            = "Save Project";
                saveFileDialog.FileName         = String.IsNullOrWhiteSpace(this.ProjectFilePath) ? String.Empty : Path.GetFileName(this.ProjectFilePath);
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.InitialDirectory = String.IsNullOrWhiteSpace(this.ProjectFilePath) ? String.Empty : Path.GetDirectoryName(this.ProjectFilePath);

                if (saveFileDialog.ShowDialog() == true)
                {
                    this.ProjectFilePath = saveFileDialog.FileName;

                    using (FileStream fileStream = new FileStream(this.ProjectFilePath, FileMode.Create, FileAccess.Write))
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                        serializer.WriteObject(fileStream, ProjectExplorerViewModel.GetInstance().ProjectItems.ToArray());
                    }

                    this.HasUnsavedChanges = false;
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, "Unable to save project", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }

            // Save the hotkey profile
            try
            {
                String hotkeyFilePath = this.GetHotkeyFilePathFromProjectFilePath(this.ProjectFilePath);

                using (FileStream fileStream = new FileStream(hotkeyFilePath, FileMode.Create, FileAccess.Write))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItemHotkey[]));
                    ProjectItemHotkey[]        hotkeys    = ProjectExplorerViewModel.GetInstance().ProjectItems?.Select(x => new ProjectItemHotkey(x.HotKey, x.Guid)).ToArray();
                    serializer.WriteObject(fileStream, hotkeys);
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to save hotkey profile", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }
        }
Пример #9
0
        public static void SnapShotPng(UIElement source, String destination, Int32 zoom)
        {
            try
            {
                Double actualHeight = source.RenderSize.Height;
                Double actualWidth  = source.RenderSize.Width;

                Double renderHeight = actualHeight * zoom;
                Double renderWidth  = actualWidth * zoom;

                RenderTargetBitmap renderTarget = new RenderTargetBitmap((Int32)renderWidth, (Int32)renderHeight, 96, 96, PixelFormats.Pbgra32);
                VisualBrush        sourceBrush  = new VisualBrush(source);

                DrawingVisual  drawingVisual  = new DrawingVisual();
                DrawingContext drawingContext = drawingVisual.RenderOpen();

                using (drawingContext)
                {
                    drawingContext.PushTransform(new ScaleTransform(zoom, zoom));
                    drawingContext.DrawRectangle(sourceBrush, null, new Rect(new System.Windows.Point(0, 0), new System.Windows.Point(actualWidth, actualHeight)));
                }

                renderTarget.Render(drawingVisual);

                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(renderTarget));

                using (FileStream stream = new FileStream(destination, FileMode.Create, FileAccess.Write))
                {
                    encoder.Save(stream);
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to export image", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
            }
        }
Пример #10
0
        /// <summary>
        /// Opens a project from disk.
        /// </summary>
        public void OpenProject()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = ProjectExtensionFilter;
            openFileDialog.Title  = "Open Project";

            if (openFileDialog.ShowDialog() == false)
            {
                return;
            }

            ProjectExplorerViewModel.GetInstance().ProjectItems = new FullyObservableCollection <ProjectItem>();
            this.ProjectFilePath = openFileDialog.FileName;

            // Open the project file
            try
            {
                if (!File.Exists(this.ProjectFilePath))
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to locate project.");
                    return;
                }

                using (FileStream fileStream = new FileStream(this.ProjectFilePath, FileMode.Open, FileAccess.Read))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                    ProjectExplorerViewModel.GetInstance().ProjectItems = new FullyObservableCollection <ProjectItem>(serializer.ReadObject(fileStream) as ProjectItem[]);
                    this.HasUnsavedChanges = false;
                }
            }
            catch (Exception ex)
            {
                this.ProjectFilePath = String.Empty;
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to open project", ex.ToString());
                return;
            }

            // Open the hotkey file
            try
            {
                String hotkeyFilePath = this.GetHotkeyFilePathFromProjectFilePath(this.ProjectFilePath);

                if (File.Exists(hotkeyFilePath))
                {
                    using (FileStream fileStream = new FileStream(hotkeyFilePath, FileMode.Open, FileAccess.Read))
                    {
                        DataContractJsonSerializer serializer         = new DataContractJsonSerializer(typeof(ProjectItemHotkey[]));
                        ProjectItemHotkey[]        projectItemHotkeys = serializer.ReadObject(fileStream) as ProjectItemHotkey[];

                        this.BindHotkeys(ProjectExplorerViewModel.GetInstance().ProjectItems, projectItemHotkeys);
                    }
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Unable to open hotkey profile", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }
        }
Пример #11
0
        /// <summary>
        /// Imports a project from disk, adding the project items to the current project.
        /// </summary>
        /// <param name="filename">The file path of the project to import.</param>
        public void ImportProject(Boolean resetGuids = true, String filename = null)
        {
            // Ask for a specific file if one was not explicitly provided
            if (filename == null || filename == String.Empty)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = ProjectExtensionFilter;
                openFileDialog.Title  = "Import Project";

                if (openFileDialog.ShowDialog() == false)
                {
                    return;
                }

                filename = openFileDialog.FileName;

                // Clear the current project, such that on save the user is prompted to reselect this
                this.ProjectFilePath = null;
            }

            // Import the project file
            ProjectItem[] importedProjectRoot = null;

            try
            {
                if (!File.Exists(filename))
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to locate project.");
                    return;
                }

                using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                    importedProjectRoot = deserializer.ReadObject(fileStream) as ProjectItem[];

                    // Add each high level child in the project root to this project
                    foreach (ProjectItem child in importedProjectRoot)
                    {
                        ProjectExplorerViewModel.GetInstance().AddNewProjectItems(false, importedProjectRoot);
                    }

                    this.HasUnsavedChanges = true;
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to import project", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }

            // Import the hotkey file
            try
            {
                String hotkeyFilePath = this.GetHotkeyFilePathFromProjectFilePath(filename);

                if (File.Exists(hotkeyFilePath))
                {
                    using (FileStream fileStream = new FileStream(hotkeyFilePath, FileMode.Open, FileAccess.Read))
                    {
                        DataContractJsonSerializer serializer         = new DataContractJsonSerializer(typeof(ProjectItemHotkey[]));
                        ProjectItemHotkey[]        projectItemHotkeys = serializer.ReadObject(fileStream) as ProjectItemHotkey[];

                        // Bind the hotkey to this project item
                        this.BindHotkeys(importedProjectRoot, projectItemHotkeys);
                    }
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Unable to open hotkey profile", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }

            // Randomize the guid for imported project items, preventing possible conflicts
            if (resetGuids && importedProjectRoot != null)
            {
                foreach (ProjectItem child in importedProjectRoot)
                {
                    child.ResetGuid();
                }
            }
        }