Beispiel #1
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var flags         = reader.ReadUInt32();
                var typeName      = reader.ReadMetadataTableIndex(indexSize);
                var typeNamespace = reader.ReadMetadataTableIndex(indexSize);
                var extends       = reader.ReadMetadataTableIndex(indexSize);
                var fieldList     = reader.ReadMetadataTableIndex(indexSize);
                var methodList    = reader.ReadMetadataTableIndex(indexSize);

                var typeNameResolved      = reader.ReadStreamStringEntry(typeName);
                var typeNamespaceResolved = reader.ReadStreamStringEntry(typeNamespace);

                result.Add(new CliMetadataTokenTypeDef
                {
                    Flags         = flags,
                    TypeName      = typeName,
                    TypeNamespace = typeNamespace,
                    Extends       = extends,
                    FieldList     = fieldList,
                    MethodList    = methodList,

                    TypeNameResolved      = typeNameResolved,
                    TypeNamespaceResolved = typeNamespaceResolved,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var number = reader.ReadUInt16();
                var flags  = reader.ReadUInt16();
                var owner  = reader.ReadMetadataTableIndex(indexSize);
                var name   = reader.ReadMetadataTableIndex(indexSize);

                var nameResolved = reader.ReadStreamStringEntry(name);

                result.Add(new CliMetadataTokenGenericParam
                {
                    Number = number,
                    Flags  = (CliMetadataGenericParamAttribute)flags,
                    Owner  = owner,
                    Name   = name,

                    NameResolved = nameResolved,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var generation = reader.ReadUInt16();
                var name       = reader.ReadMetadataTableIndex(indexSize);
                var mvid       = reader.ReadMetadataTableIndex(indexSize);
                var encId      = reader.ReadMetadataTableIndex(indexSize);
                var encBaseId  = reader.ReadMetadataTableIndex(indexSize);

                var nameResolved = reader.ReadStreamStringEntry(name);
                var mvidResolved = reader.ReadStreamGuidEntry(mvid);

                result.Add(new CliMetadataTokenModule
                {
                    Generation = generation,
                    Name       = name,
                    Mvid       = mvid,
                    EncId      = encId,
                    EncBaseId  = encBaseId,

                    NameResolved = nameResolved,
                    MvidResolved = mvidResolved,
                });
            }

            return(result);
        }
Beispiel #4
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var rva       = reader.ReadUInt32();
                var implFlags = reader.ReadUInt16();
                var flags     = reader.ReadUInt16();
                var name      = reader.ReadMetadataTableIndex(indexSize);
                var signature = reader.ReadMetadataTableIndex(indexSize);
                var paramList = reader.ReadMetadataTableIndex(indexSize);

                var nameResolved = reader.ReadStreamStringEntry(name);

                result.Add(new CliMetadataTokenMethodDef
                {
                    Rva       = rva,
                    ImplFlags = implFlags,
                    Flags     = flags,
                    Name      = name,
                    Signature = signature,
                    ParamList = paramList,

                    NameResolved = nameResolved,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var resolutionScope = reader.ReadMetadataTableIndex(indexSize);
                var typeName        = reader.ReadMetadataTableIndex(indexSize);
                var typeNamespace   = reader.ReadMetadataTableIndex(indexSize);

                var typeNameResolved      = reader.ReadStreamStringEntry(typeName);
                var typeNamespaceResolved = reader.ReadStreamStringEntry(typeNamespace);

                result.Add(new CliMetadataTokenTypeRef
                {
                    ResolutionScope = resolutionScope,
                    TypeName        = typeName,
                    TypeNamespace   = typeNamespace,

                    TypeNameResolved      = typeNameResolved,
                    TypeNamespaceResolved = typeNamespaceResolved,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var hashAlgId      = reader.ReadUInt32();
                var majorVersion   = reader.ReadUInt16();
                var minorVersion   = reader.ReadUInt16();
                var buildNumber    = reader.ReadUInt16();
                var revisionNumber = reader.ReadUInt16();
                var flags          = reader.ReadUInt32();
                var publickKey     = reader.ReadMetadataTableIndex(indexSize);
                var name           = reader.ReadMetadataTableIndex(indexSize);
                var culture        = reader.ReadMetadataTableIndex(indexSize);

                var nameResolved = reader.ReadStreamStringEntry(name);

                result.Add(new CliMetadataTokenAssembly
                {
                    HashAlgId      = (AssemblyHashAlgorithm)hashAlgId,
                    MajorVersion   = majorVersion,
                    MinorVersion   = minorVersion,
                    BuildNumber    = buildNumber,
                    RevisionNumber = revisionNumber,
                    Flags          = (CliMetadataAssemblyFlags)flags,
                    PublickKey     = publickKey,
                    Name           = name,
                    Culture        = culture,
                    NameResolved   = nameResolved,
                });
            }

            return(result);
        }
Beispiel #7
0
        private static CliMetadataTableStream ReadCliMetadataTableStream(ImageReader reader, uint metadataRva, ushort numberOfStreams, bool present)
        {
            var result               = new CliMetadataTableStream();
            var streamHeaders        = ReadCliMetadataStreamHeaders(reader, numberOfStreams, present);
            var metadataStreamReader = new MetadataStreamReader(reader, streamHeaders, metadataRva);

            result.Streams = streamHeaders;

            foreach (var item in streamHeaders)
            {
                reader.ToRva(item.Offset + metadataRva);

                if (present)
                {
                    Shell.WriteHeader($"CLI Metadata Table Stream Header [{item.Name}]");
                }

                switch (item.Name)
                {
                case "#~":
                {
                    result.DefaultCompressed = ReadCliMetadataTableStreamDefaultCompressed(metadataStreamReader, present);
                    break;
                }

                case "#Strings":
                {
                    // Should not be read directly, It may contain garbage!
                    break;
                }

                case "#US":
                {
                    // Should not be read directly, It may contain garbage!
                    break;
                }

                case "#GUID":
                {
                    // Should not be read directly, It may contain garbage, I'm not sure!
                    break;
                }

                case "#Blob":
                {
                    // Should not be read directly!
                    break;
                }

                default:
                {
                    throw new NotSupportedException();
                }
                }
            }

            return(result);
        }
Beispiel #8
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var processor = reader.ReadUInt32();

                result.Add(new CliMetadataTokenAssemblyProcessor
                {
                    Processor = processor,
                });
            }

            return(result);
        }
Beispiel #9
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var signature = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenTypeSpec
                {
                    Signature = signature,
                });
            }

            return(result);
        }
Beispiel #10
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var processor   = reader.ReadUInt32();
                var assemblyRef = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenAssemblyRefProcessor
                {
                    Processor   = processor,
                    AssemblyRef = assemblyRef,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var parent     = reader.ReadMetadataTableIndex(indexSize);
                var nativeType = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenFieldMarshal
                {
                    Parent     = parent,
                    NativeType = nativeType,
                });
            }

            return(result);
        }
Beispiel #12
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var name         = reader.ReadMetadataTableIndex(indexSize);
                var nameResolved = reader.ReadStreamStringEntry(name);

                result.Add(new CliMetadataTokenModuleRef
                {
                    Name         = name,
                    NameResolved = nameResolved,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var nestedClass    = reader.ReadMetadataTableIndex(indexSize);
                var enclosingClass = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenNestedClass
                {
                    NestedClass    = nestedClass,
                    EnclosingClass = enclosingClass,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var parent       = reader.ReadMetadataTableIndex(indexSize);
                var propertyList = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenPropertyMap
                {
                    Parent       = parent,
                    PropertyList = propertyList,
                });
            }

            return(result);
        }
Beispiel #15
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var offset = reader.ReadUInt32();
                var field  = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenFieldLayout
                {
                    Offset = offset,
                    Field  = field,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var owner      = reader.ReadMetadataTableIndex(indexSize);
                var constraint = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenGenericParamConstraint
                {
                    Owner      = owner,
                    Constraint = constraint,
                });
            }

            return(result);
        }
Beispiel #17
0
        private static void PresentIL(ImageReader br, IList <CoffDirectoryTable> directoryTables)
        {
            var table = directoryTables.OfType <CoffDirectoryTableCli>().FirstOrDefault();

            if (table == null)
            {
                return;
            }

            var tokens = table.Tables.DefaultCompressed.Tokens.SelectMany(x => x).OfType <CliMetadataTokenMethodDef>().ToArray();
            var reader = new MetadataStreamReader(br, table.Tables.Streams, table.Header.MetadataRva);

            var size = 80;

            foreach (var item in tokens)
            {
                Console.WriteLine("\t|" + new string('-', size) + "|");

                var a = string.Format("\t| RVA : {0:x4}", item.Rva);
                var b = string.Format("\t| Name: '{0}'", item.NameResolved);

                Console.WriteLine(a + new string(' ', size + 2 - a.Length) + "|");
                Console.WriteLine(b + new string(' ', size + 2 - b.Length) + "|");
                Console.WriteLine("\t|" + new string('-', size) + "|");

                foreach (var inst in ILInstructionDecoder.Decode(reader, item.Rva))
                {
                    if (inst.OpCode.Length == 1)
                    {
                        var line = string.Format("\t| IL_{0:x4} 0x{1:x2}      {2}", inst.Offset, inst.OpCode[0], inst.Name);
                        Console.WriteLine(line + new string(' ', size + 2 - line.Length) + "|");
                    }
                    else
                    {
                        var line = string.Format("\t| IL_{0:x4} 0x{1:x2} 0x{2:x2} {3}", inst.Offset, inst.OpCode[0], inst.OpCode[1], inst.Name);
                        Console.WriteLine(line + new string(' ', size + 2 - line.Length) + "|");
                    }
                }

                Console.WriteLine("\t|" + new string('-', size) + "|");
                Console.WriteLine();
            }
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var semantics   = reader.ReadUInt16();
                var method      = reader.ReadMetadataTableIndex(indexSize);
                var association = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenMethodSemantics
                {
                    Semantics   = (CliMetadataMethodSemanticsAttribute)semantics,
                    Method      = method,
                    Association = association,
                });
            }

            return(result);
        }
Beispiel #19
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var flags = reader.ReadUInt16();
                var name  = reader.ReadMetadataTableIndex(indexSize);
                var type  = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenEvent
                {
                    Flags = (CliMetadataEventAttribute)flags,
                    Name  = name,
                    Type  = type,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var packingSize = reader.ReadUInt16();
                var classSize   = reader.ReadUInt32();
                var parent      = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenClassLayout
                {
                    PackingSize = packingSize,
                    ClassSize   = classSize,
                    Parent      = parent,
                });
            }

            return(result);
        }
Beispiel #21
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var osPlatformID   = reader.ReadUInt32();
                var osMajorVersion = reader.ReadUInt32();
                var osMinorVersion = reader.ReadUInt32();

                result.Add(new CliMetadataTokenAssemblyOS
                {
                    OsPlatformID   = osPlatformID,
                    OsMajorVersion = osMajorVersion,
                    OsMinorVersion = osMinorVersion,
                });
            }

            return(result);
        }
Beispiel #22
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var type   = reader.ReadUInt16();
                var parent = reader.ReadMetadataTableIndex(indexSize);
                var value  = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenConstant
                {
                    Type   = type,
                    Parent = parent,
                    Value  = value,
                });
            }

            return(result);
        }
Beispiel #23
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var action        = reader.ReadUInt16();
                var parent        = reader.ReadMetadataTableIndex(indexSize);
                var permissionSet = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenDeclSecurity
                {
                    Action        = action,
                    Parent        = parent,
                    PermissionSet = permissionSet,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var flags     = reader.ReadUInt32();
                var name      = reader.ReadMetadataTableIndex(indexSize);
                var hashValue = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenFile
                {
                    Flags     = (CliMetadataFileFlags)flags,
                    Name      = name,
                    HashValue = hashValue,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var @class            = reader.ReadMetadataTableIndex(indexSize);
                var methodBody        = reader.ReadMetadataTableIndex(indexSize);
                var methodDeclaration = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenMethodImpl
                {
                    Class             = @class,
                    MethodBody        = methodBody,
                    MethodDeclaration = methodDeclaration,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var @class     = reader.ReadMetadataTableIndex(indexSize);
                var @interface = reader.ReadMetadataTableIndex(indexSize);

                var classResolved = reader.ReadStreamStringEntry(@class);

                result.Add(new CliMetadataTokenInterfaceImpl
                {
                    Class         = @class,
                    Interface     = @interface,
                    ClassResolved = classResolved,
                });
            }

            return(result);
        }
Beispiel #27
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var osPlatformId   = reader.ReadUInt32();
                var osMajorVersion = reader.ReadUInt32();
                var osMinorVersion = reader.ReadUInt32();
                var assemblyRef    = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenAssemblyRefOS
                {
                    OsPlatformId   = osPlatformId,
                    OsMajorVersion = osMajorVersion,
                    OsMinorVersion = osMinorVersion,
                    AssemblyRef    = assemblyRef,
                });
            }

            return(result);
        }
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var offset         = reader.ReadUInt32();
                var flags          = reader.ReadUInt32();
                var name           = reader.ReadMetadataTableIndex(indexSize);
                var implementation = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenManifestResource
                {
                    Offset         = offset,
                    Flags          = (CliMetadataManifestResourceFlags)flags,
                    Name           = name,
                    Implementation = implementation,
                });
            }

            return(result);
        }
Beispiel #29
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var mappingFlags    = reader.ReadUInt16();
                var memberForwarded = reader.ReadMetadataTableIndex(indexSize);
                var importName      = reader.ReadMetadataTableIndex(indexSize);
                var importScope     = reader.ReadMetadataTableIndex(indexSize);

                result.Add(new CliMetadataTokenImplMap
                {
                    MappingFlags    = (CliMetadataPinvokeMap)mappingFlags,
                    MemberForwarded = memberForwarded,
                    ImportName      = importName,
                    ImportScope     = importScope,
                });
            }

            return(result);
        }
Beispiel #30
0
        internal static IList <CliMetadataTokenBase> Read(MetadataStreamReader reader, uint count, uint indexSize)
        {
            var result = new List <CliMetadataTokenBase>();

            for (int i = 0; i < count; i++)
            {
                var flags = reader.ReadUInt16();
                var name  = reader.ReadMetadataTableIndex(indexSize);
                var type  = reader.ReadMetadataTableIndex(indexSize);

                var nameResolved = reader.ReadStreamStringEntry(name);

                result.Add(new CliMetadataTokenProperty
                {
                    Flags        = (CliMetadataPropertyAttribute)flags,
                    Name         = name,
                    Type         = type,
                    NameResolved = nameResolved
                });
            }

            return(result);
        }