Skip to content

Commit

Permalink
Fix FIRM validation before boot
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k3 committed Aug 12, 2017
1 parent 2387cb9 commit fdb93b5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions source/game/firm.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ u32 ValidateFirm(void* firm, u32 firm_size) {
u32 valid_address[] = { FIRM_VALID_ADDRESS };
FirmSectionHeader* section = header->sections + i;
if (!section->size) continue;
if (sha_cmp(section->hash, (u8*) firm + section->offset, section->size, SHA256_MODE) != 0) {
if (sha_cmp(section->hash, ((u8*) firm) + section->offset, section->size, SHA256_MODE) != 0)
return 1;
}
bool is_valid_address = false;
for (u32 a = 0; a < sizeof(valid_address) / (2*sizeof(u32)); a++) {
if ((valid_address[2*a] >= section->address) && (valid_address[(2*a)+1] <= section->address + section->size))
if ((section->address >= valid_address[2*a]) && (section->address + section->size <= valid_address[(2*a)+1]))
is_valid_address = true;
}
if (!is_valid_address) return 1;
Expand Down
2 changes: 1 addition & 1 deletion source/godmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur
ShowPrompt(false, "FIRM too big, can't launch"); // unlikely
} else if (ShowUnlockSequence(3, "%s (%dkB)\nBoot FIRM via chainloader?", pathstr, firm_size / 1024)) {
if ((FileGetData(curr_entry->path, TEMP_BUFFER, firm_size, 0) == firm_size) &&
(ValidateFirm(TEMP_BUFFER, firm_size) != 0)) {
(ValidateFirm(TEMP_BUFFER, firm_size) == 0)) {
// fix the boot path first ("sdmc"/"nand" for Luma et al, hacky af)
const char* bootpath = curr_entry->path;
char fixpath[256] = { 0 };
Expand Down

0 comments on commit fdb93b5

Please sign in to comment.