Skip to content

Instantly share code, notes, and snippets.

@3096
Forked from Reisyukaku/DumpSave.js
Last active April 3, 2018 19:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3096/78828ae6576bd7ce2075745b0c94e90e to your computer and use it in GitHub Desktop.
Save 3096/78828ae6576bd7ce2075745b0c94e90e to your computer and use it in GitHub Desktop.
Game save dumper
sc.getFSPPR = function () {
if (sc.closed_pr !== undefined) {
return;
}
sc.enableTurbo();
var i = 0;
var srv = null;
while (true) {
sc.ipcMsg(2).setType(5).sendTo('pm:shell');
var srvResult = sc.getService("fsp-pr");
if(srvResult.isOk) {
srv = srvResult.getValue();
break;
}
i++;
}
utils.log('Got fsp-pr handle after ' + i + ' iterations: ');
utils.log('fsp-pr handle: 0x' + srv.toString(16));
sc.svcCloseHandle(srv).assertOk();
sc.closed_pr = true;
};
var tid = '0000000000000000'; //Set appropriate game TID; Need to find a way to get TID automatically...
utils.log("stage1, hijack fsppr and set perms");
sc.getFSPPR();
sc.ipcMsg(1).sendPid().data(0).sendTo('fsp-srv').assertOk();
var pid = sc.read4(sc.ipcBufAddr, 0xC >> 2);
utils.log('Got process PID: '+pid.toString(16));
var buf1_sz = 0x1C;
var buf2_sz = 0x2C;
var buf = sc.malloc(buf1_sz + buf2_sz);
var buf2 = utils.add2(buf, buf1_sz);
//buffer init
sc.write4(1, buf, 0x0>>2);
sc.write8([0xFFFFFFFF, 0xFFFFFFFF], buf, 0x4 >> 2); //This is the permissions value.
sc.write4(buf1_sz, buf, 0xC >> 2);
sc.write4(buf1_sz, buf, 0x14 >> 2);
sc.write4(1, buf2, 0x0 >> 2);
sc.write8([0xFFFFFFFF, 0xFFFFFFFF], buf2, 0x4 >> 2); //This is the permissions value -- actual perms = buf2_val & buf1_val
sc.write4(0xFFFFFFFF, buf2, 0x14 >> 2);
sc.write4(0xFFFFFFFF, buf2, 0x18 >> 2);
sc.write4(0xFFFFFFFF, buf2, 0x24 >> 2);
sc.write4(0xFFFFFFFF, buf2, 0x28 >> 2);
sc.ipcMsg(256).data(0).sendTo('fsp-pr').assertOk().show();
sc.ipcMsg(1).data(pid).sendTo('fsp-pr').assertOk().show();
sc.ipcMsg(0).data(2, [pid,0], utils.parseAddr(tid), buf1_sz, buf2_sz, pid, pid, 0, 0, 0, 0, 0).aDescriptor(buf, buf1_sz).aDescriptor(buf2, buf2_sz).sendTo('fsp-pr').assertOk().show();
sc.free(buf);
sc.free(buf2);
utils.log("stage2, open save data");
utils.log("GetLastUserProfile");
res = sc.ipcMsg(4).sendTo('acc:u1').assertOk();
var userID = res.data;
utils.log('MountSaveData');
res = sc.ipcMsg(51).datau64(1, utils.parseAddr(tid), [userID[0], userID[1]], [userID[2], userID[3]], [0,0], 1, 0, 0, 0).sendTo('fsp-srv').assertOk();
sc.withHandle(res.movedHandles[0], (ifile) => {
utils.log('Got IFileSystem handle: 0x'+ ifile.toString(16));
var fs = new sc.IFileSystem(sc, ifile);
var path = utils.str2ab('/');
var res = sc.ipcMsg(9).datau64(3).xDescriptor(path, path.byteLength, 0).sendTo(ifile);
var dir = new sc.IDirectory(sc, '/', res.movedHandles[0], fs);
dir.DirDump('SaveData');
});
@RyuSeisuke1992
Copy link

RyuSeisuke1992 commented Mar 24, 2018

Thank you for this Mod.
you could also modify the script WriteSave.js, too?
I always get this error code: ERROR: [15, 'sc.getFSPPR is not a function. (In \ 'sc.getFSPPR()\', \ 'sc.getFSPPR\' is undefined)' ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment