mirror of
https://github.com/claunia/libexeinfo.git
synced 2025-12-16 19:14:24 +00:00
Decode ELF GNU ABI tag and build ID.
This commit is contained in:
@@ -4,7 +4,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace libexeinfo
|
namespace libexeinfo
|
||||||
{
|
{
|
||||||
@@ -13,9 +12,9 @@ namespace libexeinfo
|
|||||||
List<Architecture> architectures;
|
List<Architecture> architectures;
|
||||||
Elf64_Ehdr Header;
|
Elf64_Ehdr Header;
|
||||||
string interpreter;
|
string interpreter;
|
||||||
|
Dictionary<string, ElfNote> notes;
|
||||||
string[] sectionNames;
|
string[] sectionNames;
|
||||||
Elf64_Shdr[] sections;
|
Elf64_Shdr[] sections;
|
||||||
Dictionary<string, ElfNote> notes;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="T:libexeinfo.ELF" /> class.
|
/// Initializes a new instance of the <see cref="T:libexeinfo.ELF" /> class.
|
||||||
@@ -58,7 +57,7 @@ namespace libexeinfo
|
|||||||
public IEnumerable<Architecture> Architectures => architectures;
|
public IEnumerable<Architecture> Architectures => architectures;
|
||||||
public OperatingSystem RequiredOperatingSystem { get; private set; }
|
public OperatingSystem RequiredOperatingSystem { get; private set; }
|
||||||
public IEnumerable<string> Strings { get; private set; }
|
public IEnumerable<string> Strings { get; private set; }
|
||||||
public IEnumerable<Segment> Segments { get; }
|
public IEnumerable<Segment> Segments { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="FileStream" /> that contains the executable represented by this instance
|
/// The <see cref="FileStream" /> that contains the executable represented by this instance
|
||||||
@@ -235,10 +234,13 @@ namespace libexeinfo
|
|||||||
|
|
||||||
pos += (int)namesz;
|
pos += (int)namesz;
|
||||||
|
|
||||||
switch(Header.ei_class) {
|
switch(Header.ei_class)
|
||||||
case eiClass.ELFCLASS32: pos += pos % 4;
|
{
|
||||||
|
case eiClass.ELFCLASS32:
|
||||||
|
pos += pos % 4;
|
||||||
break;
|
break;
|
||||||
case eiClass.ELFCLASS64: pos += pos % 8;
|
case eiClass.ELFCLASS64:
|
||||||
|
pos += pos % 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +250,18 @@ namespace libexeinfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(notes.TryGetValue(".note.ABI-tag", out ElfNote abiTag))
|
||||||
|
{
|
||||||
|
GnuAbiTag gnuAbiTag = DecodeGnuAbiTag(abiTag, IsBigEndian);
|
||||||
|
if(gnuAbiTag != null)
|
||||||
|
RequiredOperatingSystem = new OperatingSystem
|
||||||
|
{
|
||||||
|
Name = $"{gnuAbiTag.system}",
|
||||||
|
MajorVersion = (int)gnuAbiTag.major,
|
||||||
|
MinorVersion = (int)gnuAbiTag.minor
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if(strings.Count > 0)
|
if(strings.Count > 0)
|
||||||
{
|
{
|
||||||
strings.Remove(null);
|
strings.Remove(null);
|
||||||
@@ -255,6 +269,8 @@ namespace libexeinfo
|
|||||||
strings.Sort();
|
strings.Sort();
|
||||||
Strings = strings.Distinct();
|
Strings = strings.Distinct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Segments = segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Elf64_Ehdr UpBits(byte[] buffer, bool bigEndian)
|
static Elf64_Ehdr UpBits(byte[] buffer, bool bigEndian)
|
||||||
|
|||||||
@@ -941,5 +941,10 @@ namespace libexeinfo
|
|||||||
/// <summary>PA-RISC 2.0</summary>
|
/// <summary>PA-RISC 2.0</summary>
|
||||||
EFA_PARISC_2_0 = 0x0214
|
EFA_PARISC_2_0 = 0x0214
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum GnuAbiSystem : uint
|
||||||
|
{
|
||||||
|
Linux = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
37
libexeinfo/ELF/GNU.cs
Normal file
37
libexeinfo/ELF/GNU.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace libexeinfo
|
||||||
|
{
|
||||||
|
public partial class ELF
|
||||||
|
{
|
||||||
|
static GnuAbiTag DecodeGnuAbiTag(ElfNote note, bool bigEndian)
|
||||||
|
{
|
||||||
|
if(note.name != "GNU") return null;
|
||||||
|
|
||||||
|
return bigEndian
|
||||||
|
? new GnuAbiTag
|
||||||
|
{
|
||||||
|
system = (GnuAbiSystem)Swapping.Swap(BitConverter.ToUInt32(note.contents, 0)),
|
||||||
|
major = Swapping.Swap(BitConverter.ToUInt32(note.contents, 4)),
|
||||||
|
minor = Swapping.Swap(BitConverter.ToUInt32(note.contents, 8)),
|
||||||
|
revision = Swapping.Swap(BitConverter.ToUInt32(note.contents, 0))
|
||||||
|
}
|
||||||
|
: new GnuAbiTag
|
||||||
|
{
|
||||||
|
system = (GnuAbiSystem)BitConverter.ToUInt32(note.contents, 0),
|
||||||
|
major = BitConverter.ToUInt32(note.contents, 4),
|
||||||
|
minor = BitConverter.ToUInt32(note.contents, 8),
|
||||||
|
revision = BitConverter.ToUInt32(note.contents, 0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static string DecodeGnuBuildId(ElfNote note)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
foreach(byte b in note.contents) { sb.AppendFormat("{0:x2}", b); }
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -83,6 +83,17 @@ namespace libexeinfo
|
|||||||
sb.AppendFormat("\t\t\tLength: {0} bytes", note.contents.Length).AppendLine();
|
sb.AppendFormat("\t\t\tLength: {0} bytes", note.contents.Length).AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(notes.TryGetValue(".note.ABI-tag", out ElfNote abiTag))
|
||||||
|
{
|
||||||
|
GnuAbiTag gnuAbiTag = DecodeGnuAbiTag(abiTag, IsBigEndian);
|
||||||
|
if(gnuAbiTag != null)
|
||||||
|
sb.AppendFormat("\tGNU ABI tag: Requires {0} version {1}.{2}.{3}", gnuAbiTag.system,
|
||||||
|
gnuAbiTag.major, gnuAbiTag.minor, gnuAbiTag.revision).AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(notes.TryGetValue(".note.gnu.build-id", out ElfNote buildId))
|
||||||
|
sb.AppendFormat("\tGNU build ID: {0}", DecodeGnuBuildId(buildId));
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,5 +376,13 @@ namespace libexeinfo
|
|||||||
public uint type;
|
public uint type;
|
||||||
public byte[] contents;
|
public byte[] contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GnuAbiTag
|
||||||
|
{
|
||||||
|
public GnuAbiSystem system;
|
||||||
|
public uint major;
|
||||||
|
public uint minor;
|
||||||
|
public uint revision;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,7 @@
|
|||||||
<Compile Include="ELF\Consts.cs" />
|
<Compile Include="ELF\Consts.cs" />
|
||||||
<Compile Include="ELF\ELF.cs" />
|
<Compile Include="ELF\ELF.cs" />
|
||||||
<Compile Include="ELF\Enums.cs" />
|
<Compile Include="ELF\Enums.cs" />
|
||||||
|
<Compile Include="ELF\GNU.cs" />
|
||||||
<Compile Include="ELF\Info.cs" />
|
<Compile Include="ELF\Info.cs" />
|
||||||
<Compile Include="ELF\Structs.cs" />
|
<Compile Include="ELF\Structs.cs" />
|
||||||
<Compile Include="Enums.cs" />
|
<Compile Include="Enums.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user