コード例 #1
0
ファイル: VarType.cs プロジェクト: stallonederek/meddle
        public VarType(PythonBoss pyBoss, VarTypes varTypes, XElement element)
        {
            // Load this variable type

            _pyBoss = pyBoss;

            // Load the scripts
            foreach (XElement el in element.Elements("global_script"))
            {
                if (!_pyBoss.AddCode(el.Value, "variable types <global_script>"))
                {
                    return;
                }
            }
            foreach (XElement el in element.Elements("local_script"))
            {
                _pyLocal += "\r\n" + element.Value;
            }

            // Load the name
            XElement name = element.Element("name");

            if (name != null)
            {
                _name = name.Value;
            }

            _parent = varTypes;
        }
コード例 #2
0
ファイル: Target.cs プロジェクト: stallonederek/meddle
 public Target(object targetClass, PythonBoss pyBoss, Process process)
 {
     _targetClass = targetClass;
     _process     = process;
     _pyBoss      = pyBoss;
     _breakpoints = new List <Breakpoint>(1);
     _name        = Target.GetName(targetClass);
 }
コード例 #3
0
        public RegisterArgument(PythonBoss pyBoss, Context context, PythonDictionary spec, Process process, Arguments parent, string namePrefix)
        {
            NamePrefix   = namePrefix;
            this.process = process;

            // Parse the spec for this argument
            // regspec: [{"name": "socket",
            //		      "register": "rcx",
            //		      "type": None,
            //		      "fuzz": NOFUZZ},]

            Register      = ((string)spec.get("register")).ToLower();
            Fuzz          = (bool)spec.get("fuzz");
            Name          = (string)spec.get("name");
            _argumentType = (object)spec.get("type");
            if (spec.ContainsKey("type_args"))
            {
                _typeArgs = spec.get("type_args");
            }

            // Validate required fields
            if (Name == null)
            {
                throw new Exception("ERROR: Argument specification must include 'name' attribute. Failed when parsing name prefix '" + namePrefix + "'.");
            }
            else if (Fuzz == null)
            {
                throw new Exception("ERROR: Argument specification must include 'fuzz' attribute. Failed when parsing type '" + namePrefix + Name + "'.");
            }

            this.process = process;
            _pyBoss      = pyBoss;
            _parent      = parent;

            // Read the data
            var tmpData = context.GetMember(Register);

            if (tmpData is UInt32)
            {
                Data = BitConverter.GetBytes((UInt32)tmpData);
            }
            else if (tmpData is UInt64)
            {
                Data = BitConverter.GetBytes((UInt64)tmpData);
            }
            else
            {
                throw new Exception("Register argument type definition problem. The register must be of type 'int' or 'long'. The is likely an engine bug. Argument name: " + Name + ". The unsupported register type is: " + tmpData.ToString());
            }
            Size = Data.Length;

            PointerTarget = null;
        }
コード例 #4
0
ファイル: Controller.cs プロジェクト: stallonederek/meddle
        public Controller(string startScript, string[] args)
        {
            _scriptPath = System.IO.Path.GetFullPath(startScript);

            // Now that we slightly verified the xml structure, lets initialize
            _pyBoss = new PythonBoss(_scriptPath);
            string filename = System.IO.Path.GetFileName(startScript);

            if (filename.EndsWith(".py"))
            {
                filename = filename.Substring(0, filename.Length - 3);
            }

            if (!_pyBoss.AddCode(String.Format(@"from {0} import *", filename), startScript))
            {
                return;
            }

            try
            {
                // Create the controller
                var pyTypeController = _pyBoss.PyScope.GetVariable("Controller");
                PyController = _pyBoss.PyEngine.Operations.CreateInstance(pyTypeController, this);

                // Create the new process dispatcher check
                ProcessWatcher procWatcher = new ProcessWatcher();
                procWatcher.ProcessCreated += new ProcessEventHandler(procWatcher_ProcessCreated);
                procWatcher.Start();

                // Execute the controller main function
                try
                {
                    PyController.main(args);
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR: Python class controller.main() not found or failed while executing.");
                    Console.WriteLine(e.ToString());
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: Python class controller(...) not found or failed while executing constructor.");
                Console.WriteLine(e.ToString());
                return;
            }


            // Success, this controller is now loaded
            Initialized = true;
        }
コード例 #5
0
        public FunctionArguments(PythonBoss pyBoss, Context context, List stackSpec, List registerSpec, Process process)
        {
            _process     = process;
            _address     = (long)context.GetSP();
            _pyBoss      = pyBoss;
            _depth       = 0;
            _args        = new List <Argument>(stackSpec.Count + registerSpec.Count);
            _arg_offsets = new List <long>(stackSpec.Count);
            _parent      = null;

            ParseCurrentRegisterLevel(registerSpec, context);
            ParseCurrentLevel(stackSpec);
            ParseNextLevel();
        }
コード例 #6
0
        public VarTypes(XDocument reader, PythonBoss pyBoss)
        {
            _pyBoss = pyBoss;

            // Load all the <type>'s but in reverse-order because of
            // dependencies on one-another.
            IEnumerable <XElement> elements = reader.Descendants("types").Elements("type");

            _types = new List <VarType>(10);
            for (int i = elements.Count() - 1; i >= 0; i--)
            {
                // Load this <type> description
                _types.Add(new VarType(pyBoss, this, elements.ElementAt(i)));
            }
        }
コード例 #7
0
ファイル: Arguments.cs プロジェクト: stallonederek/meddle
        public Arguments(PythonBoss pyBoss, long address, List specs, Process process, int depth, Argument parent, string namePrefix)
        {
            NamePrefix   = namePrefix;
            _process     = process;
            _address     = address;
            _pyBoss      = pyBoss;
            _depth       = depth;
            _parent      = parent;
            _args        = new List <Argument>(specs.Count);
            _arg_offsets = new List <long>(specs.Count);

            // Handle the case of infinite recursion
            if (depth > 1000)
            {
                throw new Exception("Error when processing argument types: An infinite loop has been detected, this is caused by a type somehow including a pointer to itself. Name: " + namePrefix);
            }

            ParseCurrentLevel(specs);
            ParseNextLevel();
        }
コード例 #8
0
        public Process(PythonBoss pyBoss, Controller parent, dynamic pyProcess)
        {
            _targets       = new Hashtable(10);
            _pyBoss        = pyBoss;
            _parent        = parent;
            _targetsToLoad = new List <object>(10);
            PyProcess      = pyProcess;
            _name          = PyProcess.get_name();

            try
            {
                // Initialize the DotNet process class
                int pid = PyProcess.get_pid();

                if (pid >= 0)
                {
                    ProcessDotNet = System.Diagnostics.Process.GetProcessById(pid);

                    // Start the debugger instance
                    _debugger = new Debugger(pid, this);
                }
                else
                {
                    Console.WriteLine(string.Format("ERROR: Constructor of dot net class 'Process' {0} failed. Python process class returned 'get_pid()' of -1, this is invalid.", _name));
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("ERROR: Constructor of python class 'Process' {0} failed:", _name));
                Console.WriteLine(e.ToString());
                return;
            }

            Initialized = true;
        }
コード例 #9
0
ファイル: Arguments.cs プロジェクト: stallonederek/meddle
        public Argument(PythonBoss pyBoss, long address, PythonDictionary spec, Process process, int depth, Arguments parent, string namePrefix)
        {
            Address      = address;
            this.process = process;
            _pyBoss      = pyBoss;
            _parent      = parent;
            NamePrefix   = namePrefix;


            // Parse the spec for this argument
            // stackspec: [{"name": "socket",
            //		      "size": 4,
            //		      "type": None,
            //		      "fuzz": NOFUZZ,
            //            "type_args": None},]

            Fuzz          = (bool)spec.get("fuzz");
            Name          = (string)spec.get("name");
            _argumentType = (object)spec.get("type");
            if (spec.ContainsKey("type_args"))
            {
                _typeArgs = spec.get("type_args");
            }


            // Validate required fields
            if (Name == null)
            {
                throw new Exception("ERROR: Argument specification must include 'name' attribute. Failed when parsing name prefix '" + namePrefix + "'.");
            }
            else if (Fuzz == null)
            {
                throw new Exception("ERROR: Argument specification must include 'fuzz' attribute. Failed when parsing type '" + namePrefix + Name + "'.");
            }
            else if (spec.get("size") == null)
            {
                throw new Exception("ERROR: Argument specification must include 'size' attribute. Failed when parsing type '" + namePrefix + Name + "'.");
            }


            if (spec.get("size") is string)
            {
                object sizeArgument = null;
                if (parent.TryGetMemberSearchUp((string)spec.get("size"), out sizeArgument))
                {
                    Size = ((Argument)sizeArgument).ToInt();
                }
                else
                {
                    throw new Exception("ERROR: Unable to load size for type '" + Name + "' from parent member named '" + (string)spec.get("size") + "'. Please make sure this field exists in the parent.");
                }
            }
            else if (spec.get("size") is int)
            {
                Size = (int)spec.get("size");
            }
            else
            {
                throw new Exception("ERROR: Unable to load size for type '" + Name + "'. The size must be of type 'int' or type 'string'. Size is type: '" + spec.get("size").ToString() + "'");
            }

            // Read the data
            try
            {
                Data = MemoryFunctions.ReadMemory(process.ProcessDotNet, address, (uint)Size);
            }
            catch (Exception e)
            {
                Data = null;
            }


            PointerTarget = null;
        }