Skip to content

Commit

Permalink
Add ElfMachine enum and accompanying tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjeremic committed Dec 20, 2019
1 parent 81d376d commit fb7d3a7
Show file tree
Hide file tree
Showing 5 changed files with 649 additions and 3 deletions.
30 changes: 30 additions & 0 deletions BinaryTools.Elf.Tests/TestElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,35 @@ public void CorrectType()

Assert.Equal(ElfType.Executable, elfFile.Header.Type);
}

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

Assert.Equal(ElfMachine.X8664, elfFile.Header.Machine);
}

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

Assert.Equal(ElfMachine.I386, elfFile.Header.Machine);
}

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

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

// Represents Elf32_Ehdr.e_machine
Machine = reader.ReadUInt16();
Machine = (ElfMachine)reader.ReadUInt16();

// Represents Elf32_Ehdr.e_version
Version = reader.ReadUInt32();
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 @@ -75,7 +75,7 @@ internal ElfHeader(BinaryReader reader, Int64 position)
Type = (ElfType)reader.ReadUInt16();

// Represents Elf64_Ehdr.e_machine
Machine = reader.ReadUInt16();
Machine = (ElfMachine)reader.ReadUInt16();

// Represents Elf64_Ehdr.e_version
Version = reader.ReadUInt32();
Expand Down
2 changes: 1 addition & 1 deletion BinaryTools.Elf/ElfHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public UInt32 Version
/// <summary>
/// Gets the ELF file Instruction Set Architecture (ISA).
/// </summary>
public UInt16 Machine
public ElfMachine Machine
{
get; protected set;
}
Expand Down
Loading

0 comments on commit fb7d3a7

Please sign in to comment.