mirror of
https://github.com/naehrwert/scetool.git
synced 2025-06-08 09:27:44 +00:00
Header parser fix
Minor update
This commit is contained in:
parent
7fa60e7590
commit
e5bb42387f
5 changed files with 93 additions and 42 deletions
Binary file not shown.
12
src/sce.cpp
12
src/sce.cpp
|
@ -233,9 +233,9 @@ sce_buffer_ctxt_t *sce_create_ctxt_from_buffer(u8 *scebuffer)
|
|||
res->self.ai = (app_info_t *)(res->scebuffer + _ES64(res->self.selfh->app_info_offset));
|
||||
|
||||
//Section infos.
|
||||
if (_ES64(res->self.selfh->section_info_offset) != NULL)
|
||||
if (_ES64(res->self.selfh->segment_info_offset) != NULL)
|
||||
{
|
||||
res->self.si = (section_info_t *)(res->scebuffer + _ES64(res->self.selfh->section_info_offset));
|
||||
res->self.si = (segment_info_t *)(res->scebuffer + _ES64(res->self.selfh->segment_info_offset));
|
||||
}
|
||||
else
|
||||
res->self.si = 0;
|
||||
|
@ -376,7 +376,7 @@ void sce_compress_data(sce_buffer_ctxt_t *ctxt)
|
|||
//Set compression in section info.
|
||||
if(_ES16(ctxt->cfh->category) == CF_CATEGORY_SELF && i < ctxt->makeself->si_sec_cnt)
|
||||
{
|
||||
ctxt->self.si[i].compressed = SECTION_INFO_COMPRESSED;
|
||||
ctxt->self.si[i].compressed = SEGMENT_INFO_COMPRESSED;
|
||||
//Update size too.
|
||||
ctxt->self.si[i].size = size_comp;
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ void _sce_fixup_ctxt(sce_buffer_ctxt_t *ctxt)
|
|||
ctxt->self.selfh->app_info_offset = _ES64(ctxt->off_self.off_ai);
|
||||
ctxt->self.selfh->elf_offset = _ES64(ctxt->off_self.off_ehdr);
|
||||
ctxt->self.selfh->phdr_offset = _ES64(ctxt->off_self.off_phdr);
|
||||
ctxt->self.selfh->section_info_offset = _ES64(ctxt->off_self.off_si);
|
||||
ctxt->self.selfh->segment_info_offset = _ES64(ctxt->off_self.off_si);
|
||||
ctxt->self.selfh->sce_version_offset = _ES64(ctxt->off_self.off_sv);
|
||||
ctxt->self.selfh->control_info_offset = _ES64(ctxt->off_self.off_cis);
|
||||
ctxt->self.selfh->control_info_size = _ES64(_sce_get_ci_len(ctxt));
|
||||
|
@ -557,7 +557,7 @@ void sce_layout_ctxt(sce_buffer_ctxt_t *ctxt)
|
|||
//ELF Program headers.
|
||||
ctxt->off_self.off_phdr = _INC_OFF_SIZE(coff, ctxt->makeself->phsize);
|
||||
//Section info.
|
||||
ctxt->off_self.off_si = _INC_OFF_SIZE(coff, sizeof(section_info_t) * ctxt->makeself->si_cnt);
|
||||
ctxt->off_self.off_si = _INC_OFF_SIZE(coff, sizeof(segment_info_t) * ctxt->makeself->si_cnt);
|
||||
//SCE version.
|
||||
ctxt->off_self.off_sv = _INC_OFF_TYPE(coff, sce_version_t);
|
||||
//Control infos.
|
||||
|
@ -637,7 +637,7 @@ static void _sce_build_header(sce_buffer_ctxt_t *ctxt)
|
|||
//Section info.
|
||||
u32 i;
|
||||
for(i = 0; i < ctxt->makeself->si_cnt; i++)
|
||||
_copy_es_section_info((section_info_t *)(ctxt->scebuffer + ctxt->off_self.off_si + sizeof(section_info_t) * i), &ctxt->self.si[i]);
|
||||
_copy_es_segment_info((segment_info_t *)(ctxt->scebuffer + ctxt->off_self.off_si + sizeof(segment_info_t) * i), &ctxt->self.si[i]);
|
||||
|
||||
//SCE version.
|
||||
memcpy((sce_version_t *)(ctxt->scebuffer + ctxt->off_self.off_sv), ctxt->self.sv, sizeof(sce_version_t));
|
||||
|
|
18
src/sce.h
18
src/sce.h
|
@ -118,9 +118,9 @@
|
|||
#define SIGNATURE_R_SIZE 21
|
||||
|
||||
/*! Compressed. */
|
||||
#define SECTION_INFO_COMPRESSED 2
|
||||
#define SEGMENT_INFO_COMPRESSED 2
|
||||
/*! Not compressed. */
|
||||
#define SECTION_INFO_NOT_COMPRESSED 1
|
||||
#define SEGMENT_INFO_NOT_COMPRESSED 1
|
||||
|
||||
/*! SCE version not present. */
|
||||
#define SCE_VERSION_NOT_PRESENT 0
|
||||
|
@ -192,8 +192,8 @@ typedef struct _self_header
|
|||
u64 phdr_offset;
|
||||
/*! Section headers offset. */
|
||||
u64 shdr_offset;
|
||||
/*! Section info offset. */
|
||||
u64 section_info_offset;
|
||||
/*! Segment info offset. */
|
||||
u64 segment_info_offset;
|
||||
/*! SCE version offset. */
|
||||
u64 sce_version_offset;
|
||||
/*! Control info offset. */
|
||||
|
@ -266,8 +266,8 @@ typedef struct _signature
|
|||
u8 padding[6];
|
||||
} signature_t;
|
||||
|
||||
/*! Section info. */
|
||||
typedef struct _section_info
|
||||
/*! Segment info. */
|
||||
typedef struct _segment_info
|
||||
{
|
||||
u64 offset;
|
||||
u64 size;
|
||||
|
@ -275,7 +275,7 @@ typedef struct _section_info
|
|||
u32 unknown_0;
|
||||
u32 unknown_1;
|
||||
u32 encrypted;
|
||||
} section_info_t;
|
||||
} segment_info_t;
|
||||
|
||||
/*! SCE version. */
|
||||
typedef struct _sce_version
|
||||
|
@ -498,7 +498,7 @@ typedef struct _sce_buffer_ctxt
|
|||
/*! Program info. */
|
||||
app_info_t *ai;
|
||||
/*! Section info. */
|
||||
section_info_t *si;
|
||||
segment_info_t *si;
|
||||
/*! SCE version. */
|
||||
sce_version_t *sv;
|
||||
/*! Control infos. */
|
||||
|
@ -538,7 +538,7 @@ typedef struct _sce_buffer_ctxt
|
|||
u32 off_ehdr;
|
||||
/*! Program header offset. */
|
||||
u32 off_phdr;
|
||||
/*! Section info offset. */
|
||||
/*! Segment info offset. */
|
||||
u32 off_si;
|
||||
/*! SCE version offset. */
|
||||
u32 off_sv;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "sce.h"
|
||||
|
||||
|
||||
static inline void _es_section_info(section_info_t *si)
|
||||
static inline void _es_segment_info(segment_info_t *si)
|
||||
{
|
||||
si->offset = _ES64(si->offset);
|
||||
si->size = _ES64(si->size);
|
||||
|
@ -22,10 +22,10 @@ static inline void _es_section_info(section_info_t *si)
|
|||
si->encrypted = _ES32(si->encrypted);
|
||||
}
|
||||
|
||||
static inline void _copy_es_section_info(section_info_t *dst, section_info_t *src)
|
||||
static inline void _copy_es_segment_info(segment_info_t *dst, segment_info_t *src)
|
||||
{
|
||||
memcpy(dst, src, sizeof(section_info_t));
|
||||
_es_section_info(dst);
|
||||
memcpy(dst, src, sizeof(segment_info_t));
|
||||
_es_segment_info(dst);
|
||||
}
|
||||
|
||||
static inline void _es_ci_data_digest_40(ci_data_digest_40_t *dig)
|
||||
|
|
89
src/self.cpp
89
src/self.cpp
|
@ -54,11 +54,29 @@ void _print_self_header(FILE *fp, self_header_t *h)
|
|||
fprintf(fp, " Program Info Offset 0x%016llX\n", _ES64(h->app_info_offset));
|
||||
fprintf(fp, " ELF Offset 0x%016llX\n", _ES64(h->elf_offset));
|
||||
fprintf(fp, " PH Offset 0x%016llX\n", _ES64(h->phdr_offset));
|
||||
|
||||
if ((_ES64(h->shdr_offset)) != 0)
|
||||
fprintf(fp, " SH Offset 0x%016llX\n", _ES64(h->shdr_offset));
|
||||
fprintf(fp, " Section Info Offset 0x%016llX\n", _ES64(h->section_info_offset));
|
||||
else
|
||||
fprintf(fp, " SH Offset N\\A\n");
|
||||
|
||||
fprintf(fp, " Segment Info Offset 0x%016llX\n", _ES64(h->segment_info_offset));
|
||||
|
||||
if ((_ES64(h->sce_version_offset)) != 0)
|
||||
fprintf(fp, " SCE Version Offset 0x%016llX\n", _ES64(h->sce_version_offset));
|
||||
else
|
||||
fprintf(fp, " SCE Version Offset N\\A\n");
|
||||
|
||||
if ((_ES64(h->control_info_offset)) != 0)
|
||||
{
|
||||
fprintf(fp, " Control Info Offset 0x%016llX\n", _ES64(h->control_info_offset));
|
||||
fprintf(fp, " Control Info Size 0x%016llX\n", _ES64(h->control_info_size));
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(fp, " Control Info Offset N\\A\n");
|
||||
fprintf(fp, " Control Info Size N\\A\n");
|
||||
}
|
||||
//fprintf(fp, " padding 0x%016llX\n", _ES64(h->padding));
|
||||
}
|
||||
|
||||
|
@ -103,13 +121,25 @@ void _print_app_info(FILE *fp, app_info_t *ai)
|
|||
//fprintf(fp, " padding 0x%016llX\n", _ES64(ai->padding));
|
||||
}
|
||||
|
||||
void _print_section_info_header(FILE *fp)
|
||||
void _print_segment_info_header_2(FILE *fp)
|
||||
{
|
||||
fprintf(fp, "[*] Section Infos:\n");
|
||||
fprintf(fp, "[*] Segment Infos:\n");
|
||||
fprintf(fp, " Idx Offset Size\n");
|
||||
}
|
||||
|
||||
void _print_segment_info_header_3(FILE *fp)
|
||||
{
|
||||
fprintf(fp, "[*] Segment Infos:\n");
|
||||
fprintf(fp, " Idx Offset Size Compressed unk0 unk1 Encrypted\n");
|
||||
}
|
||||
|
||||
void _print_section_info(FILE *fp, section_info_t *si, u32 idx)
|
||||
void _print_segment_info_2(FILE *fp, segment_info_t *si, u32 idx)
|
||||
{
|
||||
fprintf(fp, " %03d %08X %08X\n",
|
||||
idx, (u32)_ES64(si->offset), (u32)_ES64(si->size));
|
||||
}
|
||||
|
||||
void _print_segment_info_3(FILE *fp, segment_info_t *si, u32 idx)
|
||||
{
|
||||
fprintf(fp, " %03d %08X %08X %s %08X %08X %s\n",
|
||||
idx, (u32)_ES64(si->offset), (u32)_ES64(si->size), _ES32(si->compressed) == 2 ? "[YES]" : "[NO ]",
|
||||
|
@ -481,10 +511,22 @@ bool self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
//32 bit ELF.
|
||||
Elf32_Ehdr *eh = (Elf32_Ehdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset));
|
||||
|
||||
//Print section infos.
|
||||
_print_section_info_header(fp);
|
||||
//Print segment infos.
|
||||
|
||||
|
||||
if (_ES64(ctxt->self.selfh->header_type) == 3)
|
||||
_print_segment_info_header_3(fp);
|
||||
else
|
||||
_print_segment_info_header_2(fp);
|
||||
|
||||
for(i = 0; i < _ES16(eh->e_phnum); i++)
|
||||
_print_section_info(fp, &ctxt->self.si[i], i);
|
||||
{
|
||||
if (_ES64(ctxt->self.selfh->header_type) == 3)
|
||||
_print_segment_info_3(fp, &ctxt->self.si[i], i);
|
||||
else
|
||||
_print_segment_info_2(fp, &ctxt->self.si[i], i);
|
||||
}
|
||||
|
||||
|
||||
//Print ELF header.
|
||||
_print_elf32_ehdr(fp, eh);
|
||||
|
@ -511,12 +553,21 @@ bool self_print_info(FILE *fp, sce_buffer_ctxt_t *ctxt)
|
|||
//64 bit ELF.
|
||||
Elf64_Ehdr *eh = (Elf64_Ehdr *)(ctxt->scebuffer + _ES64(ctxt->self.selfh->elf_offset));
|
||||
|
||||
//Print section infos.
|
||||
//Print segment infos.
|
||||
if(ctxt->self.si != NULL)
|
||||
{
|
||||
_print_section_info_header(fp);
|
||||
if (_ES64(ctxt->self.selfh->header_type) == 3)
|
||||
_print_segment_info_header_3(fp);
|
||||
else
|
||||
_print_segment_info_header_2(fp);
|
||||
|
||||
for(i = 0; i < _ES16(eh->e_phnum); i++)
|
||||
_print_section_info(fp, &ctxt->self.si[i], i);
|
||||
{
|
||||
if (_ES64(ctxt->self.selfh->header_type) == 3)
|
||||
_print_segment_info_3(fp, &ctxt->self.si[i], i);
|
||||
else
|
||||
_print_segment_info_2(fp, &ctxt->self.si[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
//Print ELF header.
|
||||
|
@ -930,7 +981,7 @@ static void _add_phdr_section(sce_buffer_ctxt_t *ctxt, u32 p_type, u32 size, u32
|
|||
else
|
||||
ctxt->self.si[idx].encrypted = 0; //No LOAD (?).
|
||||
|
||||
ctxt->self.si[idx].compressed = SECTION_INFO_NOT_COMPRESSED;
|
||||
ctxt->self.si[idx].compressed = SEGMENT_INFO_NOT_COMPRESSED;
|
||||
ctxt->self.si[idx].unknown_0 = 0; //Unknown.
|
||||
ctxt->self.si[idx].unknown_1 = 0; //Unknown.
|
||||
}
|
||||
|
@ -983,8 +1034,8 @@ static bool _build_self_32(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
//Allocate metadata section headers (one for each program header and one for the section headers).
|
||||
ctxt->metash = (metadata_section_header_t *)malloc(sizeof(metadata_section_header_t) * (ehdr->e_phnum + 1));
|
||||
|
||||
//Copy sections, fill section infos and metadata section headers.
|
||||
ctxt->self.si = (section_info_t *)malloc(sizeof(section_info_t) * ehdr->e_phnum);
|
||||
//Copy segments, fill segment infos and metadata section headers.
|
||||
ctxt->self.si = (segment_info_t *)malloc(sizeof(segment_info_t) * ehdr->e_phnum);
|
||||
u32 loff = 0xFFFFFFFF, skip = 0;
|
||||
for(i = 0; i < ehdr->e_phnum; i++)
|
||||
{
|
||||
|
@ -1014,9 +1065,9 @@ static bool _build_self_32(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
loff = phdrs[i].p_offset;
|
||||
}
|
||||
|
||||
//Section info count.
|
||||
//Segment info count.
|
||||
ctxt->makeself->si_cnt = ehdr->e_phnum;
|
||||
//Number of section infos that are present as data sections.
|
||||
//Number of segment infos that are present as data sections.
|
||||
ctxt->makeself->si_sec_cnt = ehdr->e_phnum;
|
||||
|
||||
//Add a section for the section headers.
|
||||
|
@ -1061,8 +1112,8 @@ static bool _build_self_64(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
//Allocate metadata section headers (one for each program header and one for the section headers).
|
||||
ctxt->metash = (metadata_section_header_t *)malloc(sizeof(metadata_section_header_t) * (ehdr->e_phnum + 1));
|
||||
|
||||
//Copy sections, fill section infos and metadata section headers.
|
||||
ctxt->self.si = (section_info_t *)malloc(sizeof(section_info_t) * ehdr->e_phnum);
|
||||
//Copy segments, fill segment infos and metadata section headers.
|
||||
ctxt->self.si = (segment_info_t *)malloc(sizeof(segment_info_t) * ehdr->e_phnum);
|
||||
u32 loff = 0xFFFFFFFF, skip = 0;
|
||||
for(i = 0; i < ehdr->e_phnum; i++)
|
||||
{
|
||||
|
@ -1093,9 +1144,9 @@ static bool _build_self_64(sce_buffer_ctxt_t *ctxt, self_config_t *sconf)
|
|||
loff = phdrs[i].p_offset;
|
||||
}
|
||||
|
||||
//Section info count.
|
||||
//Segment info count.
|
||||
ctxt->makeself->si_cnt = ehdr->e_phnum;
|
||||
//Number of section infos that are present as data sections.
|
||||
//Number of segment infos that are present as data sections.
|
||||
ctxt->makeself->si_sec_cnt = i - skip;
|
||||
|
||||
//Add a section for the section headers.
|
||||
|
|
Loading…
Add table
Reference in a new issue