Skip to content

Commit

Permalink
Merge pull request #4 from suloku/patch-1
Browse files Browse the repository at this point in the history
Fetch title ID from suloku/3ds_hb_menu, and use relative paths for flag/config files
  • Loading branch information
meladroit committed Sep 16, 2015
2 parents 3d87ea4 + b908936 commit 641c817
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -58,7 +58,7 @@ LIBS := -lctru -lm -lz
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(DEVKITPRO)/ctrulib/libctru $(DEVKITPRO)/portlibs/armv6k
LIBDIRS := $(DEVKITPRO)/ctrulib/libctru $(DEVKITPRO)/portlibs/armv6k $(CTRULIB)


#---------------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions asr.dat
@@ -1,6 +1,8 @@
CTR-P-EGD /garden.dat 00000000
CTR-P-NXC /account_data.bin 00000010
CTR-P-NXC /system_data.bin 00000010
CTR-P-NXC /save_data/account_data.bin 00000010
CTR-P-NXC /save_data/system_data.bin 00000010
CTR-T-AXC /save_data/account_data.bin 00000010
CTR-T-AXC /save_data/system_data.bin 00000010
CTR-P-EKJ /main 00065400
CTR-P-EK2 /main 00065400
CTR-P-ECL /main 00075e00
Expand Down
27 changes: 25 additions & 2 deletions source/filesystem.c
@@ -1,5 +1,6 @@
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <3ds.h>

Expand Down Expand Up @@ -285,3 +286,25 @@ Result doesFileNotExist(const char* filename, Handle* fsHandle, FS_archive archi
else
return -1;
}

int file_exist(const char * filename)
{
FILE * pFile;
long lSize;
char * buffer;
size_t result;

pFile = fopen ( filename , "rb" );
if (pFile==NULL) return 0;
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) return 0;
result = fread (buffer,1,lSize,pFile);
if (result != lSize) return 0;
fclose (pFile);
free (buffer);
if (lSize > 0) return 1;
return 0;
}
3 changes: 2 additions & 1 deletion source/filesystem.h
Expand Up @@ -16,5 +16,6 @@ u64 sizeFile(char* path, FS_archive* archive, Handle* fsHandle);
Result readBytesFromSaveFile(const char* filename, u64 offset, u8* buffer, u32 size);
Result writeBytesToSaveFile(const char* filename, u64 offset, u8* buffer, u32 size);
Result getSaveGameFileSize(const char* filename, u64* size);
Result doesFileNotExist(const char* filename, Handle* fsHandle, FS_archive archive);
Result doesFileNotExist(const char* filename, Handle* fsHandle, FS_archive archive);
int file_exist (const char *filename);
#endif
51 changes: 47 additions & 4 deletions source/main.c
Expand Up @@ -525,11 +525,14 @@ int checkInjectDirectory(char* path, lsDir* dir)
int main()
{
filesystemInit();
if (!doesFileNotExist("/3ds/svdt/no_alpha_sort",&sdmcFsHandle,sdmcArchive))
//if (!doesFileNotExist("/3ds/svdt/no_alpha_sort",&sdmcFsHandle,sdmcArchive))
if (file_exist("no_alpha_sort"))
alphabetSort = 0;

FSUSER_CreateDirectory(&sdmcFsHandle,sdmcArchive,FS_makePath(PATH_CHAR,"/svdt"));

u64 tid;
u64 tid2 = 0;
int titleTitles_available;
char destPath[MAX_PATH_LENGTH];
char tempStr[16] = {0};
Expand All @@ -543,6 +546,23 @@ int main()
getTitleTitle(0x0,2,titleTitle);
titleTitle_set = 1;
} else {
//Fetch title from /svdt/tid.bin
FILE * pFile;
long lSize;
size_t result;
pFile = fopen ( "/svdt/tid.bin" , "rb" );
if (pFile!=NULL) {
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
result = fread (&tid2,1,sizeof(tid2),pFile);
if (result == lSize) {
fclose (pFile);
//Make sure we can't load this again without going trough HBL
remove("/svdt/tid.bin");
}
}
fclose (pFile);
secureGameFromFilesystem();
getSecureValue();
}
Expand All @@ -555,7 +575,8 @@ int main()

hidScanInput();

if ((hidKeysHeld() & KEY_L) != doesFileNotExist("/3ds/svdt/disable_auto_backups",&sdmcFsHandle,sdmcArchive))
//if ((hidKeysHeld() & KEY_L) != doesFileNotExist("/3ds/svdt/disable_auto_backups",&sdmcFsHandle,sdmcArchive))
if ((hidKeysHeld() & KEY_L) == file_exist("disable_auto_backups"))
{
// always back up the data if one and only one of two conditions is met:
// no disable_auto_backups file (cannot be empty)
Expand Down Expand Up @@ -666,7 +687,7 @@ int main()

consoleSelect(&titleBar);
textcolour(TEAL);
printf("svdt 0.10, meladroit/willidleaway\n");
printf("svdt 0.10.1, meladroit/willidleaway/suloku\n");
printf("a hacked-together save data explorer/manager\n");
gotoxy(CURSOR_WIDTH,2);
textcolour(GREY);
Expand Down Expand Up @@ -705,7 +726,22 @@ int main()
gotoxy(0,10);
int i;
for (i=0;i<BOTTOM_WIDTH;i++) { printf(" "); }
nthTitleInList(titleTitle_set,mediatype,titleTitle,&tid);
if (tid2 != 0){
lsTitle* currentTitle = firstTitle;
int i = 0;
while(currentTitle != NULL){
if (currentTitle->thisTitle == tid2){
titleTitle_set = i;
getTitleTitle(tid2, mediatype, titleTitle);
tid = tid2;
break;
}
currentTitle = currentTitle->nextTitle;
i++;
}
}
if (!titleTitle_set)
nthTitleInList(titleTitle_set,mediatype,titleTitle,&tid);
AM_GetTitleProductCode(mediatype,tid,productCodeBuffer);
strncpy(productCode,productCodeBuffer,9);
gotoxy(1,10);
Expand All @@ -715,6 +751,10 @@ int main()
gotoxy((BOTTOM_WIDTH-strlen(titleTitle))/2,10);
textcolour(NEONGREEN);
printf(titleTitle);
gotoxy(0,29);
textcolour(WHITE);
printf(productCode);
printf(" - %llx", tid);
gotoxy(0,12);
textcolour(SALMON);
wordwrap("Target app is not on gamecard. Fetching target app titles automatically is not implemented for NAND/SD apps. Use left/right on D-pad with the A button to select the correct target app name. Press B to skip.",BOTTOM_WIDTH);
Expand Down Expand Up @@ -761,6 +801,9 @@ int main()
textcolour(WHITE);
AM_GetTitleProductCode(mediatype,tid,productCodeBuffer);
strncpy(productCode,productCodeBuffer,9);
gotoxy(0,29);
printf(productCode);
printf(" - %llx", tid);
}
if(hidKeysDown() & KEY_A)
{
Expand Down
24 changes: 13 additions & 11 deletions source/secure_values.c
Expand Up @@ -15,7 +15,7 @@ u8 secureValue[SECURE_VALUE_SIZE] = {0};
secureGame whichSecureGame = SECURE_UNKNOWN;

const u32 const secureOffsets[PRECONF_GAMES] = {ACNL_OFFSET, SSB_OFFSET, POKETORU_OFFSET, POKEXY_OFFSET, POKEXY_OFFSET, POKEORAS_OFFSET, POKEORAS_OFFSET};
const char const secureFilenames[PRECONF_GAMES][MAX_PATH_LENGTH] = {"/garden.dat", "/account_data.bin", "/savedata.bin", "/main", "/main", "/main", "/main"};
const char const secureFilenames[PRECONF_GAMES][MAX_PATH_LENGTH] = {"/garden.dat", "/save_data/account_data.bin", "/save_data/savedata.bin", "/main", "/main", "/main", "/main"};
const char const secureProductCodes[PRECONF_GAMES][16] = {"CTR-P-EGD",
"CTR-P-NXC", "CTR-N-KRX",
"CTR-P-EKJ", "CTR-P-EK2",
Expand All @@ -26,7 +26,7 @@ char configProductCode[9] = {0};

const char* const POKERW_SVPATH = "/00slot00/00main.dat";
const char* const customSecurePath = "/svdt_sv_data";
const char* const secureConfigPath = "/3ds/svdt/asr.dat";
const char* const secureConfigPath = "asr.dat";
const char* const secureConfigBasename = "asr.dat";

int isSecureFile(const char* destPath)
Expand Down Expand Up @@ -78,7 +78,7 @@ int isSecureFile2(const char* destPath, const char* productCode)
{
if (!strncmp(productCode,pokeRumbleWorldCode,9))
return (!strcmp(destPath,POKERW_SVPATH));
if(checkSecureConfig())
if(!checkSecureConfig())
return -1;
if(!secureValueSet)
return -1;
Expand All @@ -98,12 +98,14 @@ int isSecureFile2(const char* destPath, const char* productCode)

Result checkCustomSecureGame()
{
return doesFileNotExist(customSecurePath,&sdmcFsHandle,sdmcArchive);
//return doesFileNotExist(customSecurePath,&sdmcFsHandle,sdmcArchive);
return file_exist(customSecurePath);
}

Result checkSecureConfig()
{
return doesFileNotExist(secureConfigPath,&sdmcFsHandle,sdmcArchive);
//return doesFileNotExist(secureConfigPath,&sdmcFsHandle,sdmcArchive);
return file_exist(secureConfigPath);
}

void secureGameFromProductCode(const char* productCode)
Expand All @@ -117,7 +119,7 @@ void secureGameFromProductCode(const char* productCode)
return;
}
// ideally we actually have asr.dat in /3ds/svdt
if(!checkSecureConfig())
if(checkSecureConfig())
{
// and ideally we actually have the product code in there ...
FILE* config = fopen(secureConfigBasename,"rb");
Expand Down Expand Up @@ -150,7 +152,7 @@ void secureGameFromProductCode(const char* productCode)
}
}
// custom specifier does not take precedence over having the actual product code
if(!checkCustomSecureGame())
if(checkCustomSecureGame())
{
whichSecureGame = SECURE_EMERGENCY;
return;
Expand All @@ -163,7 +165,7 @@ void secureGameFromFilesystem()
u64 size = 0;
secureValueSet = 0;
// custom specifier absolutely takes precedence over these guesses
if(!checkCustomSecureGame())
if(checkCustomSecureGame())
{
whichSecureGame = SECURE_EMERGENCY;
return;
Expand All @@ -176,9 +178,9 @@ void secureGameFromFilesystem()
}
// from here, the guesses are much less safe
// (there's a reason we override these if we can get to the target title prompt)
if(!getSaveGameFileSize("/account_data.bin",&size))
if(!getSaveGameFileSize("/save_data/account_data.bin",&size))
{
if(!getSaveGameFileSize("/system_data.bin",&size))
if(!getSaveGameFileSize("/save_data/system_data.bin",&size))
{
whichSecureGame = SECURE_SSB;
return;
Expand Down Expand Up @@ -292,7 +294,7 @@ Result getSecureValue2(const char* productCode)
{
if (!strncmp(productCode,pokeRumbleWorldCode,9))
return getPokeRumbleSecureValue();
if(checkSecureConfig())
if(!checkSecureConfig())
return -1;
//printf("\nopening asr.dat\n");
FILE* config = fopen(secureConfigBasename,"rb");
Expand Down
Binary file modified svdt.3dsx
Binary file not shown.

0 comments on commit 641c817

Please sign in to comment.