Fixed a few issues related to encrypted PRXes

This commit is contained in:
Arthur Blot 2012-11-05 16:54:35 +01:00
parent ac910d7e75
commit d0542e3531
4 changed files with 51 additions and 33 deletions

View File

@ -51,7 +51,7 @@ void addrToHiLo(u32 addr, u16 &hi, s16 &lo)
}
bool ElfReader::LoadInto(u32 vaddr)
bool ElfReader::LoadInto(u32 loadAddress)
{
DEBUG_LOG(LOADER,"String section: %i", header->e_shstrndx);
@ -89,8 +89,8 @@ bool ElfReader::LoadInto(u32 vaddr)
}
}
u32 totalSize = totalEnd - totalStart;
if (vaddr)
vaddr = userMemory.AllocAt(vaddr, totalSize, "ELF");
if (loadAddress)
vaddr = userMemory.AllocAt(loadAddress, totalSize, "ELF");
else
vaddr = userMemory.Alloc(totalSize, false, "ELF");
@ -110,7 +110,6 @@ bool ElfReader::LoadInto(u32 vaddr)
for (int i=0; i<header->e_phnum; i++)
{
Elf32_Phdr *p = segments + i;
INFO_LOG(LOADER, "p = %p", p);
DEBUG_LOG(LOADER, "Type: %i Vaddr: %08x Filesz: %i Memsz: %i ", (int)p->p_type, (u32)p->p_vaddr, (int)p->p_filesz, (int)p->p_memsz);
if (p->p_type == PT_LOAD)

View File

@ -41,6 +41,7 @@ class ElfReader
u32 *sectionAddrs;
bool bRelocate;
u32 entryPoint;
u32 vaddr;
public:
ElfReader(void *ptr)
{
@ -107,6 +108,12 @@ public:
bool DidRelocate() {
return bRelocate;
}
u32 GetVaddr()
{
return vaddr;
}
// More indepth stuff:)
bool LoadInto(u32 vaddr);
bool LoadSymbols();

View File

@ -600,11 +600,6 @@ static int DecryptPRX2(const u8 *inbuf, u8 *outbuf, u32 size, u32 tag)
return -2;
}
if (((size_t)(void*)outbuf & 0x3F))
{
return -3;
}
if ((size - 0x150) < retsize)
{
return -4;

View File

@ -145,20 +145,28 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
u8 *newptr = 0;
if (*(u32*)ptr == 0x5053507e) { // "~PSP"
// Decrypt module! YAY!
INFO_LOG(HLE, "Decrypting ~PSP file");
PSP_Header *head = (PSP_Header*)ptr;
const u8 *in = ptr;
newptr = new u8[std::max(head->elf_size, head->psp_size) + 0x40];
ptr = (u8*)(((size_t)(newptr + 0x3F) & ~0x3F));
pspDecryptPRX(in, (u8*)ptr, head->psp_size);
// Decrypt module! YAY!
INFO_LOG(HLE, "Decrypting ~PSP file");
PSP_Header *head = (PSP_Header*)ptr;
const u8 *in = ptr;
u32 size = head->elf_size;
if (head->psp_size > size)
{
size = head->psp_size;
}
newptr = new u8[head->elf_size + head->psp_size];
ptr = newptr;
pspDecryptPRX(in, (u8*)ptr, head->psp_size);
}
if (*(u32*)ptr != 0x464c457f)
{
ERROR_LOG(HLE, "Wrong magic number %08x",*(u32*)ptr);
*error_string = "File corrupt";
delete [] newptr;
if (newptr)
{
delete [] newptr;
}
kernelObjects.Destroy<Module>(module->GetUID());
return 0;
}
@ -168,7 +176,10 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
if (!reader.LoadInto(loadAddress))
{
ERROR_LOG(HLE, "LoadInto failed");
delete [] newptr;
if (newptr)
{
delete [] newptr;
}
kernelObjects.Destroy<Module>(module->GetUID());
return 0;
}
@ -203,34 +214,37 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
if (sceModuleInfoSection != -1)
modinfo = (PspModuleInfo *)Memory::GetPointer(reader.GetSectionAddr(sceModuleInfoSection));
else
modinfo = (PspModuleInfo *)reader.GetPtr(reader.GetSegmentPaddr(0) + reader.GetSegmentOffset(0));
modinfo = (PspModuleInfo *)Memory::GetPointer(reader.GetVaddr() + (reader.GetSegmentPaddr(0) & 0x7FFFFFFF) - reader.GetSegmentOffset(0));
bool hasSymbols = false;
bool dontadd = false;
SectionID textSection = reader.GetSectionByName(".text");
u32 textStart = reader.GetSectionAddr(textSection);
u32 textSize = reader.GetSectionSize(textSection);
if (textSection != -1)
{
u32 textStart = reader.GetSectionAddr(textSection);
u32 textSize = reader.GetSectionSize(textSection);
if (!host->AttemptLoadSymbolMap())
{
hasSymbols = reader.LoadSymbols();
if (!hasSymbols)
if (!host->AttemptLoadSymbolMap())
{
symbolMap.ResetSymbolMap();
MIPSAnalyst::ScanForFunctions(textStart, textStart+textSize);
hasSymbols = reader.LoadSymbols();
if (!hasSymbols)
{
symbolMap.ResetSymbolMap();
MIPSAnalyst::ScanForFunctions(textStart, textStart+textSize);
}
}
else
{
dontadd = true;
}
}
else
{
dontadd = true;
}
module->gp_value = modinfo->gp;
strncpy(module->name, modinfo->name, 28);
DEBUG_LOG(LOADER,"Module %s: %08x %08x %08x", modinfo->name, modinfo->gp, modinfo->libent,modinfo->libstub);
INFO_LOG(LOADER,"Module %s: %08x %08x %08x", modinfo->name, modinfo->gp, modinfo->libent,modinfo->libstub);
struct PspLibStubEntry
{
@ -343,7 +357,10 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
module->entry_addr = reader.GetEntryPoint();
delete [] newptr;
if (newptr)
{
delete [] newptr;
}
return module;
}