Exemple #1
0
 public Task <RegisterNames> GetRegisterNamesAsync()
 {
     if (registerNames != null)
     {
         return(registerNames.AsTask());
     }
     return(Task.Factory.StartNew(() =>
     {
         var loc = GetDocumentLocationAsync().Await(DalvikProcess.VmTimeout);
         MethodDisassembly methodDiss = thread.Manager.Process.DisassemblyProvider.GetFromLocation(loc);
         registerNames = new RegisterNames(methodDiss == null ? null : methodDiss.Method.Body,
                                           HasMethodParametersInLastRegisters);
         return registerNames;
     }));
 }
Exemple #2
0
        /// <summary>
        /// Get all local registers for this frame.
        /// </summary>
        /// <returns></returns>
        public Task <List <DalvikStackFrameValue> > GetRegistersAsync(bool parametersOnly = false, Jdwp.Tag type = Jdwp.Tag.Int, params int[] indizes)
        {
            if (parametersOnly && parameters != null)
            {
                return(parameters.AsTask());
            }
            if (!parametersOnly && registers != null && indizes.Length == 0)
            {
                return(registers.AsTask());
            }

            return(Task.Factory.StartNew(() =>
            {
                var ret = new List <DalvikStackFrameValue>();

                var loc = GetDocumentLocationAsync().Await(DalvikProcess.VmTimeout);

                List <Register> regDefs;

                MethodDisassembly methodDiss = thread.Manager.Process.DisassemblyProvider.GetFromLocation(loc);

                registerNames = registerNames ??
                                new RegisterNames(methodDiss == null ? null : methodDiss.Method.Body, HasMethodParametersInLastRegisters);

                if (indizes.Length == 0)
                {
                    if (methodDiss == null)
                    {
                        return ret;
                    }

                    var body = methodDiss.Method.Body;

                    regDefs = (parametersOnly ? body.Registers.Where(r => registerNames.IsParameter(r))
                                              : body.Registers)
                              .Where(p => indizes.Length == 0 || indizes.Contains(p.Index))
                              .OrderBy(p => p.Index)
                              .ToList();
                }
                else
                {
                    regDefs = indizes.Select(i => new Register(i)).ToList();
                }

                var requests = regDefs.Select(reg => new SlotRequest(reg.Index, type)).ToList();

                var regValues = Debugger.StackFrame.GetValuesAsync(thread.Id, Id, requests.ToArray())
                                .Await(DalvikProcess.VmTimeout);

                var process = thread.Manager.Process;
                for (int i = 0; i < regDefs.Count && i < regValues.Count; ++i)
                {
                    var reg = regDefs[i];
                    int numRegs = methodDiss == null ? int.MaxValue : methodDiss.Method.Body.Instructions.Count;
                    bool isParam = registerNames.IsParameter(reg);
                    string regName = registerNames.GetName(reg);

                    var valInfo = new VariableInfo(0, regName, null, null, numRegs, reg.Index);

                    DalvikStackFrameValue val = new DalvikStackFrameValue(regValues[i], valInfo, isParam, process);
                    ret.Add(val);
                }

                if (indizes.Length > 0)
                {
                    return ret;
                }

                if (parametersOnly)
                {
                    parameters = parameters ?? ret;
                }
                else
                {
                    registers = registers ?? ret;
                }
                return ret;
            }));
        }
Exemple #3
0
        /// <summary>
        /// Get all local registers for this frame.
        /// </summary>
        /// <returns></returns>
        public Task<List<DalvikStackFrameValue>> GetRegistersAsync(bool parametersOnly = false, Jdwp.Tag type = Jdwp.Tag.Int, params int[] indizes)
        {
            if (parametersOnly && parameters != null)
                return parameters.AsTask();
            if (!parametersOnly && registers != null && indizes.Length == 0)
                return registers.AsTask();

            return Task.Factory.StartNew(() =>
            {
                var ret = new List<DalvikStackFrameValue>();

                var loc = GetDocumentLocationAsync().Await(DalvikProcess.VmTimeout);

                List<Register> regDefs;

                MethodDisassembly methodDiss = thread.Manager.Process.DisassemblyProvider.GetFromLocation(loc);

                registerNames = registerNames ??
                                new RegisterNames(methodDiss == null ? null : methodDiss.Method.Body, HasMethodParametersInLastRegisters);

                if(indizes.Length == 0)
                {
                    if (methodDiss == null)
                        return ret;

                    var body = methodDiss.Method.Body;

                    regDefs = (parametersOnly ? body.Registers.Where(r => registerNames.IsParameter(r))
                                              : body.Registers)
                              .Where(p => indizes.Length == 0 || indizes.Contains(p.Index))
                              .OrderBy(p=>p.Index)
                              .ToList();
                }
                else
                {
                    regDefs = indizes.Select(i => new Register(i)).ToList();
                }

                var requests = regDefs.Select(reg => new SlotRequest(reg.Index, type)).ToList();

                var regValues = Debugger.StackFrame.GetValuesAsync(thread.Id, Id, requests.ToArray())
                                                   .Await(DalvikProcess.VmTimeout);

                var process = thread.Manager.Process;
                for (int i = 0; i < regDefs.Count && i < regValues.Count; ++i)
                {
                    var reg = regDefs[i];
                    int numRegs = methodDiss == null ? int.MaxValue : methodDiss.Method.Body.Instructions.Count;
                    bool isParam = registerNames.IsParameter(reg);
                    string regName = registerNames.GetName(reg);

                    var valInfo = new VariableInfo(0, regName, null, null, numRegs, reg.Index);

                    DalvikStackFrameValue val = new DalvikStackFrameValue(regValues[i], valInfo, isParam, process);
                    ret.Add(val);
                }

                if (indizes.Length > 0)
                    return ret;

                if(parametersOnly)
                    parameters = parameters ?? ret;
                else
                    registers = registers ?? ret;
                return ret;
            });
        }
Exemple #4
0
        public static string SmartReadline()
        {
            var key = Console.ReadKey(true);

            if (KeyAliases.ContainsKey(key.Key))
            {
                return(KeyAliases[key.Key]);
            }

            string buffer = "";

            if (key.KeyChar != '\0' && key.KeyChar != '\t')
            {
                buffer += key.KeyChar;
            }

            int index = buffer.Length;

            bool          autocomplete            = false;
            List <string> possibilities           = new List <string>();
            int           autocomplete_index      = -1;
            int           autocomplete_word_index = 0;
            bool          autocomplete_full       = false;
            int           history_index           = -1;

            while (true)
            {
                var           words             = buffer.Split(' ');
                List <string> autocomplete_pool = new List <string>();

                if (words.Length == 1)
                {
                    autocomplete_pool = AutocompleteCommands.ToList();
                    autocomplete_full = false;
                }
                else if (words.Length > 1)
                {
                    if (OpcodeCommands.Contains(words[0]))
                    {
                        autocomplete_pool = OpcodeList;
                    }
                    else if (RegisterCommands.Contains(words[0]))
                    {
                        autocomplete_pool = RegisterNames.ToList();
                    }
                    else if (words[0] == "help")
                    {
                        autocomplete_pool = CommandHelp.Keys.ToList();
                    }

                    if (AdditionalComplete.ContainsKey(words[0]))
                    {
                        autocomplete_pool = autocomplete_pool.Concat(AdditionalComplete[words[0]]).ToList();
                    }

                    autocomplete_full = true;
                }

                autocomplete_word_index = words.Length - 1;

                string partial = words.Last().ToLower();

                if (autocomplete_full || !autocomplete_pool.Contains(partial)) // we don't wanna autocomplete full commands
                {
                    if (autocomplete_pool.Any(c => c.StartsWith(partial)))
                    {
                        var possibilities_temp = autocomplete_pool.Where(c => c.StartsWith(partial)).ToList();

                        if (!possibilities.SequenceEqual(possibilities_temp)) // don't reset autocomplete index
                        {
                            possibilities      = possibilities_temp;
                            autocomplete_index = 0;
                        }
                        autocomplete = true;
                    }
                    else
                    {
                        autocomplete = false;
                    }
                }
                else
                {
                    autocomplete = false;
                }

                if (buffer.Length == 0)
                {
                    autocomplete = false;
                }

                string autocomplete_left = "";

                if (autocomplete)
                {
                    autocomplete_left = possibilities[autocomplete_index].Substring(words.Last().Length);
                }

                string possibility_indicator = string.Format("({0} possibilit{1})", possibilities.Count, possibilities.Count == 1 ? "y" : "ies");

                if (4 + buffer.Length + autocomplete_left.Length + 2 + possibility_indicator.Length >= Console.BufferWidth)
                {
                    autocomplete = false;
                }

                if (!autocomplete)
                {
                    possibility_indicator = "";
                }

                int cursor = index + 4;

                Console.CursorLeft = 0;
                Console.Write(">>> ");

                if (4 + buffer.Length + autocomplete_left.Length + 2 + possibility_indicator.Length >= Console.BufferWidth)
                {
                    int offset = (4 + buffer.Length + autocomplete_left.Length + 2 + possibility_indicator.Length) - Console.BufferWidth;
                    cursor -= offset;
                    int front_offset = cursor - offset - 4;
                    if (cursor - offset < 4)
                    {
                    }
                    Console.Write(buffer.Substring(offset));
                }
                else
                {
                    Console.Write(buffer);
                }

                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write(autocomplete_left);
                Console.Write(new string(' ', Console.BufferWidth - (Console.CursorLeft + 2 + possibility_indicator.Length)));
                Console.Write(possibility_indicator);
                Console.ForegroundColor = ConsoleColor.Gray;

                Console.Write(new string(' ', Console.BufferWidth - Console.CursorLeft - 1));
                Console.CursorLeft = cursor;
                key = Console.ReadKey(true);

                switch (key.Key)
                {
                case ConsoleKey.LeftArrow:
                    index = (index - 1) < 0 ? 0 : (index - 1);
                    break;

                case ConsoleKey.RightArrow:
                    if (index == buffer.Length && autocomplete)
                    {
                        words[autocomplete_word_index] = possibilities[autocomplete_index];
                        buffer = string.Join(" ", words);
                        index  = buffer.Length;
                        break;
                    }

                    index = (index + 1) > buffer.Length ? buffer.Length : (index + 1);
                    break;

                case ConsoleKey.Tab:
                    if (autocomplete)
                    {
                        words[autocomplete_word_index] = possibilities[autocomplete_index];
                        buffer = string.Join(" ", words);
                        index  = buffer.Length;
                    }
                    break;

                case ConsoleKey.Enter:
                    Console.WriteLine();
                    History.Add(buffer);
                    return(buffer);

                case ConsoleKey.Backspace:
                    if (index == 0)
                    {
                        break;
                    }
                    if (index == buffer.Length)
                    {
                        buffer = buffer.Substring(0, buffer.Length - 1);
                    }
                    else
                    {
                        buffer = buffer.Substring(0, index - 1) + buffer.Substring(index);
                    }
                    history_index = -1;
                    index--;
                    break;

                case ConsoleKey.Delete:
                    if (index == buffer.Length)
                    {
                        break;
                    }
                    if (index == 0)
                    {
                        buffer = buffer.Substring(1);
                    }
                    else
                    {
                        buffer = buffer.Substring(0, index) + buffer.Substring(index + 1);
                    }
                    history_index = -1;
                    break;

                case ConsoleKey.Home:
                    index = 0;
                    break;

                case ConsoleKey.End:
                    index = buffer.Length;
                    break;

                case ConsoleKey.UpArrow:
                    if (autocomplete && history_index == -1)
                    {
                        autocomplete_index = (autocomplete_index - 1) < 0 ? 0 : (autocomplete_index - 1);
                    }
                    else if (History.Any())
                    {
                        if (history_index == -1)
                        {
                            history_index = History.Count - 1;
                        }
                        else
                        {
                            history_index = (history_index - 1) < 0 ? 0 : (history_index - 1);
                        }

                        buffer = History[history_index];
                        index  = 0;
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (autocomplete && history_index == -1)
                    {
                        autocomplete_index = (autocomplete_index + 1) >= possibilities.Count ? autocomplete_index : (autocomplete_index + 1);
                    }
                    else if (History.Any())
                    {
                        if (history_index == -1)
                        {
                            history_index = History.Count - 1;
                        }
                        else
                        {
                            if ((history_index + 1) >= History.Count)
                            {
                                history_index = -1;
                                buffer        = "";
                                index         = 0;
                                break;
                            }
                            else
                            {
                                history_index++;
                            }
                        }

                        buffer = History[history_index];
                        index  = 0;
                    }
                    break;

                default:
                    if (KeyAliases.ContainsKey(key.Key))
                    {
                        return(KeyAliases[key.Key]);
                    }
                    history_index = -1;

                    if (key.KeyChar == '\0')
                    {
                        break;
                    }

                    if (4 + buffer.Length + autocomplete_left.Length + 2 + possibility_indicator.Length + 1 >= Console.BufferWidth)
                    {
                        break;
                    }

                    if (index == buffer.Length)
                    {
                        buffer += key.KeyChar;
                    }
                    else
                    {
                        buffer = buffer.Substring(0, index) + key.KeyChar + buffer.Substring(index);
                    }
                    index++;
                    break;
                }
            }
        }
Exemple #5
0
 public Task<RegisterNames> GetRegisterNamesAsync()
 {
     if (registerNames != null) return registerNames.AsTask();
     return Task.Factory.StartNew(() =>
     {
         var loc = GetDocumentLocationAsync().Await(DalvikProcess.VmTimeout);
         MethodDisassembly methodDiss = thread.Manager.Process.DisassemblyProvider.GetFromLocation(loc);
         registerNames = new RegisterNames(methodDiss == null ? null : methodDiss.Method.Body,
             HasMethodParametersInLastRegisters);
         return registerNames;
     });
 }