Exemplo n.º 1
0
 protected MetadataIterator(MetadataTables _tables, byte[] _data, uint _pos, CorTokenType _tokenType)
 {
     tables    = _tables;
     data      = _data;
     pos       = _pos;
     tokenType = _tokenType;
 }
Exemplo n.º 2
0
        public MetadataRoot(byte[] data, uint _pos)
        {
            uint pos = _pos;

            signature    = MetadataTables.ReadUInt(data, pos);
            pos         += sizeof(uint);
            majorVersion = MetadataTables.ReadUShort(data, pos);
            pos         += sizeof(ushort);
            minorVersion = MetadataTables.ReadUShort(data, pos);
            pos         += sizeof(ushort);
            pos         += 4;//Reserved;
            uint len = MetadataTables.ReadUInt(data, pos);

            pos       += sizeof(uint);
            version    = System.Text.Encoding.UTF8.GetString(data, (int)pos, (int)len);
            len        = Alignment.Calc(len, 4);
            pos       += len;
            pos       += 2;//Flags
            structSize = pos - _pos;
        }
Exemplo n.º 3
0
        private void Modify(string nsName, string className, string methodName, Action <uint> callback)
        {
            int  srcStart, srcEnd;
            bool srcValid = GetTypeMethods(nsName, className, out srcStart, out srcEnd);

            if (!srcValid)
            {
                s_ErrorTxts.Add(string.Format("Can't find src {0}->{1}", className, srcValid));
                return;
            }
            MethodDefIterator it = m_ClrFile.Metadata.Tables[(int)CorTokenType.mdtMethodDef] as MethodDefIterator;

            for (uint ix = (uint)srcStart; ix < (uint)srcEnd; ++ix)
            {
                it.MoveTo(ix - 1);
                string name = GetString(m_ClrFile.Buffer, m_StringStart, it.Name);
                if (name == methodName)
                {
                    uint offset   = m_ClrFile.GetFileOffset(it.RVA);
                    byte ilheader = m_ClrFile.Buffer[offset];
                    if ((ilheader & 0x03) == 0x02)
                    {
                        uint size       = (uint)(ilheader >> 2);
                        uint headerSize = 1;

                        callback(offset + headerSize);
                    }
                    else if ((ilheader & 0x03) == 0x03)
                    {
                        uint one   = MetadataTables.ReadUInt(m_ClrFile.Buffer, offset);
                        uint two   = MetadataTables.ReadUInt(m_ClrFile.Buffer, offset + 4);
                        uint three = MetadataTables.ReadUInt(m_ClrFile.Buffer, offset + 8);

                        uint headerSize = ((one & 0x0000f000) >> 12) * 4;

                        callback(offset + headerSize);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public StreamHeader(byte[] _data, uint _pos)
        {
            data     = _data;
            position = _pos;

            uint pos = _pos;

            offset = MetadataTables.ReadUInt(data, pos);
            pos   += sizeof(uint);
            size   = MetadataTables.ReadUInt(data, pos);
            pos   += sizeof(uint);
            int nlen = 0;

            for (; data[pos + nlen] > 0; nlen++)
            {
                ;
            }
            name       = System.Text.Encoding.ASCII.GetString(data, (int)pos, nlen);
            nlen       = Alignment.Calc(nlen + 1, 4);
            pos       += (uint)nlen;
            structSize = pos - position;
        }
Exemplo n.º 5
0
 public ExportedTypeIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtExportedType)
 {
 }
Exemplo n.º 6
0
 public EventIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtEvent)
 {
 }
Exemplo n.º 7
0
 public ModuleRefIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtModuleRef)
 {
 }
Exemplo n.º 8
0
 public ManifestResourceIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtManifestResource)
 {
 }
Exemplo n.º 9
0
 public ImplMapIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtImplMap)
 {
 }
Exemplo n.º 10
0
 public TypeSpecIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtTypeSpec)
 {
 }
Exemplo n.º 11
0
        public static IMetadataIterator Create(MetadataTables _tables, byte[] _data, uint _pos, CorTokenType _tokenType)
        {
            switch (_tokenType)
            {
            case CorTokenType.mdtAssembly:
                return(new AssemblyIterator(_tables, _data, _pos));

            case CorTokenType.mdtAssemblyOS:
                return(new AssemblyOSIterator(_tables, _data, _pos));

            case CorTokenType.mdtAssemblyProcessor:
                return(new AssemblyProcessorIterator(_tables, _data, _pos));

            case CorTokenType.mdtAssemblyRef:
                return(new AssemblyRefIterator(_tables, _data, _pos));

            case CorTokenType.mdtAssemblyRefOS:
                return(new AssemblyRefOSIterator(_tables, _data, _pos));

            case CorTokenType.mdtAssemblyRefProcessor:
                return(new AssemblyRefProcessorIterator(_tables, _data, _pos));

            case CorTokenType.mdtClassLayout:
                return(new ClassLayoutIterator(_tables, _data, _pos));

            case CorTokenType.mdtConstant:
                return(new ConstantIterator(_tables, _data, _pos));

            case CorTokenType.mdtCustomAttribute:
                return(new CustomAttributeIterator(_tables, _data, _pos));

            case CorTokenType.mdtDeclSecurity:
                return(new DeclSecurityIterator(_tables, _data, _pos));

            case CorTokenType.mdtEvent:
                return(new EventIterator(_tables, _data, _pos));

            case CorTokenType.mdtEventMap:
                return(new EventMapIterator(_tables, _data, _pos));

            case CorTokenType.mdtExportedType:
                return(new ExportedTypeIterator(_tables, _data, _pos));

            case CorTokenType.mdtFieldDef:
                return(new FieldIterator(_tables, _data, _pos));

            case CorTokenType.mdtFieldLayout:
                return(new FieldLayoutIterator(_tables, _data, _pos));

            case CorTokenType.mdtFieldMarshal:
                return(new FieldMarshalIterator(_tables, _data, _pos));

            case CorTokenType.mdtFieldRVA:
                return(new FieldRVAIterator(_tables, _data, _pos));

            case CorTokenType.mdtFile:
                return(new FileIterator(_tables, _data, _pos));

            case CorTokenType.mdtGenericParam:
                return(new GenericParamIterator(_tables, _data, _pos));

            case CorTokenType.mdtGenericParamConstraint:
                return(new GenericParamConstraintIterator(_tables, _data, _pos));

            case CorTokenType.mdtImplMap:
                return(new ImplMapIterator(_tables, _data, _pos));

            case CorTokenType.mdtInterfaceImpl:
                return(new InterfaceImplIterator(_tables, _data, _pos));

            case CorTokenType.mdtManifestResource:
                return(new ManifestResourceIterator(_tables, _data, _pos));

            case CorTokenType.mdtMemberRef:
                return(new MemberRefIterator(_tables, _data, _pos));

            case CorTokenType.mdtMethodDef:
                return(new MethodDefIterator(_tables, _data, _pos));

            case CorTokenType.mdtMethodImpl:
                return(new MethodImplIterator(_tables, _data, _pos));

            case CorTokenType.mdtMethodSemantics:
                return(new MethodSemanticsIterator(_tables, _data, _pos));

            case CorTokenType.mdtMethodSpec:
                return(new MethodSpecIterator(_tables, _data, _pos));

            case CorTokenType.mdtModule:
                return(new ModuleIterator(_tables, _data, _pos));

            case CorTokenType.mdtModuleRef:
                return(new ModuleRefIterator(_tables, _data, _pos));

            case CorTokenType.mdtNestedClass:
                return(new NestedClassIterator(_tables, _data, _pos));

            case CorTokenType.mdtParamDef:
                return(new ParamIterator(_tables, _data, _pos));

            case CorTokenType.mdtProperty:
                return(new PropertyIterator(_tables, _data, _pos));

            case CorTokenType.mdtPropertyMap:
                return(new PropertyMapIterator(_tables, _data, _pos));

            case CorTokenType.mdtSignature:
                return(new StandAloneSigIterator(_tables, _data, _pos));

            case CorTokenType.mdtTypeDef:
                return(new TypeDefIterator(_tables, _data, _pos));

            case CorTokenType.mdtTypeRef:
                return(new TypeRefIterator(_tables, _data, _pos));

            case CorTokenType.mdtTypeSpec:
                return(new TypeSpecIterator(_tables, _data, _pos));

            default:
                return(new NullIterator(_tables, _data, _pos));
            }
        }
Exemplo n.º 12
0
 public StandAloneSigIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtSignature)
 {
 }
Exemplo n.º 13
0
 public PropertyIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtProperty)
 {
 }
Exemplo n.º 14
0
 public ParamIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtParamDef)
 {
 }
Exemplo n.º 15
0
 public NestedClassIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtNestedClass)
 {
 }
Exemplo n.º 16
0
 public FileIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtFile)
 {
 }
Exemplo n.º 17
0
 public GenericParamConstraintIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtGenericParamConstraint)
 {
 }
Exemplo n.º 18
0
 public NullIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtMaxTokenType)
 {
 }
Exemplo n.º 19
0
 public InterfaceImplIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtInterfaceImpl)
 {
 }
Exemplo n.º 20
0
 public AssemblyRefProcessorIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtAssemblyRefProcessor)
 {
 }
Exemplo n.º 21
0
        private static MetadataTables ReadMetadataTables(byte[] buffer, uint pos, uint size)
        {
            MetadataTables table = new MetadataTables(buffer, pos, size);

            return(table);
        }
Exemplo n.º 22
0
 public ClassLayoutIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtClassLayout)
 {
 }
Exemplo n.º 23
0
        public void Extend(string fullName, string methodName, uint insertSize)
        {
            string classNs   = string.Empty;
            string className = fullName;
            int    srcIx     = fullName.LastIndexOf('.');

            if (srcIx > 0)
            {
                classNs   = fullName.Substring(0, srcIx);
                className = fullName.Substring(srcIx + 1);
            }

            int  srcStart, srcEnd;
            bool srcValid = GetTypeMethods(classNs, className, out srcStart, out srcEnd);

            if (!srcValid)
            {
                s_ErrorTxts.Add(string.Format("Can't find src {0}->{1}", className, srcValid));
                return;
            }
            MethodDefIterator it = m_ClrFile.Metadata.Tables[(int)CorTokenType.mdtMethodDef] as MethodDefIterator;

            for (uint ix = (uint)srcStart; ix < (uint)srcEnd; ++ix)
            {
                it.MoveTo(ix - 1);
                string name = GetString(m_ClrFile.Buffer, m_StringStart, it.Name);
                if (name == methodName)
                {
                    uint offset   = m_ClrFile.GetFileOffset(it.RVA);
                    byte ilheader = m_ClrFile.Buffer[offset];
                    if ((ilheader & 0x03) == 0x02)
                    {
                        uint size = (uint)(ilheader >> 2);
                        if (size + insertSize < 64)
                        {
                            m_Methods[m_Pos] = (byte)(((size + insertSize) << 2) | 0x02);
                            Array.Copy(m_ClrFile.Buffer, offset + 1, m_Methods, m_Pos + 1 + insertSize, size);
                            it.RVA = m_Header.VirtualAddress + m_Pos;
                        }
                        else
                        {
                            MetadataTables.WriteUInt(m_Methods, m_Pos, 0x7fff3003);
                            MetadataTables.WriteUInt(m_Methods, m_Pos + 4, size + insertSize);
                            MetadataTables.WriteUInt(m_Methods, m_Pos + 8, 0);
                            Array.Copy(m_ClrFile.Buffer, offset + 1, m_Methods, m_Pos + 12 + insertSize, size);
                            it.RVA = m_Header.VirtualAddress + m_Pos;
                        }
                    }
                    else if ((ilheader & 0x03) == 0x03)
                    {
                        uint one   = MetadataTables.ReadUInt(m_ClrFile.Buffer, offset);
                        uint two   = MetadataTables.ReadUInt(m_ClrFile.Buffer, offset + 4);
                        uint three = MetadataTables.ReadUInt(m_ClrFile.Buffer, offset + 8);
                        MetadataTables.WriteUInt(m_Methods, m_Pos, one);
                        MetadataTables.WriteUInt(m_Methods, m_Pos + 4, two + insertSize);
                        MetadataTables.WriteUInt(m_Methods, m_Pos + 8, three);
                        Array.Copy(m_ClrFile.Buffer, offset + 12, m_Methods, m_Pos + 12 + insertSize, two);
                        it.RVA = m_Header.VirtualAddress + m_Pos;
                    }
                    m_Find = true;
                    break;
                }
            }
        }
Exemplo n.º 24
0
 public CustomAttributeIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtCustomAttribute)
 {
 }
Exemplo n.º 25
0
 public DeclSecurityIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtDeclSecurity)
 {
 }
Exemplo n.º 26
0
 public MethodSemanticsIterator(MetadataTables _tables, byte[] _data, uint _pos)
     : base(_tables, _data, _pos, CorTokenType.mdtMethodSemantics)
 {
 }