Skip to content

Commit

Permalink
Add ElfType enum and accompanying test
Browse files Browse the repository at this point in the history
  • Loading branch information
fjeremic committed Dec 19, 2019
1 parent 98e9709 commit 81d376d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
10 changes: 10 additions & 0 deletions BinaryTools.Elf.Tests/TestElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,15 @@ public void CorrectFlags()

Assert.Equal(0U, elfFile.Header.Flags);
}

[Fact]
public void CorrectType()
{
var stream = new FileStream("Binaries/base32", FileMode.Open, FileAccess.Read);
var reader = new EndianBinaryReader(stream, EndianBitConverter.NativeEndianness);
ElfFile elfFile = ElfFile.ReadElfFile(reader);

Assert.Equal(ElfType.Executable, elfFile.Header.Type);
}
}
}
2 changes: 1 addition & 1 deletion BinaryTools.Elf/Bit32/ElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal ElfHeader(BinaryReader reader, Int64 position)
reader.BaseStream.Position += 1;

// Represents Elf32_Ehdr.e_type
Type = reader.ReadUInt16();
Type = (ElfType)reader.ReadUInt16();

// Represents Elf32_Ehdr.e_machine
Machine = reader.ReadUInt16();
Expand Down
2 changes: 1 addition & 1 deletion BinaryTools.Elf/Bit64/ElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal ElfHeader(BinaryReader reader, Int64 position)
reader.BaseStream.Position += 1;

// Represents Elf64_Ehdr.e_type
Type = reader.ReadUInt16();
Type = (ElfType)reader.ReadUInt16();

// Represents Elf64_Ehdr.e_machine
Machine = reader.ReadUInt16();
Expand Down
2 changes: 1 addition & 1 deletion BinaryTools.Elf/ElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public UInt32 Flags
/// <summary>
/// Gets the ELF file type.
/// </summary>
public UInt16 Type
public ElfType Type
{
get; protected set;
}
Expand Down
40 changes: 40 additions & 0 deletions BinaryTools.Elf/ElfType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.ComponentModel;

namespace BinaryTools.Elf
{
/// <summary>
/// Enumerates the object file type.
/// </summary>
public enum ElfType : ushort
{
/// <summary>
/// No file type
/// </summary>
[Description("No file type")]
None,

/// <summary>
/// Relocatable file
/// </summary>
[Description("Relocatable file")]
Relocatable,

/// <summary>
/// Executable file
/// </summary>
[Description("Executable file")]
Executable,

/// <summary>
/// Shared object file
/// </summary>
[Description("Shared object file")]
Shared,

/// <summary>
/// Core file
/// </summary>
[Description("Core file")]
Core,
}
}

0 comments on commit 81d376d

Please sign in to comment.