コード例 #1
0
        private unsafe bool CompareStringEqualsName(string name)
        {
            int length = this._store.Read7BitEncodedInt();

            if (length < 0)
            {
                throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_NegativeStringLength"));
            }
            if (this._ums != null)
            {
                byte *positionPointer = this._ums.PositionPointer;
                this._ums.Seek((long)length, SeekOrigin.Current);
                if (this._ums.Position > this._ums.Length)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourcesNameTooLong"));
                }
                int    byteLen = length;
                string b       = name;
                return(FastResourceComparer.CompareOrdinal(positionPointer, byteLen, b) == 0);
            }
            byte[] numArray = new byte[length];
            int    count    = length;

            while (count > 0)
            {
                int num = this._store.Read(numArray, length - count, count);
                if (num == 0)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourceNameCorrupted"));
                }
                count -= num;
            }
            return(FastResourceComparer.CompareOrdinal(numArray, length / 2, name) == 0);
        }
コード例 #2
0
        private unsafe bool CompareStringEqualsName(string name)
        {
            int num3;
            int byteLen = this._store.Read7BitEncodedInt();

            if (byteLen < 0)
            {
                throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_NegativeStringLength"));
            }
            if (this._ums != null)
            {
                byte *positionPointer = this._ums.PositionPointer;
                this._ums.Seek((long)byteLen, SeekOrigin.Current);
                if (this._ums.Position > this._ums.Length)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourcesNameTooLong"));
                }
                return(FastResourceComparer.CompareOrdinal(positionPointer, byteLen, name) == 0);
            }
            byte[] buffer = new byte[byteLen];
            for (int i = byteLen; i > 0; i -= num3)
            {
                num3 = this._store.Read(buffer, byteLen - i, i);
                if (num3 == 0)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourceNameCorrupted"));
                }
            }
            return(FastResourceComparer.CompareOrdinal(buffer, byteLen / 2, name) == 0);
        }
コード例 #3
0
        // This compares the String in the .resources file at the current position
        // with the string you pass in.
        // Whoever calls this method should make sure that they take a lock
        // so no one else can cause us to seek in the stream.
        private unsafe bool CompareStringEqualsName(String name)
        {
            BCLDebug.Assert(_store != null, "ResourceReader is closed!");
            //int byteLen = Read7BitEncodedInt(_store);
            int byteLen = _store.Read7BitEncodedInt();

            if (_ums != null)
            {
                //BCLDebug.Log("RESMGRFILEFORMAT", "CompareStringEqualsName using UnmanagedMemoryStream code path");
                byte *bytes = _ums.PositionPointer;
                // Skip over the data in the Stream, positioning ourselves right after it.
                _ums.Seek(byteLen, SeekOrigin.Current);

                if (_ums.Position > _ums.Length)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourcesNameTooLong"));
                }

                // On 64-bit machines, these char*'s may be misaligned.  Use a
                // byte-by-byte comparison instead.
                //return FastResourceComparer.CompareOrdinal((char*)bytes, byteLen/2, name) == 0;
                return(FastResourceComparer.CompareOrdinal(bytes, byteLen, name) == 0);
            }
            else
            {
                // This code needs to be fast
                byte[] bytes          = new byte[byteLen];
                int    numBytesToRead = byteLen;
                while (numBytesToRead > 0)
                {
                    int n = _store.Read(bytes, byteLen - numBytesToRead, numBytesToRead);
                    if (n == 0)
                    {
                        throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ResourceNameCorrupted"));
                    }
                    numBytesToRead -= n;
                }
                return(FastResourceComparer.CompareOrdinal(bytes, byteLen / 2, name) == 0);
            }
        }
コード例 #4
0
        // This compares the String in the .resources file at the current position
        // with the string you pass in.
        // Whoever calls this method should make sure that they take a lock
        // so no one else can cause us to seek in the stream.
        private unsafe bool CompareStringEqualsName(String name)
        {
            BCLDebug.Assert(_store != null, "ResourceReader is closed!");
            int byteLen = Read7BitEncodedInt(_store);

            if (_ums != null)
            {
                //BCLDebug.Log("RESMGRFILEFORMAT", "CompareStringEqualsName using UnmanagedMemoryStream code path");
                byte *bytes = _ums.GetBytePtr();
                // Skip over the data in the Stream, positioning ourselves right after it.
                _ums.Seek(byteLen, SeekOrigin.Current);

                if (_ums.Position > _ums.Length)
                {
                    throw new BadImageFormatException("Found a corrupted .resources file!  Resource name extends past the end of the file!");
                }

                // On 64-bit machines, these char*'s may be misaligned.  Use a
                // byte-by-byte comparison instead.
                //return FastResourceComparer.CompareOrdinal((char*)bytes, byteLen/2, name) == 0;
                return(FastResourceComparer.CompareOrdinal(bytes, byteLen, name) == 0);
            }
            else
            {
                // @TODO Perf: Make this fast
                byte[] bytes          = new byte[byteLen];
                int    numBytesToRead = byteLen;
                while (numBytesToRead > 0)
                {
                    int n = _store.Read(bytes, byteLen - numBytesToRead, numBytesToRead);
                    if (n == 0)
                    {
                        throw new EndOfStreamException("oops.  Hit EOF while trying to read a resource name from the name section.");
                    }
                    numBytesToRead -= n;
                }
                return(FastResourceComparer.CompareOrdinal(bytes, byteLen / 2, name) == 0);
            }
        }
コード例 #5
0
 public static int CompareOrdinal(byte[] bytes, int aCharLength, string b)
 {
     return(-FastResourceComparer.CompareOrdinal(b, bytes, aCharLength));
 }