Skip to content

Commit

Permalink
Compatibility for mounting fb3ds.firm
Browse files Browse the repository at this point in the history
This allows handling of the superhaxed fb3ds firm.
  • Loading branch information
d0k3 committed May 11, 2018
1 parent aee5827 commit 87890eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ These short instructions apply to all users who have [boot9strap](https://github
You may now run GodMode9 via holding the X Button (or any other button you chose) at startup. See below for a list of stuff you can do with it.


## Buttons in GodMode9 usage
## Buttons in GodMode9
GodMode9 is designed to be intuitive, buttons leading to the results you'd expect. However, some stuff may not be obvious at first glance. So, here's a quick, incomplete rundown of what each button / button combo does.
* __<A> button__: The <A> button is the 'confirm' / 'choose' button. It confirms prompts and selects entries in menus. In the main file view, it pulls up a submenu for files and opens directories (use <R+A> on directories for a submenu, also including the invaluable title search). In the hexviewer, <A> switches into edit mode.
* __<B> button__: The <B> button is the 'cancel' / 'return' button. Use it to leave menus without action, hold it on file operations to cancel said file operations.
Expand Down
8 changes: 5 additions & 3 deletions arm9/source/game/firm.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ u32 GetFirmSize(FirmHeader* header) {
FirmSectionHeader* section = header->sections + i;
if (!section->size) continue;
if (section->offset < firm_size) return 0;
if ((section->offset % 512) || (section->address % 16) || (section->size % 512)) return 0;
if ((section->offset % 512) || (section->size % 512)) return 0;
if ((header->entry_arm11 >= section->address) &&
(header->entry_arm11 < section->address + section->size))
section_arm11 = i;
Expand Down Expand Up @@ -79,8 +79,10 @@ u32 ValidateFirm(void* firm, u32 firm_size, bool installable) {
if ((firm_size < sizeof(FirmHeader)) || (ValidateFirmHeader(header, firm_size) != 0))
return 1;

// check for boot9strap magic
// overrides for b9s / superhax fb3ds firms
bool b9s_fix = installable && (memcmp(&(header->reserved0[0x2D]), "B9S", 3) == 0);
bool fb3ds_fix = installable && (header->sections[1].size == 0x200) &&
(header->sections[1].address == 0x07FFFE8C);

// hash verify all available sections and check load address
for (u32 i = 0; i < 4; i++) {
Expand All @@ -92,7 +94,7 @@ u32 ValidateFirm(void* firm, u32 firm_size, bool installable) {
if (!section->size) continue;
if (sha_cmp(section->hash, ((u8*) firm) + section->offset, section->size, SHA256_MODE) != 0)
return 1;
bool is_whitelisted = (b9s_fix && (i == 3)); // don't check last section in b9s
bool is_whitelisted = (b9s_fix && (i == 3)) || (fb3ds_fix && (i == 1)); // b9s / fb3ds overrides
for (u32 a = 0; (a < whitelist_size) && !is_whitelisted; a++) {
if ((section->address >= whitelist[2*a]) && (section->address + section->size <= whitelist[(2*a)+1]))
is_whitelisted = true;
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/virtual/vgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ bool BuildVGameFirmDir(void) {
u8* buffer = (u8*) malloc(section->size);
if (buffer) {
if (ReadGameImageBytes(buffer, section->offset, section->size) != 0) break;
for (u32 s = 0; (s < section->size - 0x400) && (!offset_p9); s += 0x10) {
for (u32 s = 0; (s + 0x400 < section->size) && (!offset_p9); s += 0x10) {
if ((ValidateNcchHeader((NcchHeader*) (void*) (buffer + s)) == 0) &&
(ReadGameImageBytes((u8*) name, section->offset + s + 0x200, 8) == 0)) {
offset_p9 = section->offset + s;
Expand Down

0 comments on commit 87890eb

Please sign in to comment.