Esempio n. 1
0
            public object RemoteExec(string fx, object args)
            {
                RemoteCall call = new RemoteCall();

                call.seqID = ++seqIDctr;
                call.type  = "call";
                call.func  = fx;
                call.args  = args;

                retObj = null;
                done.Reset();
                Send(ObjectToByteArray(call));
                done.WaitOne();

                if (retObj == null)
                {
                    throw new Exception("Pipe Broke!");
                }

                if (retObj.args is Exception)
                {
                    throw (Exception)retObj.args;
                }

                return(retObj.args);
            }
Esempio n. 2
0
            public bool Connect(int TimeOut = 10000)
            {
                try
                {
                    pipeStream.Connect(TimeOut);
                }
                catch
                {
                    return(false); // timeout
                }

                DataReceived += (sndr, data) =>
                {
                    RemoteCall call = ByteArrayToObject(data);

                    if (call.type == "push")
                    {
                        PushNotification?.Invoke(this, call);
                    }
                    else if (call.type == "call" && call.seqID == seqIDctr)
                    {
                        retObj = call;
                        done.Set();
                    }
                };

                PipeClosed += (sndr, args) => {
                    done.Set();
                };

                initAsyncReader();
                return(true);
            }
Esempio n. 3
0
        public static byte[] ObjectToByteArray(RemoteCall obj)
        {
            BinaryFormatter bf = new BinaryFormatter();
            var             ms = new MemoryStream();

            bf.Serialize(ms, obj);
            return(ms.ToArray());
        }
Esempio n. 4
0
        public void SendPushNotification(string func, object args)
        {
            foreach (PipeListener serverPipes in serverPipes)
            {
                if (!serverPipes.IsConnected())
                {
                    continue;
                }

                RemoteCall call = new RemoteCall();
                call.seqID = 0;
                call.type  = "push";
                call.func  = func;
                call.args  = args;

                serverPipes.Send(PipeListener.ObjectToByteArray(call));
            }
        }
Esempio n. 5
0
        public void AddListener()
        {
            PipeListener serverPipe = new PipeListener(PipeListener.Name);

            serverPipes.Add(serverPipe);

            serverPipe.DataReceived += (sndr, data) => {
                mDispatcher.BeginInvoke(new Action(() => {
                    RemoteCall call = PipeListener.ByteArrayToObject(data);

                    if (call.func == "InitSession")
                    {
                        int SessionId = (int)call.args;

                        IPCSession session = new IPCSession();
                        session.version    = App.mVersion;
                        session.duplicate  = CountSessions(SessionId) > 0;
                        call.args          = session;

                        serverPipe.SessionID = SessionId;
                    }
                    else
                    {
                        call = Process(call);
                    }

                    serverPipe.Send(PipeListener.ObjectToByteArray(call));
                }));
            };

            serverPipe.Connected += (sndr, args) => {
                mDispatcher.BeginInvoke(new Action(() => {
                    // if we used a listener allocate a replacement one
                    AddListener();
                }));
            };

            serverPipe.PipeClosed += (sndr, args) => {
                mDispatcher.BeginInvoke(new Action(() => {
                    serverPipes.Remove(serverPipe);
                }));
            };
        }
Esempio n. 6
0
        protected void Process(PipeListener pipe, byte[] data)
        {
            string t = Thread.CurrentThread.Name;

            RemoteCall call = PipeListener.ByteArrayToObject(data);

            //try
            {
                if (call.func == "GetVersion")
                {
                    call.args = App.mVersion;
                }
                else if (call.func == "GetFilteringMode")
                {
                    call.args = App.engine.GetFilteringMode();
                }
                else if (call.func == "SetFilteringMode")
                {
                    call.args = App.engine.SetFilteringMode((Firewall.FilteringModes)call.args);
                }
                else if (call.func == "GetAuditPol")
                {
                    call.args = App.engine.GetAuditPol();
                }
                else if (call.func == "SetAuditPol")
                {
                    call.args = App.engine.SetAuditPol((Firewall.Auditing)call.args);
                }
                else if (call.func == "GetPrograms")
                {
                    call.args = App.engine.GetPrograms(GetArg <List <Guid> >(call.args, 0));
                }
                else if (call.func == "GetProgram")
                {
                    call.args = App.engine.GetProgram(GetArg <ProgramList.ID>(call.args, 0), GetArg <bool>(call.args, 1));
                }
                else if (call.func == "AddProgram")
                {
                    call.args = App.engine.AddProgram(GetArg <ProgramList.ID> (call.args, 0), GetArg <Guid>(call.args, 1));
                }
                else if (call.func == "UpdateProgram")
                {
                    call.args = App.engine.UpdateProgram(GetArg <Guid>(call.args, 0), GetArg <Program.Config>(call.args, 1));
                }
                else if (call.func == "MergePrograms")
                {
                    call.args = App.engine.MergePrograms(GetArg <Guid>(call.args, 0), GetArg <Guid>(call.args, 1));
                }
                else if (call.func == "SplitPrograms")
                {
                    call.args = App.engine.SplitPrograms(GetArg <Guid>(call.args, 0), GetArg <ProgramList.ID>(call.args, 1));
                }
                else if (call.func == "RemoveProgram")
                {
                    call.args = App.engine.RemoveProgram(GetArg <Guid>(call.args, 0), GetArg <ProgramList.ID>(call.args, 1));
                }
                else if (call.func == "LoadRules")
                {
                    call.args = App.engine.LoadRules();
                }
                else if (call.func == "GetRules")
                {
                    call.args = App.engine.GetRules((List <Guid>)call.args);
                }
                else if (call.func == "UpdateRule")
                {
                    call.args = App.engine.UpdateRule((FirewallRule)call.args);
                }
                else if (call.func == "RemoveRule")
                {
                    call.args = App.engine.RemoveRule((FirewallRule)call.args);
                }
                else if (call.func == "ClearLog")
                {
                    call.args = App.engine.ClearLog((bool)call.args);
                }
                else if (call.func == "CleanUpPrograms")
                {
                    call.args = App.engine.CleanUpPrograms();
                }
                else if (call.func == "GetConnections")
                {
                    call.args = App.engine.GetConnections((List <Guid>)call.args);
                }
                else if (call.func == "GetAllApps")
                {
                    call.args = App.engine.GetAllApps();
                }

                /*else if (call.func == "ApplyTweak")
                 * {
                 *  call.args = App.engine.ApplyTweak((Tweak)call.args);
                 * }
                 * else if (call.func == "TestTweak")
                 * {
                 *  call.args = App.engine.TestTweak((Tweak)call.args);
                 * }
                 * else if (call.func == "UndoTweak")
                 * {
                 *  call.args = App.engine.UndoTweak((Tweak)call.args);
                 * }*/

                else
                {
                    call.args = new Exception("Unknon FunctionCall");
                }
            }

            /*catch (Exception err)
             * {
             *  AppLog.Line("Error in {0}: {1}", MiscFunc.GetCurrentMethod(), err.Message);
             *  call.args = err;
             * }*/
            pipe.Send(PipeListener.ObjectToByteArray(call));
        }
Esempio n. 7
0
        protected RemoteCall Process(RemoteCall call)
        {
            //try
            {
                if (call.func == "GetFilteringMode")
                {
                    call.args = App.engine.GetFilteringMode();
                }
                else if (call.func == "SetFilteringMode")
                {
                    call.args = App.engine.SetFilteringMode((Firewall.FilteringModes)call.args);
                }
                else if (call.func == "GetAuditPol")
                {
                    call.args = App.engine.GetAuditPol();
                }
                else if (call.func == "SetAuditPol")
                {
                    call.args = App.engine.SetAuditPol((Firewall.Auditing)call.args);
                }
                else if (call.func == "GetPrograms")
                {
                    call.args = App.engine.GetPrograms(GetArg <List <Guid> >(call.args, 0));
                }
                else if (call.func == "GetProgram")
                {
                    call.args = App.engine.GetProgram(GetArg <ProgramList.ID>(call.args, 0), GetArg <bool>(call.args, 1));
                }
                else if (call.func == "AddProgram")
                {
                    call.args = App.engine.AddProgram(GetArg <ProgramList.ID> (call.args, 0), GetArg <Guid>(call.args, 1));
                }
                else if (call.func == "UpdateProgram")
                {
                    call.args = App.engine.UpdateProgram(GetArg <Guid>(call.args, 0), GetArg <Program.Config>(call.args, 1));
                }
                else if (call.func == "MergePrograms")
                {
                    call.args = App.engine.MergePrograms(GetArg <Guid>(call.args, 0), GetArg <Guid>(call.args, 1));
                }
                else if (call.func == "SplitPrograms")
                {
                    call.args = App.engine.SplitPrograms(GetArg <Guid>(call.args, 0), GetArg <ProgramList.ID>(call.args, 1));
                }
                else if (call.func == "RemoveProgram")
                {
                    call.args = App.engine.RemoveProgram(GetArg <Guid>(call.args, 0), GetArg <ProgramList.ID>(call.args, 1));
                }
                else if (call.func == "LoadRules")
                {
                    call.args = App.engine.LoadRules();
                }
                else if (call.func == "GetRules")
                {
                    call.args = App.engine.GetRules((List <Guid>)call.args);
                }
                else if (call.func == "UpdateRule")
                {
                    call.args = App.engine.UpdateRule((FirewallRule)call.args);
                }
                else if (call.func == "ClearRules")
                {
                    call.args = App.engine.ClearRules(GetArg <ProgramList.ID>(call.args, 0), GetArg <bool>(call.args, 1));
                }
                else if (call.func == "RemoveRule")
                {
                    call.args = App.engine.RemoveRule((FirewallRule)call.args);
                }
                else if (call.func == "BlockInternet")
                {
                    call.args = App.engine.BlockInternet((bool)call.args);
                }
                else if (call.func == "ClearLog")
                {
                    call.args = App.engine.ClearLog((bool)call.args);
                }
                else if (call.func == "CleanUpPrograms")
                {
                    call.args = App.engine.CleanUpPrograms();
                }
                else if (call.func == "GetConnections")
                {
                    call.args = App.engine.GetConnections((List <Guid>)call.args);
                }
                else if (call.func == "GetAllApps")
                {
                    call.args = App.engine.GetAllApps();
                }

                /*else if (call.func == "ApplyTweak")
                 * {
                 *  call.args = App.engine.ApplyTweak((Tweak)call.args);
                 * }
                 * else if (call.func == "TestTweak")
                 * {
                 *  call.args = App.engine.TestTweak((Tweak)call.args);
                 * }
                 * else if (call.func == "UndoTweak")
                 * {
                 *  call.args = App.engine.UndoTweak((Tweak)call.args);
                 * }*/

                else
                {
                    call.args = new Exception("Unknon FunctionCall");
                }
            }

            /*catch (Exception err)
             * {
             *  AppLog.Line("Error in {0}: {1}", MiscFunc.GetCurrentMethod(), err.Message);
             *  call.args = err;
             * }*/
            return(call);
        }