Class SectionHeader
- All Implemented Interfaces:
ByteArrayConverter, StructConverter
A class to the represent the IMAGE_SECTION_HEADER struct as defined in winnt.h
typedef struct _IMAGE_SECTION_HEADER {
BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
union {
DWORD PhysicalAddress;
DWORD VirtualSize; // MANDATORY
} Misc;
DWORD VirtualAddress; // MANDATORY
DWORD SizeOfRawData; // MANDATORY
DWORD PointerToRawData; // MANDATORY
DWORD PointerToRelocations;
DWORD PointerToLinenumbers;
WORD NumberOfRelocations;
WORD NumberOfLinenumbers;
DWORD Characteristics; // MANDATORY
} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
#define IMAGE_SIZEOF_SECTION_HEADER 40
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAlign on 1024-byte boundarystatic final intAlign on 128-byte boundarystatic final intAlign on 16-byte boundarystatic final intAlign on 1-byte boundarystatic final intAlign on 2048-byte boundarystatic final intAlign on 256-byte boundarystatic final intAlign on 2-byte boundarystatic final intAlign on 32-byte boundarystatic final intAlign on 4096-byte boundarystatic final intAlign on 4-byte boundarystatic final intAlign on 512-byte boundarystatic final intAlign on 64-byte boundarystatic final intAlign on 8192-byte boundarystatic final intAlign on 8-byte boundarystatic final intMask for alignment flagsstatic final intSection contains codestatic final intSection contains initialized datastatic final intSection contains uninitialized datastatic final intSection content can be accessed relative to GPstatic final intSection contents is communal data (comdat).static final intSection contains information for use by the linker (only exists in OBJs)static final intSection contains extended relocationsstatic final intReserved for future usestatic final intSection contents will not become part of the image (this only appears in OBJ files)static final intReserved for future usestatic final intThe section can be discarded from the final executable.static final intSection is executablestatic final intReserved for future usestatic final intSection is not cachablestatic final intThe section is not pageable, so it should always be physically present in memory.static final intReserved for future usestatic final intReserved for future usestatic final intSection is readablestatic final intSection is shareable.static final intSection is writeablestatic final intReset speculative exceptions handling bits in the TLB entries for this sectionstatic final intReserved for future usestatic final intReserved for future usestatic final intReserved for future usestatic final intReserved for future usestatic final intReserved for future usestatic final intReserved for future usestatic final intstatic final intThe size of the section headerstatic final intThe size of the section header short namestatic final StringThe name to use when converting into a structure data type -
Constructor Summary
ConstructorsConstructorDescriptionSectionHeader(BinaryReader reader, long index, long stringTableOffset, int sectionNumber) Creates a newSectionHeaderfrom the specified stream starting atindex -
Method Summary
Modifier and TypeMethodDescriptionintgetAlignedPointerToRawData(OptionalHeader optionalHeader, MessageLog log) Returns the aligned offset of the section in the file.intgetAlignedSizeOfRawData(OptionalHeader optionalHeader, MessageLog log) Returns the aligned size of the section in the file.intgetAlignedVirtualAddress(OptionalHeader optionalHeader) Returns the aligned RVA where the section begins in memory.intgetAlignedVirtualSize(OptionalHeader optionalHeader, MessageLog log) Returns the actual, used size of the section.intReturns the flags OR'ed together, indicating the attributes of this section.Returns aByteProviderto underlying bytes of this section.Returns anInputStreamto underlying bytes of this section.getName()Returns the ASCII name of the section.shortReturns the number of line numbers pointed to by thePointerToLinenumbersfield.shortReturns the number of relocations pointed to by thePointerToRelocationsfield.intReturns the original, unaligned physical address of this section.intReturns the file offset for COFF-style line numbers for this section.intReturns the original, unaligned offset of the section in the file.intReturns the file offset of relocations for this section.Returns a readable ascii version of the name (all non-readable characters are replaced with underscores.intReturns the original, unaligned size of the section in the file.intReturns the original, unaligned RVA where the section begins in memory.intReturns the original, unaligned size of the section in memory.booleanReturns whether or not this section has execute permissions.booleanisRead()Returns whether or not this section has read permissions.booleanisWrite()Returns whether or not this section has write permissions.byte[]toBytes(DataConverter dc) Returns a byte array representing this implementor of this interface.Returns a structure datatype representing the contents of the implementor of this interface.toString()
-
Field Details
-
NAME
The name to use when converting into a structure data type- See Also:
-
IMAGE_SIZEOF_SHORT_NAME
public static final int IMAGE_SIZEOF_SHORT_NAMEThe size of the section header short name- See Also:
-
IMAGE_SIZEOF_SECTION_HEADER
public static final int IMAGE_SIZEOF_SECTION_HEADERThe size of the section header- See Also:
-
IMAGE_SCN_RESERVED1
public static final int IMAGE_SCN_RESERVED1Reserved for future use- See Also:
-
IMAGE_SCN_RESERVED2
public static final int IMAGE_SCN_RESERVED2Reserved for future use- See Also:
-
IMAGE_SCN_RESERVED3
public static final int IMAGE_SCN_RESERVED3Reserved for future use- See Also:
-
IMAGE_SCN_RESERVED4
public static final int IMAGE_SCN_RESERVED4Reserved for future use- See Also:
-
IMAGE_SCN_TYPE_NO_PAD
public static final int IMAGE_SCN_TYPE_NO_PAD- See Also:
-
IMAGE_SCN_RESERVED5
public static final int IMAGE_SCN_RESERVED5Reserved for future use- See Also:
-
IMAGE_SCN_CNT_CODE
public static final int IMAGE_SCN_CNT_CODESection contains code- See Also:
-
IMAGE_SCN_CNT_INITIALIZED_DATA
public static final int IMAGE_SCN_CNT_INITIALIZED_DATASection contains initialized data- See Also:
-
IMAGE_SCN_CNT_UNINITIALIZED_DATA
public static final int IMAGE_SCN_CNT_UNINITIALIZED_DATASection contains uninitialized data- See Also:
-
IMAGE_SCN_LNK_OTHER
public static final int IMAGE_SCN_LNK_OTHERReserved for future use- See Also:
-
IMAGE_SCN_LNK_INFO
public static final int IMAGE_SCN_LNK_INFOSection contains information for use by the linker (only exists in OBJs)- See Also:
-
IMAGE_SCN_RESERVED6
public static final int IMAGE_SCN_RESERVED6Reserved for future use- See Also:
-
IMAGE_SCN_LNK_REMOVE
public static final int IMAGE_SCN_LNK_REMOVESection contents will not become part of the image (this only appears in OBJ files)- See Also:
-
IMAGE_SCN_LNK_COMDAT
public static final int IMAGE_SCN_LNK_COMDATSection contents is communal data (comdat). Communal data is data (or code) that can be defined in multiple OBJs. The linker will select one copy to include in the executable. Comdats are vital for support of C++ template functions and function-level linking. Comdat sections only appear in OBJ files.- See Also:
-
IMAGE_SCN_NO_DEFER_SPEC_EXC
public static final int IMAGE_SCN_NO_DEFER_SPEC_EXCReset speculative exceptions handling bits in the TLB entries for this section- See Also:
-
IMAGE_SCN_GPREL
public static final int IMAGE_SCN_GPRELSection content can be accessed relative to GP- See Also:
-
IMAGE_SCN_MEM_PURGEABLE
public static final int IMAGE_SCN_MEM_PURGEABLEReserved for future use- See Also:
-
IMAGE_SCN_MEM_16BIT
public static final int IMAGE_SCN_MEM_16BITReserved for future use- See Also:
-
IMAGE_SCN_MEM_LOCKED
public static final int IMAGE_SCN_MEM_LOCKEDReserved for future use- See Also:
-
IMAGE_SCN_MEM_PRELOAD
public static final int IMAGE_SCN_MEM_PRELOADReserved for future use- See Also:
-
IMAGE_SCN_ALIGN_1BYTES
public static final int IMAGE_SCN_ALIGN_1BYTESAlign on 1-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_2BYTES
public static final int IMAGE_SCN_ALIGN_2BYTESAlign on 2-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_4BYTES
public static final int IMAGE_SCN_ALIGN_4BYTESAlign on 4-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_8BYTES
public static final int IMAGE_SCN_ALIGN_8BYTESAlign on 8-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_16BYTES
public static final int IMAGE_SCN_ALIGN_16BYTESAlign on 16-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_32BYTES
public static final int IMAGE_SCN_ALIGN_32BYTESAlign on 32-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_64BYTES
public static final int IMAGE_SCN_ALIGN_64BYTESAlign on 64-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_128BYTES
public static final int IMAGE_SCN_ALIGN_128BYTESAlign on 128-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_256BYTES
public static final int IMAGE_SCN_ALIGN_256BYTESAlign on 256-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_512BYTES
public static final int IMAGE_SCN_ALIGN_512BYTESAlign on 512-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_1024BYTES
public static final int IMAGE_SCN_ALIGN_1024BYTESAlign on 1024-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_2048BYTES
public static final int IMAGE_SCN_ALIGN_2048BYTESAlign on 2048-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_4096BYTES
public static final int IMAGE_SCN_ALIGN_4096BYTESAlign on 4096-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_8192BYTES
public static final int IMAGE_SCN_ALIGN_8192BYTESAlign on 8192-byte boundary- See Also:
-
IMAGE_SCN_ALIGN_MASK
public static final int IMAGE_SCN_ALIGN_MASKMask for alignment flags- See Also:
-
IMAGE_SCN_LNK_NRELOC_OVFL
public static final int IMAGE_SCN_LNK_NRELOC_OVFLSection contains extended relocations- See Also:
-
IMAGE_SCN_MEM_DISCARDABLE
public static final int IMAGE_SCN_MEM_DISCARDABLEThe section can be discarded from the final executable. Used to hold information for the linker's use, including the .debug$ sections.- See Also:
-
IMAGE_SCN_MEM_NOT_CACHED
public static final int IMAGE_SCN_MEM_NOT_CACHEDSection is not cachable- See Also:
-
IMAGE_SCN_MEM_NOT_PAGED
public static final int IMAGE_SCN_MEM_NOT_PAGEDThe section is not pageable, so it should always be physically present in memory. Often used for kernel-mode drivers.- See Also:
-
IMAGE_SCN_MEM_SHARED
public static final int IMAGE_SCN_MEM_SHAREDSection is shareable. The physical pages containing this section's data will be shared between all processes that have this executable loaded. Thus, every process will see the exact same values for data in this section. Useful for making global variables shared between all instances of a process. To make a section shared, use the /section:name,S linker switch.- See Also:
-
IMAGE_SCN_MEM_EXECUTE
public static final int IMAGE_SCN_MEM_EXECUTESection is executable- See Also:
-
IMAGE_SCN_MEM_READ
public static final int IMAGE_SCN_MEM_READSection is readable- See Also:
-
IMAGE_SCN_MEM_WRITE
public static final int IMAGE_SCN_MEM_WRITESection is writeable- See Also:
-
-
Constructor Details
-
SectionHeader
public SectionHeader(BinaryReader reader, long index, long stringTableOffset, int sectionNumber) throws IOException Creates a newSectionHeaderfrom the specified stream starting atindex- Parameters:
reader-BinaryReaderto read fromindex- long offset in the reader where the section header startsstringTableOffset- offset of the string table, or -1 if not availablesectionNumber- The section number (0-based)- Throws:
IOException- if error reading data
-
-
Method Details
-
getName
Returns the ASCII name of the section.A section name is not guaranteed to be null-terminated. If you specify a section name longer than eight characters, the linker truncates it to eight characters in the executable. A mechanism exists for allowing longer section names in OBJ files. Section names often start with a period, but this is not a requirement. Section names with a $ in the name get special treatment from the linker. Sections with identical names prior to the $ character are merged. The characters following the $ provide an alphabetic ordering for how the merged sections appear in the final section. There's quite a bit more to the subject of sections with $ in the name and how they're combined, but the details are outside the scope of this article.
- Returns:
- the ASCII name of the section
-
getReadableName
Returns a readable ascii version of the name (all non-readable characters are replaced with underscores.- Returns:
- a readable ascii version of the name (all non-readable characters are replaced with underscores
-
getPhysicalAddress
public int getPhysicalAddress()Returns the original, unaligned physical address of this section.- Returns:
- the original, unaligned physical address of this section
-
getVirtualAddress
public int getVirtualAddress()Returns the original, unaligned RVA where the section begins in memory.- Returns:
- the original, unaligned RVA where the section begins in memory
-
getAlignedVirtualAddress
Returns the aligned RVA where the section begins in memory.- Parameters:
optionalHeader- TheOptionalHeader, ornullif not available- Returns:
- the aligned RVA where the section begins in memory
-
getVirtualSize
public int getVirtualSize()Returns the original, unaligned size of the section in memory.- Returns:
- the original, unaligned size of the section in memory
-
getAlignedVirtualSize
Returns the actual, used size of the section.- Parameters:
optionalHeader- TheOptionalHeader, ornullif not availablelog- A log to report errors to- Returns:
- the actual, used size of the section
-
getPointerToRawData
public int getPointerToRawData()Returns the original, unaligned offset of the section in the file.- Returns:
- the original, unaligned offset of the section in the file
-
getAlignedPointerToRawData
Returns the aligned offset of the section in the file.- Parameters:
optionalHeader- TheOptionalHeader, ornullif not availablelog- A log to report errors to- Returns:
- the aligned offset of the section in the file
-
getSizeOfRawData
public int getSizeOfRawData()Returns the original, unaligned size of the section in the file.- Returns:
- the original, unaligned size of the section in the file
-
getAlignedSizeOfRawData
Returns the aligned size of the section in the file.- Parameters:
optionalHeader- TheOptionalHeader, ornullif not availablelog- A log to report errors to- Returns:
- the aligned size of the section in the file
-
getPointerToRelocations
public int getPointerToRelocations()Returns the file offset of relocations for this section.- Returns:
- the file offset of relocations for this section
-
getNumberOfRelocations
public short getNumberOfRelocations()Returns the number of relocations pointed to by thePointerToRelocationsfield.- Returns:
- the number of relocations pointed to by the
PointerToRelocationsfield
-
getPointerToLinenumbers
public int getPointerToLinenumbers()Returns the file offset for COFF-style line numbers for this section.- Returns:
- the file offset for COFF-style line numbers for this section
-
getCharacteristics
public int getCharacteristics()Returns the flags OR'ed together, indicating the attributes of this section. Many of these flags can be set with the linker's /SECTION option. Common values include those listed in Figure 7.- Returns:
- the flags OR'ed together, indicating the attributes of this section
-
getNumberOfLinenumbers
public short getNumberOfLinenumbers()Returns the number of line numbers pointed to by thePointerToLinenumbersfield.- Returns:
- the number of line numbers pointed to by the
PointerToLinenumbersfield
-
toBytes
Description copied from interface:ByteArrayConverterReturns a byte array representing this implementor of this interface.- Specified by:
toBytesin interfaceByteArrayConverter- Parameters:
dc- the data converter to use- Returns:
- a byte array representing this object
- Throws:
IOException- if an IO-related error occurs
-
getDataStream
Returns anInputStreamto underlying bytes of this section.- Returns:
- an
InputStreamto underlying bytes of this section - Throws:
IOException- if an IO-related error occurred
-
getDataByteProvider
Returns aByteProviderto underlying bytes of this section.- Returns:
- a
ByteProviderto underlying bytes of this section
-
isRead
public boolean isRead()Returns whether or not this section has read permissions.- Returns:
- whether or not this section has read permissions
-
isWrite
public boolean isWrite()Returns whether or not this section has write permissions.- Returns:
- whether or not this section has write permissions
-
isExecute
public boolean isExecute()Returns whether or not this section has execute permissions.- Returns:
- whether or not this section has execute permissions
-
toString
-
toDataType
Description copied from interface:StructConverterReturns a structure datatype representing the contents of the implementor of this interface.For example, given:
class A { int foo; double bar; }The return value should be a structure data type with two data type components; an INT and a DOUBLE. The structure should contain field names and, if possible, field comments.
- Specified by:
toDataTypein interfaceStructConverter- Returns:
- returns a structure datatype representing the implementor of this interface
- Throws:
DuplicateNameException- when a datatype of the same name already exists- See Also:
-