コード例 #1
0
        private void InvokeMethod(MethodBase method, Object context)
        {
            try
            {
                var    arguments = CreateInjectMethodArguments(method.GetParameters(), context);
                Object thisObj   = null;

                // check if I have to create an instance to invoke the method
                if (!method.IsStatic)
                {
                    var constructor = method.DeclaringType.GetConstructors().FirstOrDefault();
                    if (constructor != null)
                    {
                        var constructorArguments = CreateArgumentArray(constructor.GetParameters());
                        thisObj = Activator.CreateInstance(method.DeclaringType, constructorArguments);
                    }
                }
                // invoke the method
                var task = Task.Factory.StartNew(() => method.Invoke(thisObj, arguments), TaskCreationOptions.LongRunning);

                // wait one second to grab early execution exceptions
                Thread.Sleep(1000);

                if (task.Exception != null)
                {
                    _lastError        = InjectionResult.ErrorDuringInvocation;
                    _lastErrorMessage = task.Exception.ToString();
                }
            }
            catch
            {
                _lastError = InjectionResult.ErrorDuringInvocation;
            }
        }
コード例 #2
0
 private void AfterRead(InjectionResult r)
 {
     if (r == InjectionResult.Success)
     {
         set(Items.ToArray());
     }
 }
コード例 #3
0
    public void WriteToSource()
    {
        uint offset = sbc.GetDefaultOffset();

        injector.SetWriteOffset(offset);
        try
        {
            InjectionResult injectionResult = injector.Write(true);
            if (injectionResult == InjectionResult.Success)
            {
                HappyParticles.gameObject.SetActive(true);
                HappyParticles.Stop();
                HappyParticles.Play();
            }
            else
            {
                Debug.Log(injectionResult.ToString());
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.Message);
            UISB.ConnectedText.text = (ex.Message);
            UISB.SetConnected(val: false);
        }
    }
コード例 #4
0
ファイル: UI_ACItemGrid.cs プロジェクト: StirlingPM/Nookazon
 private static void AfterWrite(InjectionResult r)
 {
     Debug.Log($"Write result: {r}");
     if (r != InjectionResult.Success)
         if (r != InjectionResult.Same)
             PopupHelper.CreateError($"Write result: {r}", 2f);
 }
コード例 #5
0
ファイル: UI_ACItemGrid.cs プロジェクト: StirlingPM/Nookazon
    public void ReadFromSourceUSBA()
    {
        uint offset = sbc.GetDefaultOffset();
        AutoInjector platformInjector;
#if UNITY_STANDALONE || UNITY_EDITOR
        platformInjector = usbInjector;
#else
        platformInjector = usbaInjector;
#endif
        platformInjector.SetWriteOffset(offset);
        platformInjector.ValidateEnabled = UI_Settings.GetValidateData();
        try
        {
            InjectionResult injectionResult = platformInjector.Read(true);
            if (injectionResult != InjectionResult.Success)
            {
                Debug.Log(injectionResult.ToString());
#if UNITY_STANDALONE || UNITY_EDITOR
                PopupHelper.CreateError(injectionResult.ToString(), 2f);
#endif
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.Message);
            UISB.ConnectedText.text = (ex.Message);
            UISB.SetConnected(false);
#if UNITY_STANDALONE || UNITY_EDITOR
            PopupHelper.CreateError(ex.Message, 2f);
#endif
        }
    }
コード例 #6
0
 private void SetLastError()
 {
     if (_lastError == InjectionResult.Success)
     {
         _lastError = _pipeChanell.GetLastError();
     }
 }
コード例 #7
0
        void InjectDLL()
        {
            InjectionResult Result = DllInjector.Instance.Inject("RocketLeague", Properties.Settings.Default.FolderPath + "\\BakkesMod\\bakkesmod.dll");

            switch (Result)
            {
            case InjectionResult.DLL_NOT_FOUND:
                StatusLbl.Text  = "Status: Could Not Find DLL File.";
                InjectionStatus = StatusStrings.INSTALLATION_WRONG;
                break;

            case InjectionResult.GAME_PROCESS_NOT_FOUND:
                StatusLbl.Text  = "Status: Uninjected.";
                InjectionStatus = StatusStrings.PROCESS_NOT_ACTIVE;
                break;

            case InjectionResult.INJECTION_FAILED:
                StatusLbl.Text  = "Status: Injection Failed.";
                InjectionStatus = StatusStrings.INJECTION_FAILED;
                break;

            case InjectionResult.SUCCESS:
                StatusLbl.Text  = "Status: Successfully Injected.";
                InjectionStatus = StatusStrings.INJECTED;
                IsInjected      = true;
                break;
            }
        }
コード例 #8
0
    public void WriteToSource()
    {
        uint offset = sbc.GetDefaultOffset();

        injector.SetWriteOffset(offset);
        injector.ValidateEnabled = UI_Settings.GetValidateData();
        try
        {
            InjectionResult injectionResult = injector.Write(true);
            if (injectionResult == InjectionResult.Success)
            {
                PlayHappyParticles();
            }
            else
            {
                Debug.Log(injectionResult.ToString());
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.Message);
            UISB.ConnectedText.text = (ex.Message);
            UISB.SetConnected(val: false);
        }
    }
コード例 #9
0
        private Boolean ProcessCommand(PipeMessage msg)
        {
            var exit    = false;
            var msgType = msg.GetType();

            if (msgType.Equals(Constants.Token, StringComparison.OrdinalIgnoreCase))
            {
                _metadataToken = Int32.Parse(msg.GetData());
            }
            else if (msgType.Equals(Constants.Assembly, StringComparison.OrdinalIgnoreCase))
            {
                _assemblyBuffer = Convert.FromBase64String(msg.GetData());
            }
            else if (msgType.Equals(Constants.Dependency, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    var assemblyBuffer = Convert.FromBase64String(msg.GetData());
                    var assembly       = Assembly.Load(assemblyBuffer);
                    if (!_dependencies.ContainsKey(assembly.FullName))
                    {
                        _dependencies.Add(assembly.FullName, assembly);
                    }
                }
                catch
                {
                    _lastError = InjectionResult.InvalidAssemblyDependencyBuffer;
                }
            }
            else if (msgType.Equals(Constants.File, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    var data           = msg.GetData();
                    var indexOfPipe    = data.IndexOf("|");
                    var filenameLength = Int32.Parse(data.Substring(0, indexOfPipe));
                    var filename       = data.Substring(indexOfPipe + 1, filenameLength);
                    var fileContent    = Convert.FromBase64String(data.Substring(indexOfPipe + 1 + filenameLength));
                    File.WriteAllBytes(filename, fileContent);
                }
                catch
                {
                    _lastError = InjectionResult.InvalidFileBuffer;
                }
            }
            else if (msgType.Equals(Constants.Run, StringComparison.OrdinalIgnoreCase))
            {
                if (_assemblyBuffer == null)
                {
                    _lastError = InjectionResult.InvalidAssemblyBuffer;
                }
                else
                {
                    ActivateDll();
                }

                exit = true;
            }
            return(exit);
        }
コード例 #10
0
        public void ActivateAssembly()
        {
            try
            {
                _client.Connect(3000);
                if (_client.IsConnected)
                {
                    // send assembly and run it
                    var invocationResult =
                        _pipeChanell.SendMessage(Constants.Ping) &&
                        SendDependencies() &&
                        SendFiles() &&
                        SendToken() &&
                        SendAssembly() &&
                        _pipeChanell.SendMessage(Constants.Run);

                    _client.Dispose();
                    SetLastError();
                }
                else
                {
                    _lastError = InjectionResult.UnableToConnectToNamedPipe;
                }
            }
            catch (TimeoutException)
            {
                _lastError = InjectionResult.UnableToConnectToNamedPipe;
            }
        }
コード例 #11
0
        private void Attach_Click(object sender, RoutedEventArgs e)
        {
            InjectionResult val = Injector.Inject();

            if ((int)val.Result == 0)
            {
                //		scripts.Items.Add(">Connected and Injected");
                Bridge.Sentinel.Start();
            }
            if ((int)val.Result == 3)
            {
                //		scripts.Items.Add(">Injection Failed, Make sure you have all files");
            }
            if ((int)val.Result == 4)
            {
                //		scripts.Items.Add(">Injection failed, something interfered with injection.");
            }
            if ((int)val.Result == 2)
            {
                //		scripts.Items.Add(">Injection failed, multiple Roblox processes are running.");
            }
            if ((int)val.Result == 1)
            {
                //		scripts.Items.Add(">Injection failed, Roblox is not opened.");
            }
            if ((int)val.Result == 5)
            {
                //scripts.Items.Add(">Already Injected");
            }
        }
コード例 #12
0
ファイル: PipeChanell.cs プロジェクト: gavz/ManagedInjector
        public void SendAck(InjectionResult code)
        {
            var type   = code == InjectionResult.Success ? Constants.Ok : Constants.Error;
            var ackMsg = new PipeMessage(type, ((Int32)code).ToString());

            _writer.WriteLine(ackMsg.Serialize());
            _writer.Flush();
        }
コード例 #13
0
        public void SendAck(InjectionResult code, String message)
        {
            var value  = String.Format("{0}|{1}", code, message);
            var type   = code == InjectionResult.Success ? Constants.Ok : Constants.Error;
            var ackMsg = new PipeMessage(type, value);

            _writer.WriteLine(ackMsg.Serialize());
            _writer.Flush();
        }
コード例 #14
0
    private static void AfterWrite(InjectionResult r)
    {
        Debug.Log($"Write result: {r}");
#if PLATFORM_ANDROID
        if (r != InjectionResult.Success)
        {
            AndroidUSBUtils.CurrentInstance.DebugToast($"Write result: {r}");
        }
#endif
    }
コード例 #15
0
ファイル: PipeChanell.cs プロジェクト: gavz/ManagedInjector
        public Boolean SendMessage(PipeMessage msg)
        {
            var response = SendData(msg);

            if (!response.IsSuccess())
            {
                _lastError = (InjectionResult)Int32.Parse(response.GetData());
            }
            return(response.IsSuccess());
        }
コード例 #16
0
        private void button3_Click(object sender, EventArgs e)
        {
            InjectionResult result = Injector.Inject();

            if (result.Result == InjectionError.Success)
            {
                Sentinel.Start();
                MessageBox.Show("Injetado");
            }
        }
コード例 #17
0
 private void AfterRead(InjectionResult r)
 {
     if (r == InjectionResult.Success)
     {
         set(Items.ToArray());
     }
     else
     {
         Debug.LogError(r.ToString());
         PopupHelper.CreateError(r.ToString(), 2f);
     }
 }
コード例 #18
0
        public Boolean SendMessage(PipeMessage msg)
        {
            var response = SendData(msg);

            if (!response.IsSuccess())
            {
                var items = response.GetData().Split('|');
                _lastError        = (InjectionResult)Enum.Parse(typeof(InjectionResult), items[0]);
                _lastErrorMessage = items[1];
            }
            return(response.IsSuccess());
        }
コード例 #19
0
    private void AfterRead(InjectionResult r)
    {
        if (r == InjectionResult.Success)
        {
            set(Items.ToArray());
        }
        else
        {
            Debug.LogError(r.ToString());
#if PLATFORM_ANDROID
            AndroidUSBUtils.CurrentInstance.DebugToast(r.ToString());
#endif
        }
    }
コード例 #20
0
        private void HandleInjectionResult(InjectionResult helperProcessResult, bool showErrors = false)
        {
            string message = null;

            switch (helperProcessResult.ResultCode)
            {
            case DllInjectionResult.DllNotFound:
                message =
                    "Could not find osuOverlay file to add to osu!... this shouldn't happen, if it does(you see this message) please report this.";
                break;

            case DllInjectionResult.InjectionFailed:
            {
                //ERROR_ACCESS_DENIED
                if (helperProcessResult.Win32ErrorCode == 5)
                {
                    message =
                        $"Your antivirus has blocked an attempt to add ingame overlay to osu!.";
                }
                else
                {
                    message =
                        "Could not add overlay to osu! most likely SC doesn't have enough premissions - restart SC as administrator and try again. If that doesn't solve it - please report ";
                }
                break;
            }

            case DllInjectionResult.GameProcessNotFound:
            case DllInjectionResult.Timeout:
                return;

            case DllInjectionResult.Success:
                _logger.Log("Injection success.", LogLevel.Basic);
                return;
            }
            _logger.Log($"Injection failed: {message}", LogLevel.Basic);
            _logger.Log($"{helperProcessResult}", LogLevel.Advanced);

            if (showErrors && helperProcessResult.ResultCode != DllInjectionResult.GameProcessNotFound && !cancellationToken.IsCancellationRequested)
            {
                MessageBox.Show(message + Environment.NewLine + Environment.NewLine + $"Ingame Overlay result: {helperProcessResult}", "StreamCompanion - ingameOverlay Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
コード例 #21
0
        private void ActivateDll()
        {
            try
            {
                var assembly       = Assembly.Load(_assemblyBuffer.ToArray());
                var methodToInvoke = ResolveMethod(assembly);

                if (methodToInvoke != null)
                {
                    InvokeMethod(methodToInvoke);
                }
                else
                {
                    _lastError = InjectionResult.MethodNotFound;
                }
            }
            catch {
                _lastError = InjectionResult.InvalidAssemblyBuffer;
            }
        }
コード例 #22
0
    public void ReadFromSource()
    {
        uint offset = sbc.GetDefaultOffset();

        injector.SetWriteOffset(offset);
        try
        {
            InjectionResult injectionResult = injector.Read(true);
            if (injectionResult != InjectionResult.Success)
            {
                Debug.Log(injectionResult.ToString());
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.Message);
            UISB.ConnectedText.text = (ex.Message);
            UISB.SetConnected(val: false);
        }
    }
コード例 #23
0
ファイル: IPCInterface.cs プロジェクト: rwrc/OpenSandbox
        /// <summary>
        /// The method is called in the host process to wait until the injection is done and initialization
        /// of the injected code is complete.
        /// </summary>
        public static void WaitForInjection(int clientPID)
        {
            do
            {
                lock (resultsByPID_)
                {
                    if (resultsByPID_.ContainsKey(clientPID))
                    {
                        InjectionResult result = resultsByPID_[clientPID];
                        resultsByPID_.Remove(clientPID);

                        if (!result.Success)
                        {
                            throw result.Error;
                        }
                        return;
                    }
                }
            } while (resultAdded_.WaitOne());
        }
コード例 #24
0
        private Boolean SendToken()
        {
            var result = false;

            var(moduleName, methodToken) = GetModuleNameAndMethodToken();

            if (moduleName == null)
            {
                _lastError = InjectionResult.InvalidAssemblyBuffer;
            }
            else if (methodToken == 0)
            {
                _lastError = InjectionResult.MethodNotFound;
            }
            else
            {
                result = _pipeChanell.SendMessage(Constants.Token, methodToken.ToString());
            }

            return(result);
        }
コード例 #25
0
        private void ActivateDll(Object context)
        {
            try
            {
                var assembly       = Assembly.Load(_assemblyBuffer.ToArray());
                var methodToInvoke = ResolveMethod(assembly);

                if (methodToInvoke != null)
                {
                    InvokeMethod(methodToInvoke, context);
                }
                else
                {
                    _lastError = InjectionResult.MethodNotFound;
                }
            }
            catch (Exception e) {
                _lastError        = InjectionResult.InvalidAssemblyBuffer;
                _lastErrorMessage = e.ToString();
            }
        }
コード例 #26
0
        private Boolean ProcessCommand(PipeMessage msg)
        {
            var exit    = false;
            var msgType = msg.GetType();

            if (msgType.Equals(Constants.Token, StringComparison.OrdinalIgnoreCase))
            {
                _metadataToken = Int32.Parse(msg.GetData());
            }
            else if (msgType.Equals(Constants.Assembly, StringComparison.OrdinalIgnoreCase))
            {
                _assemblyBuffer = Convert.FromBase64String(msg.GetData());
            }
            else if (msgType.Equals(Constants.Dependency, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    var assemblyBuffer = Convert.FromBase64String(msg.GetData());
                    var assembly       = Assembly.Load(assemblyBuffer);
                    if (!_dependencies.ContainsKey(assembly.FullName))
                    {
                        _dependencies.Add(assembly.FullName, assembly);
                    }
                }
                catch (Exception e)
                {
                    _lastError        = InjectionResult.InvalidAssemblyDependencyBuffer;
                    _lastErrorMessage = e.ToString();
                }
            }
            else if (msgType.Equals(Constants.File, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    var data           = msg.GetData();
                    var indexOfPipe    = data.IndexOf("|");
                    var filenameLength = Int32.Parse(data.Substring(0, indexOfPipe));
                    var filename       = data.Substring(indexOfPipe + 1, filenameLength);
                    var fileContent    = Convert.FromBase64String(data.Substring(indexOfPipe + 1 + filenameLength));
                    File.WriteAllBytes(filename, fileContent);
                }
                catch (Exception e)
                {
                    _lastError        = InjectionResult.InvalidFileBuffer;
                    _lastErrorMessage = e.ToString();
                }
            }
            else if (msgType.Equals(Constants.Context, StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    var dataString = msg.GetData();
                    var data       = Convert.FromBase64String(dataString);
                    var formatter  = new BinaryFormatter();
                    using (var memStream = new MemoryStream(data))
                    {
                        _context = formatter.Deserialize(memStream);
                    }
                }
                catch (SerializationException e)
                {
                    _lastError        = InjectionResult.ErrorInContextDeSerialization;
                    _lastErrorMessage = e.ToString();
                }
                catch (Exception e)
                {
                    _lastError        = InjectionResult.UnknownError;
                    _lastErrorMessage = e.ToString();
                }
            }
            else if (msgType.Equals(Constants.Run, StringComparison.OrdinalIgnoreCase))
            {
                if (_assemblyBuffer == null)
                {
                    _lastError        = InjectionResult.InvalidAssemblyBuffer;
                    _lastErrorMessage = "Assembly bytes to inject not received";
                }
                else
                {
                    ActivateDll(_context);
                }

                exit = true;
            }
            return(exit);
        }
コード例 #27
0
 private static void AfterWrite(InjectionResult r)
 {
     Debug.Log($"Write result: {r}");
 }
コード例 #28
0
ファイル: PlayerItemEditor.cs プロジェクト: JuicyBerger/NHSE
 static void AfterWrite(InjectionResult r)
 {
     Debug.WriteLine($"Write result: {r}");
     System.Media.SystemSounds.Asterisk.Play();
 }
コード例 #29
0
        public async Task WatchForProcessStart(CancellationToken token)
        {
            HelperProcessResult RunHelperProcess(bool silent, bool checkInjectionStatus = false)
            {
                var proc = new ProcessStartInfo
                {
                    FileName               = Path.Combine("Plugins", "bin", "osuOverlayLoader.exe"),
                    Arguments              = $"\"{GetFullDllLocation()}\" {silent.ToString().ToLower()} {checkInjectionStatus.ToString().ToLower()}",
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardOutput = true
                };

                _osuLoaderProcess = Process.Start(proc);
                while (_osuLoaderProcess?.WaitForExit(100) == false)
                {
                    if (token.IsCancellationRequested)
                    {
                        _osuLoaderProcess?.Kill();
                        return(new HelperProcessResult(-2, 0, 0, string.Empty));
                    }
                }

                var resultData = _osuLoaderProcess.StandardOutput.ReadToEnd().Split(',');

                if (resultData.Length != 3)
                {
                    return(new HelperProcessResult(-3, 0, 0, string.Empty));
                }

                return(new HelperProcessResult(_osuLoaderProcess?.ExitCode ?? -1, Convert.ToInt32(resultData[0]), Convert.ToInt32(resultData[1]), resultData[2]));
            }

            try
            {
                InjectionResult lastResult = InjectionResult.GameProcessNotFound;
                while (true)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    if (_currentOsuProcess == null || SafeHasExited(_currentOsuProcess))
                    {
                        var helperProcessResult = RunHelperProcess(true, true);
                        var isAlreadyInjected   = helperProcessResult.ExitCode == 0;
                        int exitCode            = 0;
                        if (!isAlreadyInjected)
                        {
                            if (_currentOsuProcess == null && GetOsuProcess() != null && lastResult != InjectionResult.Timeout)
                            {
                                _ = Task.Run(() =>
                                {
                                    MessageBox.Show(
                                        "In order to load StreamCompanion osu! overlay you need to restart your osu!",
                                        "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                });
                            }

                            helperProcessResult = RunHelperProcess(true);
                            exitCode            = helperProcessResult.ExitCode;
                            HandleHelperProcessResult(helperProcessResult, true);
                            lastResult = (InjectionResult)helperProcessResult.ExitCode;
                        }

                        if (exitCode == 0)
                        {
                            if (_currentOsuProcess == null || SafeHasExited(_currentOsuProcess))
                            {
                                _currentOsuProcess = GetOsuProcess();
                            }
                        }
                    }

                    while (_pauseProcessTracking)
                    {
                        await Task.Delay(1000);
                    }

                    await Task.Delay(2000);
                }
            }
            catch (TaskCanceledException)
            {
            }
        }