Welcome! Log In Create A New Profile

Advanced

[SOLVED] How to read from ISFS?

Posted by Superyoshi 
[SOLVED] How to read from ISFS?
May 23, 2010 04:14PM
So I recently got the urge to read some stuff from ISFS, to be exact, a savegame. I already decrypted the system, but now I fail at reading it in my App.

My code:
		ISFS_Initialize();
		fd=ISFS_Open("/title/00010001/57525550/data/savefile.dat",ISFS_OPEN_READ);
		if (fd < 0) {
            printf("\n              Error: ISFS_OpenFile() returned %d", fd);
			if (fd == -106) {
				printf("\n              It seems like you haven't got BIT.TRIP Runner (PAL)...");
				}
            reload();
			} else {
			printf("\n\n\n              File found!");
			ret = ISFS_Read(fd, buffer, 2);
			if (ret < 0) {
				printf("\n              Error: ISFS_Read() returned %d", ret);
				ISFS_Close(fd);
				reload();
				} else {
				printf("\n              First Value: %s",buffer);
				ISFS_Close(fd);
				reload();
				}
			}
It does open the file, but as soon as I try to read a value, it gives me error -101. I looked at the sources of Playstats and FSToolbox, did a Google Search, but nothing helped me.
So my question is: How to read hexadecimal values one by one* from a file on ISFS?

*as in "if the file would be '01 01 01 0C', the function would return '01' the first three times, then '0C'"

EDIT: Wrong forum ^.^" Please move



Edited 2 time(s). Last edit at 05/25/2010 07:08PM by Superyoshi.
Re: How to read from ISFS?
May 24, 2010 01:53PM
Sorry for DP...

I came a bit farther, I "borrowed" some code from FSToolbox:

		u8 *buffer;

        int fd;
        s32 ret;
        u32 size;

        fd = ISFS_Open("/title/00010001/57525550/data/savefile.dat", ISFS_OPEN_READ);
        if (fd < 0) 
        {
                printf("\nError: ISFS_OpenFile() returned %d\n", fd);
				return 0;
        }
		buffer = (u8 *)memalign(32, 2048);
		size = 2048;
		
		ret = ISFS_Read(fd, buffer, size);
        if (ret < 0)
        {
            printf("\nISFS_Read(%d, %p, %d) returned %d\n", fd, buffer, size, ret);
            ISFS_Close(fd);
            free(buffer);
            return 0;
        }
		ISFS_Close(fd);
        free(buffer);
        printf("\n\n%h\n", buffer);
It properly displays the hex value 8030bbc0... but the file begins 0101010c... what the?
What is the real method to read one byte in Hex from the file? Thanks in advance.
Re: How to read from ISFS?
May 24, 2010 03:09PM
use %x, %02x, %04x, %08x, %016llx. for hex with uppercase letters, use a capitol X.

and you dont really want to read 1 byte at a time. instead read a bunch of bytes from the file into a buffer and then get the byte you want from the buffer.



Edited 1 time(s). Last edit at 05/24/2010 03:16PM by giantpune.
Re: How to read from ISFS?
May 24, 2010 03:21PM
With %x, %02x, %04x, %08x, it still gives me 8030bbc0.
With %016llx, %032llx and so on it gives me 933E0F9000000000 with some zeroes before the higher the number is.
Re: How to read from ISFS?
May 24, 2010 03:36PM
you see anything wrong with this?

free(buffer);
printf("\n\n%h\n", buffer);
Re: How to read from ISFS?
May 24, 2010 03:49PM
...oops. ^.^" Yes, there is something wrong. But even if I change it to

printf("\n\n%x\n", buffer);
free(buffer);

It still gives me 8030bbc0.
Re: How to read from ISFS?
May 25, 2010 12:19AM
Try adding ISFS_Initialize() before doing anything.


oops you've got that in your first example but not your second. Is it still there?



Edited 1 time(s). Last edit at 05/25/2010 12:32AM by chris.
Re: How to read from ISFS?
May 25, 2010 10:23AM
Yes, it is there. I just cut it out on the extract.

Should I uplaod the whole code and the file I want to read?
Re: How to read from ISFS?
May 25, 2010 11:39AM
Yes, do that.
Re: How to read from ISFS?
May 25, 2010 01:24PM
main.cpp
[pastebin.com]

File to read (aka. BIT.TRIP RUNNER savegame)
[www.file-upload.net]
Re: How to read from ISFS?
May 25, 2010 03:50PM
libmii reads from the ISFS and the method it implores is quite different from your method above. If you continue to get stuck, you can try the way I did it in libmii.

Not saying it's a better way, but it might be something worth trying if you get stuck.
Re: How to read from ISFS?
May 25, 2010 05:41PM
You're printing the address of the buffer, not the content of the buffer. Something like this should work:
u32 temp;
memcpy(&temp, buffer, 4);
printf("\n\n%x\n", temp);
Re: How to read from ISFS?
May 25, 2010 05:46PM
or a hexdump function.
char ascii(char s) {
  if(s < 0x20) return '.';
  if(s > 0x7E) return '.';
  return s;
}

void hexdump(void *d, int len) {
  u8 *data;
  int i, off;
  data = (u8*)d;

  
  for (off=0; off=len) printf("   ");
      else printf("%02x ",data[off+i]);

    gprintf(" ");
    for(i=0; i<16; i++)
      if((i+off)>=len) printf(" ");
      else printf("%c",ascii(data[off+i]));
    printf("\n");
  }
}

then say
hexdump( buffer, however_much_you_want_to_see );

EDIT___
this website is not parsing the code tag right, so it is not displaying the code correctly. press the quote button to see the correct code



Edited 3 time(s). Last edit at 05/25/2010 05:53PM by giantpune.
Re: How to read from ISFS?
May 25, 2010 07:08PM
Quote
giantpune
or a hexdump function.

This exactly what I looked for. Thank you very much!
Sorry, only registered users may post in this forum.

Click here to login