2011-12-12 07:52:50 +01:00
|
|
|
#include "dol.h"
|
|
|
|
|
|
|
|
Dol::Dol( const QByteArray &dol ) : dh( NULL )
|
|
|
|
{
|
|
|
|
if( (quint32)dol.size() > sizeof( Dolheader ) )
|
|
|
|
{
|
|
|
|
Parse( dol );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Dol::Parse( const QByteArray &dol )
|
|
|
|
{
|
|
|
|
dh = NULL;
|
|
|
|
text.clear();
|
|
|
|
data.clear();
|
|
|
|
|
|
|
|
if( (quint32)dol.size() < sizeof( Dolheader ) )
|
|
|
|
{
|
|
|
|
WRN << "dol.size() < sizeof( Dolheader )";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
headerBuf = dol.left( sizeof( Dolheader ) );
|
|
|
|
dh = reinterpret_cast< Dolheader * >( headerBuf.data() );
|
|
|
|
if( !dh )
|
|
|
|
{
|
|
|
|
WRN << "!dh";
|
|
|
|
return false;
|
|
|
|
}
|
2024-07-20 13:36:42 +02:00
|
|
|
//DBG << Qt::hex << (*(dh->entrypoint));
|
2011-12-12 07:52:50 +01:00
|
|
|
|
|
|
|
for( quint32 i = 0; i < 7; i ++ )
|
|
|
|
{
|
|
|
|
quint32 fileOff = (*(dh->offsetText[ i ] ) );
|
|
|
|
quint32 len = (*(dh->sizeText[ i ] ) );
|
|
|
|
quint32 addr = (*(dh->addressText[ i ] ) );
|
|
|
|
if( !fileOff || !len || !addr )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( fileOff + len > (quint32) dol.size() )
|
|
|
|
{
|
2024-07-20 13:36:42 +02:00
|
|
|
WRN << "text section is out of range:" << i << Qt::hex << fileOff << len;
|
2011-12-12 07:52:50 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DolSection sec;
|
|
|
|
sec.addr = addr;
|
|
|
|
sec.data = dol.mid( fileOff, len );
|
|
|
|
|
|
|
|
text << sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( quint32 i = 0; i < 11; i ++ )
|
|
|
|
{
|
|
|
|
quint32 fileOff = (*(dh->offsetData[ i ] ) );
|
|
|
|
quint32 len = (*(dh->sizeData[ i ] ) );
|
|
|
|
quint32 addr = (*(dh->addressData[ i ] ) );
|
|
|
|
if( !fileOff || !len || !addr )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( fileOff + len > (quint32) dol.size() )
|
|
|
|
{
|
2024-07-20 13:36:42 +02:00
|
|
|
WRN << "data section is out of range:" << i << Qt::hex << fileOff << len;
|
2011-12-12 07:52:50 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DolSection sec;
|
|
|
|
sec.addr = addr;
|
|
|
|
sec.data = dol.mid( fileOff, len );
|
|
|
|
|
|
|
|
data << sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dol Dol::FakeDol( const QByteArray &mem, quint32 loadAddress )
|
|
|
|
{
|
|
|
|
Dol ret;
|
|
|
|
DolSection sec;
|
|
|
|
sec.addr = loadAddress;
|
|
|
|
sec.data = mem;
|
|
|
|
ret.text << sec;
|
|
|
|
return ret;
|
|
|
|
}
|