Example #1
0
        internal void resolveReferences(MetaDataLoader loader,
                                        PELoader peLoader,
                                        Stream fileStream)
        {
            this.field.resolveReferences(this);
            int dataOffset = peLoader.VaToOffsetSafe(this.rva);

            if (dataOffset != -1)
            {
                fileStream.Seek(dataOffset, SeekOrigin.Begin);
                BinaryReader   reader         = new BinaryReader(fileStream);
                SignatureField fieldSignature = (SignatureField)
                                                this.field.Signature;
                Signature.Type fieldType = fieldSignature.FieldType;
                int            dataSize  = this.getFieldSize(fieldType);
                byte[]         data      = new byte[dataSize];
                int            count     = reader.Read(data, 0, dataSize);
                if (loader.HasVtableFixup() &&
                    loader.RVAHasRelocation(dataOffset) &&
                    dataSize == 4)
                {
                    // if this corresponds to a vtable label, we need to fix it
                    int location = data[0] | (data[1] << 8) |
                                   (data[2] << 16) | (data[3] << 24);
                    int imageBase = peLoader.getImageBase();
                    location -= imageBase; // use RVA
                    fileStream.Seek(location, SeekOrigin.Begin);
                    BinaryReader binaryReader = new BinaryReader(fileStream);
                    short        prefix       = binaryReader.ReadInt16();
                    if (prefix == 0x25FF) // this starts a vtable lable
                    {
                        count = binaryReader.Read(data, 0, 4);
                    }
                }
                this.dataBytes = data;

                if (count != dataSize)
                {
                    throw new MetaDataLoader.IllegalMetaDataFormatException("Only got " + count + " out of " + dataSize + " data bytes for FieldRVA " + this.rva);
                }
            }
            else
            {
                Console.WriteLine("Found no data for " + this.field);
            }
        }