i'm trying to modify a save throught this function, by using as reference shine's savedata tool (thanks for this great tool :))
but after i called it and while waiting for it to finish the psp crashes, so i added the exception handler and i got this:
printf("A");
int lenght = strlen(name);
printf("B%d", lenght);
int parsepos = strlen(g_gameName);
int result = 0;
printf("C%d", parsepos);
printf("C- %d - %d =", lenght-parsepos, (int)name+(lenght-parsepos));
g_saveName = malloc((lenght-parsepos)*sizeof(char));
memset(g_saveName,0, sizeof(g_saveName));
strcpy(g_saveName, name+(lenght-parsepos+1));
printf("D");
printf("%s - %s", g_saveName, name);
printf("E");
SceUtilitySavedataParam savedata;
initSavedata(&savedata, 0);
savedata.readIcon0Buf = g_readIcon0;
savedata.sizeOfReadIcon0Buf = 0x100000;
savedata.readIcon1Buf = g_readIcon1;
savedata.sizeOfReadIcon1Buf = 0x100000;
savedata.readPic1Buf = g_readPic1;
savedata.sizeOfReadPic1Buf = 0x100000;
printf("ready\n");
result = sceUtilitySavedataInitStart(savedata);
printf("result: %d", result);
if (result)
{
printf("sceUtilitySavedataInitStart failed");
return -1;
}
while (1) {
printf("while"); //when it arrives here i see a lot of while (3 lines) then crash without exeception handler, if there is the exception handler the while loop continue without any limit
result = sceUtilitySavedataGetStatus();
if (result == 3) break;
sceUtilitySavedataUpdate(1);
sceDisplayWaitVblankStart();
}
printf("stopping 1\n");
sceUtilitySavedataShutdownStart();
printf("A");
int lenght = strlen(name);
printf("B%d", lenght);
int parsepos = strlen(g_gameName);
int result = 0;
printf("C%d", parsepos);
printf("C- %d - %d =", lenght-parsepos, (int)name+(lenght-parsepos));
g_saveName = malloc((lenght-parsepos)*sizeof(char));
memset(g_saveName,0, sizeof(g_saveName));
strcpy(g_saveName, name+(lenght-parsepos+1));
printf("D");
The strcpy is starting from the wrong place in the string instead of the part after the gamename like I think you intended. This string is going to be longer than the memory you allocated and overrun the buffer.
Also, the memset uses sizeof(g_saveName) which equals 4, the size of the pointer, not the size of the memory allocated, but that line isn't needed anyway.
Here it is with corrections:
printf("A");
int length = strlen(name);
printf("B%d", length);
int parsepos = strlen(g_gameName);
int result = 0;
printf("C%d", parsepos);
printf("C- %d - %d =", length-parsepos, (int)name+(length-parsepos));
g_saveName = malloc((length-parsepos+1)*sizeof(char)); // added +1 for the '\0' string terminator
strcpy(g_saveName, name+parsepos);
printf("D g_gameName=%s g_saveName=%s", g_gameName, g_saveName);
I would probably do it this way to be a little less error prone:
int parsepos = strlen(g_gameName);
if (parsepos > strlen(name))
parsepos = strlen(name);
g_saveName = malloc(strlen(name+parsepos)+1);
strcpy(g_saveName, name+parsepos);
ok, i tried also this but it still don't work :(
actually i tried also hardcoding the name but still it didn't work and commenting out that section but nothing.
so i decided to save on ms the structure as a file. the result file seems corrent, but being not an expert of how this function work it could be wrong. now i put the file up there. maybe i'll also put the source somewhere
ok, i finally got it to work it was working under kernel mode and so crashing, i changed the main thread attribute to user and it started working perfectly :)
thanks EdisonCarter for the help and to the others over at irc channel and thanks to shine for his original source :)