From 873155068837421a44bab87c0769da3b59766b95 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sat, 7 Dec 2019 21:49:58 +0100 Subject: [PATCH] print hex --- source/libs/fatfs/ff.c | 2 +- source/tegraexplorer/fs.c | 52 +++++++++++++++++++++++++++++++++--- source/tegraexplorer/fs.h | 3 ++- source/tegraexplorer/gfx.c | 5 ++++ source/tegraexplorer/gfx.h | 3 ++- source/tegraexplorer/tools.c | 2 +- 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/source/libs/fatfs/ff.c b/source/libs/fatfs/ff.c index 3c254a7..8bf67ee 100644 --- a/source/libs/fatfs/ff.c +++ b/source/libs/fatfs/ff.c @@ -6134,7 +6134,7 @@ FRESULT f_fdisk ( sz_part = (DWORD)sz_cyl * p_cyl; if (i == 0) { /* Exclude first track of cylinder 0 */ s_hd = 1; - s_part += 32831; sz_part -= 32831; + s_part += 32768; sz_part -= 32768; } else { s_hd = 0; } diff --git a/source/tegraexplorer/fs.c b/source/tegraexplorer/fs.c index dea00d4..dd99858 100644 --- a/source/tegraexplorer/fs.c +++ b/source/tegraexplorer/fs.c @@ -17,15 +17,16 @@ u8 clipboardhelper = 0; extern const char sizevalues[4][3]; extern int launch_payload(char *path); -menu_item explfilemenu[8] = { +menu_item explfilemenu[9] = { {"-- File Menu --", COLOR_BLUE, -1, 0}, {"FILE", COLOR_GREEN, -1, 0}, {"\nSIZE", COLOR_VIOLET, -1, 0}, {"\n\n\nBack", COLOR_WHITE, -1, 1}, {"\nCopy to clipboard", COLOR_BLUE, COPY, 1}, {"Move to clipboard", COLOR_BLUE, MOVE, 1}, - {"\nDelete file", COLOR_RED, DELETE, 1}, - {"\nLaunch Payload", COLOR_ORANGE, PAYLOAD, 1} + {"\nDelete file\n", COLOR_RED, DELETE, 1}, + {"Launch Payload", COLOR_ORANGE, PAYLOAD, 1}, + {"View Hex", COLOR_GREEN, HEXVIEW, 1} }; void writecurpath(const char *in){ @@ -104,6 +105,46 @@ bool checkfile(char* path){ return true; } +void viewbytes(char *path){ + FIL in; + u8 print[2048]; + u32 size; + QWORD offset = 0; + int res; + + clearscreen(); + res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING); + if (res != FR_OK){ + message("fuck", COLOR_RED); + return; + } + + msleep(200); + + while (1){ + f_lseek(&in, offset * 16); + + res = f_read(&in, &print, 2048 * sizeof(u8), &size); + if (res != FR_OK){ + message("ohgod", COLOR_RED); + } + + printbytes(print, size, offset * 16); + res = btn_read(); + + if (!res) + res = btn_wait(); + + if (res & BTN_VOL_DOWN && 2048 * sizeof(u8) == size) + offset++; + if (res & BTN_VOL_UP && offset > 0) + offset--; + if (res & BTN_POWER) + break; + } + f_close(&in); +} + void addobject(char* name, int spot, bool isfol, bool isarc){ size_t size = strlen(name) + 1; fileobjects[spot].property = 0; @@ -206,7 +247,7 @@ void filemenu(const char *startpath){ else explfilemenu[7].property = -1; - tempint = makemenu(explfilemenu, 8); + tempint = makemenu(explfilemenu, 9); switch (tempint){ case COPY: @@ -227,6 +268,9 @@ void filemenu(const char *startpath){ case PAYLOAD: launch_payload(getnextloc(currentpath, fileobjects[res - 1].name)); break; + case HEXVIEW: + viewbytes(getnextloc(currentpath, fileobjects[res - 1].name)); + break; } } } diff --git a/source/tegraexplorer/fs.h b/source/tegraexplorer/fs.h index 5a2b5f0..de5638e 100644 --- a/source/tegraexplorer/fs.h +++ b/source/tegraexplorer/fs.h @@ -30,7 +30,8 @@ enum filemenuoptions { COPY = 1, MOVE, DELETE, - PAYLOAD + PAYLOAD, + HEXVIEW }; int readfolder(const char *path); diff --git a/source/tegraexplorer/gfx.c b/source/tegraexplorer/gfx.c index fd1aa1a..77b97bf 100644 --- a/source/tegraexplorer/gfx.c +++ b/source/tegraexplorer/gfx.c @@ -80,6 +80,11 @@ int makemenu(menu_item menu[], int menuamount){ } } +void printbytes(u8 print[], u32 size, u32 offset){ + gfx_con_setpos(0, 31); + gfx_hexdump(offset, print, size * sizeof(u8)); +} + void printfsentry(fs_entry file, bool highlight, bool refresh){ int size = 0; char *display; diff --git a/source/tegraexplorer/gfx.h b/source/tegraexplorer/gfx.h index cf9806c..729820a 100644 --- a/source/tegraexplorer/gfx.h +++ b/source/tegraexplorer/gfx.h @@ -5,4 +5,5 @@ int makemenu(menu_item menu[], int menuamount); int message(char* message, u32 color); void clearscreen(); -int makefilemenu(fs_entry *files, int amount, char *path); \ No newline at end of file +int makefilemenu(fs_entry *files, int amount, char *path); +void printbytes(u8 print[], u32 size, u32 offset); \ No newline at end of file diff --git a/source/tegraexplorer/tools.c b/source/tegraexplorer/tools.c index a8ed9c3..69be6a9 100644 --- a/source/tegraexplorer/tools.c +++ b/source/tegraexplorer/tools.c @@ -31,7 +31,7 @@ void displayinfo(){ temp_sect = tot_sect; temp_sect -= 61145088; - gfx_printf("\n1st part: %d\n2nd part: 61145088\n\n", temp_sect); + gfx_printf("\n%k1st part: %d\n2nd part: 61145088\n\n%k", COLOR_RED, temp_sect, COLOR_WHITE); disk_initialize(0); disk_ioctl(0, GET_SECTOR_COUNT, &sz_disk);