protected MetadataIterator(MetadataTables _tables, byte[] _data, uint _pos, CorTokenType _tokenType) { tables = _tables; data = _data; pos = _pos; tokenType = _tokenType; }
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; }
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); } } } }
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; }
public ExportedTypeIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtExportedType) { }
public EventIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtEvent) { }
public ModuleRefIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtModuleRef) { }
public ManifestResourceIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtManifestResource) { }
public ImplMapIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtImplMap) { }
public TypeSpecIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtTypeSpec) { }
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)); } }
public StandAloneSigIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtSignature) { }
public PropertyIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtProperty) { }
public ParamIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtParamDef) { }
public NestedClassIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtNestedClass) { }
public FileIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtFile) { }
public GenericParamConstraintIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtGenericParamConstraint) { }
public NullIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtMaxTokenType) { }
public InterfaceImplIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtInterfaceImpl) { }
public AssemblyRefProcessorIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtAssemblyRefProcessor) { }
private static MetadataTables ReadMetadataTables(byte[] buffer, uint pos, uint size) { MetadataTables table = new MetadataTables(buffer, pos, size); return(table); }
public ClassLayoutIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtClassLayout) { }
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; } } }
public CustomAttributeIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtCustomAttribute) { }
public DeclSecurityIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtDeclSecurity) { }
public MethodSemanticsIterator(MetadataTables _tables, byte[] _data, uint _pos) : base(_tables, _data, _pos, CorTokenType.mdtMethodSemantics) { }