1
0
mirror of https://github.com/mastercodeon314/KsDumper-11.git synced 2024-11-28 08:20:53 +01:00
KsDumper-11/KsDumper11/PE/PESection.cs
2023-01-21 19:32:57 -06:00

73 lines
2.4 KiB
C#

using System.IO;
using static KsDumper11.PE.NativePEStructs;
namespace KsDumper11.PE
{
public class PESection
{
public PESectionHeader Header { get; set; }
public byte[] Content { get; set; }
public int InitialSize { get; set; }
public int DataSize { get; set; }
public class PESectionHeader
{
public string Name { get; set; }
public uint VirtualSize { get; set; }
public uint VirtualAddress { get; set; }
public uint SizeOfRawData { get; set; }
public uint PointerToRawData { get; set; }
public uint PointerToRelocations { get; set; }
public uint PointerToLinenumbers { get; set; }
public ushort NumberOfRelocations { get; set; }
public ushort NumberOfLinenumbers { get; set; }
public DataSectionFlags Characteristics { get; set; }
public void AppendToStream(BinaryWriter writer)
{
writer.Write(Name.ToCharArray());
writer.Write(VirtualSize);
writer.Write(VirtualAddress);
writer.Write(SizeOfRawData);
writer.Write(PointerToRawData);
writer.Write(PointerToRelocations);
writer.Write(PointerToLinenumbers);
writer.Write(NumberOfRelocations);
writer.Write(NumberOfLinenumbers);
writer.Write((uint)Characteristics);
}
public static PESectionHeader FromNativeStruct(IMAGE_SECTION_HEADER nativeStruct)
{
return new PESectionHeader
{
Name = nativeStruct.SectionName,
VirtualSize = nativeStruct.VirtualSize,
VirtualAddress = nativeStruct.VirtualAddress,
SizeOfRawData = nativeStruct.SizeOfRawData,
PointerToRawData = nativeStruct.PointerToRawData,
PointerToRelocations = nativeStruct.PointerToRelocations,
PointerToLinenumbers = nativeStruct.PointerToLinenumbers,
NumberOfRelocations = nativeStruct.NumberOfRelocations,
NumberOfLinenumbers = nativeStruct.NumberOfLinenumbers,
Characteristics = nativeStruct.Characteristics
};
}
}
}
}