Skip to content

Commit

Permalink
Update to v1.1.10.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkMatterCore committed Apr 19, 2020
1 parent a999447 commit ff3141f
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 121 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include $(DEVKITPRO)/libnx/switch_rules

VERSION_MAJOR := 1
VERSION_MINOR := 1
VERSION_MICRO := 9
VERSION_MICRO := 10

APP_TITLE := nxdumptool
APP_AUTHOR := DarkMatterCore
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ If you like my work and you'd like to support me in any way, it's not necessary,
Changelog
--------------

**v1.1.10:**

* Built using libnx v3.1.0.
* Updated save.c/h to reflect changes made by shchmue in Lockpick_RCM. Fixes crashes under HOS 10.0.0.
* Fixed a nasty stack corruption issue caused by improper handling of FatFs objects. Fixes ES savefile mounting errors throughout the application (e.g. batch mode, ticket dumping).

This is only a bugfix release. I don't expect to release any new versions until the rewrite is finished - the only exception being fixing some kind of feature-breaking bug. Please understand.

**v1.1.9:**

* Built using libnx commit d7e6207.
Expand Down
1 change: 0 additions & 1 deletion source/es.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <switch/arm/atomics.h>
#include <switch/services/sm.h>
#include <stdlib.h>
#include <string.h>
Expand Down
88 changes: 23 additions & 65 deletions source/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool retrieveProcessMemory(keyLocation *location)
u64 pids[300];
u32 num_processes;

result = svcGetProcessList(&num_processes, pids, 300);
result = svcGetProcessList((s32*)&num_processes, pids, 300);
if (R_FAILED(result))
{
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, "%s: svcGetProcessList failed! (0x%08X)", __func__, result);
Expand Down Expand Up @@ -763,59 +763,6 @@ void mgf1(const u8 *data, size_t data_length, u8 *mask, size_t mask_length)
free(data_counter);
}

void dumpSharedTikSavedata(void)
{
FRESULT fr;
FIL save;
u32 size, blk, i, j;
u32 rd_b, wr_b;

FILE *out;

for(i = 0; i < 2; i++)
{
fr = FR_OK;
memset(&save, 0, sizeof(FIL));
size = 0;
blk = DUMP_BUFFER_SIZE;

out = NULL;

fr = f_open(&save, (i == 0 ? "sys:/save/80000000000000e3" : "sys:/save/80000000000000e4"), FA_READ | FA_OPEN_EXISTING);
if (fr) continue;

size = f_size(&save);
if (!size)
{
f_close(&save);
continue;
}

out = fopen((i == 0 ? "sdmc:/80000000000000e3" : "sdmc:/80000000000000e4"), "wb");
if (!out)
{
f_close(&save);
continue;
}

for(j = 0; j < size; j += blk)
{
if ((size - j) < blk) blk = (size - j);

rd_b = wr_b = 0;

fr = f_read(&save, dumpBuf, blk, &rd_b);
if (fr || rd_b != blk) break;

wr_b = fwrite(dumpBuf, 1, blk, out);
if (wr_b != blk) break;
}

fclose(out);
f_close(&save);
}
}

int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_enc_key, u8 *out_dec_key)
{
int ret = -1;
Expand Down Expand Up @@ -865,8 +812,8 @@ int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_en

u8 *D = NULL, *N = NULL, *E = NULL;

FRESULT fr;
FIL eTicketSave;
FRESULT fr = FR_OK;
FIL *eTicketSave = NULL;

save_ctx_t *save_ctx = NULL;
allocation_table_storage_ctx_t fat_storage;
Expand Down Expand Up @@ -984,7 +931,6 @@ int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_en
{
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, "%s: NCA rights ID unavailable in this console!", __func__);
ret = -2;
dumpSharedTikSavedata();
return ret;
}

Expand Down Expand Up @@ -1037,23 +983,32 @@ int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_en
setcal_eticket_retrieved = true;
}

eTicketSave = calloc(1, sizeof(FIL));
if (!eTicketSave)
{
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, "%s: unable to allocate memory for FatFs file descriptor!", __func__);
return ret;
}

// FatFs is used to mount the BIS System partition and read the ES savedata files to avoid 0xE02 (file already in use) errors
fr = f_open(&eTicketSave, (rightsIdType == 1 ? BIS_COMMON_TIK_SAVE_NAME : BIS_PERSONALIZED_TIK_SAVE_NAME), FA_READ | FA_OPEN_EXISTING);
fr = f_open(eTicketSave, (rightsIdType == 1 ? BIS_COMMON_TIK_SAVE_NAME : BIS_PERSONALIZED_TIK_SAVE_NAME), FA_READ | FA_OPEN_EXISTING);
if (fr)
{
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, "%s: failed to open ES %s eTicket save! (%u)", __func__, (rightsIdType == 1 ? "common" : "personalized"), fr);
free(eTicketSave);
return ret;
}

save_ctx = calloc(1, sizeof(save_ctx_t));
if (!save_ctx)
{
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, "%s: failed to allocate memory for ticket savefile context!");
f_close(&eTicketSave);
f_close(eTicketSave);
free(eTicketSave);
return ret;
}

save_ctx->file = &eTicketSave;
save_ctx->file = eTicketSave;
save_ctx->tool_ctx.action = 0;

if (!save_process(save_ctx))
Expand All @@ -1062,7 +1017,8 @@ int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_en
strcat(strbuf, tmp);
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, strbuf);
free(save_ctx);
f_close(&eTicketSave);
f_close(eTicketSave);
free(eTicketSave);
return ret;
}

Expand All @@ -1073,7 +1029,8 @@ int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_en
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, strbuf);
save_free_contexts(save_ctx);
free(save_ctx);
f_close(&eTicketSave);
f_close(eTicketSave);
free(eTicketSave);
return ret;
}

Expand All @@ -1084,7 +1041,8 @@ int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_en
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, strbuf);
save_free_contexts(save_ctx);
free(save_ctx);
f_close(&eTicketSave);
f_close(eTicketSave);
free(eTicketSave);
return ret;
}

Expand Down Expand Up @@ -1156,15 +1114,15 @@ int retrieveNcaTikTitleKey(nca_header_t *dec_nca_header, u8 *out_tik, u8 *out_en

save_free_contexts(save_ctx);
free(save_ctx);
f_close(&eTicketSave);
f_close(eTicketSave);
free(eTicketSave);

if (!proceed) return ret;

if (!foundEticket)
{
uiDrawString(STRING_X_POS, STRING_Y_POS(breaks), FONT_COLOR_ERROR_RGB, "%s: unable to find a matching eTicket entry for NCA rights ID!", __func__);
ret = -2;
dumpSharedTikSavedata();
return ret;
}

Expand Down
Loading

0 comments on commit ff3141f

Please sign in to comment.