forked from CTCaer/hekate
hos: simplify emummc patch
This commit is contained in:
parent
dca350bfe9
commit
547cfca0c9
@ -442,6 +442,8 @@ static int _kipm_inject(const char *kipm_path, char *target_name, pkg2_kip1_info
|
|||||||
|
|
||||||
const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
||||||
{
|
{
|
||||||
|
bool emummc_patch_selected = false;
|
||||||
|
|
||||||
if (patch_names == NULL || patch_names[0] == 0)
|
if (patch_names == NULL || patch_names[0] == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -500,7 +502,15 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
// Parse external patches if needed.
|
// Parse external patches if needed.
|
||||||
for (u32 i = 0; i < patches_num; i++)
|
for (u32 i = 0; i < patches_num; i++)
|
||||||
{
|
{
|
||||||
if (strcmp(patches[i], "emummc") && strcmp(patches[i], "nogc"))
|
if (!strcmp(patches[i], "emummc"))
|
||||||
|
{
|
||||||
|
// emuMMC patch is managed on its own.
|
||||||
|
emummc_patch_selected = true;
|
||||||
|
patches_applied |= BIT(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(patches[i], "nogc"))
|
||||||
{
|
{
|
||||||
parse_external_kip_patches();
|
parse_external_kip_patches();
|
||||||
break;
|
break;
|
||||||
@ -513,6 +523,8 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
// Reset hash so it can be calculated for the new kip.
|
// Reset hash so it can be calculated for the new kip.
|
||||||
kip_hash[0] = 0;
|
kip_hash[0] = 0;
|
||||||
|
|
||||||
|
bool emummc_patch_apply = emummc_patch_selected && !strcmp((char *)ki->kip1->name, "FS");
|
||||||
|
|
||||||
// Check all SHA256 ID sets. (IDs are grouped per KIP. IDs are still unique.)
|
// Check all SHA256 ID sets. (IDs are grouped per KIP. IDs are still unique.)
|
||||||
for (u32 kip_id_idx = 0; kip_id_idx < _kip_id_sets_cnt; kip_id_idx++)
|
for (u32 kip_id_idx = 0; kip_id_idx < _kip_id_sets_cnt; kip_id_idx++)
|
||||||
{
|
{
|
||||||
@ -538,7 +550,7 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't bother hashing this KIP if no patches are enabled for it.
|
// Don't bother hashing this KIP if no patches are enabled for it.
|
||||||
if (!patches_found)
|
if (!patches_found && !emummc_patch_apply)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check if current KIP not hashed and hash it.
|
// Check if current KIP not hashed and hash it.
|
||||||
@ -562,9 +574,6 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
if (strcmp(patchset->name, patches[patch_idx]))
|
if (strcmp(patchset->name, patches[patch_idx]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!strcmp(patchset->name, "emummc"))
|
|
||||||
sections_affected |= BIT(GET_KIP_PATCH_SECTION(patchset->patches->offset));
|
|
||||||
|
|
||||||
for (const kip1_patch_t *patch = patchset->patches; patch != NULL && (patch->length != 0); patch++)
|
for (const kip1_patch_t *patch = patchset->patches; patch != NULL && (patch->length != 0); patch++)
|
||||||
sections_affected |= BIT(GET_KIP_PATCH_SECTION(patch->offset));
|
sections_affected |= BIT(GET_KIP_PATCH_SECTION(patch->offset));
|
||||||
}
|
}
|
||||||
@ -572,13 +581,16 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
patchset++;
|
patchset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If emuMMC is enabled, set its affected section.
|
||||||
|
if (emummc_patch_apply)
|
||||||
|
sections_affected |= BIT(KIP_TEXT);
|
||||||
|
|
||||||
// Got patches to apply to this kip, have to decompress it.
|
// Got patches to apply to this kip, have to decompress it.
|
||||||
if (_decompress_kip(ki, sections_affected))
|
if (_decompress_kip(ki, sections_affected))
|
||||||
return (char *)ki->kip1->name; // Failed to decompress.
|
return (char *)ki->kip1->name; // Failed to decompress.
|
||||||
|
|
||||||
// Apply all patches from matched ID.
|
// Apply all patches for matched ID.
|
||||||
patchset = _kip_id_sets[kip_id_idx].patchset;
|
patchset = _kip_id_sets[kip_id_idx].patchset;
|
||||||
bool emummc_patch_selected = false;
|
|
||||||
while (patchset != NULL && patchset->name != NULL)
|
while (patchset != NULL && patchset->name != NULL)
|
||||||
{
|
{
|
||||||
for (u32 patch_idx = 0; patch_idx < patches_num; patch_idx++)
|
for (u32 patch_idx = 0; patch_idx < patches_num; patch_idx++)
|
||||||
@ -589,14 +601,6 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
|
|
||||||
u32 applied_mask = BIT(patch_idx);
|
u32 applied_mask = BIT(patch_idx);
|
||||||
|
|
||||||
if (!strcmp(patchset->name, "emummc"))
|
|
||||||
{
|
|
||||||
emummc_patch_selected = true;
|
|
||||||
patches_applied |= applied_mask;
|
|
||||||
|
|
||||||
continue; // Patching is done later.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if patchset is empty.
|
// Check if patchset is empty.
|
||||||
if (patchset->patches == NULL)
|
if (patchset->patches == NULL)
|
||||||
{
|
{
|
||||||
@ -652,7 +656,8 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
patchset++;
|
patchset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emummc_patch_selected && !strcmp((char *)_kip_id_sets[kip_id_idx].name, "FS"))
|
// emuMMC must be applied after all other patches, since it affects TEXT offset.
|
||||||
|
if (emummc_patch_apply)
|
||||||
{
|
{
|
||||||
// Encode ID.
|
// Encode ID.
|
||||||
emu_cfg.fs_ver = kip_id_idx;
|
emu_cfg.fs_ver = kip_id_idx;
|
||||||
@ -668,6 +673,7 @@ const char *pkg2_patch_kips(link_t *info, char *patch_names)
|
|||||||
|
|
||||||
// Skip checking again.
|
// Skip checking again.
|
||||||
emummc_patch_selected = false;
|
emummc_patch_selected = false;
|
||||||
|
emummc_patch_apply = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -448,14 +448,8 @@ static const pkg2_kernel_id_t _pkg2_kernel_ids[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
// All kip patch offsets are without the 0x100-sized header.
|
// All kip patch offsets are without the 0x100-sized header.
|
||||||
static kip1_patch_t _fs_emummc[] = {
|
|
||||||
{ KPS(KIP_TEXT) | 1, 0, "", "" },
|
|
||||||
{ 0, 0, NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
static kip1_patchset_t _fs_patches_100[] = {
|
static kip1_patchset_t _fs_patches_100[] = {
|
||||||
{ "nogc", NULL },
|
{ "nogc", NULL },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -467,7 +461,6 @@ static kip1_patch_t _fs_nogc_40x[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_40x[] = {
|
static kip1_patchset_t _fs_patches_40x[] = {
|
||||||
{ "nogc", _fs_nogc_40x },
|
{ "nogc", _fs_nogc_40x },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -479,7 +472,6 @@ static kip1_patch_t _fs_nogc_410[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_410[] = {
|
static kip1_patchset_t _fs_patches_410[] = {
|
||||||
{ "nogc", _fs_nogc_410 },
|
{ "nogc", _fs_nogc_410 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -491,7 +483,6 @@ static kip1_patch_t _fs_nogc_50x[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_50x[] = {
|
static kip1_patchset_t _fs_patches_50x[] = {
|
||||||
{ "nogc", _fs_nogc_50x },
|
{ "nogc", _fs_nogc_50x },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -503,7 +494,6 @@ static kip1_patch_t _fs_nogc_510[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_510[] = {
|
static kip1_patchset_t _fs_patches_510[] = {
|
||||||
{ "nogc", _fs_nogc_510 },
|
{ "nogc", _fs_nogc_510 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -521,13 +511,11 @@ static kip1_patch_t _fs_nogc_600_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_600[] = {
|
static kip1_patchset_t _fs_patches_600[] = {
|
||||||
{ "nogc", _fs_nogc_600 },
|
{ "nogc", _fs_nogc_600 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static kip1_patchset_t _fs_patches_600_exfat[] = {
|
static kip1_patchset_t _fs_patches_600_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_600_exfat },
|
{ "nogc", _fs_nogc_600_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -545,13 +533,11 @@ static kip1_patch_t _fs_nogc_700_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_700[] = {
|
static kip1_patchset_t _fs_patches_700[] = {
|
||||||
{ "nogc", _fs_nogc_700 },
|
{ "nogc", _fs_nogc_700 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static kip1_patchset_t _fs_patches_700_exfat[] = {
|
static kip1_patchset_t _fs_patches_700_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_700_exfat },
|
{ "nogc", _fs_nogc_700_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -569,13 +555,11 @@ static kip1_patch_t _fs_nogc_800_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_800[] = {
|
static kip1_patchset_t _fs_patches_800[] = {
|
||||||
{ "nogc", _fs_nogc_800 },
|
{ "nogc", _fs_nogc_800 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static kip1_patchset_t _fs_patches_800_exfat[] = {
|
static kip1_patchset_t _fs_patches_800_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_800_exfat },
|
{ "nogc", _fs_nogc_800_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -587,7 +571,6 @@ static kip1_patch_t _fs_nogc_900[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_900[] = {
|
static kip1_patchset_t _fs_patches_900[] = {
|
||||||
{ "nogc", _fs_nogc_900 },
|
{ "nogc", _fs_nogc_900 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -599,7 +582,6 @@ static kip1_patch_t _fs_nogc_910[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_910[] = {
|
static kip1_patchset_t _fs_patches_910[] = {
|
||||||
{ "nogc", _fs_nogc_910 },
|
{ "nogc", _fs_nogc_910 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -611,7 +593,6 @@ static kip1_patch_t _fs_nogc_1000[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1000[] = {
|
static kip1_patchset_t _fs_patches_1000[] = {
|
||||||
{ "nogc", _fs_nogc_1000 },
|
{ "nogc", _fs_nogc_1000 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -623,7 +604,6 @@ static kip1_patch_t _fs_nogc_1020[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1020[] = {
|
static kip1_patchset_t _fs_patches_1020[] = {
|
||||||
{ "nogc", _fs_nogc_1020 },
|
{ "nogc", _fs_nogc_1020 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -635,7 +615,6 @@ static kip1_patch_t _fs_nogc_1100[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1100[] = {
|
static kip1_patchset_t _fs_patches_1100[] = {
|
||||||
{ "nogc", _fs_nogc_1100 },
|
{ "nogc", _fs_nogc_1100 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -647,7 +626,6 @@ static kip1_patch_t _fs_nogc_1200[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1200[] = {
|
static kip1_patchset_t _fs_patches_1200[] = {
|
||||||
{ "nogc", _fs_nogc_1200 },
|
{ "nogc", _fs_nogc_1200 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -659,7 +637,6 @@ static kip1_patch_t _fs_nogc_1203[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1203[] = {
|
static kip1_patchset_t _fs_patches_1203[] = {
|
||||||
{ "nogc", _fs_nogc_1203 },
|
{ "nogc", _fs_nogc_1203 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -671,7 +648,6 @@ static kip1_patch_t _fs_nogc_1300[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1300[] = {
|
static kip1_patchset_t _fs_patches_1300[] = {
|
||||||
{ "nogc", _fs_nogc_1300 },
|
{ "nogc", _fs_nogc_1300 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -683,7 +659,6 @@ static kip1_patch_t _fs_nogc_1310[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1310[] = {
|
static kip1_patchset_t _fs_patches_1310[] = {
|
||||||
{ "nogc", _fs_nogc_1310 },
|
{ "nogc", _fs_nogc_1310 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -695,7 +670,6 @@ static kip1_patch_t _fs_nogc_1400[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1400[] = {
|
static kip1_patchset_t _fs_patches_1400[] = {
|
||||||
{ "nogc", _fs_nogc_1400 },
|
{ "nogc", _fs_nogc_1400 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -707,7 +681,6 @@ static kip1_patch_t _fs_nogc_1400_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1400_exfat[] = {
|
static kip1_patchset_t _fs_patches_1400_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_1400_exfat },
|
{ "nogc", _fs_nogc_1400_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -719,7 +692,6 @@ static kip1_patch_t _fs_nogc_1500[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1500[] = {
|
static kip1_patchset_t _fs_patches_1500[] = {
|
||||||
{ "nogc", _fs_nogc_1500 },
|
{ "nogc", _fs_nogc_1500 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -731,7 +703,6 @@ static kip1_patch_t _fs_nogc_1500_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1500_exfat[] = {
|
static kip1_patchset_t _fs_patches_1500_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_1500_exfat },
|
{ "nogc", _fs_nogc_1500_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -743,7 +714,6 @@ static kip1_patch_t _fs_nogc_1600[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1600[] = {
|
static kip1_patchset_t _fs_patches_1600[] = {
|
||||||
{ "nogc", _fs_nogc_1600 },
|
{ "nogc", _fs_nogc_1600 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -755,7 +725,6 @@ static kip1_patch_t _fs_nogc_1600_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1600_exfat[] = {
|
static kip1_patchset_t _fs_patches_1600_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_1600_exfat },
|
{ "nogc", _fs_nogc_1600_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -767,7 +736,6 @@ static kip1_patch_t _fs_nogc_1603[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1603[] = {
|
static kip1_patchset_t _fs_patches_1603[] = {
|
||||||
{ "nogc", _fs_nogc_1603 },
|
{ "nogc", _fs_nogc_1603 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -779,7 +747,6 @@ static kip1_patch_t _fs_nogc_1603_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1603_exfat[] = {
|
static kip1_patchset_t _fs_patches_1603_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_1603_exfat },
|
{ "nogc", _fs_nogc_1603_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -791,7 +758,6 @@ static kip1_patch_t _fs_nogc_1700[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1700[] = {
|
static kip1_patchset_t _fs_patches_1700[] = {
|
||||||
{ "nogc", _fs_nogc_1700 },
|
{ "nogc", _fs_nogc_1700 },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -803,7 +769,6 @@ static kip1_patch_t _fs_nogc_1700_exfat[] = {
|
|||||||
|
|
||||||
static kip1_patchset_t _fs_patches_1700_exfat[] = {
|
static kip1_patchset_t _fs_patches_1700_exfat[] = {
|
||||||
{ "nogc", _fs_nogc_1700_exfat },
|
{ "nogc", _fs_nogc_1700_exfat },
|
||||||
{ "emummc", _fs_emummc },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user