private static void PrintDictionary(ClrObject dictClrObject)
        {
            var entries = dictClrObject.GetObjectField("entries");

            if (entries.IsNull)
            {
                return;
            }

            var count         = dictClrObject.GetField <int>("count");
            var arrayType     = entries.Type;
            var elementType   = arrayType.ComponentType;
            var entriesLength = Math.Min(count, arrayType.GetArrayLength(entries.Address));
            var heap          = arrayType.Heap;

            var keyField   = elementType.GetFieldByName("key");
            var valueField = elementType.GetFieldByName("value");
            var hashField  = elementType.GetFieldByName("hashCode");

            for (var i = 0; i < entriesLength; i++)
            {
                var entryAddr = arrayType.GetArrayElementAddress(entries.Address, i);
                var hash      = (int)hashField.GetValue(entryAddr, true);
                if (hash < 0)
                {
                    continue;
                }

                var key   = Repr(heap, keyField.GetValue(entryAddr, true));
                var value = Repr(heap, valueField.GetValue(entryAddr, true));
                Console.WriteLine(key + ": " + value);
            }
        }
Ejemplo n.º 2
0
        public void Print(ClrObject clrObject)
        {
            var entries = clrObject.GetObjectField("_entries");

            if (entries.IsNull)
            {
                return;
            }

            var count         = clrObject.GetField <int>("_count");
            var arrayType     = entries.Type;
            var elementType   = arrayType.ComponentType;
            var entriesLength = count;

            for (var i = 0; i < entriesLength; i++)
            {
                var entryAddr = arrayType.GetArrayElementAddress(entries.Address, i);

                var dictEntry = ClrValueClassFactory.Create(entryAddr, elementType);

                var hash = dictEntry.GetField <int>("hashCode");
                if (hash < 0)
                {
                    continue;
                }

                var key   = ClrMdHelper.ToString(dictEntry.GetObjectField("key"));
                var value = ClrMdHelper.ToString(dictEntry.GetObjectField("value"));
                Console.WriteLine(key + ": " + value);
            }
        }
Ejemplo n.º 3
0
        internal void Extract()
        {
            Console.WriteLine(@"SafeInCloudExtractor is working.");
            Process appProcess = GetAppProcess();

            if (appProcess == null)
            {
                Console.WriteLine(@"Couldn't find application process.");
                return;
            }
            Console.WriteLine($@"Found SafeInCloud process. ID: {appProcess.Id}");
            ClrRuntime runtime = GetRuntime(appProcess);

            if (runtime == null)
            {
                Console.WriteLine(@"Couldn't find ClrRuntime.");
                return;
            }
            ClrObject dBModelTypeObj = GetInfoObject(runtime, Resources.DbModelTypeName);

            if (dBModelTypeObj.IsNull)
            {
                Console.WriteLine(@"Couldn't find DatabaseModel type object.");
                return;
            }
            int state;

            try
            {
                state = dBModelTypeObj.GetField <int>(Resources.StateFieldName);
            }
            catch (Exception)
            {
                Console.WriteLine(@"Couldn't find program state.");
                return;
            }
            if (state != 2)
            {
                Console.WriteLine(@"Password must be entered at least once.");
                return;
            }

            string dbPath   = dBModelTypeObj.GetStringField(Resources.DbModelDbPathField);
            string password = dBModelTypeObj.GetStringField(Resources.DbModelPasswordField);

            Console.WriteLine($@"Database path: {dbPath}");
            Console.WriteLine($@"Database password: {password}");
        }
Ejemplo n.º 4
0
        private static void MarkThreadingBlockTasks(DebuggerContext context, List <AsyncStateMachine> allStateMachines)
        {
            foreach (var thread in context.Runtime.Threads)
            {
                var stackFrame = thread.EnumerateStackTrace().Take(50).FirstOrDefault(
                    f => f.Method is { } method &&
                    string.Equals(f.Method.Name, "CompleteOnCurrentThread", StringComparison.Ordinal) &&
                    string.Equals(f.Method.Type?.Name, "Microsoft.VisualStudio.Threading.JoinableTask", StringComparison.Ordinal));

                if (stackFrame != null)
                {
                    var visitedObjects = new HashSet <ulong>();
                    foreach (var stackObject in thread.EnumerateStackObjects())
                    {
                        if (string.Equals(stackObject.Type?.Name, "Microsoft.VisualStudio.Threading.JoinableTask", StringComparison.Ordinal) ||
                            string.Equals(stackObject.Type?.BaseType?.Name, "Microsoft.VisualStudio.Threading.JoinableTask", StringComparison.Ordinal))
                        {
                            if (visitedObjects.Add(stackObject.Object))
                            {
                                var joinableTaskObject = new ClrObject(stackObject.Object, stackObject.Type);
                                int state = joinableTaskObject.GetField <int>("state");
                                if ((state & 0x10) == 0x10)
                                {
                                    // This flag indicates the JTF is blocking the thread
                                    var wrappedTask = joinableTaskObject.TryGetObjectField("wrappedTask");
                                    if (!wrappedTask.IsNull)
                                    {
                                        var blockingStateMachine = allStateMachines
                                                                   .FirstOrDefault(s => s.Task.Address == wrappedTask.Address);
                                        if (blockingStateMachine != null)
                                        {
                                            blockingStateMachine.BlockedThread       = thread.OSThreadId;
                                            blockingStateMachine.BlockedJoinableTask = joinableTaskObject;
                                        }
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public object GetFieldValueImpl(ulong address, ClrType type, List <string> fieldNames)
        {
            ClrObject obj = new ClrObject(address, type);

            for (int i = 0; i < fieldNames.Count; i++)
            {
                var fieldName          = fieldNames[i];
                ClrInstanceField field = obj.GetField(fieldName);
                if (field == null)
                {
                    return(null);
                }

                obj = obj[field];
                if (obj.IsNull)
                {
                    return(null);
                }
            }

            return(obj.HasSimpleValue ? obj.SimpleValue : obj.Address);
        }
Ejemplo n.º 6
0
 static void PrintHttpWebRequestFields(ClrObject o, string prefix)
 {
     Console.WriteLine($"{prefix}m_KeepAlive = {o.GetField<bool>("m_KeepAlive")}");
     //Console.WriteLine($"{prefix}m_NtlmKeepAlive = {o.GetField<bool>("m_NtlmKeepAlive")}");
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     Gets the value of a primitive field.  This will throw an InvalidCastException if the type parameter
 ///     does not match the field's type.
 /// </summary>
 /// <typeparam name="T">The type of the field itself.</typeparam>
 /// <param name="fieldName">The name of the field.</param>
 /// <returns>The value of this field.</returns>
 /// <inheritdoc />
 public T GetField <T>(string fieldName) where T : struct => Object.GetField <T>(fieldName);