Beispiel #1
0
        TypeSig ReadTypeDefOrRefSig()
        {
            uint codedToken;

            if (!reader.ReadCompressedUInt32(out codedToken))
            {
                return(null);
            }
            ISignatureReaderHelper helper = module;
            var tdr = helper.ResolveTypeDefOrRef(codedToken, gpContext);

            return(tdr.ToTypeSig());
        }
		void Populate(IImageStream reader) {
			var chars = new char[0x200];
			reader.Position = 1;
			while (reader.Position < reader.Length) {
				uint offset = (uint)reader.Position;
				uint len;
				if (!reader.ReadCompressedUInt32(out len)) {
					if (offset == reader.Position)
						reader.Position++;
					continue;
				}
				if (len == 0 || reader.Position + len > reader.Length)
					continue;

				int stringLen = (int)len / 2;
				if (stringLen > chars.Length)
					Array.Resize(ref chars, stringLen);
				for (int i = 0; i < stringLen; i++)
					chars[i] = (char)reader.ReadUInt16();
				if ((len & 1) != 0)
					reader.ReadByte();
				var s = new string(chars, 0, stringLen);

				if (!cachedDict.ContainsKey(s))
					cachedDict[s] = offset;
			}
		}
Beispiel #3
0
        void Populate(IImageStream reader)
        {
            reader.Position = 1;
            while (reader.Position < reader.Length)
            {
                uint offset = (uint)reader.Position;
                uint len;
                if (!reader.ReadCompressedUInt32(out len))
                {
                    if (offset == reader.Position)
                    {
                        reader.Position++;
                    }
                    continue;
                }
                if (len == 0 || reader.Position + len > reader.Length)
                {
                    continue;
                }

                var data = reader.ReadBytes((int)len);
                if (!cachedDict.ContainsKey(data))
                {
                    cachedDict[data] = offset;
                }
            }
        }
Beispiel #4
0
		int GetReader_NoLock(uint offset, out IImageStream reader) {
			reader = null;
			if (!IsValidOffset(offset))
				return -1;
			reader = GetReader_NoLock(offset);
			uint length;
			if (!reader.ReadCompressedUInt32(out length))
				return -1;
			if (reader.Position + length < length || reader.Position + length > reader.Length)
				return -1;

			return (int)length;	// length <= 0x1FFFFFFF so this cast does not make it negative
		}
		void Populate(IImageStream reader) {
			reader.Position = 1;
			while (reader.Position < reader.Length) {
				uint offset = (uint)reader.Position;
				uint len;
				if (!reader.ReadCompressedUInt32(out len)) {
					if (offset == reader.Position)
						reader.Position++;
					continue;
				}
				if (len == 0 || reader.Position + len > reader.Length)
					continue;

				var data = reader.ReadBytes((int)len);
				if (!cachedDict.ContainsKey(data))
					cachedDict[data] = offset;
			}
		}
Beispiel #6
0
        void Populate(IImageStream reader)
        {
            var chars = new char[0x200];

            reader.Position = 1;
            while (reader.Position < reader.Length)
            {
                uint offset = (uint)reader.Position;
                uint len;
                if (!reader.ReadCompressedUInt32(out len))
                {
                    if (offset == reader.Position)
                    {
                        reader.Position++;
                    }
                    continue;
                }
                if (len == 0 || reader.Position + len > reader.Length)
                {
                    continue;
                }

                int stringLen = (int)len / 2;
                if (stringLen > chars.Length)
                {
                    Array.Resize(ref chars, stringLen);
                }
                for (int i = 0; i < stringLen; i++)
                {
                    chars[i] = (char)reader.ReadUInt16();
                }
                if ((len & 1) != 0)
                {
                    reader.ReadByte();
                }
                var s = new string(chars, 0, stringLen);

                if (!cachedDict.ContainsKey(s))
                {
                    cachedDict[s] = offset;
                }
            }
        }
Beispiel #7
0
        UTF8String ReadUTF8String()
        {
            if (reader.ReadByte() == 0xFF)
            {
                return(null);
            }
            reader.Position--;
            uint len;

            if (!reader.ReadCompressedUInt32(out len))
            {
                throw new CABlobParserException("Could not read compressed UInt32");
            }
            if (len == 0)
            {
                return(UTF8String.Empty);
            }
            return(new UTF8String(reader.ReadBytes((int)len)));
        }
Beispiel #8
0
        private int GetReader_NoLock(uint offset, out IImageStream reader)
        {
            reader = null;
            if (!IsValidOffset(offset))
            {
                return(-1);
            }
            reader = GetReader_NoLock(offset);
            uint length;

            if (!reader.ReadCompressedUInt32(out length))
            {
                return(-1);
            }
            if (reader.Position + length < length || reader.Position + length > reader.Length)
            {
                return(-1);
            }

            return((int)length); // length <= 0x1FFFFFFF so this cast does not make it negative
        }
Beispiel #9
0
        T ReadSig <T>(T methodSig) where T : MethodBaseSig
        {
            if (methodSig.Generic)
            {
                uint count;
                if (!reader.ReadCompressedUInt32(out count))
                {
                    return(null);
                }
                methodSig.GenParamCount = count;
            }

            uint numParams;

            if (!reader.ReadCompressedUInt32(out numParams))
            {
                return(null);
            }

            methodSig.RetType = ReadType();

            var parameters = methodSig.Params;

            for (uint i = 0; i < numParams; i++)
            {
                var type = ReadType();
                if (type is SentinelSig)
                {
                    if (methodSig.ParamsAfterSentinel == null)
                    {
                        methodSig.ParamsAfterSentinel = parameters = ThreadSafeListCreator.Create <TypeSig>((int)(numParams - i));
                    }
                    i--;
                }
                else
                {
                    parameters.Add(type);
                }
            }

            return(methodSig);
        }