mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Cleanup: combine several .h files into one
This commit is contained in:
parent
0f3fc2a5d1
commit
643b58533e
@ -58,11 +58,14 @@ u64 IdentifyFileType(const char* path) {
|
||||
u64 type = GAME_NCCH;
|
||||
if (NCCH_IS_CXI(ncch)) {
|
||||
type |= FLAG_CXI;
|
||||
/* the below is unused for now
|
||||
type |= NCCH_IS_FIRM(ncch) ? FLAG_FIRM : 0;
|
||||
NcchExtHeader exhdr;
|
||||
if ((FileGetData(path, &exhdr, 0x400, 0x200) == 0x400) && // read only what we need
|
||||
(DecryptNcch(&exhdr, 0x200, 0x400, ncch, NULL) == 0) &&
|
||||
NCCH_IS_GBAVC(&exhdr))
|
||||
type |= FLAG_GBAVC;
|
||||
*/
|
||||
}
|
||||
if (fsize >= (ncch->size * NCCH_MEDIA_UNIT))
|
||||
return type; // NCCH (".APP") file
|
||||
|
@ -30,7 +30,8 @@
|
||||
#define HDR_NAND (1ULL<<25)
|
||||
#define TYPE_BASE 0xFFFFFFFFULL // 32 bit reserved for base types
|
||||
|
||||
#define FLAG_GBAVC (1ULL<<59)
|
||||
// #define FLAG_FIRM (1ULL<<58) // <--- for CXIs containing FIRMs
|
||||
// #define FLAG_GBAVC (1ULL<<59) // <--- for GBAVC CXIs
|
||||
#define FLAG_ENC (1ULL<<60)
|
||||
#define FLAG_CTR (1ULL<<61)
|
||||
#define FLAG_NUSCDN (1ULL<<62)
|
||||
|
11
source/filesys/fs.h
Normal file
11
source/filesys/fs.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "filetype.h"
|
||||
#include "fsdir.h"
|
||||
#include "fsdrive.h"
|
||||
#include "fsgame.h"
|
||||
#include "fsinit.h"
|
||||
#include "fsperm.h"
|
||||
#include "fsutil.h"
|
||||
#include "image.h"
|
||||
#include "vff.h"
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "gba.h"
|
||||
|
||||
#define GBAVC_MAGIC '.', 'C', 'A', 'A'
|
||||
#define AGBSAVE_MAGIC '.', 'S', 'A', 'V'
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#define NCCH_ENCRYPTED(ncch) (!((ncch)->flags[7] & 0x04))
|
||||
#define NCCH_IS_CXI(ncch) ((ncch)->flags[5] & 0x02)
|
||||
#define NCCH_IS_FIRM(ncch) (((ncch)->programId >> 32) == 0x00040138)
|
||||
#define NCCH_IS_GBAVC(exhdr) (getle32((exhdr)->aci_data + 8) == 0x00000202)
|
||||
|
||||
#define NCCH_NOCRYPTO 0x0004
|
||||
|
@ -1,33 +1,19 @@
|
||||
#include "godmode.h"
|
||||
#include "ui.h"
|
||||
#include "hid.h"
|
||||
#include "fsinit.h"
|
||||
#include "fsdrive.h"
|
||||
#include "fsutil.h"
|
||||
#include "fsperm.h"
|
||||
#include "fsgame.h"
|
||||
#include "scripting.h"
|
||||
#include "gameutil.h"
|
||||
#include "keydbutil.h"
|
||||
#include "nandutil.h"
|
||||
#include "filetype.h"
|
||||
#include "unittype.h"
|
||||
#include "entrypoints.h"
|
||||
#include "fs.h"
|
||||
#include "utils.h"
|
||||
#include "nand.h"
|
||||
#include "virtual.h"
|
||||
#include "vcart.h"
|
||||
#include "game.h"
|
||||
#include "nandcmac.h"
|
||||
#include "ctrtransfer.h"
|
||||
#include "ncchinfo.h"
|
||||
#include "sysinfo.h"
|
||||
#include "image.h"
|
||||
#include "unittype.h"
|
||||
#include "entrypoints.h"
|
||||
#include "bootfirm.h"
|
||||
#include "qlzcomp.h"
|
||||
#include "timer.h"
|
||||
#include "rtc.h"
|
||||
#include "power.h"
|
||||
#include "vff.h"
|
||||
#include "vram0.h"
|
||||
|
||||
|
||||
|
@ -1,10 +1,6 @@
|
||||
#include "ctrtransfer.h"
|
||||
#include "nandcmac.h"
|
||||
#include "fsutil.h"
|
||||
#include "fsinit.h"
|
||||
#include "fsperm.h"
|
||||
#include "image.h"
|
||||
#include "gameutil.h"
|
||||
#include "fs.h"
|
||||
#include "essentials.h"
|
||||
#include "ui.h"
|
||||
|
||||
|
@ -2,12 +2,10 @@
|
||||
#include "game.h"
|
||||
#include "hid.h"
|
||||
#include "ui.h"
|
||||
#include "fsperm.h"
|
||||
#include "filetype.h"
|
||||
#include "fs.h"
|
||||
#include "unittype.h"
|
||||
#include "aes.h"
|
||||
#include "sha.h"
|
||||
#include "vff.h"
|
||||
|
||||
// use NCCH crypto defines for everything
|
||||
#define CRYPTO_DECRYPT NCCH_NOCRYPTO
|
||||
|
@ -1,9 +1,7 @@
|
||||
#include "keydbutil.h"
|
||||
#include "fsperm.h"
|
||||
#include "filetype.h"
|
||||
#include "unittype.h"
|
||||
#include "vff.h"
|
||||
#include "fs.h"
|
||||
#include "ui.h"
|
||||
#include "unittype.h"
|
||||
|
||||
#define MAX_KEYDB_SIZE (TEMP_BUFFER_SIZE)
|
||||
|
||||
|
@ -1,20 +1,16 @@
|
||||
#include "nandutil.h"
|
||||
#include "gameutil.h"
|
||||
#include "nandcmac.h"
|
||||
#include "nand.h"
|
||||
#include "firm.h"
|
||||
#include "fatmbr.h"
|
||||
#include "essentials.h" // for essential backup struct
|
||||
#include "nandcmac.h"
|
||||
#include "gba.h"
|
||||
#include "image.h"
|
||||
#include "fsinit.h"
|
||||
#include "fsperm.h"
|
||||
#include "sighax.h"
|
||||
#include "unittype.h"
|
||||
#include "fs.h"
|
||||
#include "ui.h"
|
||||
#include "sdmmc.h"
|
||||
#include "sha.h"
|
||||
#include "ui.h"
|
||||
#include "vff.h"
|
||||
#include "sighax.h"
|
||||
#include "essentials.h" // for essential backup struct
|
||||
#include "unittype.h"
|
||||
|
||||
|
||||
static const u8 twl_mbr_std[0x42] = {
|
||||
|
@ -1,24 +1,17 @@
|
||||
#include "scripting.h"
|
||||
#include "fsutil.h"
|
||||
#include "fsinit.h"
|
||||
#include "fsperm.h"
|
||||
#include "fs.h"
|
||||
#include "utils.h"
|
||||
#include "nand.h"
|
||||
#include "nandcmac.h"
|
||||
#include "nandutil.h"
|
||||
#include "gameutil.h"
|
||||
#include "keydbutil.h"
|
||||
#include "filetype.h"
|
||||
#include "bootfirm.h"
|
||||
#include "qrcodegen.h"
|
||||
#include "firm.h"
|
||||
#include "power.h"
|
||||
#include "vff.h"
|
||||
#include "unittype.h"
|
||||
#include "region.h"
|
||||
#include "rtc.h"
|
||||
#include "sha.h"
|
||||
#include "hid.h"
|
||||
#include "ui.h"
|
||||
#include "region.h"
|
||||
|
||||
#define _MAX_ARGS 3
|
||||
#define _ARG_MAX_LEN 512
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include "itcm.h"
|
||||
#include "region.h"
|
||||
#include "unittype.h"
|
||||
#include "essentials.h" // for SecureInfo
|
||||
#include "vff.h"
|
||||
#include "nand/essentials.h" // For SecureInfo
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
9
source/utils/utils.h
Normal file
9
source/utils/utils.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "ctrtransfer.h"
|
||||
#include "gameutil.h"
|
||||
#include "keydbutil.h"
|
||||
#include "nandcmac.h"
|
||||
#include "nandutil.h"
|
||||
#include "scripting.h"
|
||||
#include "sysinfo.h"
|
@ -104,24 +104,21 @@ static RomFsLv3Index lv3idx;
|
||||
static u8 cia_titlekey[16];
|
||||
|
||||
|
||||
int ReadCiaContentImageBlocks(void* buffer, u64 block, u64 count, u32 cia_cnt_idx, u64 block0) {
|
||||
int ReadCbcImageBlocks(void* buffer, u64 block, u64 count, u8* iv0, u64 block0) {
|
||||
int ret = ReadImageBytes(buffer, block * AES_BLOCK_SIZE, count * AES_BLOCK_SIZE);
|
||||
if ((ret == 0) && (cia_cnt_idx <= 0xFFFF)) {
|
||||
if ((ret == 0) && iv0) {
|
||||
u8 ctr[AES_BLOCK_SIZE] = { 0 };
|
||||
if (block == block0) {
|
||||
ctr[0] = (cia_cnt_idx >> 8) & 0xFF;
|
||||
ctr[1] = (cia_cnt_idx >> 0) & 0xFF;
|
||||
} else {
|
||||
if ((ret = ReadImageBytes(ctr, (block-1) * AES_BLOCK_SIZE, AES_BLOCK_SIZE)) != 0)
|
||||
if (block == block0) memcpy(ctr, iv0, AES_BLOCK_SIZE);
|
||||
else if ((ret = ReadImageBytes(ctr, (block-1) * AES_BLOCK_SIZE, AES_BLOCK_SIZE)) != 0)
|
||||
return ret;
|
||||
}
|
||||
if (DecryptCiaContentSequential(buffer, count * AES_BLOCK_SIZE, ctr, cia_titlekey) != 0)
|
||||
return -1;
|
||||
|
||||
u32 mode = AES_CNT_TITLEKEY_DECRYPT_MODE;
|
||||
cbc_decrypt(buffer, buffer, count, mode, ctr);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ReadCiaContentImageBytes(void* buffer, u64 offset, u64 count, u32 cia_cnt_idx, u64 offset0) {
|
||||
int ReadCbcImageBytes(void* buffer, u64 offset, u64 count, u8* iv0, u64 offset0) {
|
||||
u32 off_fix = offset % AES_BLOCK_SIZE;
|
||||
u64 block0 = offset0 / AES_BLOCK_SIZE;
|
||||
u8 __attribute__((aligned(32))) temp[AES_BLOCK_SIZE];
|
||||
@ -130,7 +127,7 @@ int ReadCiaContentImageBytes(void* buffer, u64 offset, u64 count, u32 cia_cnt_id
|
||||
|
||||
if (off_fix) { // misaligned offset (at beginning)
|
||||
u32 fix_byte = ((off_fix + count) >= AES_BLOCK_SIZE) ? AES_BLOCK_SIZE - off_fix : count;
|
||||
if ((ret = ReadCiaContentImageBlocks(temp, offset / AES_BLOCK_SIZE, 1, cia_cnt_idx, block0)) != 0)
|
||||
if ((ret = ReadCbcImageBlocks(temp, offset / AES_BLOCK_SIZE, 1, iv0, block0)) != 0)
|
||||
return ret;
|
||||
memcpy(buffer8, temp + off_fix, fix_byte);
|
||||
buffer8 += fix_byte;
|
||||
@ -140,7 +137,7 @@ int ReadCiaContentImageBytes(void* buffer, u64 offset, u64 count, u32 cia_cnt_id
|
||||
|
||||
if (count >= AES_BLOCK_SIZE) {
|
||||
u64 blocks = count / AES_BLOCK_SIZE;
|
||||
if ((ret = ReadCiaContentImageBlocks(buffer8, offset / AES_BLOCK_SIZE, blocks, cia_cnt_idx, block0)) != 0)
|
||||
if ((ret = ReadCbcImageBlocks(buffer8, offset / AES_BLOCK_SIZE, blocks, iv0, block0)) != 0)
|
||||
return ret;
|
||||
buffer8 += AES_BLOCK_SIZE * blocks;
|
||||
offset += AES_BLOCK_SIZE * blocks;
|
||||
@ -148,7 +145,7 @@ int ReadCiaContentImageBytes(void* buffer, u64 offset, u64 count, u32 cia_cnt_id
|
||||
}
|
||||
|
||||
if (count) { // misaligned offset (at end)
|
||||
if ((ret = ReadCiaContentImageBlocks(temp, offset / AES_BLOCK_SIZE, 1, cia_cnt_idx, block0)) != 0)
|
||||
if ((ret = ReadCbcImageBlocks(temp, offset / AES_BLOCK_SIZE, 1, iv0, block0)) != 0)
|
||||
return ret;
|
||||
memcpy(buffer8, temp, count);
|
||||
count = 0;
|
||||
@ -157,6 +154,23 @@ int ReadCiaContentImageBytes(void* buffer, u64 offset, u64 count, u32 cia_cnt_id
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ReadCiaContentImageBytes(void* buffer, u64 offset, u64 count, u32 cia_cnt_idx, u64 offset0) {
|
||||
// setup key for CIA
|
||||
u8 tik[16] __attribute__((aligned(32)));
|
||||
memcpy(tik, cia_titlekey, 16);
|
||||
setup_aeskey(0x11, tik);
|
||||
use_aeskey(0x11);
|
||||
|
||||
// setup IV0
|
||||
u8 iv0[AES_BLOCK_SIZE] = { 0 };
|
||||
iv0[0] = (cia_cnt_idx >> 8) & 0xFF;
|
||||
iv0[1] = (cia_cnt_idx >> 0) & 0xFF;
|
||||
|
||||
// continue in next function
|
||||
u8* iv0_ptr = (cia_cnt_idx <= 0xFFFF) ? iv0 : NULL;
|
||||
return ReadCbcImageBytes(buffer, offset, count, iv0_ptr, offset0);
|
||||
}
|
||||
|
||||
int ReadGameImageBytes(void* buffer, u64 offset, u64 count) {
|
||||
int ret = ((offset_ccnt != (u64) -1) && (index_ccnt <= 0xFFFF)) ?
|
||||
ReadCiaContentImageBytes(buffer, offset, count, index_ccnt, offset_ccnt) :
|
||||
|
Loading…
x
Reference in New Issue
Block a user