Skip to content

Commit

Permalink
Add ElfData and ElfClass enumerations
Browse files Browse the repository at this point in the history
  • Loading branch information
fjeremic committed May 21, 2020
1 parent 5657b21 commit a43ae96
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 14 deletions.
8 changes: 4 additions & 4 deletions BinaryTools.Elf.Tests/TestElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void CorrectClass32()
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
ElfFile elfFile = ElfFile.ReadElfFile(reader);

Assert.Equal(ElfHeader.ELFCLASS32, elfFile.Header.Class);
Assert.Equal(ElfClass.Elf32, elfFile.Header.Class);
}

[Fact]
Expand All @@ -23,7 +23,7 @@ public void CorrectClass64()
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
ElfFile elfFile = ElfFile.ReadElfFile(reader);

Assert.Equal(ElfHeader.ELFCLASS64, elfFile.Header.Class);
Assert.Equal(ElfClass.Elf64, elfFile.Header.Class);
}

[Fact]
Expand All @@ -33,7 +33,7 @@ public void CorrectEndiannessLE()
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
ElfFile elfFile = ElfFile.ReadElfFile(reader);

Assert.Equal(ElfHeader.ELFDATA2LSB, elfFile.Header.Data);
Assert.Equal(ElfData.Lsb, elfFile.Header.Data);
}

[Fact]
Expand All @@ -43,7 +43,7 @@ public void CorrectEndiannessBE()
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
ElfFile elfFile = ElfFile.ReadElfFile(reader);

Assert.Equal(ElfHeader.ELFDATA2MSB, elfFile.Header.Data);
Assert.Equal(ElfData.Msb, elfFile.Header.Data);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions BinaryTools.Elf/Bit32/ElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ internal ElfHeader(BinaryReader reader, Int64 position)
reader.BaseStream.Position += 1;

// Represents Elf32_Ehdr.e_ident[4]
Class = reader.ReadByte();
Class = (ElfClass)reader.ReadByte();

// Represents Elf32_Ehdr.e_ident[5]
Data = reader.ReadByte();
Data = (ElfData)reader.ReadByte();

// Represents Elf32_Ehdr.e_ident[6]
reader.BaseStream.Position += 1;
Expand Down
4 changes: 2 additions & 2 deletions BinaryTools.Elf/Bit64/ElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ internal ElfHeader(BinaryReader reader, Int64 position)
reader.BaseStream.Position += 1;

// Represents Elf64_Ehdr.e_ident[4]
Class = reader.ReadByte();
Class = (ElfClass)reader.ReadByte();

// Represents Elf32_Ehdr.e_ident[5]
Data = reader.ReadByte();
Data = (ElfData)reader.ReadByte();

// Represents Elf64_Ehdr.e_ident[6]
reader.BaseStream.Position += 1;
Expand Down
28 changes: 28 additions & 0 deletions BinaryTools.Elf/ElfClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel;

namespace BinaryTools.Elf
{
/// <summary>
/// Enumerates the ELF file bitness.
/// </summary>
public enum ElfClass : byte
{
/// <summary>
/// Invalid class
/// </summary>
[Description("Invalid class")]
None,

/// <summary>
/// 32-bit objects
/// </summary>
[Description("ELF32")]
Elf32,

/// <summary>
/// 64-bit objects
/// </summary>
[Description("ELF64")]
Elf64,
}
}
28 changes: 28 additions & 0 deletions BinaryTools.Elf/ElfData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel;

namespace BinaryTools.Elf
{
/// <summary>
/// Enumerates the ELF file endianness.
/// </summary>
public enum ElfData : byte
{
/// <summary>
/// Invalid data encoding
/// </summary>
[Description("Invalid data encoding")]
None,

/// <summary>
/// 2's complement, little endian
/// </summary>
[Description("2's complement, little endian")]
Lsb,

/// <summary>
/// 2's complement, big endian
/// </summary>
[Description("2's complement, big endian")]
Msb,
}
}
4 changes: 2 additions & 2 deletions BinaryTools.Elf/ElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ public UInt16 Size
/// <summary>
/// Gets the ELF file bitness.
/// </summary>
public Byte Class
public ElfClass Class
{
get; protected set;
}

/// <summary>
/// Gets the ELF file endianness.
/// </summary>
public Byte Data
public ElfData Data
{
get; protected set;
}
Expand Down
4 changes: 2 additions & 2 deletions BinaryTools.Elf/ElfProgramHeaderTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ internal ElfProgramHeaderTable(BinaryReader reader, ElfHeader header, ElfSection

switch (header.Class)
{
case ElfHeader.ELFCLASS32:
case ElfClass.Elf32:
{
segment = new Bit32.ElfSegment(reader, (Int64)(header.ProgramHeaderOffset + (UInt64)(i * header.ProgramHeaderSize)));
}
break;

case ElfHeader.ELFCLASS64:
case ElfClass.Elf64:
{
segment = new Bit64.ElfSegment(reader, (Int64)(header.ProgramHeaderOffset + (UInt64)(i * header.ProgramHeaderSize)));
}
Expand Down
4 changes: 2 additions & 2 deletions BinaryTools.Elf/ElfSectionHeaderTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal ElfSectionHeaderTable(BinaryReader reader, ElfHeader header)

switch (header.Class)
{
case ElfHeader.ELFCLASS32:
case ElfClass.Elf32:
{
section = new Bit32.ElfSection(reader, (Int64)(header.SectionHeaderOffset + (UInt64)(i * header.SectionHeaderSize)));

Expand Down Expand Up @@ -119,7 +119,7 @@ internal ElfSectionHeaderTable(BinaryReader reader, ElfHeader header)
}
break;

case ElfHeader.ELFCLASS64:
case ElfClass.Elf64:
{
section = new Bit64.ElfSection(reader, (Int64)(header.SectionHeaderOffset + (UInt64)(i * header.SectionHeaderSize)));

Expand Down

0 comments on commit a43ae96

Please sign in to comment.