Esempio n. 1
0
        public dynamic GetValue(ClrAppDomain appDomain)
        {
            if (m_field.IsPrimitive())
            {
                object value = m_field.GetFieldValue(appDomain);
                if (value != null)
                {
                    return(new ClrPrimitiveValue(value, m_field.ElementType));
                }
            }
            else if (m_field.IsValueClass())
            {
                ulong addr = m_field.GetFieldAddress(appDomain);
                if (addr != 0)
                {
                    return(new ClrObject(m_heap, m_field.Type, addr, true));
                }
            }
            else if (m_field.ElementType == ClrElementType.String)
            {
                ulong addr = m_field.GetFieldAddress(appDomain);
                if (m_heap.GetRuntime().ReadPointer(addr, out addr))
                {
                    return(new ClrObject(m_heap, m_field.Type, addr));
                }
            }
            else
            {
                object value = m_field.GetFieldValue(appDomain);
                if (value != null)
                {
                    return(new ClrObject(m_heap, m_field.Type, (ulong)value));
                }
            }

            return(new ClrNullValue(m_heap));
        }
Esempio n. 2
0
        private IEnumerable <ulong> EnumerateManagedThreadpoolObjects()
        {
            m_heap = m_runtime.GetHeap();

            ClrModule mscorlib = GetMscorlib();

            if (mscorlib != null)
            {
                ClrType queueType = mscorlib.GetTypeByName("System.Threading.ThreadPoolGlobals");
                if (queueType != null)
                {
                    ClrStaticField workQueueField = queueType.GetStaticFieldByName("workQueue");
                    if (workQueueField != null)
                    {
                        foreach (var appDomain in m_runtime.AppDomains)
                        {
                            ulong   workQueue     = (ulong)workQueueField.GetFieldValue(appDomain);
                            ClrType workQueueType = m_heap.GetObjectType(workQueue);

                            if (workQueue == 0 || workQueueType == null)
                            {
                                continue;
                            }

                            ulong   queueHead;
                            ClrType queueHeadType;
                            do
                            {
                                if (!GetFieldObject(workQueueType, workQueue, "queueHead", out queueHeadType, out queueHead))
                                {
                                    break;
                                }

                                ulong   nodes;
                                ClrType nodesType;
                                if (GetFieldObject(queueHeadType, queueHead, "nodes", out nodesType, out nodes) && nodesType.IsArray)
                                {
                                    int len = nodesType.GetArrayLength(nodes);
                                    for (int i = 0; i < len; ++i)
                                    {
                                        ulong addr = (ulong)nodesType.GetArrayElementValue(nodes, i);
                                        if (addr != 0)
                                        {
                                            yield return(addr);
                                        }
                                    }
                                }

                                if (!GetFieldObject(queueHeadType, queueHead, "Next", out queueHeadType, out queueHead))
                                {
                                    break;
                                }
                            } while (queueHead != 0);
                        }
                    }
                }


                queueType = mscorlib.GetTypeByName("System.Threading.ThreadPoolWorkQueue");
                if (queueType != null)
                {
                    ClrStaticField threadQueuesField = queueType.GetStaticFieldByName("allThreadQueues");
                    if (threadQueuesField != null)
                    {
                        foreach (ClrAppDomain domain in m_runtime.AppDomains)
                        {
                            ulong threadQueue = (ulong)threadQueuesField.GetFieldValue(domain);
                            if (threadQueue == 0)
                            {
                                continue;
                            }

                            ClrType threadQueueType = m_heap.GetObjectType(threadQueue);
                            if (threadQueueType == null)
                            {
                                continue;
                            }

                            ulong   outerArray     = 0;
                            ClrType outerArrayType = null;
                            if (!GetFieldObject(threadQueueType, threadQueue, "m_array", out outerArrayType, out outerArray) || !outerArrayType.IsArray)
                            {
                                continue;
                            }

                            int outerLen = outerArrayType.GetArrayLength(outerArray);
                            for (int i = 0; i < outerLen; ++i)
                            {
                                ulong entry = (ulong)outerArrayType.GetArrayElementValue(outerArray, i);
                                if (entry == 0)
                                {
                                    continue;
                                }

                                ClrType entryType = m_heap.GetObjectType(entry);
                                if (entryType == null)
                                {
                                    continue;
                                }

                                ulong   array;
                                ClrType arrayType;
                                if (!GetFieldObject(entryType, entry, "m_array", out arrayType, out array) || !arrayType.IsArray)
                                {
                                    continue;
                                }

                                int len = arrayType.GetArrayLength(array);
                                for (int j = 0; j < len; ++j)
                                {
                                    ulong addr = (ulong)arrayType.GetArrayElementValue(array, i);
                                    if (addr != 0)
                                    {
                                        yield return(addr);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void GetFieldValue(IMDAppDomain appDomain, out IMDValue ppValue)
        {
            object value = m_field.GetFieldValue((ClrAppDomain)appDomain);

            ppValue = new MDValue(value, m_field.ElementType);
        }