Prevent alignment issues

This commit is contained in:
d0k3 2016-12-08 22:08:19 +01:00
parent db8bbdb224
commit 648f314a0a
6 changed files with 15 additions and 15 deletions

View File

@ -160,7 +160,7 @@ u32 CheckKeySlot(u32 keyslot, char type)
u32 LoadKeyFromFile(u8* key, u32 keyslot, char type, char* id) u32 LoadKeyFromFile(u8* key, u32 keyslot, char type, char* id)
{ {
const char* base[] = { INPUT_PATHS }; const char* base[] = { INPUT_PATHS };
u8 keystore[16] = {0}; u8 keystore[16] __attribute__((aligned(32))) = {0};
bool found = false; bool found = false;
// use keystore if key == NULL // use keystore if key == NULL

View File

@ -4,7 +4,7 @@
#include "ff.h" #include "ff.h"
u32 IdentifyFileType(const char* path) { u32 IdentifyFileType(const char* path) {
u8 __attribute__((aligned(16))) header[0x200]; // minimum required size u8 header[0x200] __attribute__((aligned(32))); // minimum required size
FIL file; FIL file;
if (fx_open(&file, path, FA_READ | FA_OPEN_EXISTING) != FR_OK) if (fx_open(&file, path, FA_READ | FA_OPEN_EXISTING) != FR_OK)
return 0; return 0;
@ -32,18 +32,18 @@ u32 IdentifyFileType(const char* path) {
(header[0x1BE + 0x4] == 0xB) || (header[0x1BE + 0x4] == 0xC) || (header[0x1BE + 0x4] == 0xE))) { (header[0x1BE + 0x4] == 0xB) || (header[0x1BE + 0x4] == 0xC) || (header[0x1BE + 0x4] == 0xE))) {
return IMG_FAT; // this might be an MBR -> give it the benefit of doubt return IMG_FAT; // this might be an MBR -> give it the benefit of doubt
} }
} else if (ValidateCiaHeader((CiaHeader*) header) == 0) { } else if (ValidateCiaHeader((CiaHeader*) (void*) header) == 0) {
// this only works because these functions ignore CIA content index // this only works because these functions ignore CIA content index
CiaInfo info; CiaInfo info;
GetCiaInfo(&info, (CiaHeader*) header); GetCiaInfo(&info, (CiaHeader*) header);
if (fsize >= info.size_cia) if (fsize >= info.size_cia)
return GAME_CIA; // CIA file return GAME_CIA; // CIA file
} else if (ValidateNcsdHeader((NcsdHeader*) header) == 0) { } else if (ValidateNcsdHeader((NcsdHeader*) (void*) header) == 0) {
NcsdHeader* ncsd = (NcsdHeader*) header; NcsdHeader* ncsd = (NcsdHeader*) (void*) header;
if (fsize >= (ncsd->size * NCSD_MEDIA_UNIT)) if (fsize >= (ncsd->size * NCSD_MEDIA_UNIT))
return GAME_NCSD; // NCSD (".3DS") file return GAME_NCSD; // NCSD (".3DS") file
} else if (ValidateNcchHeader((NcchHeader*) header) == 0) { } else if (ValidateNcchHeader((NcchHeader*) (void*) header) == 0) {
NcchHeader* ncch = (NcchHeader*) header; NcchHeader* ncch = (NcchHeader*) (void*) header;
if (fsize >= (ncch->size * NCCH_MEDIA_UNIT)) if (fsize >= (ncch->size * NCCH_MEDIA_UNIT))
return GAME_NCCH; // NCSD (".3DS") file return GAME_NCCH; // NCSD (".3DS") file
} }

View File

@ -172,7 +172,7 @@ u32 SetNcchKey(NcchHeader* ncch, u32 keyid) {
// key Y for seed and non seed // key Y for seed and non seed
if (keyid && (ncch->flags[7] & 0x20)) { // seed crypto if (keyid && (ncch->flags[7] & 0x20)) { // seed crypto
static u8 seedkeyY[16+16] = { 0 }; static u8 seedkeyY[16+16] __attribute__((aligned(32))) = { 0 };
static u8 lsignature[16] = { 0 }; static u8 lsignature[16] = { 0 };
static u64 ltitleId = 0; static u64 ltitleId = 0;
if ((memcmp(lsignature, ncch->signature, 16) != 0) || (ltitleId != ncch->programId)) { if ((memcmp(lsignature, ncch->signature, 16) != 0) || (ltitleId != ncch->programId)) {

View File

@ -57,7 +57,7 @@ typedef struct {
u8 reserved3[0x4]; u8 reserved3[0x4];
u8 hash_exefs[0x20]; u8 hash_exefs[0x20];
u8 hash_romfs[0x20]; u8 hash_romfs[0x20];
} __attribute__((packed)) NcchHeader; } __attribute__((packed, aligned(16))) NcchHeader;
u32 ValidateNcchHeader(NcchHeader* header); u32 ValidateNcchHeader(NcchHeader* header);
u32 SetupNcchCrypto(NcchHeader* ncch); u32 SetupNcchCrypto(NcchHeader* ncch);

View File

@ -74,8 +74,8 @@ bool InitNandCrypto(void)
// see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM // see: https://www.3dbrew.org/wiki/Memory_layout#ARM9_ITCM
if (CheckA9lh()) { // only for a9lh if (CheckA9lh()) { // only for a9lh
u32* TwlCustId = (u32*) (0x01FFB808); u32* TwlCustId = (u32*) (0x01FFB808);
u8 TwlKeyX[16]; u8 TwlKeyX[16] __attribute__((aligned(32)));
u8 TwlKeyY[16]; u8 TwlKeyY[16] __attribute__((aligned(32)));
// thanks b1l1s & Normmatt // thanks b1l1s & Normmatt
// see source from https://gbatemp.net/threads/release-twltool-dsi-downgrading-save-injection-etc-multitool.393488/ // see source from https://gbatemp.net/threads/release-twltool-dsi-downgrading-save-injection-etc-multitool.393488/

View File

@ -61,10 +61,10 @@ static u64 offset_romfs = (u64) -1;
static u64 offset_lv3 = (u64) -1; static u64 offset_lv3 = (u64) -1;
static u64 offset_lv3fd = (u64) -1; static u64 offset_lv3fd = (u64) -1;
static CiaStub* cia = (CiaStub*) (VGAME_BUFFER + 0x10000); // 62.5kB reserved - should be enough by far static CiaStub* cia = (CiaStub*) (void*) (VGAME_BUFFER + 0x10000); // 62.5kB reserved - should be enough by far
static NcsdHeader* ncsd = (NcsdHeader*) (VGAME_BUFFER + 0x1FA00); // 512 byte reserved static NcsdHeader* ncsd = (NcsdHeader*) (void*) (VGAME_BUFFER + 0x1FA00); // 512 byte reserved
static NcchHeader* ncch = (NcchHeader*) (VGAME_BUFFER + 0x1FC00); // 512 byte reserved static NcchHeader* ncch = (NcchHeader*) (void*) (VGAME_BUFFER + 0x1FC00); // 512 byte reserved
static ExeFsHeader* exefs = (ExeFsHeader*) (VGAME_BUFFER + 0x1FE00); // 512 byte reserved static ExeFsHeader* exefs = (ExeFsHeader*) (void*) (VGAME_BUFFER + 0x1FE00); // 512 byte reserved
static u8* romfslv3 = (u8*) (VGAME_BUFFER + 0x20000); // 1920kB reserved static u8* romfslv3 = (u8*) (VGAME_BUFFER + 0x20000); // 1920kB reserved
static RomFsLv3Index lv3idx; static RomFsLv3Index lv3idx;