2012-11-15 00:39:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
#include "Loader.h"
|
|
|
|
|
|
2014-08-25 16:56:13 +02:00
|
|
|
struct vfsStream;
|
|
|
|
|
class rFile;
|
|
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
struct Elf64_Ehdr
|
|
|
|
|
{
|
|
|
|
|
u32 e_magic;
|
|
|
|
|
u8 e_class;
|
|
|
|
|
u8 e_data;
|
|
|
|
|
u8 e_curver;
|
|
|
|
|
u8 e_os_abi;
|
|
|
|
|
u64 e_abi_ver;
|
|
|
|
|
u16 e_type;
|
|
|
|
|
u16 e_machine;
|
|
|
|
|
u32 e_version;
|
|
|
|
|
u64 e_entry;
|
|
|
|
|
u64 e_phoff;
|
|
|
|
|
u64 e_shoff;
|
|
|
|
|
u32 e_flags;
|
|
|
|
|
u16 e_ehsize;
|
|
|
|
|
u16 e_phentsize;
|
|
|
|
|
u16 e_phnum;
|
|
|
|
|
u16 e_shentsize;
|
|
|
|
|
u16 e_shnum;
|
|
|
|
|
u16 e_shstrndx;
|
|
|
|
|
|
2014-08-23 22:40:04 +02:00
|
|
|
void Load(vfsStream& f);
|
|
|
|
|
|
|
|
|
|
void Show();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
bool CheckMagic() const { return e_magic == 0x7F454C46; }
|
2014-08-30 20:35:18 +02:00
|
|
|
u64 GetEntry() const { return e_entry; }
|
2012-11-15 00:39:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Elf64_Shdr
|
|
|
|
|
{
|
|
|
|
|
u32 sh_name;
|
|
|
|
|
u32 sh_type;
|
|
|
|
|
u64 sh_flags;
|
|
|
|
|
u64 sh_addr;
|
|
|
|
|
u64 sh_offset;
|
|
|
|
|
u64 sh_size;
|
|
|
|
|
u32 sh_link;
|
|
|
|
|
u32 sh_info;
|
|
|
|
|
u64 sh_addralign;
|
|
|
|
|
u64 sh_entsize;
|
|
|
|
|
|
2014-08-23 22:40:04 +02:00
|
|
|
void Load(vfsStream& f);
|
|
|
|
|
|
|
|
|
|
void Show();
|
2012-11-15 00:39:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Elf64_Phdr
|
|
|
|
|
{
|
|
|
|
|
u32 p_type;
|
|
|
|
|
u32 p_flags;
|
|
|
|
|
u64 p_offset;
|
|
|
|
|
u64 p_vaddr;
|
|
|
|
|
u64 p_paddr;
|
|
|
|
|
u64 p_filesz;
|
|
|
|
|
u64 p_memsz;
|
|
|
|
|
u64 p_align;
|
|
|
|
|
|
2014-08-23 22:40:04 +02:00
|
|
|
void Load(vfsStream& f);
|
|
|
|
|
|
|
|
|
|
void Show();
|
2012-11-15 00:39:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ELF64Loader : public LoaderBase
|
|
|
|
|
{
|
2013-06-30 10:46:29 +02:00
|
|
|
vfsStream& elf64_f;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Elf64_Ehdr ehdr;
|
2014-04-01 02:33:55 +02:00
|
|
|
std::vector<std::string> shdr_name_arr;
|
2014-04-10 00:54:32 +02:00
|
|
|
std::vector<Elf64_Shdr> shdr_arr;
|
|
|
|
|
std::vector<Elf64_Phdr> phdr_arr;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
ELF64Loader(vfsStream& f);
|
2012-11-15 00:39:56 +01:00
|
|
|
~ELF64Loader() {Close();}
|
|
|
|
|
|
|
|
|
|
virtual bool LoadInfo();
|
2013-06-30 10:46:29 +02:00
|
|
|
virtual bool LoadData(u64 offset = 0);
|
2012-11-15 00:39:56 +01:00
|
|
|
virtual bool Close();
|
|
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
bool LoadEhdrInfo(s64 offset=-1);
|
|
|
|
|
bool LoadPhdrInfo(s64 offset=-1);
|
|
|
|
|
bool LoadShdrInfo(s64 offset=-1);
|
|
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
private:
|
2013-06-30 10:46:29 +02:00
|
|
|
bool LoadEhdrData(u64 offset);
|
|
|
|
|
bool LoadPhdrData(u64 offset);
|
|
|
|
|
bool LoadShdrData(u64 offset);
|
|
|
|
|
|
|
|
|
|
//bool LoadImports();
|
2013-07-03 18:17:16 +02:00
|
|
|
};
|
|
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
void WriteEhdr(rFile& f, Elf64_Ehdr& ehdr);
|
|
|
|
|
void WritePhdr(rFile& f, Elf64_Phdr& phdr);
|
|
|
|
|
void WriteShdr(rFile& f, Elf64_Shdr& shdr);
|