string GetResourceName(int index, out int dataOffset) { long pos = nameSectionPosition + namePositions[index]; byte[] bytes; lock (reader) { reader.Seek(pos, SeekOrigin.Begin); // Can't use reader.ReadString, since it's using UTF-8! int byteLen = reader.Read7BitEncodedInt(); if (byteLen < 0) { throw new BadImageFormatException("Resource name has negative length"); } bytes = new byte[byteLen]; // We must read byteLen bytes, or we have a corrupted file. // Use a blocking read in case the stream doesn't give us back // everything immediately. int count = byteLen; while (count > 0) { int n = reader.Read(bytes, byteLen - count, count); if (n == 0) { throw new BadImageFormatException("End of stream within a resource name"); } count -= n; } dataOffset = reader.ReadInt32(); if (dataOffset < 0) { throw new BadImageFormatException("Negative data offset"); } } return(Encoding.Unicode.GetString(bytes)); }
public static QBitmap <T> Read(MyBinaryReader reader, Func <MyBinaryReader, T> read) { int width = reader.Read7BitEncodedInt(); int height = reader.Read7BitEncodedInt(); T[,] array = new T[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { array[x, y] = read(reader); } } return(new QBitmap <T>(array)); }