Fix elf64 unself and style nits

This commit is contained in:
ggf906 2018-01-05 12:23:46 +01:00
commit 97c6d8407a
3 changed files with 95 additions and 58 deletions

View file

@ -101,9 +101,6 @@ void WriteEhdr(const fs::file& f, Elf64_Ehdr& ehdr)
Write8(f, ehdr.e_os_abi); Write8(f, ehdr.e_os_abi);
Write64(f, ehdr.e_abi_ver); Write64(f, ehdr.e_abi_ver);
Write16(f, ehdr.e_type); Write16(f, ehdr.e_type);
if(ehdr.e_data==1)
Write16LE(f, ehdr.e_machine);
else
Write16(f, ehdr.e_machine); Write16(f, ehdr.e_machine);
Write32(f, ehdr.e_version); Write32(f, ehdr.e_version);
Write64(f, ehdr.e_entry); Write64(f, ehdr.e_entry);
@ -423,7 +420,6 @@ void ControlInfo::LoadLE(const fs::file& f)
{ {
f.read(type7.unk, 0x40); f.read(type7.unk, 0x40);
} }
} }
void ControlInfo::Show() void ControlInfo::Show()
@ -1039,14 +1035,19 @@ SELFDecrypter::SELFDecrypter(const fs::file& s)
{ {
} }
static bool isVita(const SceHeader hdr)
{
return (hdr.se_hver == 3);
}
bool SELFDecrypter::LoadHeaders(bool isElf32) bool SELFDecrypter::LoadHeaders(bool isElf32)
{ {
// Read SCE header. // Read SCE header.
self_f.seek(0); self_f.seek(0);
sce_hdr.LoadLE(self_f); sce_hdr.LoadLE(self_f);
const bool isVita = sce_hdr.se_hver == 3;
if (!isVita) { if (!isVita(sce_hdr))
{
self_f.seek(0); self_f.seek(0);
sce_hdr.Load(self_f); sce_hdr.Load(self_f);
} }
@ -1059,18 +1060,26 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
} }
// Read SELF header. // Read SELF header.
if(!isVita) if (!isVita(sce_hdr))
{
self_hdr.Load(self_f); self_hdr.Load(self_f);
}
else else
{
self_hdr.LoadLE(self_f); self_hdr.LoadLE(self_f);
}
// Read the APP INFO. // Read the APP INFO.
self_f.seek(self_hdr.se_appinfooff); self_f.seek(self_hdr.se_appinfooff);
if(!isVita) if (!isVita(sce_hdr))
{
app_info.Load(self_f); app_info.Load(self_f);
}
else else
{
app_info.LoadLE(self_f); app_info.LoadLE(self_f);
}
// Read ELF header. // Read ELF header.
self_f.seek(self_hdr.se_elfoff); self_f.seek(self_hdr.se_elfoff);
@ -1093,12 +1102,16 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
for(u32 i = 0; i < elf32_hdr.e_phnum; ++i) for(u32 i = 0; i < elf32_hdr.e_phnum; ++i)
{ {
phdr32_arr.emplace_back(); phdr32_arr.emplace_back();
if(!isVita) if (!isVita(sce_hdr))
{
phdr32_arr.back().Load(self_f); phdr32_arr.back().Load(self_f);
}
else else
{
phdr32_arr.back().LoadLE(self_f); phdr32_arr.back().LoadLE(self_f);
} }
} }
}
else else
{ {
phdr64_arr.clear(); phdr64_arr.clear();
@ -1126,18 +1139,27 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
for(u32 i = 0; i < ((isElf32) ? elf32_hdr.e_phnum : elf64_hdr.e_phnum); ++i) for(u32 i = 0; i < ((isElf32) ? elf32_hdr.e_phnum : elf64_hdr.e_phnum); ++i)
{ {
secinfo_arr.emplace_back(); secinfo_arr.emplace_back();
if(!isVita) if (!isVita(sce_hdr))
{
secinfo_arr.back().Load(self_f); secinfo_arr.back().Load(self_f);
}
else else
{
secinfo_arr.back().LoadLE(self_f); secinfo_arr.back().LoadLE(self_f);
} }
}
// Read SCE version info. // Read SCE version info.
self_f.seek(self_hdr.se_sceveroff); self_f.seek(self_hdr.se_sceveroff);
if(!isVita) if (!isVita(sce_hdr))
{
scev_info.Load(self_f); scev_info.Load(self_f);
}
else else
{
scev_info.LoadLE(self_f); scev_info.LoadLE(self_f);
}
// Read control info. // Read control info.
ctrlinfo_arr.clear(); ctrlinfo_arr.clear();
self_f.seek(self_hdr.se_controloff); self_f.seek(self_hdr.se_controloff);
@ -1147,10 +1169,14 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
{ {
ctrlinfo_arr.emplace_back(); ctrlinfo_arr.emplace_back();
ControlInfo &cinfo = ctrlinfo_arr.back(); ControlInfo &cinfo = ctrlinfo_arr.back();
if(!isVita) if (!isVita(sce_hdr))
{
cinfo.Load(self_f); cinfo.Load(self_f);
}
else else
{
cinfo.LoadLE(self_f); cinfo.LoadLE(self_f);
}
i += cinfo.size; i += cinfo.size;
} }
@ -1170,12 +1196,16 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
for(u32 i = 0; i < elf32_hdr.e_shnum; ++i) for(u32 i = 0; i < elf32_hdr.e_shnum; ++i)
{ {
shdr32_arr.emplace_back(); shdr32_arr.emplace_back();
if (!isVita) if (!isVita(sce_hdr))
{
shdr32_arr.back().Load(self_f); shdr32_arr.back().Load(self_f);
}
else else
{
shdr32_arr.back().LoadLE(self_f); shdr32_arr.back().LoadLE(self_f);
} }
} }
}
else else
{ {
shdr64_arr.clear(); shdr64_arr.clear();
@ -1402,7 +1432,8 @@ bool SELFDecrypter::DecryptData()
} }
} }
if (meta_hdr.section_count == 0) { if (meta_hdr.section_count == 0)
{
for (unsigned int i = 0; i < secinfo_arr.size(); i++) for (unsigned int i = 0; i < secinfo_arr.size(); i++)
{ {
data_buf_length += secinfo_arr[i].size; data_buf_length += secinfo_arr[i].size;
@ -1456,7 +1487,8 @@ bool SELFDecrypter::DecryptData()
} }
} }
if (meta_hdr.section_count == 0) { if (meta_hdr.section_count == 0)
{
for (unsigned int i = 0; i < secinfo_arr.size(); i++) for (unsigned int i = 0; i < secinfo_arr.size(); i++)
{ {
self_f.seek(secinfo_arr[i].offset); self_f.seek(secinfo_arr[i].offset);
@ -1686,13 +1718,15 @@ static bool IsSelfElf32(const fs::file& f)
SelfHeader sh; SelfHeader sh;
hdr.LoadLE(f); hdr.LoadLE(f);
const bool isVita = hdr.se_hver == 3;
if (!isVita) { if (!isVita(hdr))
{
f.seek(0); f.seek(0);
hdr.Load(f); hdr.Load(f);
sh.Load(f); sh.Load(f);
}else{ }
else
{
sh.LoadLE(f); sh.LoadLE(f);
} }
@ -1726,7 +1760,9 @@ static bool CheckDebugSelf(fs::file& s)
const u16 version = s.read<le_t<u16>>(); const u16 version = s.read<le_t<u16>>();
if (version == 3) if (version == 3)
{
return false; return false;
}
LOG_WARNING(LOADER, "Debug SELF detected! Removing fake header..."); LOG_WARNING(LOADER, "Debug SELF detected! Removing fake header...");

View file

@ -652,15 +652,15 @@ void arm_load_exec(const arm_exec_object& elf)
else else
{ {
LOG_NOTICE(LOADER, "Loading libent at *0x%x", libent); LOG_NOTICE(LOADER, "Loading libent at *0x%x", libent);
LOG_NOTICE(LOADER, "** 0x%x, 0x%x", libent->version, libent->flags); LOG_NOTICE(LOADER, "** Version: 0x%x, Flags: 0x%x", libent->version, libent->flags);
LOG_NOTICE(LOADER, "** Functions: %u", libent->fcount); LOG_NOTICE(LOADER, "** Functions: %u", libent->fcount);
LOG_NOTICE(LOADER, "** Variables: %u", libent->vcount); LOG_NOTICE(LOADER, "** Variables: %u", libent->vcount);
LOG_NOTICE(LOADER, "** 0x%x, 0x%08x", libent->unk2, libent->module_nid); LOG_NOTICE(LOADER, "** 0x%x, Module NID: 0x%08x", libent->unk2, libent->module_nid);
const auto export_nids = vm::cptr<u32>::make(libent->nid_table); const auto export_nids = vm::cptr<u32>::make(libent->nid_table);
const auto export_data = vm::cptr<u32>::make(libent->entry_table); const auto export_data = vm::cptr<u32>::make(libent->entry_table);
LOG_NOTICE(LOADER, "** 0x%x, 0x%08x", export_data, export_nids); LOG_NOTICE(LOADER, "** Export Data: 0x%x, Export NIDs: 0x%08x", export_data, export_nids);
for (u32 i = 0, count = export_data - export_nids; i < count; i++) for (u32 i = 0, count = export_data - export_nids; i < count; i++)
{ {
@ -738,7 +738,7 @@ void arm_load_exec(const arm_exec_object& elf)
} }
} }
LOG_NOTICE(LOADER, "** 0x%x, 0x%x", libstub->version, libstub->flags); LOG_NOTICE(LOADER, "** Version: 0x%x, Flags: 0x%x", libstub->version, libstub->flags);
LOG_NOTICE(LOADER, "** Functions: %u", libstub->fcount); LOG_NOTICE(LOADER, "** Functions: %u", libstub->fcount);
LOG_NOTICE(LOADER, "** Variables: %u", libstub->vcount); LOG_NOTICE(LOADER, "** Variables: %u", libstub->vcount);
LOG_NOTICE(LOADER, "** 0x%x, 0x%08x", libstub->unk2, libstub->unk3); LOG_NOTICE(LOADER, "** 0x%x, 0x%08x", libstub->unk2, libstub->unk3);
@ -829,7 +829,8 @@ void arm_load_exec(const arm_exec_object& elf)
const auto libc_param = proc_param->sce_libcparam; const auto libc_param = proc_param->sce_libcparam;
if (libc_param) { if (libc_param)
{
LOG_NOTICE(LOADER, "__sce_libcparam(*0x%x) analysis...", libc_param); LOG_NOTICE(LOADER, "__sce_libcparam(*0x%x) analysis...", libc_param);

View file

@ -729,7 +729,7 @@ void Emulator::Load(bool add_only)
vm::ps3::init(); vm::ps3::init();
spu_load_exec(spu_exec); spu_load_exec(spu_exec);
} }
else if (arm_exec.open(elf_file, 0, elf_opt::no_sections + elf_opt::no_sections) == elf_error::ok) else if (arm_exec.open(elf_file, 0, + elf_opt::no_sections) == elf_error::ok)
{ {
// ARMv7 executable // ARMv7 executable
g_system = system_type::psv; g_system = system_type::psv;