Skip to content

Commit

Permalink
check for ISFShax or defuse before erasing MLC
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-hofmeier committed Mar 2, 2024
1 parent 441a780 commit bc0ea13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/dump.c
Expand Up @@ -1827,6 +1827,11 @@ void dump_erase_mlc(void){
gfx_clear(GFX_ALL, BLACK);
printf("Erase MLC\n");

if(!isfs_slc_has_isfshax_installed() && !crypto_otp_is_de_Fused){
printf("MLC Erase not allowed!\nNeither ISFShax nor defuse is detected\nMLC erase would brick the consolse.");
goto erase_exit;
}

if (console_abort_confirmation_power_no_eject_yes())
goto erase_exit;

Expand Down Expand Up @@ -2055,6 +2060,19 @@ static void _dump_delete(const char* path){

static void _dump_delete_scfm(void){
gfx_clear(GFX_ALL, BLACK);

if(!isfs_slc_has_isfshax_installed() && !crypto_otp_is_de_Fused){
printf("STOP!!! Neither ISFShax nor defuse is detected\nContinuing will likely brick the consolse. You are probably doing something wrong.\nOnly continue if you really know what you are doing!");
if (console_abort_confirmation_power_no_eject_yes())
return;
printf("REALLY?\n");
if (console_abort_confirmation_power_no_eject_yes())
return;
printf("Are you really sure?\n");
if (console_abort_confirmation_power_no_eject_yes())
return;
}

_dump_delete("slc:/scfm.img");
}

Expand Down
6 changes: 6 additions & 0 deletions source/isfs.c
Expand Up @@ -609,6 +609,7 @@ static int _isfs_load_super(isfs_ctx* ctx){
if(read32((u32)ctx->super + ISFSHAX_INFO_OFFSET) == ISFSHAX_MAGIC){
// Iisfshax was found, only look for non isfshax generations to mount
max_generation = ISFSHAX_GENERATION_FIRST;
ctx->isfshax = true;
printf("ISFShax detected\n");
}
}
Expand Down Expand Up @@ -867,6 +868,10 @@ int isfs_dirclose(isfs_dir* dir)
return 0;
}

bool isfs_slc_has_isfshax_installed(void){
return isfs[ISFSVOL_SLC].isfshax;
}

int isfs_init(void)
{
for(int i = 0; i < _isfs_num_volumes(); i++)
Expand Down Expand Up @@ -906,6 +911,7 @@ int isfs_fini(void)

RemoveDevice(ctx->name);
ctx->mounted = false;
ctx->isfshax = false;
}

initialized = false;
Expand Down
3 changes: 3 additions & 0 deletions source/isfs.h
Expand Up @@ -52,6 +52,7 @@ typedef struct {
u32 generation;
u32 version;
bool mounted;
bool isfshax;
u32 aes[0x10/sizeof(u32)];
u8 hmac[0x14];
devoptab_t devoptab;
Expand Down Expand Up @@ -132,6 +133,8 @@ int isfs_write_super(isfs_ctx *ctx, void *super, int index);

u16* _isfs_get_fat(isfs_ctx* ctx);

bool isfs_slc_has_isfshax_installed(void);

void isfs_test(void);

#endif

0 comments on commit bc0ea13

Please sign in to comment.