Exemple #1
0
        /// <summary>
        /// Processes the specified type's fields to fill in required data.
        /// </summary>
        /// <param name="TheLibrary">The library from which the type originated.</param>
        /// <param name="theTypeInfo">The type info to process.</param>
        public static void ProcessTypeFields(IL.ILLibrary TheLibrary, TypeInfo theTypeInfo)
        {
            if (theTypeInfo.ProcessedFields)
            {
                return;
            }

            theTypeInfo.ProcessedFields = true;

            int totalOffset = 0;

            //Base class fields
            if (theTypeInfo.UnderlyingType.BaseType != null)
            {
                Type baseType = theTypeInfo.UnderlyingType.BaseType;
                if (!baseType.AssemblyQualifiedName.Contains("mscorlib"))
                {
                    totalOffset = TheLibrary.GetTypeInfo(baseType).SizeOnHeapInBytes;
                }
            }

            foreach (FieldInfo aFieldInfo in theTypeInfo.FieldInfos)
            {
                if (!aFieldInfo.IsStatic)
                {
                    aFieldInfo.OffsetInBytes = totalOffset;
                    TypeInfo fieldTypeInfo = TheLibrary.GetTypeInfo(aFieldInfo.FieldType);
                    totalOffset += fieldTypeInfo.IsValueType ? fieldTypeInfo.SizeOnHeapInBytes : fieldTypeInfo.SizeOnStackInBytes;
                }
            }
        }
Exemple #2
0
        public static void SaveLibraryInfo(string FolderPath, IL.ILLibrary TheLibrary)
        {
            string RootAssemblyName = Utilities.CleanFileName(TheLibrary.TheAssembly.GetName().Name);

            using (StreamWriter Str = new StreamWriter(Path.Combine(FolderPath, RootAssemblyName + "_Dependencies.txt"), false))
            {
                foreach (IL.ILLibrary DependencyLibrary in TheLibrary.Dependencies)
                {
                    Str.WriteLine(Utilities.CleanFileName(DependencyLibrary.TheAssembly.GetName().Name));
                }
            }

            using (StreamWriter Str = new StreamWriter(Path.Combine(FolderPath, RootAssemblyName + "_Library.txt"), false))
            {
                foreach (Types.TypeInfo ATypeInfo in TheLibrary.TypeInfos)
                {
                    //TypeID
                    //¬BaseTypeID:[ID]
                    //¬IsGCManaged:[Boolean]
                    //¬IsPointer:[Boolean]
                    //¬IsValueType:[Boolean]
                    //¬SizeOnHeapInBytes:[Integer]
                    //¬SizeOnStackInBytes:[Integer]
                    //|Field:[ID]
                    //~Type:[TypeID]
                    //~IsStatic:[Boolean]
                    //~Name:[String]
                    //~OffsetInBytes:[Integer]
                    //|Method:[ID]
                    //~ApplyDebug:[Boolean]
                    //~ApplyGC:[Boolean]
                    //~IDValue:[Integer]
                    //~IsConstructor:[Boolean]
                    //~IsPlugged:[Boolean]
                    //~IsStatic:[Boolean]
                    //~Signature:[String]
                    //~Argument:Offset|Position|TypeID
                    //~Local:Offset|Position|TypeID

                    Str.WriteLine(ATypeInfo.ID);
                    if (ATypeInfo.UnderlyingType.BaseType != null && 
                        !ATypeInfo.UnderlyingType.BaseType.AssemblyQualifiedName.Contains("mscorlib"))
                    {
                        Str.WriteLine("¬BaseTypeID:" + TheLibrary.GetTypeInfo(ATypeInfo.UnderlyingType.BaseType).ID);
                    }
                    Str.WriteLine("¬IsGCManaged:" + ATypeInfo.IsGCManaged.ToString());
                    Str.WriteLine("¬IsPointer:" + ATypeInfo.IsPointer.ToString());
                    Str.WriteLine("¬IsValueType:" + ATypeInfo.IsValueType.ToString());
                    Str.WriteLine("¬SizeOnHeapInBytes:" + ATypeInfo.SizeOnHeapInBytes.ToString());
                    Str.WriteLine("¬SizeOnStackInBytes:" + ATypeInfo.SizeOnStackInBytes.ToString());

                    foreach (Types.FieldInfo AFieldInfo in ATypeInfo.FieldInfos)
                    {
                        Str.WriteLine("|Field:" + AFieldInfo.ID);
                        Str.WriteLine("~Type:" + TheLibrary.GetTypeInfo(AFieldInfo.FieldType).ID);
                        Str.WriteLine("~IsStatic:" + AFieldInfo.IsStatic.ToString());
                        Str.WriteLine("~Name:" + AFieldInfo.Name);
                        Str.WriteLine("~OffsetInBytes:" + AFieldInfo.OffsetInBytes.ToString());
                    }

                    foreach (Types.MethodInfo AMethodInfo in ATypeInfo.MethodInfos)
                    {
                        Str.WriteLine("|Method:" + AMethodInfo.ID);
                        Str.WriteLine("~ApplyDebug:" + AMethodInfo.ApplyDebug.ToString());
                        Str.WriteLine("~ApplyGC:" + AMethodInfo.ApplyGC.ToString());
                        Str.WriteLine("~IDValue:" + AMethodInfo.IDValue.ToString());
                        Str.WriteLine("~IsConstructor:" + AMethodInfo.IsConstructor.ToString());
                        Str.WriteLine("~IsPlugged:" + AMethodInfo.IsPlugged.ToString());
                        Str.WriteLine("~IsStatic:" + AMethodInfo.IsStatic.ToString());
                        Str.WriteLine("~Signature:" + AMethodInfo.Signature);

                        Type RetType = (AMethodInfo.IsConstructor ?
                                            typeof(void) : ((System.Reflection.MethodInfo)AMethodInfo.UnderlyingInfo).ReturnType);
                        Str.WriteLine("~ReturnSize:" + Types.TypeScanner.GetSizeOnStackInBytes(RetType));

                        foreach (Types.VariableInfo AnArgumentInfo in AMethodInfo.ArgumentInfos)
                        {
                            Str.WriteLine("~Argument:" + AnArgumentInfo.Offset.ToString() + "|" + AnArgumentInfo.Position.ToString() + "|" + AnArgumentInfo.TheTypeInfo.ID);
                        }
                        foreach (Types.VariableInfo ALocalInfo in AMethodInfo.LocalInfos)
                        {
                            Str.WriteLine("~Local:" + ALocalInfo.Offset.ToString() + "|" + ALocalInfo.Position.ToString() + "|" + ALocalInfo.TheTypeInfo.ID);
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Processes the specified type info to fill in the required data.
        /// </summary>
        /// <param name="TheLibrary">The library from which the type originated.</param>
        /// <param name="theTypeInfo">The type info to process.</param>
        public static void ProcessType(IL.ILLibrary TheLibrary, TypeInfo theTypeInfo)
        {
            if(theTypeInfo.Processed)
            {
                return;
            }

            theTypeInfo.Processed = true;

            theTypeInfo.IsGCManaged = GetIsGCManaged(theTypeInfo.UnderlyingType);

            if (theTypeInfo.IsValueType || theTypeInfo.IsPointer)
            {
                theTypeInfo.SizeOnStackInBytes = GetSizeOnStackInBytes(theTypeInfo.UnderlyingType);
                theTypeInfo.SizeOnHeapInBytes = GetSizeOnHeapInBytes(theTypeInfo.UnderlyingType);
            }
            else
            {
                theTypeInfo.SizeOnStackInBytes = GetSizeOnStackInBytes(theTypeInfo.UnderlyingType);
                
                theTypeInfo.SizeOnHeapInBytes = 0;
                if (theTypeInfo.UnderlyingType.BaseType != null)
                {
                    Type baseType = theTypeInfo.UnderlyingType.BaseType;
                    if (!baseType.AssemblyQualifiedName.Contains("mscorlib"))
                    {
                        TypeInfo baseTypeInfo = TheLibrary.GetTypeInfo(baseType, false);
                        ProcessType(TheLibrary, baseTypeInfo);
                        theTypeInfo.SizeOnHeapInBytes += baseTypeInfo.SizeOnHeapInBytes;
                    }
                }
                foreach (FieldInfo aFieldInfo in theTypeInfo.FieldInfos)
                {
                    if (!aFieldInfo.IsStatic)
                    {
                        TypeInfo fieldTypeInfo = TheLibrary.GetTypeInfo(aFieldInfo.FieldType, false);
                        if (fieldTypeInfo.IsValueType || fieldTypeInfo.IsPointer)
                        {
                            ProcessType(TheLibrary, fieldTypeInfo);
                        }
                        theTypeInfo.SizeOnHeapInBytes += fieldTypeInfo.IsValueType ? fieldTypeInfo.SizeOnHeapInBytes : Options.AddressSizeInBytes;
                    }
                }
            }
        }