mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-11-27 13:10:24 +00:00
more enums in elf headers
This commit is contained in:
parent
0a3dc10bb2
commit
e9bc3811a9
@ -194,39 +194,40 @@ bool Elf::isElfFile() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (m_elf_header->e_ident[EI_MAG0] != ELFMAG0 || m_elf_header->e_ident[EI_MAG1] != ELFMAG1 || m_elf_header->e_ident[EI_MAG2] != ELFMAG2 ||
|
||||
m_elf_header->e_ident[EI_MAG3] != ELFMAG3)
|
||||
|
||||
if (m_elf_header->e_ident.magic[EI_MAG0] != ELFMAG0 || m_elf_header->e_ident.magic[EI_MAG1] != ELFMAG1 || m_elf_header->e_ident.magic[EI_MAG2] != ELFMAG2 ||
|
||||
m_elf_header->e_ident.magic[EI_MAG3] != ELFMAG3)
|
||||
{
|
||||
printf("ERROR:Not an ELF file magic is wrong!\n");
|
||||
return false;
|
||||
}
|
||||
if (m_elf_header->e_ident[EI_CLASS] != ELFCLASS64)
|
||||
if (m_elf_header->e_ident.ei_class != ELF_CLASS_64)
|
||||
{
|
||||
printf("ERROR:e_ident[EI_CLASS] expected 0x02 is (0x%x)\n", m_elf_header->e_ident[EI_CLASS]);
|
||||
printf("ERROR:e_ident[EI_CLASS] expected 0x02 is (0x%x)\n", m_elf_header->e_ident.ei_class);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header->e_ident[EI_DATA] != ELFDATA2LSB)
|
||||
if (m_elf_header->e_ident.ei_data != ELF_DATA_2LSB)
|
||||
{
|
||||
printf("ERROR:e_ident[EI_DATA] expected 0x01 is (0x%x)\n", m_elf_header->e_ident[EI_DATA]);
|
||||
printf("ERROR:e_ident[EI_DATA] expected 0x01 is (0x%x)\n", m_elf_header->e_ident.ei_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header->e_ident[EI_VERSION] != EV_CURRENT)
|
||||
if (m_elf_header->e_ident.ei_version != ELF_VERSION_CURRENT)
|
||||
{
|
||||
printf("ERROR:e_ident[EI_VERSION] expected 0x01 is (0x%x)\n", m_elf_header->e_ident[EI_VERSION]);
|
||||
printf("ERROR:e_ident[EI_VERSION] expected 0x01 is (0x%x)\n", m_elf_header->e_ident.ei_version);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header->e_ident[EI_OSABI] != ELFOSABI_FREEBSD)
|
||||
if (m_elf_header->e_ident.ei_osabi != ELF_OSABI_FREEBSD)
|
||||
{
|
||||
printf("ERROR:e_ident[EI_OSABI] expected 0x09 is (0x%x)\n", m_elf_header->e_ident[EI_OSABI]);
|
||||
printf("ERROR:e_ident[EI_OSABI] expected 0x09 is (0x%x)\n", m_elf_header->e_ident.ei_osabi);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_elf_header->e_ident[EI_ABIVERSION] != ELFABIVERSION_AMDGPU_HSA_V2)
|
||||
if (m_elf_header->e_ident.ei_abiversion != ELF_ABI_VERSION_AMDGPU_HSA_V2)
|
||||
{
|
||||
printf("ERROR:e_ident[EI_ABIVERSION] expected 0x00 is (0x%x)\n", m_elf_header->e_ident[EI_ABIVERSION]);
|
||||
printf("ERROR:e_ident[EI_ABIVERSION] expected 0x00 is (0x%x)\n", m_elf_header->e_ident.ei_abiversion);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -272,7 +273,7 @@ void Elf::DebugDump() {
|
||||
spdlog::set_formatter(std::move(f));
|
||||
spdlog::info("SELF header:\n");
|
||||
|
||||
spdlog::info(" magic ..............: 0x{:x}\n", m_self->magic);
|
||||
spdlog::info(" magic ..............: 0x{:X}\n", m_self->magic);
|
||||
spdlog::info(" version .........: {}\n", m_self->version);
|
||||
spdlog::info(" mode .........: {:#04x}\n", m_self->mode);
|
||||
spdlog::info(" endian .........: {}\n", m_self->endian);
|
||||
@ -303,40 +304,76 @@ void Elf::DebugDump() {
|
||||
spdlog::info("\n");
|
||||
|
||||
spdlog::info("Elf header:\n");
|
||||
spdlog::info(" ident .........: 0x");
|
||||
for (auto i : m_elf_header->e_ident)
|
||||
spdlog::info(" ident ............: 0x");
|
||||
for (auto i : m_elf_header->e_ident.magic)
|
||||
{
|
||||
spdlog::info("{:02x}", i);
|
||||
spdlog::info("{:02X}", i);
|
||||
}
|
||||
spdlog::info("\n");
|
||||
|
||||
auto ident_class = magic_enum::enum_cast<ident_class_es>(m_elf_header->e_ident.ei_class);
|
||||
if (ident_class.has_value())
|
||||
{
|
||||
spdlog::info(" ident class.......: {}\n", magic_enum::enum_name(ident_class.value()));
|
||||
}
|
||||
|
||||
auto ident_data = magic_enum::enum_cast<ident_endian_es>(m_elf_header->e_ident.ei_data);
|
||||
if (ident_data.has_value())
|
||||
{
|
||||
spdlog::info(" ident data .......: {}\n", magic_enum::enum_name(ident_data.value()));
|
||||
}
|
||||
|
||||
auto ident_version = magic_enum::enum_cast<ident_version_es>(m_elf_header->e_ident.ei_version);
|
||||
if (ident_version.has_value())
|
||||
{
|
||||
spdlog::info(" ident version.....: {}\n", magic_enum::enum_name(ident_version.value()));
|
||||
}
|
||||
|
||||
auto ident_osabi = magic_enum::enum_cast<ident_osabi_es>(m_elf_header->e_ident.ei_osabi);
|
||||
if (ident_osabi.has_value())
|
||||
{
|
||||
spdlog::info(" ident osabi .....: {}\n", magic_enum::enum_name(ident_osabi.value()));
|
||||
}
|
||||
|
||||
auto ident_abiversion = magic_enum::enum_cast<ident_abiversion_es>(m_elf_header->e_ident.ei_abiversion);
|
||||
if (ident_abiversion.has_value())
|
||||
{
|
||||
spdlog::info(" ident abiversion..: {}\n", magic_enum::enum_name(ident_abiversion.value()));
|
||||
}
|
||||
|
||||
spdlog::info(" ident UNK ........: 0x");
|
||||
for (auto i : m_elf_header->e_ident.pad)
|
||||
{
|
||||
spdlog::info("{:02X}", i);
|
||||
}
|
||||
spdlog::info("\n");
|
||||
|
||||
auto type = magic_enum::enum_cast<e_type_s>(m_elf_header->e_type);
|
||||
if (type.has_value())
|
||||
{
|
||||
spdlog::info(" type .........: {}\n", magic_enum::enum_name(type.value()));
|
||||
spdlog::info(" type ............: {}\n", magic_enum::enum_name(type.value()));
|
||||
}
|
||||
|
||||
//spdlog::info(" type .........: {:#06x}\n", (int)m_elf_header->e_type);
|
||||
|
||||
auto machine = magic_enum::enum_cast<e_machine_es>(m_elf_header->e_machine);
|
||||
if (machine.has_value())
|
||||
{
|
||||
spdlog::info(" machine .......: {}\n", magic_enum::enum_name(machine.value()));
|
||||
spdlog::info(" machine ..........: {}\n", magic_enum::enum_name(machine.value()));
|
||||
}
|
||||
auto version = magic_enum::enum_cast<e_version_es>(m_elf_header->e_version);
|
||||
if (version.has_value())
|
||||
{
|
||||
spdlog::info(" version .......: {}\n", magic_enum::enum_name(version.value()));
|
||||
spdlog::info(" version ..........: {}\n", magic_enum::enum_name(version.value()));
|
||||
}
|
||||
spdlog::info(" entry .........: {:#018x}\n", m_elf_header->e_entry);
|
||||
spdlog::info(" phoff .........: {:#018x}\n", m_elf_header->e_phoff);
|
||||
spdlog::info(" shoff .........: {:#018x}\n", m_elf_header->e_shoff);
|
||||
spdlog::info(" flags .........: {:#010x}\n", m_elf_header->e_flags);
|
||||
spdlog::info(" ehsize ........: {}\n", m_elf_header->e_ehsize);
|
||||
spdlog::info(" phentsize .....: {}\n", m_elf_header->e_phentsize);
|
||||
spdlog::info(" phnum .........: {}\n", m_elf_header->e_phnum);
|
||||
spdlog::info(" shentsize .....: {}\n", m_elf_header->e_shentsize);
|
||||
spdlog::info(" shnum .........: {}\n", m_elf_header->e_shnum);
|
||||
spdlog::info(" shstrndx ......: {}\n", m_elf_header->e_shstrndx);
|
||||
spdlog::info(" entry ............: {:#018x}\n", m_elf_header->e_entry);
|
||||
spdlog::info(" phoff ............: {:#018x}\n", m_elf_header->e_phoff);
|
||||
spdlog::info(" shoff ............: {:#018x}\n", m_elf_header->e_shoff);
|
||||
spdlog::info(" flags ............: {:#010x}\n", m_elf_header->e_flags);
|
||||
spdlog::info(" ehsize ...........: {}\n", m_elf_header->e_ehsize);
|
||||
spdlog::info(" phentsize ........: {}\n", m_elf_header->e_phentsize);
|
||||
spdlog::info(" phnum ............: {}\n", m_elf_header->e_phnum);
|
||||
spdlog::info(" shentsize ........: {}\n", m_elf_header->e_shentsize);
|
||||
spdlog::info(" shnum ............: {}\n", m_elf_header->e_shnum);
|
||||
spdlog::info(" shstrndx .........: {}\n", m_elf_header->e_shstrndx);
|
||||
|
||||
if (m_elf_header->e_phentsize > 0)
|
||||
{
|
||||
|
@ -50,16 +50,6 @@ constexpr u08 ELFMAG1 = 'E';
|
||||
constexpr u08 ELFMAG2 = 'L';
|
||||
constexpr u08 ELFMAG3 = 'F';
|
||||
|
||||
//other ident fields , only ps4 neccesary ones
|
||||
constexpr u08 ELFCLASS64 = 2;
|
||||
constexpr u08 ELFDATA2LSB = 1;
|
||||
constexpr u08 ELFOSABI_FREEBSD = 9; // FreeBSD
|
||||
constexpr u08 ELFABIVERSION_AMDGPU_HSA_V2 = 0;
|
||||
|
||||
//type fields PS4 specific
|
||||
constexpr u16 ET_DYNEXEC = 0xFE10; // Executable file
|
||||
constexpr u16 ET_DYNAMIC = 0xFE18; // Shared
|
||||
|
||||
typedef enum : u16 {
|
||||
ET_NONE = 0x0,
|
||||
ET_REL = 0x1,
|
||||
@ -171,9 +161,68 @@ typedef enum :u32 {
|
||||
EV_CURRENT = 0x1
|
||||
} e_version_es;
|
||||
|
||||
typedef enum : u08 {
|
||||
ELF_CLASS_NONE =0x0,
|
||||
ELF_CLASS_32 =0x1,
|
||||
ELF_CLASS_64 =0x2,
|
||||
ELF_CLASS_NUM =0x3
|
||||
} ident_class_es;
|
||||
|
||||
typedef enum : u08 {
|
||||
ELF_DATA_NONE = 0x0,
|
||||
ELF_DATA_2LSB = 0x1,
|
||||
ELF_DATA_2MSB = 0x2,
|
||||
ELF_DATA_NUM = 0x3
|
||||
} ident_endian_es;
|
||||
|
||||
typedef enum :u08 {
|
||||
ELF_VERSION_NONE = 0x0,
|
||||
ELF_VERSION_CURRENT = 0x1,
|
||||
ELF_VERSION_NUM = 0x2
|
||||
} ident_version_es;
|
||||
|
||||
typedef enum :u08 {
|
||||
ELF_OSABI_NONE = 0x0, /* No extensions or unspecified */
|
||||
ELF_OSABI_HPUX = 0x1, /* Hewlett-Packard HP-UX */
|
||||
ELF_OSABI_NETBSD = 0x2, /* NetBSD */
|
||||
ELF_OSABI_LINUX = 0x3, /* Linux */
|
||||
ELF_OSABI_SOLARIS = 0x6, /* Sun Solaris */
|
||||
ELF_OSABI_AIX = 0x7, /* AIX */
|
||||
ELF_OSABI_IRIX = 0x8, /* IRIX */
|
||||
ELF_OSABI_FREEBSD = 0x9, /* FreeBSD (PS4) */
|
||||
ELF_OSABI_TRU64 = 0xA, /* Compaq TRU64 UNIX */
|
||||
ELF_OSABI_MODESTO = 0xB, /* Novell Modesto */
|
||||
ELF_OSABI_OPENBSD = 0xC, /* Open BSD */
|
||||
ELF_OSABI_OPENVMS = 0xD, /* Open VMS */
|
||||
ELF_OSABI_NSK = 0xE, /* Hewlett-Packard Non-Stop Kernel */
|
||||
ELF_OSABI_AROS = 0xF, /* Amiga Research OS */
|
||||
ELF_OSABI_ARM_AEABI = 0x40, /* ARM EABI */
|
||||
ELF_OSABI_ARM = 0x61, /* ARM */
|
||||
ELF_OSABI_STANDALONE = 0xFF /* Standalone (embedded applications) */
|
||||
} ident_osabi_es;
|
||||
|
||||
typedef enum :u08 {
|
||||
ELF_ABI_VERSION_AMDGPU_HSA_V2=0x0,
|
||||
ELF_ABI_VERSION_AMDGPU_HSA_V3=0x1,
|
||||
ELF_ABI_VERSION_AMDGPU_HSA_V4=0x2,
|
||||
ELF_ABI_VERSION_AMDGPU_HSA_V5=0x3
|
||||
} ident_abiversion_es;
|
||||
|
||||
struct elf_ident {
|
||||
u08 magic[4];
|
||||
ident_class_es ei_class;
|
||||
ident_endian_es ei_data;
|
||||
ident_version_es ei_version;
|
||||
ident_osabi_es ei_osabi;
|
||||
ident_abiversion_es ei_abiversion;
|
||||
u08 pad[6];
|
||||
};
|
||||
|
||||
struct elf_header
|
||||
{
|
||||
u08 e_ident[16]; /* ELF identification */
|
||||
static const u32 signature = 0x7F454C46u;
|
||||
|
||||
elf_ident e_ident; /* ELF identification */
|
||||
e_type_s e_type; /* Object file type */
|
||||
e_machine_es e_machine; /* Machine type */
|
||||
e_version_es e_version; /* Object file version */
|
||||
|
Loading…
Reference in New Issue
Block a user