Skip to content

Commit

Permalink
Fixed gamecard mount detection
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOfficialFloW committed Jun 19, 2018
1 parent 63f371a commit 066e9c3
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 60 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ project(VitaShell)
include("${VITASDK}/share/vita.cmake" REQUIRED)
set(VITA_APP_NAME "VitaShell")
set(VITA_TITLEID "VITASHELL")
set(VITA_VERSION "01.92")
set(VITA_VERSION "01.93")

# Flags and includes
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -Wno-unused-variable -Wno-unused-but-set-variable -Wno-format-truncation -fno-lto")
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Credits
Changelog
---------

### Changelog 1.93
- Added xmc0: to partition list and added ability to mount xmc0:.
- Fixed ux0: mounting bug where it wasn't detected that the gamesd has already been mounted.

### Changelog 1.92
- Added ability to mount gamesd ux0:
- Fixed bug where the VitaShell kernel module was loaded but not started, thus it'd run out of memory after some launches.
Expand Down
2 changes: 1 addition & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

// VitaShell version major.minor
#define VITASHELL_VERSION_MAJOR 0x01
#define VITASHELL_VERSION_MINOR 0x92
#define VITASHELL_VERSION_MINOR 0x93

#define VITASHELL_VERSION ((VITASHELL_VERSION_MAJOR << 0x18) | (VITASHELL_VERSION_MINOR << 0x10))

Expand Down
6 changes: 4 additions & 2 deletions main_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ void setContextMenuHomeVisibilities() {
menu_home_entries[MENU_HOME_ENTRY_MOUNT_USB_UX0].visibility = CTX_INVISIBLE;
}

if ((kernel_modid >= 0 || kernel_modid == 0x8002D013) && user_modid >= 0 && shellUserIsUx0Redirected() == 1) {
if ((kernel_modid >= 0 || kernel_modid == 0x8002D013) && user_modid >= 0 &&
shellUserIsUx0Redirected("sdstor0:uma-pp-act-a", "sdstor0:uma-lp-act-entire") == 1) {
menu_home_entries[MENU_HOME_ENTRY_MOUNT_UMA0].visibility = CTX_INVISIBLE;
menu_home_entries[MENU_HOME_ENTRY_MOUNT_USB_UX0].visibility = CTX_INVISIBLE;
} else {
Expand All @@ -343,7 +344,8 @@ void setContextMenuHomeVisibilities() {
menu_home_entries[MENU_HOME_ENTRY_MOUNT_GAMECARD_UX0].visibility = CTX_INVISIBLE;
menu_home_entries[MENU_HOME_ENTRY_UMOUNT_GAMECARD_UX0].visibility = CTX_INVISIBLE;
} else {
if ((kernel_modid >= 0 || kernel_modid == 0x8002D013) && user_modid >= 0 && shellUserIsUx0Redirected() == 1) {
if ((kernel_modid >= 0 || kernel_modid == 0x8002D013) && user_modid >= 0 &&
shellUserIsUx0Redirected("sdstor0:gcd-lp-ign-entire", "sdstor0:gcd-lp-ign-entire") == 1) {
menu_home_entries[MENU_HOME_ENTRY_MOUNT_GAMECARD_UX0].visibility = CTX_INVISIBLE;
} else {
menu_home_entries[MENU_HOME_ENTRY_UMOUNT_GAMECARD_UX0].visibility = CTX_INVISIBLE;
Expand Down
1 change: 0 additions & 1 deletion modules/kernel/exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ VitaShellKernel2:
functions:
- shellKernelIsUx0Redirected
- shellKernelRedirectUx0
- shellKernelUnredirectUx0
- shellKernelMountById
- shellKernelGetRifVitaKey
58 changes: 17 additions & 41 deletions modules/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ static SceIoDevice ux0_dev = { "ux0:", "exfatux0", ux0_blkdev, ux0_blkdev2, MOUN

static SceIoMountPoint *(* sceIoFindMountPoint)(int id) = NULL;

static SceIoDevice *ori_dev = NULL, *ori_dev2 = NULL;

static SceUID hookid = -1;

static tai_hook_ref_t ksceSysrootIsSafeModeRef;
Expand All @@ -81,17 +79,22 @@ static int ksceSblAimgrIsDolcePatched() {
return 1;
}

int shellKernelIsUx0Redirected() {
int shellKernelIsUx0Redirected(const char *blkdev, const char *blkdev2) {
char k_blkdev[64], k_blkdev2[64];

uint32_t state;
ENTER_SYSCALL(state);

SceIoMountPoint *mount = sceIoFindMountPoint(MOUNT_POINT_ID);
if (!mount) {
EXIT_SYSCALL(state);
return -1;
return 0;
}

if (mount->dev == &ux0_dev && mount->dev2 == &ux0_dev) {
ksceKernelStrncpyUserToKernel(k_blkdev, blkdev, sizeof(k_blkdev)-1);
ksceKernelStrncpyUserToKernel(k_blkdev2, blkdev2, sizeof(k_blkdev2)-1);

if (mount && mount->dev && strcmp(mount->dev->blkdev, k_blkdev) == 0 && strcmp(mount->dev->blkdev2, k_blkdev2) == 0) {
EXIT_SYSCALL(state);
return 1;
}
Expand All @@ -110,11 +113,6 @@ int shellKernelRedirectUx0(const char *blkdev, const char *blkdev2) {
return -1;
}

if (mount->dev != &ux0_dev && mount->dev2 != &ux0_dev) {
ori_dev = mount->dev;
ori_dev2 = mount->dev2;
}

ksceKernelStrncpyUserToKernel(ux0_blkdev, blkdev, sizeof(ux0_blkdev)-1);
ksceKernelStrncpyUserToKernel(ux0_blkdev2, blkdev2, sizeof(ux0_blkdev2)-1);

Expand All @@ -125,28 +123,6 @@ int shellKernelRedirectUx0(const char *blkdev, const char *blkdev2) {
return 0;
}

int shellKernelUnredirectUx0() {
uint32_t state;
ENTER_SYSCALL(state);

SceIoMountPoint *mount = sceIoFindMountPoint(MOUNT_POINT_ID);
if (!mount) {
EXIT_SYSCALL(state);
return -1;
}

if (ori_dev && ori_dev2) {
mount->dev = ori_dev;
mount->dev2 = ori_dev2;

ori_dev = NULL;
ori_dev2 = NULL;
}

EXIT_SYSCALL(state);
return 0;
}

int _shellKernelMountById(ShellMountIdArgs *args) {
int res;

Expand All @@ -165,12 +141,12 @@ int _shellKernelMountById(ShellMountIdArgs *args) {
module_get_offset(KERNEL_PID, tai_info.modid, 0, 0x2DE1, (uintptr_t *)&sceAppMgrFindProcessInfoByPid);
module_get_offset(KERNEL_PID, tai_info.modid, 0, 0x19B51, (uintptr_t *)&sceAppMgrMountById);
break;

case 0x1C9879D6: // 3.65 retail
module_get_offset(KERNEL_PID, tai_info.modid, 0, 0x2DE1, (uintptr_t *)&sceAppMgrFindProcessInfoByPid);
module_get_offset(KERNEL_PID, tai_info.modid, 0, 0x19E61, (uintptr_t *)&sceAppMgrMountById);
break;

case 0x54E2E984: // 3.67 retail
case 0xC3C538DE: // 3.68 retail
module_get_offset(KERNEL_PID, tai_info.modid, 0, 0x2DE1, (uintptr_t *)&sceAppMgrFindProcessInfoByPid);
Expand All @@ -192,7 +168,7 @@ int _shellKernelMountById(ShellMountIdArgs *args) {
return res;

uint32_t appmgr_data_addr = (uint32_t)mod_info.segments[1].vaddr;

SceUID process_id = ksceKernelGetProcessId();

void *info = sceAppMgrFindProcessInfoByPid((void *)(appmgr_data_addr + 0x500), process_id);
Expand All @@ -215,7 +191,7 @@ int _shellKernelMountById(ShellMountIdArgs *args) {
ksceKernelStrncpyUserToKernel(desired_mount_point, (uintptr_t)args->desired_mount_point, 15);
if (args->klicensee)
ksceKernelMemcpyUserToKernel(klicensee, (uintptr_t)args->klicensee, 0x10);

res = sceAppMgrMountById(process_id, info + 0x580, args->id, args->process_titleid ? process_titleid : NULL, args->path ? path : NULL,
args->desired_mount_point ? desired_mount_point : NULL, args->klicensee ? klicensee : NULL, mount_point);

Expand All @@ -241,13 +217,13 @@ int shellKernelMountById(ShellMountIdArgs *args) {
int shellKernelGetRifVitaKey(const void *license_buf, void *klicensee) {
char k_license_buf[0x200];
char k_klicensee[0x10];

memset(k_klicensee, 0, sizeof(k_klicensee));

if (license_buf)
ksceKernelMemcpyUserToKernel(k_license_buf, license_buf, sizeof(k_license_buf));
int res = ksceNpDrmGetRifVitaKey(k_license_buf, k_klicensee, NULL, NULL, NULL, NULL);

int res = ksceNpDrmGetRifVitaKey(k_license_buf, k_klicensee, NULL, NULL, NULL, NULL);

if (klicensee)
ksceKernelMemcpyKernelToUser(klicensee, k_klicensee, sizeof(k_klicensee));
Expand All @@ -269,13 +245,13 @@ int module_start(SceSize args, void *argp) {
case 0x9642948C: // 3.60 retail
module_get_offset(KERNEL_PID, info.modid, 0, 0x138C1, (uintptr_t *)&sceIoFindMountPoint);
break;

case 0xA96ACE9D: // 3.65 retail
case 0x3347A95F: // 3.67 retail
case 0x90DA33DE: // 3.68 retail
module_get_offset(KERNEL_PID, info.modid, 0, 0x182F5, (uintptr_t *)&sceIoFindMountPoint);
break;

default:
return SCE_KERNEL_START_SUCCESS;
}
Expand Down
3 changes: 1 addition & 2 deletions modules/kernel/vitashell_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ typedef struct {
char *mount_point;
} ShellMountIdArgs;

int shellKernelIsUx0Redirected();
int shellKernelIsUx0Redirected(const char *blkdev, const char *blkdev2);
int shellKernelRedirectUx0(const char *blkdev, const char *blkdev2);
int shellKernelUnredirectUx0();
int shellKernelMountById(ShellMountIdArgs *args);
int shellKernelGetRifVitaKey(const void *license_buf, void *klicensee);

Expand Down
1 change: 0 additions & 1 deletion modules/user/exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ VitaShellUser:
functions:
- shellUserIsUx0Redirected
- shellUserRedirectUx0
- shellUserUnredirectUx0
- shellUserMountById
- shellUserGetRifVitaKey
8 changes: 2 additions & 6 deletions modules/user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@

#include "vitashell_user.h"

int shellUserIsUx0Redirected() {
return shellKernelIsUx0Redirected();
int shellUserIsUx0Redirected(const char *blkdev, const char *blkdev2) {
return shellKernelIsUx0Redirected(blkdev, blkdev2);
}

int shellUserRedirectUx0(const char *blkdev, const char *blkdev2) {
return shellKernelRedirectUx0(blkdev, blkdev2);
}

int shellUserUnredirectUx0() {
return shellKernelUnredirectUx0();
}

int shellUserMountById(ShellMountIdArgs *args) {
return shellKernelMountById(args);
}
Expand Down
3 changes: 1 addition & 2 deletions modules/user/vitashell_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@

#include <vitashell_kernel.h>

int shellUserIsUx0Redirected();
int shellUserIsUx0Redirected(const char *blkdev, const char *blkdev2);
int shellUserRedirectUx0(const char *blkdev, const char *blkdev2);
int shellUserUnredirectUx0();
int shellUserMountById(ShellMountIdArgs *args);
int shellUserGetRifVitaKey(const void *license_buf, void *klicensee);

Expand Down
2 changes: 1 addition & 1 deletion pkg/sce_sys/livearea/contents/template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<frame id="frame4">
<liveitem>
<text align="left" text-align="left" word-wrap="off" ellipsis="on">
<str size="18" color="#ffffff" shadow="on">v1.92</str>
<str size="18" color="#ffffff" shadow="on">v1.93</str>
</text>
</liveitem>
</frame>
Expand Down
Binary file modified resources/kernel.skprx
Binary file not shown.
Binary file modified resources/user.suprx
Binary file not shown.
10 changes: 8 additions & 2 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ int umountGamecardUx0() {
sceAppMgrDestroyOtherApp();

// Restore ux0: patch
shellUserUnredirectUx0();
if (checkFileExist("sdstor0:xmc-lp-ign-userext"))
shellUserRedirectUx0("sdstor0:xmc-lp-ign-userext", "sdstor0:xmc-lp-ign-userext");
else
shellUserRedirectUx0("sdstor0:int-lp-ign-userext", "sdstor0:int-lp-ign-userext");

// Remount Memory Card
remount(0x800);
Expand Down Expand Up @@ -115,7 +118,10 @@ int umountUsbUx0() {
sceAppMgrDestroyOtherApp();

// Restore ux0: patch
shellUserUnredirectUx0();
if (checkFileExist("sdstor0:xmc-lp-ign-userext"))
shellUserRedirectUx0("sdstor0:xmc-lp-ign-userext", "sdstor0:xmc-lp-ign-userext");
else
shellUserRedirectUx0("sdstor0:int-lp-ign-userext", "sdstor0:int-lp-ign-userext");

// Remount Memory Card
remount(0x800);
Expand Down

0 comments on commit 066e9c3

Please sign in to comment.