mirror of
https://github.com/libretro/Play-.git
synced 2024-12-13 20:22:25 +00:00
git-svn-id: http://svn.purei.org/purei/trunk@153 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
parent
f0c904f881
commit
e7a02f3461
224
Source/ELF.cpp
224
Source/ELF.cpp
@ -1,112 +1,112 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <exception>
|
#include <stdexcept>
|
||||||
#include "ELF.h"
|
#include "ELF.h"
|
||||||
|
|
||||||
using namespace Framework;
|
using namespace Framework;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
CELF::CELF(CStream* pS)
|
CELF::CELF(CStream* pS)
|
||||||
{
|
{
|
||||||
unsigned int nCount, i;
|
unsigned int nCount, i;
|
||||||
|
|
||||||
pS->Seek(0, STREAM_SEEK_END);
|
pS->Seek(0, STREAM_SEEK_END);
|
||||||
m_nLenght = (unsigned int)pS->Tell();
|
m_nLenght = (unsigned int)pS->Tell();
|
||||||
|
|
||||||
m_pData = new char[m_nLenght];
|
m_pData = new char[m_nLenght];
|
||||||
pS->Seek(0, STREAM_SEEK_SET);
|
pS->Seek(0, STREAM_SEEK_SET);
|
||||||
pS->Read(m_pData, m_nLenght);
|
pS->Read(m_pData, m_nLenght);
|
||||||
|
|
||||||
pS->Seek(0, STREAM_SEEK_SET);
|
pS->Seek(0, STREAM_SEEK_SET);
|
||||||
pS->Read(&m_Header, sizeof(ELFHEADER));
|
pS->Read(&m_Header, sizeof(ELFHEADER));
|
||||||
|
|
||||||
if(m_Header.nId[0] != 0x7F || m_Header.nId[1] != 'E' || m_Header.nId[2] != 'L' || m_Header.nId[3] != 'F')
|
if(m_Header.nId[0] != 0x7F || m_Header.nId[1] != 'E' || m_Header.nId[2] != 'L' || m_Header.nId[3] != 'F')
|
||||||
{
|
{
|
||||||
throw exception("This file isn't a valid ELF file.");
|
throw runtime_error("This file isn't a valid ELF file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_Header.nId[4] != 1 || m_Header.nId[5] != 1)
|
if(m_Header.nId[4] != 1 || m_Header.nId[5] != 1)
|
||||||
{
|
{
|
||||||
throw exception("This ELF file format is not supported. Only 32-bits LSB ordered ELFs are supported.");
|
throw runtime_error("This ELF file format is not supported. Only 32-bits LSB ordered ELFs are supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
nCount = m_Header.nProgHeaderCount;
|
nCount = m_Header.nProgHeaderCount;
|
||||||
m_pProgram = new ELFPROGRAMHEADER[nCount];
|
m_pProgram = new ELFPROGRAMHEADER[nCount];
|
||||||
|
|
||||||
pS->Seek(m_Header.nProgHeaderStart, STREAM_SEEK_SET);
|
pS->Seek(m_Header.nProgHeaderStart, STREAM_SEEK_SET);
|
||||||
for(i = 0; i < nCount; i++)
|
for(i = 0; i < nCount; i++)
|
||||||
{
|
{
|
||||||
pS->Read(&m_pProgram[i], sizeof(ELFPROGRAMHEADER));
|
pS->Read(&m_pProgram[i], sizeof(ELFPROGRAMHEADER));
|
||||||
}
|
}
|
||||||
|
|
||||||
nCount = m_Header.nSectHeaderCount;
|
nCount = m_Header.nSectHeaderCount;
|
||||||
m_pSection = new ELFSECTIONHEADER[nCount];
|
m_pSection = new ELFSECTIONHEADER[nCount];
|
||||||
|
|
||||||
pS->Seek(m_Header.nSectHeaderStart, STREAM_SEEK_SET);
|
pS->Seek(m_Header.nSectHeaderStart, STREAM_SEEK_SET);
|
||||||
for(i = 0; i < nCount; i++)
|
for(i = 0; i < nCount; i++)
|
||||||
{
|
{
|
||||||
pS->Read(&m_pSection[i], sizeof(ELFSECTIONHEADER));
|
pS->Read(&m_pSection[i], sizeof(ELFSECTIONHEADER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CELF::~CELF()
|
CELF::~CELF()
|
||||||
{
|
{
|
||||||
delete [] m_pProgram;
|
delete [] m_pProgram;
|
||||||
delete [] m_pSection;
|
delete [] m_pSection;
|
||||||
delete [] m_pData;
|
delete [] m_pData;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFSECTIONHEADER* CELF::GetSection(unsigned int nIndex)
|
ELFSECTIONHEADER* CELF::GetSection(unsigned int nIndex)
|
||||||
{
|
{
|
||||||
if(nIndex >= m_Header.nSectHeaderCount)
|
if(nIndex >= m_Header.nSectHeaderCount)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return &m_pSection[nIndex];
|
return &m_pSection[nIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* CELF::GetSectionData(unsigned int nIndex)
|
const void* CELF::GetSectionData(unsigned int nIndex)
|
||||||
{
|
{
|
||||||
ELFSECTIONHEADER* pSect;
|
ELFSECTIONHEADER* pSect;
|
||||||
pSect = GetSection(nIndex);
|
pSect = GetSection(nIndex);
|
||||||
if(pSect == NULL) return NULL;
|
if(pSect == NULL) return NULL;
|
||||||
return (const uint8*)m_pData + pSect->nOffset;
|
return (const uint8*)m_pData + pSect->nOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void* CELF::FindSectionData(const char* sName)
|
const void* CELF::FindSectionData(const char* sName)
|
||||||
{
|
{
|
||||||
ELFSECTIONHEADER* pSect;
|
ELFSECTIONHEADER* pSect;
|
||||||
pSect = FindSection(sName);
|
pSect = FindSection(sName);
|
||||||
if(pSect == NULL) return NULL;
|
if(pSect == NULL) return NULL;
|
||||||
return (const uint8*)m_pData + pSect->nOffset;
|
return (const uint8*)m_pData + pSect->nOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFSECTIONHEADER* CELF::FindSection(const char* sName)
|
ELFSECTIONHEADER* CELF::FindSection(const char* sName)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
ELFSECTIONHEADER* pTemp;
|
ELFSECTIONHEADER* pTemp;
|
||||||
const char* sSectData;
|
const char* sSectData;
|
||||||
const char* sSectName;
|
const char* sSectName;
|
||||||
|
|
||||||
sSectData = (const char*)GetSectionData(m_Header.nSectHeaderStringTableIndex);
|
sSectData = (const char*)GetSectionData(m_Header.nSectHeaderStringTableIndex);
|
||||||
if(sSectData == NULL) return NULL;
|
if(sSectData == NULL) return NULL;
|
||||||
for(i = 0; i < m_Header.nSectHeaderCount; i++)
|
for(i = 0; i < m_Header.nSectHeaderCount; i++)
|
||||||
{
|
{
|
||||||
pTemp = GetSection(i);
|
pTemp = GetSection(i);
|
||||||
sSectName = sSectData + pTemp->nStringTableIndex;
|
sSectName = sSectData + pTemp->nStringTableIndex;
|
||||||
if(!strcmp(sName, sSectName))
|
if(!strcmp(sName, sSectName))
|
||||||
{
|
{
|
||||||
return pTemp;
|
return pTemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELFPROGRAMHEADER* CELF::GetProgram(unsigned int nIndex)
|
ELFPROGRAMHEADER* CELF::GetProgram(unsigned int nIndex)
|
||||||
{
|
{
|
||||||
if(nIndex >= m_Header.nProgHeaderCount)
|
if(nIndex >= m_Header.nProgHeaderCount)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return &m_pProgram[nIndex];
|
return &m_pProgram[nIndex];
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public:
|
|||||||
const void* FindSectionData(const char*);
|
const void* FindSectionData(const char*);
|
||||||
ELFPROGRAMHEADER* GetProgram(unsigned int);
|
ELFPROGRAMHEADER* GetProgram(unsigned int);
|
||||||
ELFHEADER m_Header;
|
ELFHEADER m_Header;
|
||||||
void* m_pData;
|
char* m_pData;
|
||||||
int m_nLenght;
|
int m_nLenght;
|
||||||
private:
|
private:
|
||||||
ELFSECTIONHEADER* m_pSection;
|
ELFSECTIONHEADER* m_pSection;
|
||||||
|
Loading…
Reference in New Issue
Block a user