0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-21 12:51:18 +03:00

Move section code checking logic from SectionHeaderParser to SectionHeader class

This commit is contained in:
bird_egop 2025-04-12 17:20:51 +03:00
parent f1a2fca4f3
commit e4adb45ed2
3 changed files with 45 additions and 16 deletions

View File

@ -203,7 +203,7 @@ namespace X86Disassembler.PE
for (int i = 0; i < SectionHeaders.Count; i++) for (int i = 0; i < SectionHeaders.Count; i++)
{ {
if (_sectionHeaderParser.IsSectionContainsCode(SectionHeaders[i])) if (SectionHeaders[i].ContainsCode())
{ {
codeSections.Add(i); codeSections.Add(i);
} }
@ -219,7 +219,7 @@ namespace X86Disassembler.PE
/// <returns>True if the section contains code, false otherwise</returns> /// <returns>True if the section contains code, false otherwise</returns>
public bool IsSectionContainsCode(SectionHeader section) public bool IsSectionContainsCode(SectionHeader section)
{ {
return _sectionHeaderParser.IsSectionContainsCode(section); return section.ContainsCode();
} }
} }
} }

View File

@ -34,19 +34,5 @@ namespace X86Disassembler.PE.Parsers
return header; return header;
} }
/// <summary>
/// Checks if a section contains code
/// </summary>
/// <param name="section">The section to check</param>
/// <returns>True if the section contains code, false otherwise</returns>
public bool IsSectionContainsCode(SectionHeader section)
{
const uint IMAGE_SCN_CNT_CODE = 0x00000020; // Section contains code
const uint IMAGE_SCN_MEM_EXECUTE = 0x20000000; // Section is executable
return (section.Characteristics & IMAGE_SCN_CNT_CODE) != 0 ||
(section.Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
}
} }
} }

View File

@ -5,6 +5,12 @@ namespace X86Disassembler.PE
/// </summary> /// </summary>
public class SectionHeader public class SectionHeader
{ {
// Section characteristics flags
private const uint IMAGE_SCN_CNT_CODE = 0x00000020; // Section contains code
private const uint IMAGE_SCN_MEM_EXECUTE = 0x20000000; // Section is executable
private const uint IMAGE_SCN_MEM_READ = 0x40000000; // Section is readable
private const uint IMAGE_SCN_MEM_WRITE = 0x80000000; // Section is writable
public string Name; // Section name public string Name; // Section name
public uint VirtualSize; // Virtual size public uint VirtualSize; // Virtual size
public uint VirtualAddress; // Virtual address public uint VirtualAddress; // Virtual address
@ -15,5 +21,42 @@ namespace X86Disassembler.PE
public ushort NumberOfRelocations; // Number of relocations public ushort NumberOfRelocations; // Number of relocations
public ushort NumberOfLinenumbers; // Number of line numbers public ushort NumberOfLinenumbers; // Number of line numbers
public uint Characteristics; // Characteristics public uint Characteristics; // Characteristics
/// <summary>
/// Checks if the section contains code
/// </summary>
/// <returns>True if the section contains code, false otherwise</returns>
public bool ContainsCode()
{
return (Characteristics & IMAGE_SCN_CNT_CODE) != 0 ||
(Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
}
/// <summary>
/// Checks if the section is readable
/// </summary>
/// <returns>True if the section is readable, false otherwise</returns>
public bool IsReadable()
{
return (Characteristics & IMAGE_SCN_MEM_READ) != 0;
}
/// <summary>
/// Checks if the section is writable
/// </summary>
/// <returns>True if the section is writable, false otherwise</returns>
public bool IsWritable()
{
return (Characteristics & IMAGE_SCN_MEM_WRITE) != 0;
}
/// <summary>
/// Checks if the section is executable
/// </summary>
/// <returns>True if the section is executable, false otherwise</returns>
public bool IsExecutable()
{
return (Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
}
} }
} }