-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9971194
commit 3d00b54
Showing
3 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) | ||
if(DEFINED ENV{DOLCESDK}) | ||
set(CMAKE_TOOLCHAIN_FILE "$ENV{DOLCESDK}/share/dolce.toolchain.cmake" CACHE PATH "toolchain file") | ||
else() | ||
message(FATAL_ERROR "Please define DOLCESDK to point to your SDK path!") | ||
endif() | ||
endif() | ||
|
||
project(HonRipper) | ||
include("${DOLCESDK}/share/dolce.cmake" REQUIRED) | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-q -Wall -O3 -std=gnu99") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions") | ||
|
||
include_directories( | ||
) | ||
|
||
link_directories( | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
if (NOT ${RELEASE}) | ||
add_definitions(-DENABLE_LOGGING) | ||
endif() | ||
|
||
add_executable(${PROJECT_NAME} | ||
${PROJECT_NAME}.c | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
taihen_stub | ||
SceLibKernel_stub | ||
SceIofilemgr_stub | ||
SceKernelModulemgr_stub | ||
) | ||
|
||
set_target_properties(${PROJECT_NAME} | ||
PROPERTIES LINK_FLAGS "-nostdlib" | ||
) | ||
|
||
dolce_create_self(${PROJECT_NAME}.suprx ${PROJECT_NAME} | ||
CONFIG ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.yml | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright (c) 2020 Graphene | ||
*/ | ||
|
||
#include <psp2/kernel/clib.h> | ||
#include <psp2/kernel/modulemgr.h> | ||
#include <psp2/kernel/iofilemgr.h> | ||
#include <taihen.h> | ||
|
||
static SceUID g_hooks[3]; | ||
static tai_hook_ref_t g_ref_hooks[3]; | ||
|
||
void _start() __attribute__((weak, alias("module_start"))); | ||
|
||
static unsigned int image_count = 0; | ||
static SceByte savespace = 0, loaded = 0; | ||
static SceUID currentUID = 0; | ||
static char currentBook[256]; | ||
|
||
SceUID sceIoOpen_patched(const char *filename, int flag, SceIoMode mode) | ||
{ | ||
SceUID ret = TAI_CONTINUE(SceUID, g_ref_hooks[1], filename, flag, mode); | ||
|
||
char* ext = sceClibStrrchr(filename, '.'); | ||
if (!sceClibStrncasecmp(ext, ".MNH", 4)) { | ||
|
||
if (!loaded) { | ||
loaded = 1; | ||
SceUID fdi = sceIoOpen("ux0:book/HonRipper.ini", SCE_O_RDONLY, 0777); | ||
if (fdi > 0) { | ||
sceIoRead(fdi, &savespace, 1); | ||
savespace = savespace - '0'; | ||
sceClibPrintf("Read: 0x%x\n", savespace); | ||
sceIoClose(fdi); | ||
} | ||
} | ||
|
||
char* book = sceClibStrrchr(filename, '/'); | ||
book = book + 1; | ||
int name_len = ext - book; | ||
sceClibMemset(¤tBook, 0, 256); | ||
sceClibStrncpy(currentBook, book, name_len); | ||
char path[100]; | ||
sceClibMemset(&path, 0, 100); | ||
switch (savespace) { | ||
case 0: | ||
sceClibSnprintf(path, 100, "ux0:HonRipper/%s", currentBook); | ||
break; | ||
case 1: | ||
sceClibSnprintf(path, 100, "uma0:HonRipper/%s", currentBook); | ||
break; | ||
} | ||
sceIoMkdir(path, 0777); | ||
sceClibPrintf("HonRipper: opening book: %s\n", currentBook); | ||
currentUID = ret; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
int close_patched(int a1) | ||
{ | ||
if (currentUID > 0) { | ||
sceClibPrintf("HonRipper: closing book\n"); | ||
currentUID = 0; | ||
image_count = 0; | ||
} | ||
|
||
return TAI_CONTINUE(int, g_ref_hooks[2], a1); | ||
} | ||
|
||
int sceJpegDecodeMJpegYCbCr_patched( | ||
const unsigned char *pJpeg, | ||
SceSize isize, | ||
unsigned char *pYCbCr, | ||
SceSize osize, | ||
int decodeMode, | ||
void *pCoefBuffer, | ||
SceSize coefBufferSize) | ||
{ | ||
if (currentUID != 0) { | ||
image_count++; | ||
sceClibPrintf("HonRipper: decoding in progress, image num: %d\n", image_count); | ||
|
||
char path[100]; | ||
sceClibMemset(&path, 0, 100); | ||
switch (savespace) { | ||
case 0: | ||
sceClibSnprintf(path, 100, "ux0:HonRipper/%s/%d.jpg", currentBook, image_count); | ||
break; | ||
case 1: | ||
sceClibSnprintf(path, 100, "uma0:HonRipper/%s/%d.jpg", currentBook, image_count); | ||
break; | ||
} | ||
SceUID fd = sceIoOpen(path, SCE_O_WRONLY | SCE_O_CREAT, 0777); | ||
sceIoWrite(fd, pJpeg, isize); | ||
sceIoClose(fd); | ||
} | ||
|
||
return TAI_CONTINUE( | ||
int, | ||
g_ref_hooks[0], | ||
pJpeg, | ||
isize, | ||
pYCbCr, | ||
osize, | ||
decodeMode, | ||
pCoefBuffer, | ||
coefBufferSize); | ||
} | ||
|
||
int module_start(SceSize argc, const void *args) | ||
{ | ||
sceClibPrintf("HonRipper: module start\n"); | ||
|
||
tai_module_info_t info; | ||
info.size = sizeof(info); | ||
taiGetModuleInfo("ReaderForPSVita_release", &info); | ||
|
||
g_hooks[0] = taiHookFunctionImport( | ||
&g_ref_hooks[0], | ||
TAI_MAIN_MODULE, | ||
0x880BF710, | ||
0x2A769BD8, | ||
sceJpegDecodeMJpegYCbCr_patched); | ||
|
||
g_hooks[1] = taiHookFunctionImport( | ||
&g_ref_hooks[1], | ||
TAI_MAIN_MODULE, | ||
0xCAE9ACE6, | ||
0x6C60AC61, | ||
sceIoOpen_patched); | ||
|
||
g_hooks[2] = taiHookFunctionOffset( | ||
&g_ref_hooks[2], | ||
info.modid, | ||
0, | ||
0x10b4e8, | ||
1, | ||
close_patched); | ||
|
||
return SCE_KERNEL_START_SUCCESS; | ||
} | ||
|
||
int module_stop(SceSize argc, const void *args) | ||
{ | ||
if (g_hooks[0] >= 0) taiHookRelease(g_hooks[0], g_ref_hooks[0]); | ||
if (g_hooks[1] >= 0) taiHookRelease(g_hooks[1], g_ref_hooks[1]); | ||
if (g_hooks[2] >= 0) taiHookRelease(g_hooks[2], g_ref_hooks[2]); | ||
return SCE_KERNEL_STOP_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
HonRipper: | ||
attributes: 0 | ||
version: | ||
major: 1 | ||
minor: 1 | ||
main: | ||
start: module_start | ||
stop: module_stop |