예제 #1
0
        public PacketInterceptionPythonEngine(IRadio radio, string script = null, string filename = null)
        {
            if ((script == null && filename == null) || (script != null && filename != null))
            {
                throw new ConstructionException("Parameters `script` and `filename` cannot be both set or both unset.");
            }

            this.radio    = radio;
            this.script   = script;
            this.filename = filename;
            machine       = radio.GetMachine();

            InnerInit();

            Hook = packet =>
            {
                Scope.SetVariable("packet", packet);
                try
                {
                    source.Execute(Scope);
                }
                catch (Exception ex)
                {
                    throw new Exception("Hook execution failed: " + ex.Message);
                }
            };
        }
예제 #2
0
        public PacketInterceptionPythonEngine(IRadio radio, string script = null, OptionalReadFilePath filename = null)
        {
            if ((script == null && filename == null) || (script != null && filename != null))
            {
                throw new ConstructionException("Parameters `script` and `filename` cannot be both set or both unset.");
            }

            this.radio    = radio;
            this.script   = script;
            this.filename = filename;
            machine       = radio.GetMachine();

            InnerInit();

            Hook = packet =>
            {
                Scope.SetVariable("packet", packet);
                Execute(code, error =>
                {
                    this.radio.Log(LogLevel.Error, "Python runtime error: {0}", error);
                });
            };
        }