hos: automatically find new kernel ini1 offset

This commit is contained in:
CTCaer 2019-09-12 23:37:00 +03:00
parent 3b16b086f8
commit 658c3c112f
7 changed files with 46 additions and 16 deletions

View file

@ -219,8 +219,9 @@ void dump_packages12()
u32 ini1_size = pkg2_hdr->sec_size[PKG2_SEC_INI1]; u32 ini1_size = pkg2_hdr->sec_size[PKG2_SEC_INI1];
if (!ini1_size) if (!ini1_size)
{ {
ini1_off = *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_START); pkg2_get_newkern_info(pkg2_hdr->data);
ini1_size = *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_END) - *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_START); ini1_off = pkg2_newkern_ini1_start;
ini1_size = pkg2_newkern_ini1_end - pkg2_newkern_ini1_start;
} }
if (sd_save_to_file(pkg2_hdr->data + ini1_off, ini1_size, path)) if (sd_save_to_file(pkg2_hdr->data + ini1_off, ini1_size, path))
goto out; goto out;

View file

@ -570,7 +570,7 @@ DPRINTF("Generated keys\n");
se_calc_sha256(kernel_hash, ctxt.kernel, ctxt.kernel_size); se_calc_sha256(kernel_hash, ctxt.kernel, ctxt.kernel_size);
else else
se_calc_sha256(kernel_hash, ctxt.kernel + PKG2_NEWKERN_START, se_calc_sha256(kernel_hash, ctxt.kernel + PKG2_NEWKERN_START,
*(u32 *)(ctxt.kernel + PKG2_NEWKERN_INI1_START) - PKG2_NEWKERN_START); pkg2_newkern_ini1_start - PKG2_NEWKERN_START);
ctxt.pkg2_kernel_id = pkg2_identify(kernel_hash); ctxt.pkg2_kernel_id = pkg2_identify(kernel_hash);
if (!ctxt.pkg2_kernel_id) if (!ctxt.pkg2_kernel_id)

View file

@ -617,14 +617,24 @@ static u32 _pkg2_calc_kip1_size(pkg2_kip1_t *kip1)
return size; return size;
} }
void pkg2_get_newkern_info(u8 *kern_data)
{
u32 info_op = *(u32 *)(kern_data + PKG2_NEWKERN_GET_INI1);
pkg2_newkern_ini1_val = ((info_op & 0xFFFF) >> 3) + PKG2_NEWKERN_GET_INI1; // Parse ADR and PC.
pkg2_newkern_ini1_start = *(u32 *)(kern_data + pkg2_newkern_ini1_val);
pkg2_newkern_ini1_end = *(u32 *)(kern_data + pkg2_newkern_ini1_val + 0x8);
}
void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2) void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2)
{ {
u8 *ptr; u8 *ptr;
// Check for new pkg2 type. // Check for new pkg2 type.
if (!pkg2->sec_size[PKG2_SEC_INI1]) if (!pkg2->sec_size[PKG2_SEC_INI1])
{ {
u32 kernel_ini1_off = *(u32 *)(pkg2->data + PKG2_NEWKERN_INI1_START); pkg2_get_newkern_info(pkg2->data);
ptr = pkg2->data + kernel_ini1_off;
ptr = pkg2->data + pkg2_newkern_ini1_start;
*new_pkg2 = true; *new_pkg2 = true;
} }
else else
@ -1121,7 +1131,7 @@ DPRINTF("kernel @ %08X (%08X)\n", (u32)kernel, kernel_size);
else else
{ {
// Set new INI1 offset to kernel. // Set new INI1 offset to kernel.
*(u32 *)(pdst + PKG2_NEWKERN_INI1_START) = kernel_size; *(u32 *)(pdst + pkg2_newkern_ini1_val) = kernel_size;
kernel_size += _pkg2_ini1_build(pdst + kernel_size, hdr, kips_info, new_pkg2); kernel_size += _pkg2_ini1_build(pdst + kernel_size, hdr, kips_info, new_pkg2);
hdr->sec_off[PKG2_SEC_KERNEL] = 0x60000; hdr->sec_off[PKG2_SEC_KERNEL] = 0x60000;
} }

View file

@ -27,9 +27,12 @@
#define PKG2_SEC_INI1 1 #define PKG2_SEC_INI1 1
#define INI1_MAGIC 0x31494E49 #define INI1_MAGIC 0x31494E49
#define PKG2_NEWKERN_INI1_START 0x168 #define PKG2_NEWKERN_GET_INI1 0x44
#define PKG2_NEWKERN_INI1_END 0x170 #define PKG2_NEWKERN_START 0x800
#define PKG2_NEWKERN_START 0x800
u32 pkg2_newkern_ini1_val;
u32 pkg2_newkern_ini1_start;
u32 pkg2_newkern_ini1_end;
typedef struct _kernel_patch_t typedef struct _kernel_patch_t
{ {
@ -139,6 +142,7 @@ typedef struct _kip1_id_t
kip1_patchset_t* patchset; kip1_patchset_t* patchset;
} kip1_id_t; } kip1_id_t;
void pkg2_get_newkern_info(u8 *kern_data);
void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2); void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2);
int pkg2_has_kip(link_t *info, u64 tid); int pkg2_has_kip(link_t *info, u64 tid);
void pkg2_replace_kip(link_t *info, u64 tid, pkg2_kip1_t *kip1); void pkg2_replace_kip(link_t *info, u64 tid, pkg2_kip1_t *kip1);

View file

@ -546,8 +546,9 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
u32 ini1_size = pkg2_hdr->sec_size[PKG2_SEC_INI1]; u32 ini1_size = pkg2_hdr->sec_size[PKG2_SEC_INI1];
if (!ini1_size) if (!ini1_size)
{ {
ini1_off = *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_START); pkg2_get_newkern_info(pkg2_hdr->data);
ini1_size = *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_END) - *(u32 *)(pkg2_hdr->data + PKG2_NEWKERN_INI1_START); ini1_off = pkg2_newkern_ini1_start;
ini1_size = pkg2_newkern_ini1_end - pkg2_newkern_ini1_start;
} }
pkg2_ini1_t *ini1 = (pkg2_ini1_t *)(pkg2_hdr->data + ini1_off); pkg2_ini1_t *ini1 = (pkg2_ini1_t *)(pkg2_hdr->data + ini1_off);
emmcsn_path_impl(path, "/pkg2", "ini1.bin", &storage); emmcsn_path_impl(path, "/pkg2", "ini1.bin", &storage);

View file

@ -41,14 +41,24 @@ u32 pkg2_calc_kip1_size(pkg2_kip1_t *kip1)
return size; return size;
} }
void pkg2_get_newkern_info(u8 *kern_data)
{
u32 info_op = *(u32 *)(kern_data + PKG2_NEWKERN_GET_INI1);
pkg2_newkern_ini1_val = ((info_op & 0xFFFF) >> 3) + PKG2_NEWKERN_GET_INI1; // Parse ADR and PC.
pkg2_newkern_ini1_start = *(u32 *)(kern_data + pkg2_newkern_ini1_val);
pkg2_newkern_ini1_end = *(u32 *)(kern_data + pkg2_newkern_ini1_val + 0x8);
}
void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2) void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2)
{ {
u8 *ptr; u8 *ptr;
// Check for new pkg2 type. // Check for new pkg2 type.
if (!pkg2->sec_size[PKG2_SEC_INI1]) if (!pkg2->sec_size[PKG2_SEC_INI1])
{ {
u32 kernel_ini1_off = *(u32 *)(pkg2->data + PKG2_NEWKERN_INI1_START); pkg2_get_newkern_info(pkg2->data);
ptr = pkg2->data + kernel_ini1_off;
ptr = pkg2->data + pkg2_newkern_ini1_start;
*new_pkg2 = true; *new_pkg2 = true;
} }
else else

View file

@ -27,9 +27,12 @@
#define PKG2_SEC_INI1 1 #define PKG2_SEC_INI1 1
#define INI1_MAGIC 0x31494E49 #define INI1_MAGIC 0x31494E49
#define PKG2_NEWKERN_INI1_START 0x168 #define PKG2_NEWKERN_GET_INI1 0x44
#define PKG2_NEWKERN_INI1_END 0x170 #define PKG2_NEWKERN_START 0x800
#define PKG2_NEWKERN_START 0x800
u32 pkg2_newkern_ini1_val;
u32 pkg2_newkern_ini1_start;
u32 pkg2_newkern_ini1_end;
typedef struct _pkg2_hdr_t typedef struct _pkg2_hdr_t
{ {
@ -86,6 +89,7 @@ typedef struct _pkg2_kip1_info_t
link_t link; link_t link;
} pkg2_kip1_info_t; } pkg2_kip1_info_t;
void pkg2_get_newkern_info(u8 *kern_data);
u32 pkg2_calc_kip1_size(pkg2_kip1_t *kip1); u32 pkg2_calc_kip1_size(pkg2_kip1_t *kip1);
void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2); void pkg2_parse_kips(link_t *info, pkg2_hdr_t *pkg2, bool *new_pkg2);