Commit Graph

28 Commits

Author SHA1 Message Date
Pablo Curiel fc5226bfce [skip ci] Update copyright year. 2024-04-12 11:49:03 +02:00
Pablo Curiel 54c5677cd0 QoL changes
* codebase: remove all references to Lockpick / Lockpick_RCM.

* keys: retrieve Atmosphère's key generation in keysLoadKeyset().
* keys: replace all "key_gen_val" references with "mkey_index".
* keys: move latest master key checks in keysReadKeysFromFile() to keysDeriveMasterKeys().
* keys: update latest master key checks to determine if nxdumptool's hardcoded master key vectors are outdated, using the key generation value from Atmosphère. If the master key vectors are outdated, and the newer master key(s) are not available, an error will be displayed.

* nxdt_utils: update logic in utilsReplaceIllegalCharacters() to replace consecutive illegal characters with a single underscore.
* nxdt_utils: move servicesGetExosphereApiVersion() to nxdt_utils as utilsGetExosphereApiVersion().
* nxdt_utils: define internal UtilsExosphereApiVersion struct, which is used to parse the output from utilsGetExosphereApiVersion().
* nxdt_utils: add utilsGetAtmosphereVersion(), utilsGetAtmosphereKeyGeneration() and utilsGetAtmosphereTargetFirmware() functions.

* services: remove servicesGetExosphereApiVersion().
* services: Atmosphère version is now retrieved via utilsGetAtmosphereVersion().
2024-04-05 23:25:32 +02:00
Pablo Curiel c585e8f9d3 poc: add file browser for NCA FS sections.
Takes advantage of the recently implemented devoptab interfaces. Supports individual file dumping and multiple file/dir dumping via highlighting. May possibly need some additional testing. The code could potentially be improved, but I'll look into it at a later time -- I just want to release this now.

Other changes include:

* devoptab: comment out log messages.

* utils: add utilsGetDirectorySize() function.
2023-12-26 01:25:29 +01:00
Pablo Curiel d402776032 Custom devoptab wrappers (part 1).
This commit implements a devoptab wrapper for Partition FS sections within NCAs, using code from pfs.c/h.

Other changes include:

* codebase: use NX_IGNORE_ARG macro where needed.

* hfs: slight tweaks to some of the static functions.

* pfs: slight tweaks to some of the static functions.
* pfs: use pfsIsValidContext() where needed.

* utils: update utilsInitializeResources() to use __system_argc and __system_argv variables from libnx.

* todo: update text file.
2023-12-20 20:32:48 +01:00
Pablo Curiel 32bb5fd46e nxdt_utils: add more helpers.
Implement utilsParseHexString() and utilsAppletLoopDelay().

Other changes include:

* defines: add THIRTY_FPS_DELAY define.
* defines: remove unused CERT_PATH define.

* gamecard: restore original reserved_2 field in GameCardInfo struct. The last 16 bytes weren't being properly due to an issue within libnx's AES-CBC implementation.
* gamecard: rename GAMECARD_ACCESS_WAIT_TIME -> GAMECARD_ACCESS_DELAY.

* host: improve ABI documentation (thanks @v1993).

* keys: remove keysConvertHexDigitToBinary().
* keys: change keysParseHexKey() function signature + update it to use utilsParseHexString() instead.

* nso: change "NRO" to "NSO" in some misleading log error messages (thanks @liamadvance).

* nxdt_rw_poc: replace svcSleepThread() calls with utilsAppletLoopDelay().

* nxdt_utils: rename utilsGenerateHexStringFromData() -> utilsGenerateHexString().
* nxdt_utils: add static utilsConvertHexDigitToBinary() function, used by utilsParseHexString().
* nxdt_utils: update utilsAppendFormattedStringToBuffer() to avoid logging an error string if resources haven't been initialized.
* nxdt_utils: use a single call to sprintf() with a variable precision argument in utilsGenerateFormattedSizeString().
* nxdt_utils: call utilsAppletLoopDelay() in the while loop from utilsPrintConsoleError().
* nxdt_utils: remove unused utilsCloseFileDescriptor() function.

* tik: log input rights ID at the start of tikRetrieveTicketByRightsId().
2023-10-23 00:44:40 +02:00
Pablo Curiel cd73c6360f nxdt_utils: use an arbitrary filename length limit for SD card paths 2023-07-17 23:44:45 +02:00
Pablo Curiel 8f75b6b923 *FormattedStringToBuffer: relax input validation
Affects both utilsAppendFormattedStringToBuffer() and logWriteFormattedStringToBuffer(). Fixes logging issues within both the exception handler and memory debugging code.

Other changes include:

* bfttf: rename BfttfFontType_Total -> BfttfFontType_Count.
* config: rename "append_authoringtool_data" -> "generate_authoringtool_data".
* fs_ext: update FsGameCardCertificate struct
* gamecard: fix gamecardReadLotusAsicFirmwareBlob() not returning false if FS .data segment memory couldn't be retrieved; update GameCardInfo struct to reflect a recently discovered area that's not zeroed out.
* mem: expand MemoryProgramSegmentType enum; define extra macros for PID buffer size and memory page type checks; force empty memory page attribute and R/X permission checks while looking for the last FS .text segment; make memory page filtering code more readable.
* npdm: rename KernelCapability enums; rename entry_value -> bitmask in all KernelCapability descriptor structs.
* tik: force byte-for-byte memory lookup while dumping volatile tickets.
* libs: update libusbhsfs to latest commit.
* codebase: add missing comments to some enums; add missing "None" and "Count" elements to some enums. "Count" entries from enums with bitmasks will only reflect the number of available bitmask values. Enums with hex values remain unchanged.
* PoC builds: use EXIT_SUCCESS and EXIT_FAILURE as return values.
* nxdt_rw_poc: move "end" jump label within main() to avoid a crash if utilsInitializeResources() fails; reflect changes in config.c.
2023-07-17 01:03:05 +02:00
Pablo Curiel fb58d20fe3 I'm a terrible person and an even worse developer.
And I don't need anyone to tell me so, thank you very much.

* PoC: remove gc_dumper and nsp_dumper PoC; create nxdt_rw_poc with all gc_dumper and nsp_dumper capabilities + standalone ticket dumping + raw NCA dumping; use ftruncate() to set output file sizes whenever possible. PoC code is a mess, as always. Expect the features from the rest of the PoCs to be implemented into nxdt_rw_poc soon.

* workflow: temporarily disable borealis build generation; comment out manual installation of up-to-date packages from Leseratte's mirrors because the latest devkitA64 Docker image has them all.

* borealis: update to fix building issues with latest devkitA64.

* bfttf: error out on invalid NCA signatures.

* config: save configuration to the current working directory; parse and validate new "gamecard/write_raw_hfs_partition" flag.

* defines: remove CONFIG_PATH macro; rename CONFIG_FILE_NAME.

* gamecard: rename fs_ctx -> hfs_ctx everywhere; use HFS function calls to retrieve partition names.

* hfs: move GameCardHashFileSystemPartitionType enum from gamecard.h and rename it to HashFileSystemPartitionType; add hfsIsValidContext(); add hfsGetPartitionNameString().

* nca/npdm: update comments to reflect latest HOS version.

* nxdt_bfsar: always generate absolute SD card paths with the device name; error out on an invalid NCA signature.

* nxdt_includes: include dirent.h; refactor Version struct to make it a union of all known *Version structs.

* nxdt_log: don't write session separator if the logfile is empty.

* nxdt_utils: log appletIsGamePlayRecordingSupported() errors; add utilsDeleteDirectoryRecursively().

* rsa: provide clearer function descriptions in header file.

* services: handle usb:ds initialization.

* tik: update tikConvertPersonalizedTicketToCommonTicket() to allow NULL input pointers as raw certificate chain arguments (much needed for standalone ticket dumping).

* title: add titleGetApplicationIdByMetaKey().

* usb: refactor interface (de)initialization code; slightly improve ABI usage (console-side only); redefine ABI version field in StartSession command blocks; upgrade ABI to v1.1.

* FatFs: rename DIR -> FDIR to avoid conflicts with definitions from stdlib's dirent.h.

* gamecard_tab: display package ID from the inserted gamecard; fix displayed version numbers from bundled system updates below 3.0.0.

* todo: add notes about creating devoptab devices for HFS/PFS/RomFS file tree dumping.
2023-05-24 21:05:34 +02:00
Pablo Curiel 9a4b8b573d Update copyright year 2023-04-08 13:42:22 +02:00
Pablo Curiel f79680184d Runtime key derivation with hardcoded key sources
* aes: add aes128EcbCrypt() as a one-shot function to perform AES-128-ECB crypto. The rest of the codebase now calls this function whenever suitable.

* fs_ext: add const keyword to IPC input structs wherever suitable.

* key_sources: add hardcoded master key vectors (prod, dev); master KEK sources (Erista, Mariko); master key source; ticket common key source; SMC key type sources; SMC seal key masks; AES key generation source; NCA header KEK source; NCA header key source and NCA KAEK sources. Also fixed the hardcoded gamecard CardInfo key source for dev units (it was previously generated using retail keydata, my bad).

* keys: remove keysGetNcaMainSignatureModulus(); remove keysDecryptNcaKeyAreaEntry(); repurpose keyset struct to only hold keys that can actually be used for the current hardware type; remove KeysGameCardKeyset; remove keysIsXXModulusYYMandatory() helpers; remove keysRetrieveKeysFromProgramMemory(); remove keysDeriveSealedNcaKeyAreaEncryptionKeys(); add keysDeriveMasterKeys() and keysDerivePerGenerationKeys(); rename keysDeriveGameCardKeys() -> keysDeriveGcCardInfoKey(); add small reimplementations of GenerateAesKek, LoadAesKey and GenerateAesKey; add keysLoadAesKeyFromAesKek() and keysGenerateAesKeyFromAesKek() wrappers. Furthermore, master key derivation is now carried out manually using hardcoded key sources and the last known master key, which is loaded from the Lockpick_RCM keys file -- if the last known master key is unavailable, the key derivation algorithm will then fallback to TSEC root key / Mariko KEK based key derivation, depending on the hardware type.

* nca: add hardcoded NCA man signature moduli (prod, dev); merge ncaDecryptKeyArea() and ncaEncryptKeyArea() into ncaKeyAreaCrypt().

* nxdt_utils: add utilsIsMarikoUnit(); remove _utilsAppletModeCheck(); rename utilsAppletModeCheck() -> utilsIsAppletMode().

* services: remove spl:mig dependency (yay).

* smc: add SmcKeyType enum; add SmcSealKey enum; add SmcGenerateAesKekOption struct; add smcPrepareGenerateAesKekOption().
2023-04-08 13:38:28 +02:00
Pablo Curiel a9b5f7211c Some changes. Read full commit message.
* title: implemented titleGetNcmStorageIdName().

* nxdt_log: implemented log verbosity levels (debug, info, warning, error, none) and helper macros for each level. The rest of the codebase still needs to be updated to take advantange of this change.

* nxdt_log: implemented auxiliary logging via nxlink, if available.

* nxdt_utils: system CPU/MEM overclocking is now only applied through utilsSetLongRunningProcessState(), as it should have been from the beginning.

* nxdt_utils: nxlink initialization is now carried out without redirecting stdout and/or stderr, entirely removing the need for utilsRestoreConsoleOutput(). utilsGetNxLinkFileDescriptor() is used to send data to the nxlink host via dprintf() in log functions.
2022-07-12 02:27:03 +02:00
Pablo Curiel d8c0984115 romfs: slightly improve interface. 2022-07-06 11:57:31 +02:00
Pablo Curiel 2fa61dc228 Update copyright year. 2022-03-17 13:58:40 +01:00
Pablo Curiel 278cb5c72a Some changes.
* nxdt_includes: renamed VersionType1 to Version and tweaked it to add the application_version struct, renamed VersionType2 to SdkAddOnVersion.

* gc_dumper: use utilsGeneratePath() to truncate generated filenames to safe filesystem limits. Thanks to n0tw0rk for reporting the issue and testing the changes!

* nxdt_host.py: fixed a string formatting issue that made it impossible to unpack data from the SendFileProperties command block under certain circumstances.

* gamecard: modified GameCardKeySource to add a value field, added GameCardFlags_HasCa10Certificate flag.

* utils: utilsGeneratePath() no longer adds a dot on its own if it's not part of the provided extension string.
2022-03-17 13:37:24 +01:00
Pablo Curiel 3f9cde8185 Implemented exception handler.
The exception handler is capable of logging CPU registers and a stack trace using the current log implementation.

Furthermore, if borealis has been initialized, it'll also display the PC register value using a CrashFrame. Otherwise, console output is used to display the same message.

Other changes include:

* utils: made utilsPrintConsoleError non-static.
* utils: implemented a workaround to restore console output after initializing nxlink.
2021-08-25 16:48:01 -04:00
Pablo Curiel ba0c5d9e35 utils: implement utilsIsApplicationUpdatable().
Also removed legacy code that has already been reimplemented.
2021-08-07 05:44:36 -04:00
Pablo Curiel 28cd0ce10f OptionsTab: fully implement application update feature.
Other changes include:

* Codebase: move JSON parsing logic from config.c/h to nxdt_json.c/h.
* Codebase: replace all calls to localtime() with localtime_r() to guarantee thread-safety.
* Codebase: updated todo.txt.
* utils: implement utilsParseGitHubReleaseJsonData(), utilsFreeGitHubReleaseJsonData(), utilsGetApplicationUpdatedState() and utilsGetApplicationUpdatedState().
* utils: add extra logic to move the application's NRO to its proper path if the launch path isn't the right one (commented out at this moment).
* utils: add extra logic to replace the application's NRO at exit (commented out at this moment).
* defines: add DEVOPTAB_SDMC_DEVICE and tweak GitHub URL macros.
* DownloadTask: set percentage to 0 if the download size is unknown.
* DownloadTask: fix ETA string formatting.
* OptionsTab: repurpose OptionsTabUpdateFileDialogContent into OptionsTabUpdateProgress.
* OptionsTab: implement OptionsTabUpdateApplicationFrame.
* RootView: move date formatting into the static GetFormattedDateString() method.
* Makefile: use _GNU_SOURCE as part of CFLAGS to use strptime().
2021-08-07 04:42:03 -04:00
Pablo Curiel 841fd73fbf utils: implement utilsSetLongRunningProcessState().
Other changes include:

* DownloadTask: use utilsSetLongRunningProcessState() to control HOME button block status, screen dimming and auto sleep.
* Add missing utilsCommitSdCardFileSystemChanges() calls throughout the codebase.
2021-07-29 12:48:32 -04:00
Pablo Curiel dbbc5c7ebd Implemented OptionsTabUpdateFileDialog and OptionsTabUpdateFileDialogContent classes.
Other changes include:

* utils: utilsGenerateFormattedSizeString() now takes an input double instead of size_t.
* DownloadTask: calculated speed is now expressed in bytes per second, so now it's up to the caller to convert it to other units.
* DownloadTask: set download size and percentage if the download size isn't known and we're dealing with the final chunk.
* http: slightly improved CURL error info formatting.
* OptionsTab: fully implemented NSWDB XML update option.
2021-07-29 03:50:17 -04:00
Pablo Curiel 64ab1705bc Implement JSON configuration handler.
* Thread-safe.
* Provides getter/setter functions for the data types used by nxdumptool's configuration.
* Each setter function writes the modified JSON configuration back to the SD card.
* Configuration is validated on interface initialization. If validation fails, a default JSON template is loaded from the application's RomFS and written back to the SD card.

Other changes:

* Implement directory creation.
* Moved more preprocessor definitions to defines.h.
* Replaced strtok() calls throughout the code with strtok_r() to guarantee thread-safety.
2021-07-21 11:04:18 -04:00
Pablo Curiel e48aa2e937 Implemented background tasks for Borealis.
* core: implemented SCOPED_TRY_LOCK macro. Specific functions are now using it instead of SCOPED_LOCK to avoid potentially locking the Borealis UI.

* UI: implemented background tasks for Borealis, which call functions that now use SCOPED_TRY_LOCK.
2021-06-09 00:48:17 -04:00
Pablo Curiel 78f780a981 Implemented C++ scope guards.
Thanks @SciresM

These will be used for handling resource deinitialization in Borealis-related code.
2021-06-07 23:13:45 -04:00
Pablo Curiel 04abb342bb Small code refactor (part 3).
* Both gamecard header and decrypted CardInfo area are now retrieved upon gamecard insertion. LAFW version is checked against the CardInfo LAFW version right afterwards.

* Expanded GameCardStatus enum to add NoGameCardPatchEnabled and LotusAsicFirmwareUpdateRequired values.

* Updated utilsReplaceIllegalCharacters() to perform replacements on a per-codepoint basis, which means that invalid multibyte UTF-8 codepoints can now be replaced with a single ASCII underscore.

* Updated utilsGeneratePath() to truncate path elements that exceed 255 UTF-8 codepoints (safe limit for FAT and NTFS filesystems).

* Heavily simplified core logic in title functions by using newly defined TitleStorage elements (which hold the NCM database/storage handles, a TitleInfo array and a title counter) instead of the old, global index-based methods.

* Simplified background gamecard title thread logic by always returning duplicated TitleInfo data to the user.

* Update title API to account for the previously mentioned changes, including functions to free duplicated title data.

* Fallback gamecard filename string now also holds the gamecard package ID whenever possible.

* Implemented HDCP patching for Control NCAs.
2021-05-31 21:12:15 -04:00
Pablo Curiel f82d7a3db4 Small code refactor (part 2).
* Rewrote mutex handling throughout the code to use a small, macro-based scoped lock implementation.

* Removed extern variables from common.h - launch path management is now completely handled in utils.c.

* Updated NpdmSystemCallId_Count to reflect changes introduced in 12.0.0.

* Added NcaMainSignatureKeyGeneration enum.

* NCA main signature moduli are now retrieved from FS .rodata at runtime.

* Simplified lock management in usb.c by using a single global mutex with scoped locks instead of three different r/w locks.

* Updated FatFs to R0.14b.

* Enabled 64-bit LBA support in FatFs to potentially support custom eMMC replacements / resized USER partitions in the future.

* Updated LZ4 to v1.9.3.

* Fixed typos.

* USB gamecard dumper PoC now only dumps the Initial Data area.

* Updated to-do list.
2021-05-18 08:32:43 -04:00
Pablo Curiel 85f146f50c Add uppercase hex string generation to utilsGenerateHexStringFromData(). 2021-05-11 18:36:15 -04:00
Pablo Curiel 7c2d16714c Use legacy Borealis fork + add files from the legacy Borealis example.
These files will be modified to slowly add features from the nxdumptool rewrite codebase.

This commit effectively makes it impossible to build the previous PoC. The code from each PoC will be reused, though, so it hasn't been removed.
2021-03-30 15:30:10 -04:00
Pablo Curiel 194389b73f Some changes.
* Remove references to the secondary Nintendo Extended BFTTF because it's identical to the first one.

* Use format attribute in functions that need it (and fixed errors I made in the past).
2021-03-29 14:27:35 -04:00
Pablo Curiel 11da814fb2 Fix building issues with Borealis. 2021-03-26 00:35:14 -04:00
Renamed from include/core/utils.h (Browse further)