Exemple #1
0
 public CppField(CLRAssemblyCollection assemblies, CLRFieldRow field)
 {
     Type = assemblies.InternVagueType(field.Signature.Type);
     OriginallyGenericParam = (field.Signature.Type is CLRSigTypeVarOrMVar);
     Name = field.Name;
     Field = field;
     DeclaredInClassSpec = CppBuilder.CreateInstanceTypeSpec(assemblies, field.Owner);
 }
Exemple #2
0
 public void Resolve(CLRAssemblyCollection assemblies, ref bool resolvedAny, ref bool resolvedAll)
 {
     ResolveTable(CLRMetaDataTables.TableIndex.TypeSpec, assemblies, ref resolvedAny, ref resolvedAll);
     ResolveTable(CLRMetaDataTables.TableIndex.AssemblyRef, assemblies, ref resolvedAny, ref resolvedAll);
     ResolveTable(CLRMetaDataTables.TableIndex.ModuleRef, assemblies, ref resolvedAny, ref resolvedAll);
     ResolveTable(CLRMetaDataTables.TableIndex.TypeRef, assemblies, ref resolvedAny, ref resolvedAll);
     ResolveTable(CLRMetaDataTables.TableIndex.TypeSpec, assemblies, ref resolvedAny, ref resolvedAll);
 }
Exemple #3
0
 public void ParseCustomAttributes(CLRAssemblyCollection assemblies)
 {
     ICLRTable table = MetaData.MetaDataTables.GetTable(CLRMetaDataTables.TableIndex.CustomAttribute);
     for (uint i = 0; i < table.NumRows; i++)
     {
         CLRCustomAttributeRow ca = (CLRCustomAttributeRow)table.GetRow(i);
         ca.Resolve();
     }
 }
Exemple #4
0
 public void Resolve(CLRAssemblyCollection assemblies)
 {
     if (ResolutionScope == null)
         throw new NotImplementedException();    // Search ExportedType table
     else if (ResolutionScope is CLRTypeRefRow)
     {
         // Nested type
         CLRTypeRefRow typeRef = (CLRTypeRefRow)ResolutionScope;
         if (typeRef.Resolution == null)
             return;
         if (TypeNamespace != "")
             throw new ParseFailedException("Strange type namespace in nested type");
         CLRTypeDefRow typeDef = typeRef.Resolution;
         CLRMetaData assmMetaData = typeDef.Table.MetaData;
         ICLRTable nestedClassTable = assmMetaData.MetaDataTables.GetTable(CLRMetaDataTables.TableIndex.NestedClass);
         for (uint i = 0; i < nestedClassTable.NumRows; i++)
         {
             CLRNestedClassRow nestedClass = (CLRNestedClassRow)nestedClassTable.GetRow(i);
             if (nestedClass.EnclosingClass == typeDef)
             {
                 CLRTypeDefRow childClass = nestedClass.NestedClass;
                 if (childClass.TypeName == TypeName)
                 {
                     Resolution = childClass;
                     return;
                 }
             }
         }
         throw new ParseFailedException("Failed to resolve reference to nested type");
     }
     else if (ResolutionScope is CLRModuleRefRow)
         throw new NotImplementedException();
     else if (ResolutionScope is CLRModuleRow)
         throw new NotImplementedException();
     else if (ResolutionScope is CLRAssemblyRefRow)
     {
         CLRAssemblyRefRow assemblyRef = (CLRAssemblyRefRow)ResolutionScope;
         if (assemblyRef.Resolution == null)
             return;
         CLRAssembly externAssm = assemblyRef.Resolution;
         ICLRTable typeDefTable = externAssm.MetaData.MetaDataTables.GetTable(CLRMetaDataTables.TableIndex.TypeDef);
         for (uint i = 0; i < typeDefTable.NumRows; i++)
         {
             CLRTypeDefRow typeDef = (CLRTypeDefRow)typeDefTable.GetRow(i);
             if (typeDef.TypeNamespace == TypeNamespace && typeDef.TypeName == TypeName)
             {
                 Resolution = typeDef;
                 return;
             }
         }
         throw new ParseFailedException("Failed to resolve external symbol " + TypeNamespace + "." + TypeName + " in external assembly " + assemblyRef.Name);
     }
     else
         throw new ParseFailedException("Strange resolution scope");
 }
Exemple #5
0
 public void Resolve(CLRAssemblyCollection assemblies)
 {
     foreach (CLRAssembly assm in assemblies)
     {
         ICLRTable table = assm.MetaData.MetaDataTables.GetTable(CLRMetaDataTables.TableIndex.Assembly);
         CLRAssemblyRow assmRow = (CLRAssemblyRow)table.GetRow(0);
         if (assmRow.Name == Name &&
             assmRow.Culture == Culture &&
             assmRow.MajorVersion == MajorVersion &&
             assmRow.MinorVersion == MinorVersion &&
             assmRow.BuildNumber == BuildNumber &&
             assmRow.RevisionNumber == RevisionNumber)
         {
             Resolution = assm;
             break;
         }
     }
 }
Exemple #6
0
 private void ResolveTable(CLRMetaDataTables.TableIndex tableIndex, CLRAssemblyCollection assemblies, ref bool resolvedAny, ref bool resolvedAll)
 {
     CLRMetaDataTables tables = MetaData.MetaDataTables;
     ICLRTable typeRefTable = tables.GetTable(tableIndex);
     uint numRows = typeRefTable.NumRows;
     for (uint i = 0; i < numRows; i++)
     {
         ICLRResolvable typeRef = (ICLRResolvable)typeRefTable.GetRow(i);
         if (!typeRef.IsResolved)
         {
             typeRef.Resolve(assemblies);
             if (typeRef.IsResolved)
                 resolvedAny = true;
             else
                 resolvedAll = false;
         }
     }
 }
Exemple #7
0
        public void AddMethod(CLRAssemblyCollection assemblies, CLRMethodDefRow method)
        {
            CppMethod cppMethod = new CppMethod(assemblies, m_typeDef, method);
            m_methods.Add(cppMethod);
            if (cppMethod.Virtual && !cppMethod.Overrides)
            {
                m_overrideVisibleVtableSlots.Add(cppMethod.CreatesSlot);
                m_allVtableSlots.Add(cppMethod.CreatesSlot);
            }

            if (cppMethod.NumGenericParameters > 0)
                HaveAnyGenericMethods = true;
        }
Exemple #8
0
 public void AddField(CLRAssemblyCollection assemblies, CLRFieldRow field)
 {
     if (field.Static && !field.Literal)
         HaveNewStaticFields = true;
     m_fields.Add(new CppField(assemblies, field));
 }
Exemple #9
0
        public CppBuilder(string exportDir, string stubDir, CLRAssemblyCollection assemblies, IDictionary<CLRAssembly, string> pdbPaths)
        {
            m_assemblies = assemblies;
            m_exportPath = exportDir;
            m_stubDir = stubDir;
            m_typeSpecClasses = new Dictionary<CLRTypeSpec, CppClass>();
            m_fullNameClasses = new Dictionary<string, CppClass>();
            m_pdbs = new Dictionary<CLRAssembly, PdbDebugInfo>();

            foreach (KeyValuePair<CLRAssembly, string> pdbPath in pdbPaths)
            {
                using (System.IO.FileStream fs = new FileStream(pdbPath.Value, FileMode.Open, FileAccess.Read))
                {
                    PdbDebugInfo pdbDebugInfo = new PdbDebugInfo(fs);
                    m_pdbs.Add(pdbPath.Key, pdbDebugInfo);
                }
            }

            // Generate type def cache
            foreach (CLRAssembly assm in assemblies)
            {
                CLRMetaDataTables tables = assm.MetaData.MetaDataTables;
                ICLRTable typeDefs = tables.GetTable(CLRMetaDataTables.TableIndex.TypeDef);

                for (uint i = 0; i < typeDefs.NumRows; i++)
                {
                    CLRTypeDefRow typeDef = (CLRTypeDefRow)typeDefs.GetRow(i);
                    CacheTypeDef(typeDef);
                }
            }

            // Export everything
            foreach (CLRAssembly assm in assemblies)
            {
                CLRMetaDataTables tables = assm.MetaData.MetaDataTables;
                ICLRTable typeDefs = tables.GetTable(CLRMetaDataTables.TableIndex.TypeDef);

                ICLRTable assemblyTable = tables.GetTable(CLRMetaDataTables.TableIndex.Assembly);
                CLRAssemblyRow assemblyRow = (CLRAssemblyRow)assemblyTable.GetRow(0);

                Clarity.Rpa.HighFileBuilder fileBuilder = new Clarity.Rpa.HighFileBuilder();

                using (FileStream fs = new FileStream(exportDir + assemblyRow.Name + ".rpa", FileMode.Create))
                {
                    using (BinaryWriter writer = new BinaryWriter(fs))
                    {
                        using (MemoryStream objDataStream = new MemoryStream())
                        {
                            using (BinaryWriter objDataWriter = new BinaryWriter(objDataStream))
                            {
                                uint numUsableTypes = 0;

                                for (uint i = 0; i < typeDefs.NumRows; i++)
                                {
                                    CLRTypeDefRow typeDef = (CLRTypeDefRow)typeDefs.GetRow(i);
                                    if (typeDef.Extends == null)
                                    {
                                        if (typeDef.TypeNamespace == "" && typeDef.TypeName == "<Module>")
                                            continue;

                                        if (typeDef.Semantics != CLRTypeDefRow.TypeSemantics.Interface && (typeDef.TypeNamespace != "System" || typeDef.TypeName != "Object"))
                                            throw new Exception("Unexpected parentless type");
                                    }
                                    numUsableTypes++;
                                }

                                objDataWriter.Write(numUsableTypes);

                                for (uint i = 0; i < typeDefs.NumRows; i++)
                                {
                                    CLRTypeDefRow typeDef = (CLRTypeDefRow)typeDefs.GetRow(i);

                                    if (typeDef.Extends == null && typeDef.TypeNamespace == "" && typeDef.TypeName == "<Module>")
                                        continue;

                                    ExportTypeDef(fileBuilder, objDataWriter, typeDef);
                                }

                                uint assemblyNameIndex = fileBuilder.IndexString(assemblyRow.Name);

                                writer.Write(0x41503252);   // R2PA
                                fileBuilder.FlushAndWriteCatalogs(writer);
                                writer.Write(assemblyNameIndex);
                                writer.Flush();

                                objDataWriter.Flush();
                                objDataStream.WriteTo(fs);
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        public static CLRTypeSpec CreateInstanceTypeSpec(CLRAssemblyCollection assemblies, CLRTypeDefRow typeDefRow)
        {
            int numClassGenericParams = 0;
            if (typeDefRow.GenericParameters != null)
                numClassGenericParams = typeDefRow.GenericParameters.Length;

            if (numClassGenericParams == 0)
                return new CLRTypeSpecClass(typeDefRow);
            else
            {
                List<CLRTypeSpec> genericParams = new List<CLRTypeSpec>();
                for (int i = 0; i < numClassGenericParams; i++)
                    genericParams.Add(new CLRTypeSpecVarOrMVar(CLRSigType.ElementType.VAR, (uint)i));

                // Sigh...
                // This would be easier if we just resolved from the class down, but we currently allow
                // free-floating methods to be resolved.
                CLRSigTypeGenericInstantiation.InstType instType = CLRSigTypeGenericInstantiation.InstType.Class;
                {
                    CLRTableRow extendsRow = typeDefRow.Extends;
                    if (extendsRow != null)
                    {
                        CLRTypeSpec parentTypeSpec = assemblies.InternTypeDefOrRefOrSpec(typeDefRow.Extends);
                        if (parentTypeSpec is CLRTypeSpecClass)
                        {
                            CLRTypeDefRow parentClassDef = ((CLRTypeSpecClass)parentTypeSpec).TypeDef;
                            if (parentClassDef.ContainerClass == null && parentClassDef.TypeNamespace == "System" && (parentClassDef.TypeName == "ValueType" || parentClassDef.TypeName == "Enum"))
                                instType = CLRSigTypeGenericInstantiation.InstType.ValueType;
                        }
                    }
                }

                return new CLRTypeSpecGenericInstantiation(instType, new CLRTypeSpecClass(typeDefRow), genericParams.ToArray());
            }
        }