Ejemplo n.º 1
0
		/// <inheritdoc/>
		public void SetOffset(FileOffset offset, RVA rva) {
			this.offset = offset;
			this.rva = rva;

			padding = rva.AlignUp(4) - rva + 2;
			length = padding + 6;
		}
Ejemplo n.º 2
0
 /// <inheritdoc/>
 public virtual void SetOffset(FileOffset offset, RVA rva)
 {
     setOffsetCalled = true;
     this.offset     = offset;
     this.rva        = rva;
     length          = 0;
     virtualSize     = 0;
     foreach (var elem in chunks)
     {
         uint paddingF = (uint)offset.AlignUp(elem.alignment) - (uint)offset;
         uint paddingV = (uint)rva.AlignUp(elem.alignment) - (uint)rva;
         offset += paddingF;
         rva    += paddingV;
         elem.chunk.SetOffset(offset, rva);
         if (elem.chunk.GetVirtualSize() == 0)
         {
             offset -= paddingF;
             rva    -= paddingV;
         }
         else
         {
             uint chunkLenF = elem.chunk.GetFileLength();
             uint chunkLenV = elem.chunk.GetVirtualSize();
             offset      += chunkLenF;
             rva         += chunkLenV;
             length      += paddingF + chunkLenF;
             virtualSize += paddingV + chunkLenV;
         }
     }
 }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public void SetOffset(FileOffset offset, RVA rva)
        {
            this.offset = offset;
            this.rva    = rva;

            padding = rva.AlignUp(4) - rva + 2;
            length  = padding + 6;
        }
Ejemplo n.º 4
0
 /// <inheritdoc/>
 public void WriteTo(BinaryWriter writer)
 {
     writer.Write(code);
     if (HasExtraSections)
     {
         RVA rva2 = rva + (uint)code.Length;
         writer.WriteZeros((int)rva2.AlignUp(EXTRA_SECTIONS_ALIGNMENT) - (int)rva2);
         writer.Write(extraSections);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Calculates <see cref="RVA"/> and <see cref="FileOffset"/> of all <see cref="IChunk"/>s
 /// </summary>
 /// <param name="chunks">All chunks</param>
 /// <param name="offset">Starting file offset</param>
 /// <param name="rva">Starting RVA</param>
 /// <param name="fileAlignment">File alignment</param>
 /// <param name="sectionAlignment">Section alignment</param>
 protected void CalculateRvasAndFileOffsets(List <IChunk> chunks, FileOffset offset, RVA rva, uint fileAlignment, uint sectionAlignment)
 {
     foreach (var chunk in chunks)
     {
         chunk.SetOffset(offset, rva);
         offset += chunk.GetFileLength();
         rva    += chunk.GetVirtualSize();
         offset  = offset.AlignUp(fileAlignment);
         rva     = rva.AlignUp(sectionAlignment);
     }
 }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        public void WriteTo(BinaryWriter writer)
        {
            RVA rva2 = rva;

            foreach (var resourceData in resources)
            {
                writer.Write(resourceData.GetFileLength());
                resourceData.VerifyWriteTo(writer);
                rva2 += 4 + resourceData.GetFileLength();
                int padding = (int)rva2.AlignUp(alignment) - (int)rva2;
                writer.WriteZeros(padding);
                rva2 += (uint)padding;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Calculates <see cref="RVA"/> and <see cref="FileOffset"/> of all <see cref="IChunk"/>s
 /// </summary>
 /// <param name="chunks">All chunks</param>
 /// <param name="offset">Starting file offset</param>
 /// <param name="rva">Starting RVA</param>
 /// <param name="fileAlignment">File alignment</param>
 /// <param name="sectionAlignment">Section alignment</param>
 protected void CalculateRvasAndFileOffsets(List <IChunk> chunks, FileOffset offset, RVA rva, uint fileAlignment, uint sectionAlignment)
 {
     foreach (var chunk in chunks)
     {
         chunk.SetOffset(offset, rva);
         // If it has zero size, it's not present in the file (eg. a section that wasn't needed)
         if (chunk.GetVirtualSize() != 0)
         {
             offset += chunk.GetFileLength();
             rva    += chunk.GetVirtualSize();
             offset  = offset.AlignUp(fileAlignment);
             rva     = rva.AlignUp(sectionAlignment);
         }
     }
 }
Ejemplo n.º 8
0
 /// <inheritdoc/>
 public void SetOffset(FileOffset offset, RVA rva)
 {
     this.offset = offset;
     this.rva    = rva;
     if (HasExtraSections)
     {
         RVA rva2 = rva + (uint)code.Length;
         rva2   = rva2.AlignUp(EXTRA_SECTIONS_ALIGNMENT);
         rva2  += (uint)extraSections.Length;
         length = (uint)rva2 - (uint)rva;
     }
     else
     {
         length = (uint)code.Length;
     }
 }
Ejemplo n.º 9
0
		/// <inheritdoc/>
		public void SetOffset(FileOffset offset, RVA rva) {
			this.offset = offset;
			this.rva = rva;

			length = 0x28;
			importLookupTableRVA = rva + length;
			length += 8;

			stringsPadding = (int)(rva.AlignUp(STRINGS_ALIGNMENT) - rva);
			length += (uint)stringsPadding;
			corXxxMainRVA = rva + length;
			length += 0xE;
			mscoreeDllRVA = rva + length;
			length += 0xC;
			length++;
		}
Ejemplo n.º 10
0
        /// <inheritdoc/>
        public void SetOffset(FileOffset offset, RVA rva)
        {
            this.offset = offset;
            this.rva    = rva;

            length = 0x28;
            importLookupTableRVA = rva + length;
            length += 8;

            stringsPadding = (int)(rva.AlignUp(STRINGS_ALIGNMENT) - rva);
            length        += (uint)stringsPadding;
            corXxxMainRVA  = rva + length;
            length        += 0xE;
            mscoreeDllRVA  = rva + length;
            length        += 0xC;
            length++;
        }
Ejemplo n.º 11
0
 /// <inheritdoc />
 public virtual void SetOffset(FileOffset offset, RVA rva)
 {
     setOffsetCalled = true;
     FileOffset      = offset;
     RVA             = rva;
     length          = 0;
     virtualSize     = 0;
     foreach (var elem in chunks)
     {
         var paddingF = (uint)offset.AlignUp(elem.alignment) - (uint)offset;
         var paddingV = (uint)rva.AlignUp(elem.alignment) - (uint)rva;
         offset += paddingF;
         rva    += paddingV;
         elem.chunk.SetOffset(offset, rva);
         var chunkLenF = elem.chunk.GetFileLength();
         var chunkLenV = elem.chunk.GetVirtualSize();
         offset      += chunkLenF;
         rva         += chunkLenV;
         length      += paddingF + chunkLenF;
         virtualSize += paddingV + chunkLenV;
     }
 }
		/// <summary>
		/// Calculates <see cref="RVA"/> and <see cref="FileOffset"/> of all <see cref="IChunk"/>s
		/// </summary>
		/// <param name="chunks">All chunks</param>
		/// <param name="offset">Starting file offset</param>
		/// <param name="rva">Starting RVA</param>
		/// <param name="fileAlignment">File alignment</param>
		/// <param name="sectionAlignment">Section alignment</param>
		protected void CalculateRvasAndFileOffsets(List<IChunk> chunks, FileOffset offset, RVA rva, uint fileAlignment, uint sectionAlignment) {
			foreach (var chunk in chunks) {
				chunk.SetOffset(offset, rva);
				offset += chunk.GetFileLength();
				rva += chunk.GetVirtualSize();
				offset = offset.AlignUp(fileAlignment);
				rva = rva.AlignUp(sectionAlignment);
			}
		}
Ejemplo n.º 13
0
 static void Align(ref FileOffset offset, ref RVA rva)
 {
     offset = offset.AlignUp(HH_ALIGNMENT);
     rva    = rva.AlignUp(HH_ALIGNMENT);
 }
Ejemplo n.º 14
0
		static void Align(ref FileOffset offset, ref RVA rva) {
			offset = offset.AlignUp(HH_ALIGNMENT);
			rva = rva.AlignUp(HH_ALIGNMENT);
		}