some more work on self format

This commit is contained in:
georgemoralis 2023-03-28 19:21:34 +03:00
parent 9c3e9b3bef
commit 76cbb5eb11
3 changed files with 66 additions and 24 deletions

View File

@ -15,5 +15,66 @@ void Elf::Open(const std::string& file_name)
m_f->Open(file_name, fsOpenMode::fsRead); m_f->Open(file_name, fsOpenMode::fsRead);
m_self = load_self(*m_f); m_self = load_self(*m_f);
if (!isSelfFile())
{
delete m_self;
m_self = nullptr;
m_f->Seek(0,fsSeekMode::fsSeekSet); //it is not an self file move to the start of file
}
DebugDump();
}
bool Elf::isSelfFile() const
{
if (m_f == nullptr)
{
return false;
}
if (m_self == nullptr)
{
return false;//if we can't load self header return false
}
if (m_self->magic != self_header::signature)
{
printf("Not a SELF file. Magic file mismatched! current = 0x%08X required = 0x%08X\n", m_self->magic, self_header::signature);
return false;
}
if (m_self->version != 0x00 || m_self->mode != 0x01 || m_self->endian != 0x01 || m_self->attributes != 0x12)
{
printf("Unknown SELF file\n");
return false;
}
if (m_self->category != 0x01 || m_self->program_type != 0x01)
{
printf("Unknown SELF file\n");
return false;
}
return true;
}
void Elf::DebugDump() {
printf("SELF header:\n");
printf(" magic ..............: 0x%08X\n", m_self->magic);
printf(" version .........: %d\n", m_self->version);
printf(" mode .........: 0x%X\n", m_self->mode);
printf(" endian .........: %d\n", m_self->endian);
printf(" attributes .........: 0x%X\n", m_self->attributes);
printf(" category .........: 0x%X\n", m_self->category);
printf(" program_type........: 0x%X\n", m_self->program_type);
printf(" padding1 ...........: 0x%04X\n", m_self->padding1);
printf(" header size ........: 0x%X\n", m_self->header_size);
printf(" meta size .....: 0x%X\n", m_self->meta_size);
printf(" file size ..........: 0x%X\n", m_self->file_size);
printf(" padding2 ...........: 0x%08X\n", m_self->padding2);
printf(" segment count ......: %u\n", m_self->segment_count);
printf(" unknown 1A .........: 0x%04X\n", m_self->unknown1A);
printf(" padding3 ...........: 0x%04X\n", m_self->padding3);
printf("\n");
} }

View File

@ -36,7 +36,8 @@ class Elf
{ {
public: public:
void Open(const std::string & file_name); void Open(const std::string & file_name);
bool isSelfFile() const;
void DebugDump();
private: private:
FsFile* m_f = nullptr; FsFile* m_f = nullptr;
self_header* m_self = nullptr; self_header* m_self = nullptr;

View File

@ -11,7 +11,7 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
const char* const path = "eboot.bin";//argv[1]; //argument 1 is the path of self file to boot const char* const path = argv[1]; //argument 1 is the path of self file to boot
auto handle = fopen(path, "rb"); auto handle = fopen(path, "rb");
if (handle == nullptr) if (handle == nullptr)
@ -28,32 +28,12 @@ int main(int argc, char* argv[])
return 3; return 3;
} }
if (header.magic != self_header::signature)
{
printf("Not a SELF file.\n");
fclose(handle);
return 4;
}
Elf* elf = new Elf; Elf* elf = new Elf;
elf->Open(path); elf->Open(path);
printf("SELF header:\n");
printf(" magic ..............: 0x%08X\n", header.magic);
printf(" version .........: %d\n", header.version);
printf(" mode .........: 0x%X\n", header.mode);
printf(" endian .........: %d\n", header.endian);
printf(" attributes .........: 0x%X\n", header.attributes);
printf(" category .........: 0x%X\n", header.category);
printf(" program_type........: 0x%X\n", header.program_type);
printf(" header size ........: 0x%X\n", header.header_size);
printf(" meta size .....: 0x%X\n", header.meta_size);
printf(" file size ..........: 0x%X\n", header.file_size);
printf(" padding2 ...........: 0x%08X\n", header.padding2);
printf(" segment count ......: %u\n", header.segment_count);
printf(" unknown 1A .........: 0x%04X\n", header.unknown1A);
printf(" padding3 ...........: 0x%04X\n", header.padding3);
printf("\n");
auto segment_headers = (self_segment_header*)malloc(sizeof(self_segment_header) * header.segment_count); auto segment_headers = (self_segment_header*)malloc(sizeof(self_segment_header) * header.segment_count);
if (fread(segment_headers, sizeof(self_segment_header), header.segment_count, handle) != header.segment_count) if (fread(segment_headers, sizeof(self_segment_header), header.segment_count, handle) != header.segment_count)