From a5e18c82d15fae1e0cae6ba2f9380884d6564151 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Fri, 3 Nov 2017 02:15:28 +0100 Subject: [PATCH 01/15] reset scrolling when changing modes to avoid problems when the sizes dont match --- sysmodules/rosalina/source/menus/process_list.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index a0b700f..da1404a 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -183,11 +183,13 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) // Viewing void viewHeap(void) { + menus[MENU_MODE_NORMAL].selected = 0; menus[MENU_MODE_NORMAL].buf = (u8*)heapDestAddress; menus[MENU_MODE_NORMAL].max = heapTotalSize; } void viewCode(void) { + menus[MENU_MODE_NORMAL].selected = 0; menus[MENU_MODE_NORMAL].buf = (u8*)codeDestAddress; menus[MENU_MODE_NORMAL].max = codeTotalSize; } From 882c6cf0d43bd86b092dd19903118c6520d8c799 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Fri, 3 Nov 2017 02:19:15 +0100 Subject: [PATCH 02/15] show the "main" address to distinguish between heap and code --- sysmodules/rosalina/source/menus/process_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index da1404a..751d6ee 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -267,7 +267,7 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) u32 y = 44 + offset*12; u32 address = row*BYTES_PER_ROW; - Draw_DrawFormattedString(10, y, COLOR_TITLE, "%.8lx | ", address); + Draw_DrawFormattedString(10, y, COLOR_TITLE, "%.8lx | ", address + ((menuMode == MENU_MODE_NORMAL) ? (u32)menus[MENU_MODE_NORMAL].buf : 0)); for(int cursor = 0; cursor < BYTES_PER_ROW; cursor++, address++) { From 9495bf30bfcd4d1fccd3345a9518339d0d93f2c3 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sun, 5 Nov 2017 06:30:41 +0100 Subject: [PATCH 03/15] make jumping put the cursor at the top row downside: when jumping near the end, a blank is visible --- sysmodules/rosalina/source/menus/process_list.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 751d6ee..8dac268 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -203,6 +203,7 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) void finishJumping(void) { menus[MENU_MODE_NORMAL].selected = __builtin_bswap32(gotoAddress); // The data is edited in reverse, so it needs to be swapped before usage + menus[MENU_MODE_NORMAL].starti = totalRows; } menus[MENU_MODE_GOTO].buf = (u8*)&gotoAddress; @@ -299,10 +300,8 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) void handleScrolling(void) { - for(u32 i = 0; i < totalRows; i++) + for(u32 i = totalRows; i > 0 ; i--) { - if(totalRows <= ROWS_PER_SCREEN) - break; u32 scroll = menus[MENU_MODE_NORMAL].starti; u32 selectedRow = (menus[MENU_MODE_NORMAL].selected - (menus[MENU_MODE_NORMAL].selected % BYTES_PER_ROW))/BYTES_PER_ROW; From ab2ddbc2eed77f94daf2ea6bcdef3f9439e1c99f Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sun, 5 Nov 2017 06:48:56 +0100 Subject: [PATCH 04/15] fix visible blank if jumping too close to the end, the cursor won't be at the top to avoid the blank --- sysmodules/rosalina/source/menus/process_list.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 8dac268..736fd51 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -316,6 +316,9 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) menus[MENU_MODE_NORMAL].starti = scroll; } + + if (menus[MENU_MODE_NORMAL].starti > (totalRows - ROWS_PER_SCREEN)) + menus[MENU_MODE_NORMAL].starti = totalRows - ROWS_PER_SCREEN; } clearMenu(); From 48303604b0838e4da4c9cc055fb190109f0dc45f Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sun, 5 Nov 2017 06:56:54 +0100 Subject: [PATCH 05/15] show address instead of offset when jumping --- sysmodules/rosalina/source/menus/process_list.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 736fd51..4b1649d 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -202,6 +202,7 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) void finishJumping(void) { + gotoAddress -= __builtin_bswap32((u32)menus[MENU_MODE_NORMAL].buf); menus[MENU_MODE_NORMAL].selected = __builtin_bswap32(gotoAddress); // The data is edited in reverse, so it needs to be swapped before usage menus[MENU_MODE_NORMAL].starti = totalRows; } @@ -338,6 +339,8 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) { if(checkMode(MENU_MODE_GOTO)) finishJumping(); + else + gotoAddress = __builtin_bswap32((u32)menus[MENU_MODE_NORMAL].buf); } else if(pressed & BUTTON_Y) { From f9adbcc9d966b6d8eea1c2c55df381f601709df1 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Thu, 7 Dec 2017 18:23:29 +0100 Subject: [PATCH 06/15] fix same-name variables --- sysmodules/rosalina/source/menus/process_list.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 4b1649d..47a517d 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -101,12 +101,12 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) codeTotalSize = (u32)(textTotalRoundedSize + rodataTotalRoundedSize + dataTotalRoundedSize); codeDestAddress = codeStartAddress = (u32)textStartAddress; //should be 0x00100000 - MemInfo info; + MemInfo mem; PageInfo out; heapDestAddress = heapStartAddress = 0x08000000; - svcQueryProcessMemory(&info, &out, processHandle, heapStartAddress); - heapTotalSize = info.size; + svcQueryProcessMemory(&mem, &out, processHandle, heapStartAddress); + heapTotalSize = mem.size; Result codeRes = svcMapProcessMemoryEx(processHandle, codeDestAddress, codeStartAddress, codeTotalSize); Result heapRes = svcMapProcessMemoryEx(processHandle, heapDestAddress, heapStartAddress, heapTotalSize); From f156aa8cdb1726cfefd41ea4f512c8ec811fa266 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Thu, 7 Dec 2017 19:53:44 +0100 Subject: [PATCH 07/15] add dumper mostly a copy of the screenshotting function/from #937 --- .../rosalina/source/menus/process_list.c | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 47a517d..4869864 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -32,6 +32,7 @@ #include "menu.h" #include "utils.h" #include "fmt.h" +#include "ifile.h" #include "gdb/server.h" #include "minisoc.h" #include @@ -79,6 +80,119 @@ static inline int ProcessListMenu_FormatInfoLine(char *out, const ProcessInfo *i return sprintf(out, "%s%-4u %-8.8s %s", checkbox, info->pid, info->name, commentBuf); // Theoritically PIDs are 32-bit ints, but we'll only justify 4 digits } +static void ProcessListMenu_DumpMemory(const char *name, void *start, u32 size) +{ +#define TRY(expr) if(R_FAILED(res = (expr))) goto end; + + Draw_Lock(); + Draw_DrawString(10, 10, COLOR_TITLE, "Memory dump"); + const char * wait_message = "Please wait, this may take a while..."; + Draw_DrawString(10, 30, COLOR_WHITE, wait_message); + Draw_FlushFramebuffer(); + Draw_Unlock(); + + u64 total; + IFile file; + Result res; + + char filename[64] = {0}; + + FS_Archive archive; + FS_ArchiveID archiveId; + s64 out; + bool isSdMode; + + if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x203))) svcBreak(USERBREAK_ASSERT); + isSdMode = (bool)out; + + archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW; + + res = FSUSER_OpenArchive(&archive, archiveId, fsMakePath(PATH_EMPTY, "")); + if(R_SUCCEEDED(res)) + { + res = FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, "/luma/dumps"), 0); + if((u32)res == 0xC82044BE) // directory already exists + res = 0; + res = FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, "/luma/dumps/memory"), 0); + if((u32)res == 0xC82044BE) // directory already exists + res = 0; + FSUSER_CloseArchive(archive); + } + + int seconds, minutes, hours, days, year, month; + u64 milliseconds = osGetTime(); + seconds = milliseconds/1000; + milliseconds %= 1000; + minutes = seconds / 60; + seconds %= 60; + hours = minutes / 60; + minutes %= 60; + days = hours / 24; + hours %= 24; + + year = 1900; + + while(true) + { + bool leapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); + int daysInYear = leapYear ? 366 : 365; + if (days >= daysInYear) + { + days -= daysInYear; + ++year; + } + else + { + const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + for(month = 0; month < 12; ++month) + { + int dim = daysInMonth[month]; + + if (month == 1 && leapYear) + ++dim; + + if (days >= dim) + days -= dim; + else + break; + } + break; + } + } + days++; + month++; + + sprintf(filename, "/luma/dumps/memory/%.8s_%lx_%.4i-%.2i-%.2iT%.2i-%.2i-%.2i.bin", name, (u32)start, year, month, days, hours, minutes, seconds); + TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE)); + TRY(IFile_Write(&file, &total, start, size, 0)); + TRY(IFile_Close(&file)); + +end: + IFile_Close(&file); + + do + { + Draw_Lock(); + Draw_DrawString(10, 10, COLOR_TITLE, "Memory dump"); + Draw_DrawFormattedString(10, 30, COLOR_WHITE, "%*s", strlen(wait_message), " "); + if(R_FAILED(res)) + { + Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%.8lx).", res); + } + else + { + Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded."); + } + Draw_DrawString(10, 30+SPACING_Y, COLOR_WHITE, "Press B to go back."); + + Draw_FlushFramebuffer(); + Draw_Unlock(); + } + while(!(waitInput() & BUTTON_B) && !terminationRequest); + +#undef TRY +} + static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) { Handle processHandle; @@ -347,6 +461,12 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) if(checkMode(MENU_MODE_SEARCH)) finishSearching(); } + else if(pressed & BUTTON_SELECT) + { + clearMenu(); + ProcessListMenu_DumpMemory(info->name, menus[MENU_MODE_NORMAL].buf, menus[MENU_MODE_NORMAL].max); + clearMenu(); + } if(editing) { From d6a89db4959b763a8247b8b478693bea55eb9692 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Thu, 7 Dec 2017 19:56:36 +0100 Subject: [PATCH 08/15] make use of values defined in draw.h --- sysmodules/rosalina/source/menus/process_list.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 4869864..3aaf908 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -359,11 +359,10 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) { Draw_Lock(); Draw_DrawString(10, 10, COLOR_TITLE, "Memory viewer"); - Draw_DrawString(10, 26, COLOR_WHITE, "D-PAD to move, X to jump, Y to search, A to edit."); + Draw_DrawString(10, 30, COLOR_WHITE, "D-PAD to move, X to jump, Y to search, A to edit."); - #define CHARACTER_WIDTH 6 if(editing) - Draw_DrawString(10 + CHARACTER_WIDTH* 44, 26, COLOR_RED, "edit"); + Draw_DrawString(10 + SPACING_X* 44, 30, COLOR_RED, "edit"); char * modeStr[] = { "move", @@ -375,12 +374,12 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) 20, 31, }; - Draw_DrawString(10 + CHARACTER_WIDTH*modeStrPos[menuMode], 26, COLOR_GREEN, modeStr[menuMode]); + Draw_DrawString(10 + SPACING_X*modeStrPos[menuMode], 30, COLOR_GREEN, modeStr[menuMode]); for(u32 row = menus[menuMode].starti; row < (menus[menuMode].starti + ROWS_PER_SCREEN); row++) { u32 offset = row - menus[menuMode].starti; - u32 y = 44 + offset*12; + u32 y = 50 + offset*SPACING_Y; u32 address = row*BYTES_PER_ROW; Draw_DrawFormattedString(10, y, COLOR_TITLE, "%.8lx | ", address + ((menuMode == MENU_MODE_NORMAL) ? (u32)menus[MENU_MODE_NORMAL].buf : 0)); From 8353b8494418437acc2b750f7cdfefc9a4ba08a2 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Thu, 7 Dec 2017 20:07:44 +0100 Subject: [PATCH 09/15] fix dump filename --- sysmodules/rosalina/source/menus/process_list.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 3aaf908..345b116 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -119,7 +119,7 @@ static void ProcessListMenu_DumpMemory(const char *name, void *start, u32 size) FSUSER_CloseArchive(archive); } - int seconds, minutes, hours, days, year, month; + unsigned int seconds, minutes, hours, days, year, month; u64 milliseconds = osGetTime(); seconds = milliseconds/1000; milliseconds %= 1000; @@ -135,7 +135,7 @@ static void ProcessListMenu_DumpMemory(const char *name, void *start, u32 size) while(true) { bool leapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); - int daysInYear = leapYear ? 366 : 365; + unsigned int daysInYear = leapYear ? 366 : 365; if (days >= daysInYear) { days -= daysInYear; @@ -143,10 +143,10 @@ static void ProcessListMenu_DumpMemory(const char *name, void *start, u32 size) } else { - const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + const unsigned int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; for(month = 0; month < 12; ++month) { - int dim = daysInMonth[month]; + unsigned int dim = daysInMonth[month]; if (month == 1 && leapYear) ++dim; @@ -162,7 +162,7 @@ static void ProcessListMenu_DumpMemory(const char *name, void *start, u32 size) days++; month++; - sprintf(filename, "/luma/dumps/memory/%.8s_%lx_%.4i-%.2i-%.2iT%.2i-%.2i-%.2i.bin", name, (u32)start, year, month, days, hours, minutes, seconds); + sprintf(filename, "/luma/dumps/memory/%.8s_0x%.8lx_%.4u-%.2u-%.2uT%.2u-%.2u-%.2u.bin", name, (u32)start, year, month, days, hours, minutes, seconds); TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE)); TRY(IFile_Write(&file, &total, start, size, 0)); TRY(IFile_Close(&file)); From 65af93c8ce5ca356924758889eec5b43d70a5a4e Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Thu, 7 Dec 2017 22:07:53 +0100 Subject: [PATCH 10/15] other display for entering goto --- sysmodules/rosalina/source/menus/process_list.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 345b116..61536f1 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -453,6 +453,7 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) if(checkMode(MENU_MODE_GOTO)) finishJumping(); else + // gotoAddress = __builtin_bswap32(((u32)menus[MENU_MODE_NORMAL].buf) + menus[MENU_MODE_NORMAL].selected); gotoAddress = __builtin_bswap32((u32)menus[MENU_MODE_NORMAL].buf); } else if(pressed & BUTTON_Y) From 37a9fa1bf4a992eb7aa80ef65bc74bae5d8ccea9 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Thu, 14 Dec 2017 17:03:13 +0100 Subject: [PATCH 11/15] work again with heapless processes, and show wether you're currently viewing heap or code on screen (apart from the address) --- .../rosalina/source/menus/process_list.c | 64 +++++++++++++------ 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 61536f1..ece7a47 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -225,7 +225,10 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) Result codeRes = svcMapProcessMemoryEx(processHandle, codeDestAddress, codeStartAddress, codeTotalSize); Result heapRes = svcMapProcessMemoryEx(processHandle, heapDestAddress, heapStartAddress, heapTotalSize); - if(R_SUCCEEDED(codeRes | heapRes)) + bool codeAvailable = R_SUCCEEDED(codeRes); + bool heapAvailable = R_SUCCEEDED(heapRes); + + if(codeAvailable || heapAvailable) { #define ROWS_PER_SCREEN 0x10 #define BYTES_PER_ROW 0x10 @@ -297,18 +300,23 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) // Viewing void viewHeap(void) { + if(!heapAvailable) return; menus[MENU_MODE_NORMAL].selected = 0; menus[MENU_MODE_NORMAL].buf = (u8*)heapDestAddress; menus[MENU_MODE_NORMAL].max = heapTotalSize; } void viewCode(void) { + if(!codeAvailable) return; menus[MENU_MODE_NORMAL].selected = 0; menus[MENU_MODE_NORMAL].buf = (u8*)codeDestAddress; menus[MENU_MODE_NORMAL].max = codeTotalSize; } - viewHeap(); + if(heapAvailable) + viewHeap(); + else + viewCode(); // ------------------------------------------ // Jumping @@ -359,27 +367,47 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) { Draw_Lock(); Draw_DrawString(10, 10, COLOR_TITLE, "Memory viewer"); - Draw_DrawString(10, 30, COLOR_WHITE, "D-PAD to move, X to jump, Y to search, A to edit."); + + // Instructions + const u32 instructionsY = 30; + u32 viewerY = instructionsY + SPACING_Y + 6; + Draw_DrawString(10, instructionsY, COLOR_WHITE, "D-PAD to move, X to jump, Y to search, A to edit."); + + switch(menuMode) + { + case MENU_MODE_NORMAL: + Draw_DrawString(10 + SPACING_X * 9, instructionsY, COLOR_GREEN, "move"); + break; + case MENU_MODE_GOTO: + Draw_DrawString(10 + SPACING_X * 20, instructionsY, COLOR_GREEN, "jump"); + break; + case MENU_MODE_SEARCH: + Draw_DrawString(10 + SPACING_X * 31, instructionsY, COLOR_GREEN, "search"); + break; + default: break; + } if(editing) - Draw_DrawString(10 + SPACING_X* 44, 30, COLOR_RED, "edit"); + Draw_DrawString(10 + SPACING_X * 44, instructionsY, COLOR_RED, "edit"); + // ------------------------------------------ - char * modeStr[] = { - "move", - "jump", - "search", - }; - u32 modeStrPos[] = { - 9, - 20, - 31, - }; - Draw_DrawString(10 + SPACING_X*modeStrPos[menuMode], 30, COLOR_GREEN, modeStr[menuMode]); + // Location + if(codeAvailable && heapAvailable) + { + const u32 infoY = instructionsY + SPACING_Y; + viewerY += SPACING_Y; + Draw_DrawString(10, infoY, COLOR_WHITE, "Press L or R to switch between heap and code."); + if((u32)menus[MENU_MODE_NORMAL].buf == heapDestAddress) + Draw_DrawString(10 + SPACING_X * 31, infoY, COLOR_GREEN, "heap"); + if((u32)menus[MENU_MODE_NORMAL].buf == codeDestAddress) + Draw_DrawString(10 + SPACING_X * 40, infoY, COLOR_GREEN, "code"); + } + // ------------------------------------------ for(u32 row = menus[menuMode].starti; row < (menus[menuMode].starti + ROWS_PER_SCREEN); row++) { u32 offset = row - menus[menuMode].starti; - u32 y = 50 + offset*SPACING_Y; + u32 y = viewerY + offset*SPACING_Y; u32 address = row*BYTES_PER_ROW; Draw_DrawFormattedString(10, y, COLOR_TITLE, "%.8lx | ", address + ((menuMode == MENU_MODE_NORMAL) ? (u32)menus[MENU_MODE_NORMAL].buf : 0)); @@ -527,9 +555,9 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) clearMenu(); } - if(R_SUCCEEDED(codeRes)) + if(codeAvailable) svcUnmapProcessMemoryEx(processHandle, codeDestAddress, codeTotalSize); - if(R_SUCCEEDED(heapRes)) + if(heapAvailable) svcUnmapProcessMemoryEx(processHandle, heapDestAddress, heapTotalSize); svcCloseHandle(processHandle); From 2be2826b0b36588b6d1725833ff29f3efed9c9c9 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sat, 16 Dec 2017 04:14:21 +0100 Subject: [PATCH 12/15] detect jumping address and change mode accordingly --- sysmodules/rosalina/source/menus/process_list.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index ece7a47..cda9a01 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -324,8 +324,17 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) void finishJumping(void) { - gotoAddress -= __builtin_bswap32((u32)menus[MENU_MODE_NORMAL].buf); - menus[MENU_MODE_NORMAL].selected = __builtin_bswap32(gotoAddress); // The data is edited in reverse, so it needs to be swapped before usage + gotoAddress = __builtin_bswap32(gotoAddress); // The data is edited in reverse, so it needs to be swapped before usage + + u32 codeEndAddress = codeStartAddress + codeTotalSize; + u32 heapEndAddress = heapStartAddress + heapTotalSize; + if(gotoAddress >= codeStartAddress && gotoAddress < codeEndAddress) + viewCode(); + else if(gotoAddress >= heapStartAddress && gotoAddress < heapEndAddress) + viewHeap(); + + gotoAddress -= (u32)menus[MENU_MODE_NORMAL].buf; + menus[MENU_MODE_NORMAL].selected = gotoAddress; menus[MENU_MODE_NORMAL].starti = totalRows; } From 648801d4326801eeda7fe9a941b3268281cdf49c Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sat, 16 Dec 2017 04:30:40 +0100 Subject: [PATCH 13/15] make pressing X accidentally twice less punitive --- sysmodules/rosalina/source/menus/process_list.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index cda9a01..242255e 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -490,8 +490,7 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) if(checkMode(MENU_MODE_GOTO)) finishJumping(); else - // gotoAddress = __builtin_bswap32(((u32)menus[MENU_MODE_NORMAL].buf) + menus[MENU_MODE_NORMAL].selected); - gotoAddress = __builtin_bswap32((u32)menus[MENU_MODE_NORMAL].buf); + gotoAddress = __builtin_bswap32(((u32)menus[MENU_MODE_NORMAL].buf) + menus[MENU_MODE_NORMAL].selected); } else if(pressed & BUTTON_Y) { From d54417ac0a09bd6b38e4f9b81172d8718e3f0cfe Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sat, 16 Dec 2017 19:26:27 +0100 Subject: [PATCH 14/15] explicit casting --- sysmodules/rosalina/source/menus/process_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 242255e..14e32a3 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -362,7 +362,7 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) void finishSearching(void) { - u8 * startpos = menus[MENU_MODE_NORMAL].buf + menus[MENU_MODE_NORMAL].selected; + u8 * startpos = (u8*)((u32)menus[MENU_MODE_NORMAL].buf + menus[MENU_MODE_NORMAL].selected); u32 size = menus[MENU_MODE_NORMAL].max - menus[MENU_MODE_NORMAL].selected; if (size >= searchPatternSize) menus[MENU_MODE_NORMAL].selected = (u32)memsearch(startpos, searchPattern, size, searchPatternSize) - (u32)menus[MENU_MODE_NORMAL].buf; From 0075fe2aa0821fd54530a00836be7fe7556bcba0 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sat, 16 Dec 2017 19:26:55 +0100 Subject: [PATCH 15/15] work with processes with code starting at 0x14000000 --- sysmodules/rosalina/source/menus/process_list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysmodules/rosalina/source/menus/process_list.c b/sysmodules/rosalina/source/menus/process_list.c index 14e32a3..79e455a 100644 --- a/sysmodules/rosalina/source/menus/process_list.c +++ b/sysmodules/rosalina/source/menus/process_list.c @@ -213,7 +213,8 @@ static void ProcessListMenu_MemoryViewer(const ProcessInfo *info) svcGetProcessInfo(&textStartAddress, processHandle, 0x10005); codeTotalSize = (u32)(textTotalRoundedSize + rodataTotalRoundedSize + dataTotalRoundedSize); - codeDestAddress = codeStartAddress = (u32)textStartAddress; //should be 0x00100000 + codeStartAddress = (u32)textStartAddress; //should be 0x00100000, rarely 0x14000000 + codeDestAddress = 0x00100000; MemInfo mem; PageInfo out;