sceUtilitySavedataInitStart

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

sceUtilitySavedataInitStart

Post by weltall »

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:

Code: Select all

Exception - Adress load/inst fecth
EPC 		- 0878B7A0
Cause 		- 00000010
Status 		- 20008613
BadVAddr 	- 882EA1E4
zr: 00000000 at: 0008FF00 v0: 882EA1D8 v1: 08790000
a0: 0879272C a1: 08790000 a2: FFFFFFFF a3: 00000001
t0: FFFFFFFF t1: D3100000 t2: 00000018 t3: 0000000C
t4: 087FFE90 t5: 00000E00 t6: 0878B780 t7: 00008600
s0: DEADBEEF s1: DEADBEEF s2: DEADBEEF s3: DEADBEEF
s4: DEADBEEF s5: DEADBEEF s6: DEADBEEF s7: DEADBEEF
t8: 88225528 t9: 00000030 k0: 087FFF00 k1: 00000000
gp: 0879B790 sp: 087FFE90 fp: 087FFEC0 ra: 0878B780
then i tried psp-addr2line, but i got nothing
i can't understant what the problem this is the piece of code crashing

Code: Select all

	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();
thanks in advance
EdisonCarter
Posts: 2
Joined: Mon Oct 31, 2005 8:09 am
Contact:

Post by EdisonCarter »

Hey, I was just working on the same stuff.

The problem is in this section of code:

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);
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

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
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

that's the file in hexadecimal
C805000000000000000000001100000013000000120000001000000000000000000000000000000000000000000000000000
00000000000001000000554C4A533030303135000000000000002D3030300000000000000000000000000000000000000000
444154412E42494E000000000000000088DD9608000010000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000090DDA60800001000000000000000000098DDB608000010000000000000000000A0DDC6080000
100000000000000000000000000000000000000000000000000000000000

and this in ascii
............................................................ULJS00015.......-000....................
DATA.BIN............................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
................................................................................

as you can see teorycally it should be fine (at least from what i understood) but it still don't work :(
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

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 :)
Post Reply