Skip to content

Commit

Permalink
Added support for new style PRX files which are missing section heade…
Browse files Browse the repository at this point in the history
…rs (>= 3.50)
  • Loading branch information
tyranid committed Jun 30, 2007
1 parent 7516db6 commit 5415c9d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 13 deletions.
68 changes: 63 additions & 5 deletions ProcessElf.C
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,7 @@ bool CProcessElf::BuildBinaryImage()
assert(m_iElfSize > 0);
assert(m_pElfBin == NULL);
assert(m_iBinSize == 0);
assert(m_pElfSections != NULL);
assert(m_iSHCount != 0);


/* Find the maximum and minimum addresses */
for(iLoop = 0; iLoop < m_iSHCount; iLoop++)
{
Expand All @@ -500,7 +498,7 @@ bool CProcessElf::BuildBinaryImage()
}
}

COutput::Printf(LEVEL_DEBUG, "Min Address %08X, Max Address %08X, Max Sizs %d\n",
COutput::Printf(LEVEL_DEBUG, "Min Address %08X, Max Address %08X, Max Size %d\n",
iMinAddr, iMaxAddr, iMaxSize);

if(iMinAddr != 0xFFFFFFFF)
Expand Down Expand Up @@ -594,7 +592,67 @@ bool CProcessElf::LoadSections()
}
else
{
COutput::Puts(LEVEL_DEBUG, "No section headers in ELF file");
/* If we have no section headers let's build some fake sections */
if(m_iSHCount == 0)
{
if(m_iPHCount < 3)
{
COutput::Printf(LEVEL_ERROR, "Invalid number of program headers for newstyle PRX (%d)\n",
m_iPHCount);
return false;
}

/* Allocate 5 section entries */
SAFE_ALLOC(m_pElfSections, ElfSection[5]);
if(m_pElfSections == NULL)
{
return false;
}
m_iSHCount = 5;

memset(m_pElfSections, 0, sizeof(ElfSection) * 5);

m_pElfSections[1].iType = SHT_PROGBITS;
m_pElfSections[1].iFlags = SHF_ALLOC | SHF_EXECINSTR;
m_pElfSections[1].iAddr = m_pElfPrograms[0].iVaddr;
m_pElfSections[1].pData = m_pElf + m_pElfPrograms[0].iOffset;
m_pElfSections[1].iSize = m_pElfPrograms[0].iFilesz;
strcpy(m_pElfSections[1].szName, ".text");

m_pElfSections[2].iType = SHT_PROGBITS;
m_pElfSections[2].iFlags = SHF_ALLOC;
m_pElfSections[2].iAddr = m_pElfPrograms[1].iVaddr;
m_pElfSections[2].pData = m_pElf + m_pElfPrograms[1].iOffset;
m_pElfSections[2].iSize = m_pElfPrograms[1].iFilesz;
strcpy(m_pElfSections[2].szName, ".data");

m_pElfSections[3].iType = SHT_NOBITS;
m_pElfSections[3].iFlags = SHF_ALLOC;
m_pElfSections[3].iAddr = m_pElfPrograms[1].iVaddr + m_pElfPrograms[1].iFilesz;
m_pElfSections[3].pData = m_pElf + m_pElfPrograms[1].iOffset + m_pElfPrograms[1].iFilesz;
m_pElfSections[3].iSize = m_pElfPrograms[1].iMemsz - m_pElfPrograms[1].iFilesz;
strcpy(m_pElfSections[3].szName, ".bss");

m_pElfSections[4].iType = SHT_PRXRELOC;
m_pElfSections[4].iFlags = 0;
m_pElfSections[4].iAddr = 0;
m_pElfSections[4].pData = m_pElf + m_pElfPrograms[2].iOffset;
m_pElfSections[4].iSize = m_pElfPrograms[2].iFilesz;
/* Bind to section 1, not that is matters */
m_pElfSections[4].iInfo = 1;
strcpy(m_pElfSections[4].szName, ".reloc");

if(COutput::GetDebug())
{
ElfDumpSections();
}

blRet = true;
}
else
{
COutput::Puts(LEVEL_DEBUG, "No section headers in ELF file");
}
}

return blRet;
Expand Down
35 changes: 28 additions & 7 deletions ProcessPrx.C
Original file line number Diff line number Diff line change
Expand Up @@ -466,19 +466,18 @@ bool CProcessPrx::LoadExports()
return blRet;
}

bool CProcessPrx::FillModule(ElfSection *pInfoSect)
bool CProcessPrx::FillModule(u8 *pData, u32 iAddr)
{
bool blRet = false;
assert(pInfoSect != NULL);

if(pInfoSect->pData != NULL)
if(pData != NULL)
{
PspModuleInfo *pModInfo;

pModInfo = (PspModuleInfo*) pInfoSect->pData;
pModInfo = (PspModuleInfo*) pData;
memcpy(m_modInfo.name, pModInfo->name, PSP_MODULE_MAX_NAME);
m_modInfo.name[PSP_MODULE_MAX_NAME] = 0;
m_modInfo.addr = pInfoSect->iAddr;
m_modInfo.addr = iAddr;
memcpy(&m_modInfo.info, pModInfo, sizeof(PspModuleInfo));
m_modInfo.info.flags = LW(m_modInfo.info.flags);
m_modInfo.info.gp = LW(m_modInfo.info.gp);
Expand Down Expand Up @@ -592,22 +591,44 @@ bool CProcessPrx::LoadFromFile(const char *szFilename)
{
/* Do PRX specific stuff */
ElfSection *pInfoSect;
u8 *pData = NULL;
u32 iAddr = 0;

FreeMemory();
m_blPrxLoaded = false;

m_vMem = CVirtualMem(m_pElfBin, m_iBinSize, m_iBaseAddr, MEM_LITTLE_ENDIAN);

pInfoSect = ElfFindSection(PSP_MODULE_INFO_NAME);
if(pInfoSect != NULL)
if(pInfoSect == NULL)
{
/* Get from program headers */
if(m_iPHCount > 0)
{
iAddr = m_pElfPrograms[0].iVaddr + (m_pElfPrograms[0].iPaddr & 0x7FFFFFFF) - m_pElfPrograms[0].iOffset;
pData = m_pElfBin + iAddr;
}
}
else
{
if((FillModule(pInfoSect)) && (LoadExports()) && (LoadImports()) && (LoadRelocs()))
pData = pInfoSect->pData;
iAddr = pInfoSect->iAddr;
}

if(pData != NULL)
{
if((FillModule(pData, iAddr)) && (LoadExports()) && (LoadImports()) && (LoadRelocs()))
{
COutput::Printf(LEVEL_INFO, "Loaded PRX %s successfully\n", szFilename);
blRet = true;
m_blPrxLoaded = true;
BuildMaps();
}
}
else
{
COutput::Printf(LEVEL_ERROR, "Could not find module section\n");
}
}

return blRet;
Expand Down
2 changes: 1 addition & 1 deletion ProcessPrx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CProcessPrx : public CProcessElf
u32 m_dwBase;
bool m_blXmlDump;

bool FillModule(ElfSection *pInfoSect);
bool FillModule(u8 *pData, u32 iAddr);
void FreeMemory();
int LoadSingleImport(PspModuleImport *pImport, u32 addr);
bool LoadImports();
Expand Down

0 comments on commit 5415c9d

Please sign in to comment.