Ejemplo n.º 1
0
        public string ReadUnicodeString(uint processId, ulong address, int length)
        {
            return(ExecuteOnDkmInitializedThread(() =>
            {
                DkmProcess process = GetProcess(processId);

                return System.Text.UnicodeEncoding.Default.GetString(process.ReadMemoryString(address, DkmReadMemoryFlags.None, 2, length));
            }));
        }
        private void QueryColumnDetails(int columnCount)
        {
            var exprs = new List <DkmLanguageExpression>();

            try
            {
                DkmProcess  process          = this.inspectionContext.Thread.Process;
                DkmWorkList workList         = DkmWorkList.Create(null);
                SqliteVisualizerException ex = null;
                var columnNamesLocal         = new string[columnCount];
                for (int i = 0; i < columnCount; ++i)
                {
                    var i_local = i;
                    var colName = this.AddFuncEval(
                        workList,
                        $"sqlite3_column_name(*(sqlite3_stmt **){this.procMemForQuery}, {i})",
                        (r) =>
                    {
                        DkmSuccessEvaluationResult suc;
                        if (!this.VerifySuccess(r, out suc))
                        {
                            ex = ex ?? new SqliteVisualizerException(Resources.ErrMsg_FuncEvalFailed, r.FullName);
                            return;
                        }

                        ulong address      = suc.Address.Value;
                        byte[] stringMaybe = process.ReadMemoryString(address, DkmReadMemoryFlags.None, 1, 1024);
                        int len            = stringMaybe.Length;
                        if (len > 0)
                        {
                            // The debugger null terminates all strings, but encoding doesn't strip null when creating a string
                            len--;
                            columnNamesLocal[i_local] = Encoding.UTF8.GetString(stringMaybe, 0, len);
                        }
                    });

                    exprs.Add(colName);
                }

                workList.Execute();

                if (ex != null)
                {
                    throw ex;
                }

                this.ColumnNames = columnNamesLocal;
            }
            finally
            {
                foreach (var e in exprs)
                {
                    e.Close();
                }
            }
        }
Ejemplo n.º 3
0
        internal static byte[] ReadRawStringVariable(DkmProcess process, ulong address, int limit)
        {
            try
            {
                return(process.ReadMemoryString(address, DkmReadMemoryFlags.AllowPartialRead, 1, limit));
            }
            catch (DkmException)
            {
            }

            return(null);
        }
Ejemplo n.º 4
0
        internal static string ReadStringVariable(DkmProcess process, ulong address, int limit)
        {
            try
            {
                byte[] nameData = process.ReadMemoryString(address, DkmReadMemoryFlags.AllowPartialRead, 1, limit);

                if (nameData != null && nameData.Length != 0)
                {
                    return(System.Text.Encoding.UTF8.GetString(nameData, 0, nameData.Length - 1));
                }
            }
            catch (DkmException)
            {
                return(null);
            }

            return(null);
        }
Ejemplo n.º 5
0
        private static string ReadMemoryString(DkmProcess process, ulong address, int length, ushort charSize, System.Text.Encoding encoding)
        {
            bool trimNullTermination = false;

            if (length < 0)
            {
                length = ushort.MaxValue;
                trimNullTermination = true;
            }

            byte[] bytes = process.ReadMemoryString(address, DkmReadMemoryFlags.None, charSize, length);

            if (trimNullTermination && bytes[bytes.Length - 1] == 0)
            {
                return(encoding.GetString(bytes, 0, bytes.Length - 1));
            }

            return(encoding.GetString(bytes));
        }
        private bool TryGetRow(out string[] row)
        {
            // Move to the next row
            bool moreRows = false;
            var  exprs    = new List <DkmLanguageExpression>();

            try
            {
                const int SQLITE_ROW           = 100;
                SqliteVisualizerException ex   = null;
                DkmWorkList           workList = DkmWorkList.Create(null);
                DkmLanguageExpression expr     = this.AddFuncEval(
                    workList,
                    $"sqlite3_step(*(sqlite3_stmt **){this.procMemForQuery})",
                    (r) =>
                {
                    DkmSuccessEvaluationResult suc;
                    if (!this.VerifySuccess(r, out suc))
                    {
                        ex = new SqliteVisualizerException(Resources.ErrMsg_FuncEvalFailed, r.FullName);
                        return;
                    }

                    moreRows = SQLITE_ROW == (int)suc.Address.Value;
                });

                exprs.Add(expr);
                workList.Execute();

                if (ex != null)
                {
                    throw ex;
                }
            }
            finally
            {
                foreach (var e in exprs)
                {
                    e.Close();
                }

                exprs.Clear();
            }

            if (!moreRows)
            {
                row = new string[0];
                return(false);
            }

            // Read each column in the row
            var rowLocal = new string[ColumnNames.Count()];

            try
            {
                SqliteVisualizerException ex = null;
                DkmProcess  process          = this.inspectionContext.Thread.Process;
                DkmWorkList workList         = DkmWorkList.Create(null);
                for (int i = 0; i < rowLocal.Length; i++)
                {
                    var i_local = i;
                    var e       = this.AddFuncEval(
                        workList,
                        $"sqlite3_column_text(*(sqlite3_stmt **){this.procMemForQuery}, {i})",
                        (r) =>
                    {
                        DkmSuccessEvaluationResult suc;
                        if (!this.VerifySuccess(r, out suc))
                        {
                            ex = ex ?? new SqliteVisualizerException(Resources.ErrMsg_FuncEvalFailed, r.FullName);
                            return;
                        }

                        ulong address      = suc.Address.Value;
                        byte[] stringMaybe = process.ReadMemoryString(address, DkmReadMemoryFlags.None, 1, 1024);
                        int len            = stringMaybe.Length;
                        if (len > 0)
                        {
                            // The debugger null terminates all strings, but encoding doesn't strip null when creating a string
                            len--;
                            rowLocal[i_local] = Encoding.UTF8.GetString(stringMaybe, 0, len);
                        }
                    });

                    exprs.Add(e);
                }

                workList.Execute();

                if (ex != null)
                {
                    throw ex;
                }
            }
            finally
            {
                foreach (var e in exprs)
                {
                    e.Close();
                }
            }

            row = rowLocal;
            return(true);
        }