Beispiel #1
0
        private static string ProcessAttributedPartCreationInfo(ClrHeap heap, ulong partCreationInfo)
        {
            ulong   creationInfoObj     = ClrMdHelper.GetObjectAs <ulong>(heap, partCreationInfo, FIELD_Type);
            ClrType creationInfoObjType = heap.GetObjectType(creationInfoObj);

            return(creationInfoObjType.GetRuntimeType(creationInfoObj)?.Name ?? creationInfoObjType.Name);
        }
Beispiel #2
0
        private static ReflectionComposablePart ProcessReflectionComposablePartDefinition(ClrHeap heap, ulong part)
        {
            var rcp = new ReflectionComposablePart();

            ulong   creationInfoObj     = ClrMdHelper.GetLastObjectInHierarchy(heap, part, HIERARCHY_ReflectionComposablePartDefinition_To_AttributedPartCreationInfo, 0);
            ClrType creationInfoObjType = heap.GetObjectType(creationInfoObj);

            rcp.TypeName = creationInfoObjType.GetRuntimeType(creationInfoObj)?.Name ?? creationInfoObjType.Name;

            var importObjs = ClrMdHelper.GetLastObjectInHierarchyAsArray(heap, part, HIERARCHY_CreationInfo_To_ImportArray, 0, TYPE_ImportDefinitionArray);

            foreach (var importDef in importObjs)
            {
                var importDefType = heap.GetObjectType(importDef);
                var prodInfoDef   = importDefType.GetFieldByName(ProductImportDefinition);

                ulong imDef;

                if (prodInfoDef != null)
                {
                    imDef = (ulong)prodInfoDef.GetValue(importDef);
                }
                else
                {
                    imDef = importDef;
                }

                string contract = ClrMdHelper.GetObjectAs <string>(heap, imDef, FIELD_ContractName);
                string typeId   = ClrMdHelper.GetObjectAs <string>(heap, imDef, FIELD_RequiredTypeIdentity);
                rcp.Imports.Add(new ImportDefinition()
                {
                    ContractName = contract, RequiredTypeIdentity = typeId
                });
            }

            // Get ExportDefinition[]
            ulong exportArrayObj = ClrMdHelper.GetObjectAs <ulong>(heap, part, FIELD_Exports);

            if (exportArrayObj != 0)
            {
                List <ulong> exportObjs = ClrMdHelper.GetArrayItems(heap.GetObjectType(exportArrayObj), exportArrayObj);

                foreach (var exportDef in exportObjs)
                {
                    ulong  attrExpDef = ClrMdHelper.GetObjectAs <ulong>(heap, exportDef, FIELD_ExportDefinition);
                    string contract   = ClrMdHelper.GetObjectAs <string>(heap, attrExpDef, FIELD_ContractName);
                    ulong  typeObj    = ClrMdHelper.GetObjectAs <ulong>(heap, attrExpDef, FIELD_TypeIdentityType);

                    string typename = null;

                    if (typeObj == 0)
                    {
                        Console.WriteLine($"WARNING: Special export was found with no type identity (contract: {contract})");
                        typename = rcp.TypeName;
                    }
                    else
                    {
                        ClrType typeObjType = heap.GetObjectType(typeObj);
                        typename = typeObjType.GetRuntimeType(typeObj)?.Name ?? typeObjType.Name;
                    }

                    rcp.Exports.Add(new ExportDefinition()
                    {
                        ContractName = contract, TypeIdentity = typename
                    });
                }
            }

            return(rcp);
        }
Beispiel #3
0
 /// <summary>
 ///     Returns the concrete type (in the target process) that this RuntimeType represents.
 ///     Note you may only call this function if IsRuntimeType returns true.
 /// </summary>
 /// <param name="obj">The RuntimeType object to get the concrete type for.</param>
 /// <returns>
 ///     The underlying type that this RuntimeType actually represents.  May return null if the
 ///     underlying type has not been fully constructed by the runtime, or if the underlying type
 ///     is actually a typehandle (which unfortunately ClrMD cannot convert into a ClrType due to
 ///     limitations in the underlying APIs.  (So always null-check the return value of this
 ///     function.)
 /// </returns>
 public IClrType GetRuntimeType(ulong obj) => Converter.Convert(ClrType.GetRuntimeType(obj));