Пример #1
0
        /// <inheritdoc/>
        public void Clone(out IStream ppstm)
        {
            var newStream = stream.Clone();

            newStream.Position = stream.Position;
            ppstm = new ImageStreamIStream(newStream, name);
        }
Пример #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="rvaConverter"><see cref="RVA"/>/<see cref="FileOffset"/> converter</param>
 /// <param name="dataReader">Data reader (it's used after converting an <see cref="RVA"/>
 /// to a <see cref="FileOffset"/>). This instance owns the reader.</param>
 /// <param name="rsrcReader">Reader for the whole Win32 resources section (usually
 /// the .rsrc section). It's used to read <see cref="ResourceDirectory"/>'s and
 /// <see cref="ResourceData"/>'s but not the actual data blob. This instance owns the
 /// reader.</param>
 public Win32ResourcesPE(IRvaFileOffsetConverter rvaConverter, IImageStream dataReader, IBinaryReader rsrcReader)
 {
     if (dataReader == rsrcReader)
     {
         rsrcReader = dataReader.Clone();                        // Must not be the same readers
     }
     this.rvaConverter = rvaConverter;
     this.dataReader   = dataReader;
     this.rsrcReader   = rsrcReader;
     Initialize();
 }
Пример #3
0
        /// <summary>
        ///     Creates a new resource stream that can access the same data as the original
        ///     Stream. Note that the data is shared between these streams.
        /// </summary>
        /// <returns>A new <see cref="IImageStream" /> instance</returns>
        public IImageStream GetClonedResourceStream()
        {
#if THREAD_SAFE
            theLock.EnterReadLock(); try {
#endif
            return(dataStream.Clone());

#if THREAD_SAFE
        }
        finally { theLock.ExitReadLock(); }
#endif
        }
Пример #4
0
        private ThreadSafe.IList <HotHeapStream> CreateHotHeapStreams2()
        {
            var list = ThreadSafeListCreator.Create <HotHeapStream>();

            try
            {
                var dirBaseOffs = GetHotHeapDirectoryBaseOffset();
                for (var offs = dirBaseOffs; offs + 8 <= endOffset - 8; offs += 8)
                {
                    fullStream.Position = offs;
                    HeapType heapType;
                    long     hotHeapOffset;
                    ReadHotHeapDirectory(fullStream, dirBaseOffs, out heapType, out hotHeapOffset);

                    IImageStream  dataStream    = null;
                    HotHeapStream hotHeapStream = null;
                    try
                    {
                        dataStream             = fullStream.Clone();
                        list.Add(hotHeapStream = CreateHotHeapStream(heapType, dataStream, hotHeapOffset));
                        dataStream             = null;
                        hotHeapStream          = null;
                    }
                    catch
                    {
                        if (hotHeapStream != null)
                        {
                            hotHeapStream.Dispose();
                        }
                        if (dataStream != null)
                        {
                            dataStream.Dispose();
                        }
                        throw;
                    }
                }
            }
            catch
            {
                foreach (var h in list)
                {
                    h.Dispose();
                }
                throw;
            }
            return(list);
        }
Пример #5
0
 ImageDebugDirectory[] ReadImageDebugDirectories()
 {
     try {
         if (6 >= ImageNTHeaders.OptionalHeader.DataDirectories.Length)
         {
             return(emptyImageDebugDirectories);
         }
         var dataDir = ImageNTHeaders.OptionalHeader.DataDirectories[6];
         if (dataDir.VirtualAddress == 0)
         {
             return(emptyImageDebugDirectories);
         }
         using (var reader = imageStream.Clone()) {
             if (dataDir.Size > reader.Length)
             {
                 return(emptyImageDebugDirectories);
             }
             int count = (int)(dataDir.Size / 0x1C);
             if (count == 0)
             {
                 return(emptyImageDebugDirectories);
             }
             reader.Position = (long)ToFileOffset(dataDir.VirtualAddress);
             if (reader.Position + dataDir.Size > reader.Length)
             {
                 return(emptyImageDebugDirectories);
             }
             var res = new ImageDebugDirectory[count];
             for (int i = 0; i < res.Length; i++)
             {
                 res[i] = new ImageDebugDirectory(reader, true);
             }
             return(res);
         }
     }
     catch (IOException) {
     }
     return(emptyImageDebugDirectories);
 }
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="rvaConverter"><see cref="RVA"/>/<see cref="FileOffset"/> converter</param>
		/// <param name="dataReader">Data reader (it's used after converting an <see cref="RVA"/>
		/// to a <see cref="FileOffset"/>). This instance owns the reader.</param>
		/// <param name="rsrcReader">Reader for the whole Win32 resources section (usually
		/// the .rsrc section). It's used to read <see cref="ResourceDirectory"/>'s and
		/// <see cref="ResourceData"/>'s but not the actual data blob. This instance owns the
		/// reader.</param>
		public Win32ResourcesPE(IRvaFileOffsetConverter rvaConverter, IImageStream dataReader, IBinaryReader rsrcReader) {
			if (dataReader == rsrcReader)
				rsrcReader = dataReader.Clone();	// Must not be the same readers
			this.rvaConverter = rvaConverter;
			this.dataReader = dataReader;
			this.rsrcReader = rsrcReader;
			Initialize();
		}
Пример #7
0
 internal IImageStream CloneImageStream()
 {
     return(imageStream.Clone());
 }
Пример #8
0
 /// <summary>
 /// Returns a cloned <see cref="IImageStream"/> of the internal .NET blob stream.
 /// </summary>
 /// <returns>A new <see cref="IImageStream"/> instance</returns>
 public IImageStream GetClonedImageStream()
 {
     return(imageStream.Clone());
 }