当前位置: 首页>>代码示例>>C#>>正文


C# IBinaryReader.ReadUInt16方法代码示例

本文整理汇总了C#中IBinaryReader.ReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# IBinaryReader.ReadUInt16方法的具体用法?C# IBinaryReader.ReadUInt16怎么用?C# IBinaryReader.ReadUInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBinaryReader的用法示例。


在下文中一共展示了IBinaryReader.ReadUInt16方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryCreateIcon

		static byte[] TryCreateIcon(IBinaryReader reader, ResourceDirectory iconDir) {
			try {
				reader.Position = 0;
				var outStream = new MemoryStream();
				var writer = new BinaryWriter(outStream);
				// Write GRPICONDIR
				writer.Write(reader.ReadUInt16());
				writer.Write(reader.ReadUInt16());
				ushort numImages;
				writer.Write(numImages = reader.ReadUInt16());

				var entries = new List<GrpIconDirEntry>();
				for (int i = 0; i < numImages; i++) {
					var e = new GrpIconDirEntry();
					entries.Add(e);
					e.bWidth = reader.ReadByte();
					e.bHeight = reader.ReadByte();
					e.bColorCount = reader.ReadByte();
					e.bReserved = reader.ReadByte();
					e.wPlanes = reader.ReadUInt16();
					e.wBitCount = reader.ReadUInt16();
					e.dwBytesInRes = reader.ReadUInt32();
					e.nID = reader.ReadUInt16();
				}

				uint dataOffset = 2 * 3 + (uint)entries.Count * 0x10;
				foreach (var e in entries) {
					writer.Write(e.bWidth);
					writer.Write(e.bHeight);
					writer.Write(e.bColorCount);
					writer.Write(e.bReserved);
					writer.Write(e.wPlanes);
					writer.Write(e.wBitCount);
					writer.Write(e.dwBytesInRes);
					writer.Write(dataOffset);
					dataOffset += e.dwBytesInRes;
				}

				foreach (var e in entries) {
					var d = iconDir.Directories.FirstOrDefault(a => a.Name == new ResourceName(e.nID));
					if (d == null || d.Data.Count == 0)
						return null;
					var r = d.Data[0].Data;
					Debug.Assert(r.Length == e.dwBytesInRes);
					if (r.Length < e.dwBytesInRes)
						return null;
					r.Position = 0;
					writer.Write(r.ReadBytes((int)e.dwBytesInRes), 0, (int)e.dwBytesInRes);
				}

				return outStream.ToArray();
			}
			catch (IOException) {
			}
			return null;
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:56,代码来源:ApplicationIcon.cs

示例2: ReadHeader

		static bool ReadHeader(IBinaryReader reader, out ushort flags, out uint codeSize) {
			byte b = reader.ReadByte();
			switch (b & 7) {
			case 2:
			case 6:
				flags = 2;
				codeSize = (uint)(b >> 2);
				return true;

			case 3:
				flags = (ushort)((reader.ReadByte() << 8) | b);
				uint headerSize = (byte)(flags >> 12);
				ushort maxStack = reader.ReadUInt16();
				codeSize = reader.ReadUInt32();
				uint localVarSigTok = reader.ReadUInt32();

				reader.Position += -12 + headerSize * 4;
				if (headerSize < 3)
					flags &= 0xFFF7;
				return true;

			default:
				flags = 0;
				codeSize = 0;
				return false;
			}
		}
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:27,代码来源:InstructionUtils.cs

示例3: Read

		/// <summary>
		/// Reads the column
		/// </summary>
		/// <param name="reader">A reader positioned on this column</param>
		/// <returns>The column value</returns>
		public uint Read(IBinaryReader reader) {
			switch (size) {
			case 1: return reader.ReadByte();
			case 2: return reader.ReadUInt16();
			case 4: return reader.ReadUInt32();
			default: throw new InvalidOperationException("Invalid column size");
			}
		}
开发者ID:xingkongtianyu,项目名称:Protect.NET,代码行数:13,代码来源:ColumnInfo.cs

示例4: ParseMethodBody2

		static MethodBodyHeader ParseMethodBody2(IBinaryReader reader, out byte[] code, out byte[] extraSections) {
			var mbHeader = new MethodBodyHeader();

			uint codeOffset;
			byte b = Peek(reader);
			if ((b & 3) == 2) {
				mbHeader.flags = 2;
				mbHeader.maxStack = 8;
				mbHeader.codeSize = (uint)(reader.ReadByte() >> 2);
				mbHeader.localVarSigTok = 0;
				codeOffset = 1;
			}
			else if ((b & 7) == 3) {
				mbHeader.flags = reader.ReadUInt16();
				codeOffset = (uint)(4 * (mbHeader.flags >> 12));
				if (codeOffset != 12)
					throw new InvalidMethodBody();
				mbHeader.maxStack = reader.ReadUInt16();
				mbHeader.codeSize = reader.ReadUInt32();
				if (mbHeader.codeSize > int.MaxValue)
					throw new InvalidMethodBody();
				mbHeader.localVarSigTok = reader.ReadUInt32();
				if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11)
					throw new InvalidMethodBody();
			}
			else
				throw new InvalidMethodBody();

			if (mbHeader.codeSize + codeOffset > reader.Length)
				throw new InvalidMethodBody();
			code = reader.ReadBytes((int)mbHeader.codeSize);

			if ((mbHeader.flags & 8) != 0)
				extraSections = ReadExtraSections2(reader);
			else
				extraSections = null;

			return mbHeader;
		}
开发者ID:GreenDamTan,项目名称:de4dot,代码行数:39,代码来源:MethodBodyParser.cs

示例5: ReadSmallExceptionHandlers

		void ReadSmallExceptionHandlers(IBinaryReader ehReader) {
			int num = GetNumberOfExceptionHandlers((uint)ehReader.ReadByte() / 12);
			ehReader.Position += 2;
			for (int i = 0; i < num; i++) {
				var eh = new ExceptionHandler((ExceptionHandlerType)ehReader.ReadUInt16());
				uint offs = ehReader.ReadUInt16();
				eh.TryStart = GetInstruction(offs);
				eh.TryEnd = GetInstruction(offs + ehReader.ReadByte());
				offs = ehReader.ReadUInt16();
				eh.HandlerStart = GetInstruction(offs);
				eh.HandlerEnd = GetInstruction(offs + ehReader.ReadByte());
				if (eh.HandlerType == ExceptionHandlerType.Catch)
					eh.CatchType = opResolver.ResolveToken(ehReader.ReadUInt32(), gpContext) as ITypeDefOrRef;
				else if (eh.HandlerType == ExceptionHandlerType.Filter)
					eh.FilterStart = GetInstruction(ehReader.ReadUInt32());
				else
					ehReader.ReadUInt32();
				Add(eh);
			}
		}
开发者ID:xingkongtianyu,项目名称:Protect.NET,代码行数:20,代码来源:MethodBodyReader.cs

示例6: CouldBeImage

        static bool CouldBeImage(IBinaryReader reader)
        {
            reader.Position = 0;
            if (reader.Length < 0x16)
                return false;

            uint d = reader.ReadUInt32();
            if (unchecked((ushort)d) == 0x4D42) {
                // Possible BMP image
                reader.Position -= 2;
                uint size = reader.ReadUInt32();
                if (size > reader.Length)
                    return false;
                reader.Position += 4;
                uint offs = reader.ReadUInt32();
                return offs < size;
            }

            // Check if GIF87a or GIF89a
            if (d == 0x38464947)
                return (d = reader.ReadUInt16()) == 0x6139 || d == 0x6137;

            // Check if PNG
            if (d == 0x474E5089)
                return reader.ReadUInt32() == 0x0A1A0A0D;

            // Check if ICO or CUR
            if (d == 0x00010000 || d == 0x00020000) {
                int num = reader.ReadUInt16();
                if (num <= 0)
                    return false;

                reader.Position += 8;
                uint size = reader.ReadUInt32();
                uint offs = reader.ReadUInt32();
                uint end = unchecked(offs + size);
                return offs <= end && end <= reader.Length;
            }

            return false;
        }
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:41,代码来源:ImageResourceNode.cs

示例7: ReadString

		/// <summary>
		/// Reads a string
		/// </summary>
		/// <param name="reader">Reader</param>
		/// <param name="offset">Offset of string</param>
		/// <returns>The string or <c>null</c> if we could not read it</returns>
		static string ReadString(IBinaryReader reader, uint offset) {
			reader.Position = offset;
			if (!reader.CanRead(2))
				return null;
			int size = reader.ReadUInt16();
			int sizeInBytes = size * 2;
			if (!reader.CanRead(sizeInBytes))
				return null;
			var stringData = reader.ReadBytes(sizeInBytes);
			try {
				return Encoding.Unicode.GetString(stringData);
			}
			catch {
				return null;
			}
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:22,代码来源:ResourceDirectory.cs

示例8: Initialize

		/// <summary>
		/// Reads the directory header and initializes <see cref="ResourceDirectory.directories"/> and
		/// <see cref="ResourceDirectory.data"/>.
		/// </summary>
		/// <param name="reader"></param>
		void Initialize(IBinaryReader reader) {
			if (depth > MAX_DIR_DEPTH || !reader.CanRead(16)) {
				InitializeDefault();
				return;
			}

			characteristics = reader.ReadUInt32();
			timeDateStamp = reader.ReadUInt32();
			majorVersion = reader.ReadUInt16();
			minorVersion = reader.ReadUInt16();
			ushort numNamed = reader.ReadUInt16();
			ushort numIds = reader.ReadUInt16();

			int total = numNamed + numIds;
			if (!reader.CanRead(total * 8)) {
				InitializeDefault();
				return;
			}

			dataInfos = new List<EntryInfo>();
			dirInfos = new List<EntryInfo>();
			long offset = reader.Position;
			for (int i = 0; i < total; i++, offset += 8) {
				reader.Position = offset;
				uint nameOrId = reader.ReadUInt32();
				uint dataOrDirectory = reader.ReadUInt32();
				ResourceName name;
				if ((nameOrId & 0x80000000) != 0)
					name = new ResourceName(ReadString(reader, nameOrId & 0x7FFFFFFF) ?? string.Empty);
				else
					name = new ResourceName((int)nameOrId);

				if ((dataOrDirectory & 0x80000000) == 0)
					dataInfos.Add(new EntryInfo(name, dataOrDirectory));
				else
					dirInfos.Add(new EntryInfo(name, dataOrDirectory & 0x7FFFFFFF));
			}

			directories = new LazyList<ResourceDirectory>(dirInfos.Count, null, (ctx, i) => ReadResourceDirectory((int)i));
			data = new LazyList<ResourceData>(dataInfos.Count, null, (ctx, i) => ReadResourceData((int)i));
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:46,代码来源:ResourceDirectory.cs


注:本文中的IBinaryReader.ReadUInt16方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。