mirror of
https://github.com/claunia/libexeinfo.git
synced 2025-12-16 19:14:24 +00:00
Add headers.
This commit is contained in:
@@ -1,4 +1,30 @@
|
||||
namespace libexeinfo
|
||||
//
|
||||
// Consts.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2017-2018 Copyright © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace libexeinfo
|
||||
{
|
||||
public partial class ELF
|
||||
{
|
||||
|
||||
@@ -1,4 +1,30 @@
|
||||
using System;
|
||||
//
|
||||
// ELF.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2017-2018 Copyright © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -10,7 +36,7 @@ namespace libexeinfo
|
||||
public partial class ELF : IExecutable
|
||||
{
|
||||
Architecture[] architectures;
|
||||
Elf64_Ehdr Header;
|
||||
Elf64_Ehdr header;
|
||||
string interpreter;
|
||||
Dictionary<string, ElfNote> notes;
|
||||
Elf64_Phdr[] programHeaders;
|
||||
@@ -25,11 +51,6 @@ namespace libexeinfo
|
||||
{
|
||||
BaseStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
|
||||
string pathDir = Path.GetDirectoryName(path);
|
||||
string filename = Path.GetFileNameWithoutExtension(path);
|
||||
string testPath = Path.Combine(pathDir, filename);
|
||||
string resourceFilePath = null;
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
@@ -75,56 +96,56 @@ namespace libexeinfo
|
||||
|
||||
BaseStream.Position = 0;
|
||||
BaseStream.Read(buffer, 0, buffer.Length);
|
||||
Header = BigEndianMarshal.ByteArrayToStructureLittleEndian<Elf64_Ehdr>(buffer);
|
||||
Recognized = Header.ei_mag.SequenceEqual(ELFMAG);
|
||||
header = BigEndianMarshal.ByteArrayToStructureLittleEndian<Elf64_Ehdr>(buffer);
|
||||
Recognized = header.ei_mag.SequenceEqual(ELFMAG);
|
||||
|
||||
if(!Recognized) return;
|
||||
|
||||
Type = "Executable and Linkable Format (ELF)";
|
||||
IsBigEndian = Header.ei_data == eiData.ELFDATA2MSB;
|
||||
IsBigEndian = header.ei_data == eiData.ELFDATA2MSB;
|
||||
architectures = new Architecture[1];
|
||||
|
||||
switch(Header.ei_class)
|
||||
switch(header.ei_class)
|
||||
{
|
||||
case eiClass.ELFCLASS32:
|
||||
Header = UpBits(buffer, Header.ei_data == eiData.ELFDATA2MSB);
|
||||
header = UpBits(buffer, header.ei_data == eiData.ELFDATA2MSB);
|
||||
break;
|
||||
case eiClass.ELFCLASS64:
|
||||
if(Header.ei_data == eiData.ELFDATA2MSB)
|
||||
if(header.ei_data == eiData.ELFDATA2MSB)
|
||||
{
|
||||
Header = BigEndianMarshal.ByteArrayToStructureBigEndian<Elf64_Ehdr>(buffer);
|
||||
Header.e_type = (eType)Swapping.Swap((ushort)Header.e_type);
|
||||
Header.e_machine = (eMachine)Swapping.Swap((ushort)Header.e_machine);
|
||||
Header.e_version = (eVersion)Swapping.Swap((uint)Header.e_version);
|
||||
header = BigEndianMarshal.ByteArrayToStructureBigEndian<Elf64_Ehdr>(buffer);
|
||||
header.e_type = (eType)Swapping.Swap((ushort)header.e_type);
|
||||
header.e_machine = (eMachine)Swapping.Swap((ushort)header.e_machine);
|
||||
header.e_version = (eVersion)Swapping.Swap((uint)header.e_version);
|
||||
}
|
||||
else Header = BigEndianMarshal.ByteArrayToStructureLittleEndian<Elf64_Ehdr>(buffer);
|
||||
else header = BigEndianMarshal.ByteArrayToStructureLittleEndian<Elf64_Ehdr>(buffer);
|
||||
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
architectures[0] = GetArchitecture(Header.e_machine);
|
||||
architectures[0] = GetArchitecture(header.e_machine);
|
||||
|
||||
if(Header.ei_data != eiData.ELFDATA2LSB && Header.ei_data != eiData.ELFDATA2MSB ||
|
||||
Header.ei_version != eiVersion.EV_CURRENT) return;
|
||||
if(header.ei_data != eiData.ELFDATA2LSB && header.ei_data != eiData.ELFDATA2MSB ||
|
||||
header.ei_version != eiVersion.EV_CURRENT) return;
|
||||
|
||||
List<string> strings = new List<string>();
|
||||
|
||||
if(Header.e_phnum == 0 && Header.e_shnum == 0) return;
|
||||
if(header.e_phnum == 0 && header.e_shnum == 0) return;
|
||||
|
||||
buffer = new byte[Header.e_phentsize];
|
||||
BaseStream.Position = (long)Header.e_phoff;
|
||||
programHeaders = new Elf64_Phdr[Header.e_phnum];
|
||||
buffer = new byte[header.e_phentsize];
|
||||
BaseStream.Position = (long)header.e_phoff;
|
||||
programHeaders = new Elf64_Phdr[header.e_phnum];
|
||||
for(int i = 0; i < programHeaders.Length; i++)
|
||||
{
|
||||
BaseStream.Read(buffer, 0, buffer.Length);
|
||||
switch(Header.ei_class)
|
||||
switch(header.ei_class)
|
||||
{
|
||||
case eiClass.ELFCLASS32:
|
||||
programHeaders[i] = UpBitsProgramHeader(buffer, Header.ei_data == eiData.ELFDATA2MSB);
|
||||
programHeaders[i] = UpBitsProgramHeader(buffer, header.ei_data == eiData.ELFDATA2MSB);
|
||||
break;
|
||||
case eiClass.ELFCLASS64:
|
||||
if(Header.ei_data == eiData.ELFDATA2MSB)
|
||||
if(header.ei_data == eiData.ELFDATA2MSB)
|
||||
{
|
||||
programHeaders[i] =
|
||||
BigEndianMarshal.ByteArrayToStructureBigEndian<Elf64_Phdr>(buffer);
|
||||
@@ -138,7 +159,7 @@ namespace libexeinfo
|
||||
}
|
||||
}
|
||||
|
||||
int len = 0;
|
||||
int len;
|
||||
int pos;
|
||||
|
||||
for(int i = 0; i < programHeaders.Length; i++)
|
||||
@@ -194,7 +215,7 @@ namespace libexeinfo
|
||||
|
||||
Segment[] segments;
|
||||
|
||||
if(Header.e_shnum == 0)
|
||||
if(header.e_shnum == 0)
|
||||
{
|
||||
segments = new Segment[programHeaders.Length];
|
||||
for(int i = 0; i < programHeaders.Length; i++)
|
||||
@@ -240,24 +261,24 @@ namespace libexeinfo
|
||||
|
||||
if(RequiredOperatingSystem.Name == null)
|
||||
RequiredOperatingSystem =
|
||||
GetOsByInterpreter(interpreter, false, false, false, false, false, Header.e_machine);
|
||||
GetOsByInterpreter(interpreter, false, false, false, false, false, header.e_machine);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
BaseStream.Position = (long)Header.e_shoff;
|
||||
buffer = new byte[Header.e_shentsize];
|
||||
sections = new Elf64_Shdr[Header.e_shnum];
|
||||
BaseStream.Position = (long)header.e_shoff;
|
||||
buffer = new byte[header.e_shentsize];
|
||||
sections = new Elf64_Shdr[header.e_shnum];
|
||||
|
||||
// Read section 0, aka "the NULL section"
|
||||
BaseStream.Read(buffer, 0, buffer.Length);
|
||||
switch(Header.ei_class)
|
||||
switch(header.ei_class)
|
||||
{
|
||||
case eiClass.ELFCLASS32:
|
||||
sections[0] = UpBitsSection(buffer, Header.ei_data == eiData.ELFDATA2MSB);
|
||||
sections[0] = UpBitsSection(buffer, header.ei_data == eiData.ELFDATA2MSB);
|
||||
break;
|
||||
case eiClass.ELFCLASS64:
|
||||
if(Header.ei_data == eiData.ELFDATA2MSB)
|
||||
if(header.ei_data == eiData.ELFDATA2MSB)
|
||||
{
|
||||
sections[0] = BigEndianMarshal.ByteArrayToStructureBigEndian<Elf64_Shdr>(buffer);
|
||||
sections[0].sh_flags = (shFlags64)Swapping.Swap((ulong)sections[0].sh_flags);
|
||||
@@ -272,15 +293,15 @@ namespace libexeinfo
|
||||
// Not a null section, in some ELFs, header contains incorrect pointer, but section header "should" be at end of file so check there
|
||||
if(sections[0].sh_type != shType.SHT_NULL)
|
||||
{
|
||||
BaseStream.Position = BaseStream.Length - Header.e_shentsize * Header.e_shnum;
|
||||
BaseStream.Position = BaseStream.Length - header.e_shentsize * header.e_shnum;
|
||||
BaseStream.Read(buffer, 0, buffer.Length);
|
||||
switch(Header.ei_class)
|
||||
switch(header.ei_class)
|
||||
{
|
||||
case eiClass.ELFCLASS32:
|
||||
sections[0] = UpBitsSection(buffer, Header.ei_data == eiData.ELFDATA2MSB);
|
||||
sections[0] = UpBitsSection(buffer, header.ei_data == eiData.ELFDATA2MSB);
|
||||
break;
|
||||
case eiClass.ELFCLASS64:
|
||||
if(Header.ei_data == eiData.ELFDATA2MSB)
|
||||
if(header.ei_data == eiData.ELFDATA2MSB)
|
||||
{
|
||||
sections[0] = BigEndianMarshal.ByteArrayToStructureBigEndian<Elf64_Shdr>(buffer);
|
||||
sections[0].sh_flags = (shFlags64)Swapping.Swap((ulong)sections[0].sh_flags);
|
||||
@@ -296,21 +317,21 @@ namespace libexeinfo
|
||||
if(sections[0].sh_type != shType.SHT_NULL) return;
|
||||
|
||||
// Rewind
|
||||
BaseStream.Position = BaseStream.Length - Header.e_shentsize * Header.e_shnum;
|
||||
BaseStream.Position = BaseStream.Length - header.e_shentsize * header.e_shnum;
|
||||
}
|
||||
// Rewind
|
||||
else BaseStream.Position = (long)Header.e_shoff;
|
||||
else BaseStream.Position = (long)header.e_shoff;
|
||||
|
||||
for(int i = 0; i < sections.Length; i++)
|
||||
{
|
||||
BaseStream.Read(buffer, 0, buffer.Length);
|
||||
switch(Header.ei_class)
|
||||
switch(header.ei_class)
|
||||
{
|
||||
case eiClass.ELFCLASS32:
|
||||
sections[i] = UpBitsSection(buffer, Header.ei_data == eiData.ELFDATA2MSB);
|
||||
sections[i] = UpBitsSection(buffer, header.ei_data == eiData.ELFDATA2MSB);
|
||||
break;
|
||||
case eiClass.ELFCLASS64:
|
||||
if(Header.ei_data == eiData.ELFDATA2MSB)
|
||||
if(header.ei_data == eiData.ELFDATA2MSB)
|
||||
{
|
||||
sections[i] = BigEndianMarshal.ByteArrayToStructureBigEndian<Elf64_Shdr>(buffer);
|
||||
sections[i].sh_flags = (shFlags64)Swapping.Swap((ulong)sections[i].sh_flags);
|
||||
@@ -323,8 +344,8 @@ namespace libexeinfo
|
||||
}
|
||||
}
|
||||
|
||||
BaseStream.Position = (long)sections[Header.e_shstrndx].sh_offset;
|
||||
buffer = new byte[sections[Header.e_shstrndx].sh_size];
|
||||
BaseStream.Position = (long)sections[header.e_shstrndx].sh_offset;
|
||||
buffer = new byte[sections[header.e_shstrndx].sh_size];
|
||||
BaseStream.Read(buffer, 0, buffer.Length);
|
||||
sectionNames = new string[sections.Length];
|
||||
segments = new Segment[sections.Length];
|
||||
@@ -381,7 +402,7 @@ namespace libexeinfo
|
||||
bool amigaos4 = false;
|
||||
bool aros = false;
|
||||
bool morphos = false;
|
||||
bool nonstop = (uint)Header.e_type == 100;
|
||||
bool nonstop = (uint)header.e_type == 100;
|
||||
|
||||
// Sections that contain an array of null-terminated strings by definition
|
||||
for(int i = 0; i < sections.Length; i++)
|
||||
@@ -510,7 +531,7 @@ namespace libexeinfo
|
||||
BaseStream.Read(buffer, 0, buffer.Length);
|
||||
string rodataAsString = Encoding.ASCII.GetString(buffer);
|
||||
|
||||
if(Header.e_machine == eMachine.EM_PPC)
|
||||
if(header.e_machine == eMachine.EM_PPC)
|
||||
{
|
||||
if(rodataAsString.Contains("SUNW_OST_OSLIB")) solaris = true;
|
||||
else if(rodataAsString.Contains("newlib.library")) amigaos4 = true;
|
||||
@@ -532,9 +553,9 @@ namespace libexeinfo
|
||||
RequiredOperatingSystem = GetOsByNote(freebsdTag, interpreter, IsBigEndian);
|
||||
else if(notes.TryGetValue(".note.ident", out ElfNote bsdiTag) && bsdiTag.name == "BSD/OS")
|
||||
RequiredOperatingSystem = GetOsByNote(bsdiTag, interpreter, IsBigEndian);
|
||||
else if(Header.ei_osabi != eiOsabi.ELFOSABI_NONE && Header.ei_osabi != eiOsabi.ELFOSABI_GNU &&
|
||||
Header.ei_osabi != eiOsabi.ELFOSABI_ARM && Header.ei_osabi != eiOsabi.ELFOSABI_ARM_AEABI)
|
||||
switch(Header.ei_osabi)
|
||||
else if(header.ei_osabi != eiOsabi.ELFOSABI_NONE && header.ei_osabi != eiOsabi.ELFOSABI_GNU &&
|
||||
header.ei_osabi != eiOsabi.ELFOSABI_ARM && header.ei_osabi != eiOsabi.ELFOSABI_ARM_AEABI)
|
||||
switch(header.ei_osabi)
|
||||
{
|
||||
case eiOsabi.ELFOSABI_HPUX:
|
||||
RequiredOperatingSystem = new OperatingSystem {Name = "HP-UX"};
|
||||
@@ -587,7 +608,7 @@ namespace libexeinfo
|
||||
}
|
||||
else if(!string.IsNullOrEmpty(interpreter))
|
||||
RequiredOperatingSystem =
|
||||
GetOsByInterpreter(interpreter, skyos, solaris, dellsysv, unixware, os2, Header.e_machine);
|
||||
GetOsByInterpreter(interpreter, skyos, solaris, dellsysv, unixware, os2, header.e_machine);
|
||||
else if(beos) RequiredOperatingSystem = new OperatingSystem {Name = "BeOS", MajorVersion = 4};
|
||||
else if(haiku) RequiredOperatingSystem = new OperatingSystem {Name = "Haiku"};
|
||||
else if(lynxos) RequiredOperatingSystem = new OperatingSystem {Name = "LynxOS"};
|
||||
|
||||
@@ -1,4 +1,29 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
//
|
||||
// Enums.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2017-2018 Copyright © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
@@ -1,4 +1,30 @@
|
||||
namespace libexeinfo
|
||||
//
|
||||
// FreeBSD.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2017-2018 Copyright © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace libexeinfo
|
||||
{
|
||||
public partial class ELF
|
||||
{
|
||||
|
||||
@@ -1,4 +1,30 @@
|
||||
using System;
|
||||
//
|
||||
// GNU.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2017-2018 Copyright © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace libexeinfo
|
||||
@@ -29,9 +55,9 @@ namespace libexeinfo
|
||||
static string DecodeGnuBuildId(ElfNote note)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach(byte b in note.contents) { sb.AppendFormat("{0:x2}", b); }
|
||||
foreach(byte b in note.contents) sb.AppendFormat("{0:x2}", b);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,35 @@
|
||||
using System;
|
||||
//
|
||||
// Info.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2017-2018 Copyright © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace libexeinfo
|
||||
{
|
||||
public partial class ELF : IExecutable
|
||||
public partial class ELF
|
||||
{
|
||||
public string Information
|
||||
{
|
||||
@@ -13,47 +39,47 @@ namespace libexeinfo
|
||||
|
||||
string processorFlags;
|
||||
|
||||
if(Header.e_flags == 0) processorFlags = "None";
|
||||
if(header.e_flags == 0) processorFlags = "None";
|
||||
else
|
||||
switch(Header.e_machine)
|
||||
switch(header.e_machine)
|
||||
{
|
||||
case eMachine.EM_ARM:
|
||||
case eMachine.EM_AARCH64:
|
||||
processorFlags =
|
||||
$"{(eFlagsArm)(Header.e_flags & eFlagsArmMask)} ABI version {Header.e_flags >> 24}";
|
||||
$"{(eFlagsArm)(header.e_flags & eFlagsArmMask)} ABI version {header.e_flags >> 24}";
|
||||
break;
|
||||
case eMachine.EM_MIPS:
|
||||
case eMachine.EM_MIPS_RS3_LE:
|
||||
case eMachine.EM_MIPS_X:
|
||||
processorFlags = $"{(eFlagsMips)Header.e_flags}";
|
||||
processorFlags = $"{(eFlagsMips)header.e_flags}";
|
||||
break;
|
||||
case eMachine.EM_PARISC:
|
||||
processorFlags =
|
||||
$"{(eFlagsArm)(Header.e_flags & eFlagsPariscMask)} architecture version {(eFlagsPaRiscArchitecture)(Header.e_flags & EF_PARISC_ARCH)}";
|
||||
$"{(eFlagsArm)(header.e_flags & eFlagsPariscMask)} architecture version {(eFlagsPaRiscArchitecture)(header.e_flags & EF_PARISC_ARCH)}";
|
||||
break;
|
||||
default:
|
||||
processorFlags = $"{Header.e_flags}";
|
||||
processorFlags = $"{header.e_flags}";
|
||||
break;
|
||||
}
|
||||
|
||||
sb.AppendLine("Executable and Linkable Format (ELF):");
|
||||
sb.AppendFormat("\tObject class: {0}", eiClassToString(Header.ei_class)).AppendLine();
|
||||
sb.AppendFormat("\tObject endian: {0}", eiDataToString(Header.ei_data)).AppendLine();
|
||||
sb.AppendFormat("\tObject OS ABI: {0}", eiOsAbiToString(Header.ei_osabi)).AppendLine();
|
||||
sb.AppendFormat("\tObject type: {0}", eTypeToString(Header.e_type)).AppendLine();
|
||||
sb.AppendFormat("\tArchitecture: {0}", eMachineToString(Header.e_machine)).AppendLine();
|
||||
sb.AppendFormat("\tObject file version: {0}", Header.e_version).AppendLine();
|
||||
sb.AppendFormat("\tObject class: {0}", eiClassToString(header.ei_class)).AppendLine();
|
||||
sb.AppendFormat("\tObject endian: {0}", eiDataToString(header.ei_data)).AppendLine();
|
||||
sb.AppendFormat("\tObject OS ABI: {0}", eiOsAbiToString(header.ei_osabi)).AppendLine();
|
||||
sb.AppendFormat("\tObject type: {0}", eTypeToString(header.e_type)).AppendLine();
|
||||
sb.AppendFormat("\tArchitecture: {0}", eMachineToString(header.e_machine)).AppendLine();
|
||||
sb.AppendFormat("\tObject file version: {0}", header.e_version).AppendLine();
|
||||
sb.AppendFormat("\tEntry point virtual address: {0}",
|
||||
Header.ei_class == eiClass.ELFCLASS64
|
||||
? $"0x{Header.e_entry:X16}"
|
||||
: $"0x{Header.e_entry:X8}").AppendLine();
|
||||
sb.AppendFormat("\tProgram header starts at {0}, contains {1} entries of {2} bytes", Header.e_phoff,
|
||||
Header.e_phnum, Header.e_phentsize).AppendLine();
|
||||
sb.AppendFormat("\tSection header starts at {0}, contains {1} entries of {2} bytes", Header.e_shoff,
|
||||
Header.e_shnum, Header.e_shentsize).AppendLine();
|
||||
header.ei_class == eiClass.ELFCLASS64
|
||||
? $"0x{header.e_entry:X16}"
|
||||
: $"0x{header.e_entry:X8}").AppendLine();
|
||||
sb.AppendFormat("\tProgram header starts at {0}, contains {1} entries of {2} bytes", header.e_phoff,
|
||||
header.e_phnum, header.e_phentsize).AppendLine();
|
||||
sb.AppendFormat("\tSection header starts at {0}, contains {1} entries of {2} bytes", header.e_shoff,
|
||||
header.e_shnum, header.e_shentsize).AppendLine();
|
||||
sb.AppendFormat("\tProcessor specific flags: {0}", processorFlags).AppendLine();
|
||||
sb.AppendFormat("\tHeader is {0} bytes long", Header.e_ehsize).AppendLine();
|
||||
sb.AppendFormat("\tString table is at index {0} of section header", Header.e_shstrndx).AppendLine();
|
||||
sb.AppendFormat("\tHeader is {0} bytes long", header.e_ehsize).AppendLine();
|
||||
sb.AppendFormat("\tString table is at index {0} of section header", header.e_shstrndx).AppendLine();
|
||||
|
||||
if(!string.IsNullOrEmpty(interpreter)) sb.AppendFormat("\tInterpreter: {0}", interpreter).AppendLine();
|
||||
|
||||
@@ -66,7 +92,7 @@ namespace libexeinfo
|
||||
sb.AppendFormat("\t\tType: {0}", sections[i].sh_type).AppendLine();
|
||||
sb.AppendFormat("\t\tFlags: {0}", sections[i].sh_flags).AppendLine();
|
||||
sb.AppendFormat("\t\tVirtual address: {0}",
|
||||
Header.ei_class == eiClass.ELFCLASS64
|
||||
header.ei_class == eiClass.ELFCLASS64
|
||||
? $"0x{sections[i].sh_addr:X16}"
|
||||
: $"0x{sections[i].sh_addr:X8}").AppendLine();
|
||||
sb.AppendFormat("\t\tSection starts at {0} and is {1} bytes long", sections[i].sh_offset,
|
||||
|
||||
@@ -1,4 +1,30 @@
|
||||
using System.Runtime.InteropServices;
|
||||
//
|
||||
// Structs.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2017-2018 Copyright © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace libexeinfo
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user