Giter VIP home page Giter VIP logo

taihen's Introduction

大変

Build Status

taiHEN is a CFW framework for PS Vita™. When loaded with a kernel exploit, it acts as a common substrate for patching the system. taiHEN provides three main facilities:

  1. It disables code signature checks to allow unsigned executables.
  2. It exposes kernel peek/poke syscalls to user applications and allows loading of kernel modules.
  3. Most importantly, it provides an API for hooking and replacing functions based off of substitute.

The last point means that developers can add custom patches to kernel, system applications, and games alike.

Building

To build, you need the latest version of the toolchain with kernel support. Then just use CMake to build.

$ mkdir build && cd build
$ cmake ../
$ make

Installation

taiHEN requires a separate kernel exploit to run. Once the exploit loads taihen.skprx to the kernel, taiHEN will take care of the rest. Please refer to documentations for the exploit for more information.

Plugins

Plugins are loaded either into kernel after taiHEN is loaded or on demand when an application is launched. taiHEN reads the configuration file in ux0:tai/config.txt.

The configuration that determines the plugins to load and the load order can be found in ux0:tai/config.txt. The format is very simple and self explanatory.

# ignored line starting with #
# Kernel plugins are started with taiHEN and are in this section
*KERNEL
ux0:app/MLCL00001/henkaku.skprx
ux0:path/to/another.skprx
ux0:tai/plugin3.skprx
ux0:data/tai/plugin4.skprx
ux0:data/tai/plugin5.skprx
# titleid for SceSettings
*NPXS10015
ux0:app/MLCL00001/henkaku.suprx
ux0:data/tai/some_settings_plugin.suprx
# titleid for Package Installer
*NPXS10031
ux0:path/to/some_pkg_installer_plgin.suprx
# titleid for SceShell is special (does not follow the XXXXYYYYY format)
*main
ux0:app/MLCL00001/henkaku.skprx
ux0:data/tai/shell_plgin.skprx

The key things to note are

  1. # begins a comment, * begins a section, and any other character begins a path.
  2. KERNEL is a special section name denoting to load a kernel plugin when taiHEN is started up. All other section names are the title id of the application/game in which to load the plugin at startup. Note that SceShell has a special title id of main.
  3. In each section, there is a list of plugin paths that will be loaded in order. Paths can be anywhere but it is recommended that plugins reside in ux0:tai or ux0:data/tai. It is valid to have one plugin in multiple sections but the developer must ensure that the plugin knows which application it is loaded in if it needs to do things differently.

API

taiHEN exports an API interface both to kernel and to user. This interface is found in the [documentation pages](@ref taihen). You should also read the usage guide for more details. You can either download the release or build taiHEN yourself. After that, you can include taihen.h in your project and link with libtaihen_stub.a (for user modules) or libtaihen_kernel_stub.a (for kernel modules).

taihen's People

Contributors

d3m3vilurr avatar daveeftw avatar frangarcj avatar hyln9 avatar theofficialflow avatar xerpi avatar yifanlu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

taihen's Issues

Better Threading/API for Plugins

As advised by @DaveeFTW. Conversation excerpt follow.

<Kyle873> I don't suppose there's a way for me to directly manipulate the input buffer instead of just reading from it?
<Kyle873> rather, I just want to clear it
<davee[m]> Kyle873: context?
<Kyle873> davee[m], developing a game plugin, using the main thread priority hack I've seen others do to pause the main thread while I keep a menu up, on resume of the main thread, some input bleeds into the game thread
<davee[m]> threads are a bad idea
<Kyle873> don't really see another way to do it
<Kyle873> unless i want all my menu control to also flow into the game, which I don't
<Kyle873> davee[m], a very condensed view of the flow http://tinyurl.com/j3vz4a6
<davee[m]> we seriously need a better way to handle threads for plugins
<davee[m]> can you do me a favour and create an issue on taihen github requesting that?
<davee[m]> Kyle873: yeah, threading really sucks on the vita
<davee[m]> there needs to be some API to assist plugins I think

[Request] Button other than Start to access Unsafe Homebrew toggle

My Vita's Start button is apparently dying/dead and doesn't always work and thus I'm having difficulty accessing the settings menu to enable Unsafe Homebrew.

Since I have a PSTV as well and my Dualshock controller's buttons all work I should be able to move my memory card to it and do the relevant configuration but not everyone has that option available to them but may be in a similar situation.

Proposed alternate button location: Pressing Triangle on a "Drive Letter" (such as "ux0:") to pull up the same menu Start should be.

Problems in plugin "newlib"

Hello!
I am trying to create an mp3 audio player to plugin mode,
First create the code as any application, and it works,
Translate the code to be used as a plugin:
I use the flag -nostartfiles in the make,
And add a couple of functions in the main.c to evade the errors and use the newlib:
Int _free_vita_newlib () {
Return 0;
}
Int _fini () {
Return 0;
}
And finally add the export.yml and its command in the make.
When debugging the plugin in action, I notice that it is not heard, but the report indicates that it is working well internally ...

I do not know if it is due to long memory applications (buffers for samples, and readings),
Or it may be due to some failure in the newlib, since not doing _init_vita_newlib and __libc_init_array there may be incursions in the generic functions no?

Additionally it probe to use the sample of audio provided by vitasdk, and portandolo to plugin, and to arrive at some function of sceAudio, it generates a crash.

Greetings and thank you any help!

Add config.txt synchronisation

At the moment if you install a new plugin you have to cold reset your vita and restart taihen in order to have the plugin loaded. Therefore it might be a good idea to add config sync:

  • Either by exposing a sync function in the library that homebrews can use
  • Or by parsing the config at every application launch

Implement hooking of shared modules

Right now you cannot hook anything in the >= 0xE0000000 region because the pages mapped there are shared between processes. It increases the complexity as we would have to map the trampoline pages to all processes that use a specific module. Right now, I believe that most plugins would not need to hook any shared modules (they can make do with hooking imports from the main module). If we want to support this going forward, it would make sense to hook modulemgr to always allocate 1-2 additional pages at the end of the .text segment for any shared module. That would serve as the trampoline for the hooks as well as metadata for hooks.

Kernel module unloading does not work.

load:

modid = taiLoadStartKernelModule("ux0:app/STAR00001/test.skprx", 1, arg, 0);

returns successfully (with a module uid).
unload:

int res = taiStopUnloadKernelModule(modid, 1, arg, 0, NULL, &kmod_res);

returns 0x8002d002 (SCE_KERNEL_ERROR_MODULEMGR_IN_USE)
and if trying to load again, load returns 0x8002d013 (SCE_KERNEL_ERROR_MODULEMGR_OLD_LIB)

Cannot create ux0:tai/config.txt

Cannot create ux0:tai/config.txt.
Failed with Error 0x80010011 when trying to create it using shell.
The file cannot be created by copying, renaming or FTP.
Any other file under ux0:tai can be accessed normally, except for config.txt.

Using the latest taiHEN and have unsafe homebrew enabled.

Crash Cart

All games are loaded from cartridges which might be my problem as it works perfect on all dumps I've tried.
I used _start for eboot.bin vitamin / maidump calls but while testing i renamed the
ux0:/plugins/game.txt -> ux0:/plugins/game.txtbak so any dump game tests were not interfering

#GRAVITYRUSH (US)
*PCSA00011
ux0:tai/REZAPEEK.skprx #crashed
ux0:plugins/REZAPEEK.suprx #crashed

#FREEDOMWARS (US)
*PCSA00147
ux0:tai/REZAPEEK.skprx #crashed
ux0:plugins/REZAPEEK.suprx #crashed

#LBP (US)
*PCSA00017
ux0:tai/REZAPEEK.skprx #success
ux0:plugins/REZAPEEK.suprx #success

When I tested the following code and replaced my plugin rezapeek with this test dummy build
the folder was not created in any case and all games crashed again except lbp.
Lbp did not successfully call the sceiomkdir but it did not crash either.
when I loaded my plugin into lbp it was successful and loaded the bliter menu and handled my menu variables nicely, but it still did not create the directories my plugin
tried to make. are these functions deprecated ? am i not building the skprx correctly ?
I made a skprx file but its just a suprx file renamed to skprx.

#include <psp2/kernel/modulemgr.h>
#include <psp2/kernel/processmgr.h>
#include <psp2/io/stat.h>

#include <taihen.h>


int main_thread(SceSize args, void *argp) {
	
	//sceKernelDelayThread(5 * 1000 * 1000);
	sceIoMkdir("ux0:/data/plugtest", 0777);
	
	return 0;
}

//vitamin / maidump entry
int _start(SceSize args,const void *argp) {
	SceUID thid = sceKernelCreateThread("REZAPEEK", main_thread, 0x40, 0x600000, 0, 0, NULL);
	if (thid >= 0)
		sceKernelStartThread(thid, 0, NULL);
	return 0;
}

// taihen entry
int module_start(SceSize argc, const void *args) {
	//sceKernelExitProcess(0);
	_start(argc,args);
	return 0;
}

int module_stop(SceSize argc, const void *args) {
  return SCE_KERNEL_STOP_SUCCESS;
}

Write some sample plugins and document common pitfalls

There's problems people run into. We should keep a list of problems and solutions.

  • Using newlib from plugins. Should use either SceLibc, sceClib* from SceLibKernel, or libk.
  • Using user imports from kernel mode.
  • Unsafe function usage in safe homebrew
  • Need for mod.size = sizeof(mod)

Also the following samples should be created

  • "Hello world" show FPS in game
  • Port amphetamin
  • Kernel module that exports user syscall/on demand loading

taihen-parser folder empty

[parker@e73 build]$ git clone https://github.com/yifanlu/taiHEN
Cloning into 'taiHEN'...
remote: Counting objects: 915, done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 915 (delta 74), reused 0 (delta 0), pack-reused 784
Receiving objects: 100% (915/915), 745.88 KiB | 0 bytes/s, done.
Resolving deltas: 100% (567/567), done.
[parker@e73 build]$ cd taiHEN/
[parker@e73 taiHEN]$ mkdir build
[parker@e73 taiHEN]$ cd build/
[parker@e73 build]$ VITASDK="/home/parker/build/buildscripts/build/vitasdk" cmake ../
-- The C compiler identification is GNU 6.2.0
-- The CXX compiler identification is GNU 6.2.0
-- Check for working C compiler: /home/parker/build/buildscripts/build/vitasdk/bin/arm-vita-eabi-gcc
-- Check for working C compiler: /home/parker/build/buildscripts/build/vitasdk/bin/arm-vita-eabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/parker/build/buildscripts/build/vitasdk/bin/arm-vita-eabi-g++
-- Check for working CXX compiler: /home/parker/build/buildscripts/build/vitasdk/bin/arm-vita-eabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:34 (add_subdirectory):
  The source directory

    /home/parker/build/taiHEN/taihen-parser

  does not contain a CMakeLists.txt file.


-- Configuring incomplete, errors occurred!
See also "/home/parker/build/taiHEN/build/CMakeFiles/CMakeOutput.log".

my application won't boot with my plugin

Hi, while my application boot, my plugin cause a stuck on boot image

#include <stdlib.h>
#include <stdio.h>
#include <taihen.h>

// handle to our hook
static tai_hook_ref_t app_start_ref;
// our hook for app entry
int hook_app_start(SceSize argc, const void *args) {
  printf("hello world!\n");
  return TAI_CONTINUE(int, app_start_ref, argc, args);
}
// our own plugin entry
int module_start(SceSize argc, const void *args) {
  taiHookFunctionExport(&app_start_ref,  // Output a reference
                        "AppName",       // Name of module being hooked
                        TAI_ANY_LIBRARY, // If there's multiple libs exporting this
                        0x935CD196,      // Special NID specifying module_start
                        hook_app_start); // Name of the hook function
  return (0);
}
TARGET  = testplugin
OBJS    = main.o

LIBS    = -ltaihen_stub -lSceLibc_stub

PREFIX  = arm-vita-eabi
CC      = $(PREFIX)-gcc
CFLAGS  = -g -Wl,-q -Wall -O3 -nostartfiles
ASFLAGS = $(CFLAGS)
TYPE = suprx
PSVITAIP = 192.168.1.14

all: $(TARGET).$(TYPE)

%.$(TYPE): %.velf
	vita-make-fself $< $@

%.velf: %.elf
	vita-elf-create $< $@ taihen.json

$(TARGET).elf: $(OBJS)
	$(CC) $(CFLAGS) $^ $(LIBS) -o $@

clean:
	@rm -rf $(TARGET).$(TYPE) $(TARGET).velf $(TARGET).elf $(OBJS)

send: $(TARGET).$(TYPE)
	curl -T $(TARGET).$(TYPE) ftp://$(PSVITAIP):1337/ux0:/data/$(TARGET).$(TYPE)
	@echo "Plugin sended."

pretty simple plugin, but doesn't work, I looked for a long time without solution.
Thanks for your help :-)

Add PatchSyscall

Could be useful if you want to hook a function for user mode but keep kernel function untouched

Crash on load kernel module.

I am loading a kernel module from an application in user mode,
Using the API taihen, as follows:

SceUID modkernel = taiLoadStartKernelModule("ux0:/mylib.skprx", 0, NULL, 0);

Always the first time I run the application after having installed henkaku, it crashes, the second no longer gives the crash, and works great!
It should be mentioned that the user application, it imports prx functions,
In the module_start, no action is performed,
Could someone help me solve this problem?

Any help will be appreciated.

Possibility to "brick" any taihenkaku usage with broken plugin

Note: This is an untested theory

When a broken plugin is inserted to SceShell and causes it to crash, i assume the device reboots or restarts SceShell (causing an infinite loop of crashes)
After a reboot the crash would be fixed temporarily until the user reinstalls taihenkaku - which would load the plugin and cause the crashes again, effectively making taihenkaku unusable on that device.

This means there's no opportunity for the user to disable the broken plugin before causing crashes again.

Cydia Substrate prevents this by temporarily disabling plugin loading when a specific key-combo is held, so maybe that's what tai should do in the future if my theory proves to be true

I can't confirm this theory though because i'd rather not pseudo-brick my device

offlineInstaller doesnt work with taiHEN

It seems it is not detecting the mail database correctly, it keep asking to enter and close the application in order to create the database.

2016-11-08-224932

HENkaku works fine.

Research PS4 support

This one is unlikely to be taken on by me. The PS4's kernel APIs should be close enough (have same/similar functions) where a port of taiHEN to PS4 would be easier than, say, Android. substitute supports x86-64 as well.

Add blx/bl patching

Sometimes you only need to manipulate a single call. Example: sceCtrlPeekBufferPositive does output all buttons (inclusive ps btn, power btn and volumes) if called in kernel mode, whereas from syscall state only user buttons can be received. Patching the import function that checks for syscall mode (not sure if it's really like this) might cause maleffect.

Question about permissions in taihenkaku and plugins

is there a detailed explaination on how the permissions works and how to use in source?

like do i need to define Kernel somewhere to elevate my app during compile to build using the unsafe homebrew flag ? am i completely wrong ? how does it work ? i understand there is a flag on eboot.bin's for their unsafe homebrew etc , does a plugin only gain the access of the app its running in ? if i use taihen config.txt and write
*main
ux0:plugins/rezapeek.suprx # can i do this ? does a suprx and s skprx make a difference other then name ?

and will this only have access to the memory allocated by pcse ?
i guess my question is the memcpy user to kernel and kernal to user and also C memcpy does that work with what level of permisions ? does it error on certain calls to protected memory which with other access would be readable?
*pcseXXXXX
ux0:plugins/rezapeek.suprx

Partition Question

Hy Team Henkaku

Could you please add a switch to the taihen settings in order to see and write to the other partitions.
Also I can't write to the root of ux0 like creating folders and so on and a few folders are even hidden in ux0 like the game folder.

I don't persist on the switch, but please fix the ux0 partition.

Regards DarkLPs

Race condition between hooking function and setting up hook

Right now, if a function is called in middle of the hook, this series of events could be possible

  1. substitute_hook_functions is called
  2. Function is written to, old pointer is saved
  3. taiHEN sets the old pointer into the tai_hook_t object stored in user address space.
  4. Call returns to user with a reference to the tai_hook_t

It is possible, between 2 and 4 that the function is called. In that case, it jumps to the user function, which tries to call TAI_CONTINUE with an uninitialized reference.

There are a couple of possible solutions:

  • We initialize the user reference to NULL before 1, then we modify TAI_CONTINUE to not dereference the hook if NULL and return error. The problem with this is that we cannot call the original function and this may break whatever code depends on it.
  • We set the hook reference early (before returning from the hook call). This doesn't work for user hooks though.
  • We can halt all threads while the hook process is happening. This is what substitute does on iOS. Not sure if we want this for performance reasons.

Installs

Supp?!.

Well, I've installed TaiHen and after that I got a lot of problems trying to install VPKs trought vitashell, vita always restart when finishing the instalation, and show some error message in some files... I've noticed that to install beta or going back to regular exploit, you should do it from de begining, like from zero.. deleting molecularshell and doing an database restore before exploit it. otherwise you shall get some errors (sometimes...).

Well, hope I could be helpfull, and sorry about my english.
thx by the efort guys.

Hooking a weak import crashes the application

This one crashes because the screenshot module isn't loaded yet.
taiHookFunctionImport(&sceScreenShotDisableRef, "ScePspemu", 0xF26FC97D, 0x50AE9FF9, sceScreenShotDisablePatched);

Error code is: C1-2719-9

taiHookFunctionImportForKernel crashes when given a wrong module NID

inside a kernel module:

static int new_kmodStopAllowed()
{
    return 1;
}

int module_start(SceSize argc, const void *args)
{
    kmod_hook_uid = taiHookFunctionImportForKernel(KERNEL_PID,
                                            &kmod_stop_hook,
                                            "SceKernelModulemgr",
                                            0x7ABF5135, // SceSblAuthMgrForKernel
                                            0xBBA13D9C,
                                            new_kmodStopAllowed);
  <...>
  return SCE_KERNEL_START_SUCCESS;
}

crashes the vita.

launched from a usermode app with

modid = taiLoadStartKernelModule("ux0:app/STAR00003/test.skprx", 0, NULL, 0);

Build error

I installed vitasdk from https://github.com/vitasdk/buildscripts but got the following error when I was trying to build taiHEN. Any idea about this? Thanks

[100%] Linking C executable taihen.elf
[100%] Built target taihen.elf
Scanning dependencies of target taihen-libs
[100%] Built target taihen-libs
Scanning dependencies of target taihen.skprx
vita-elf-create: dest = elf_begin(fileno(*file), ELF_C_WRITE, NULL) failed: Request error: invalid ELF_C_* argument
vita-elf-create: Assertion failed: (dest = elf_utils_copy_to_file(args.output, ve->elf, &outfile))
make[2]: *** [CMakeFiles/taihen.skprx] Error 1
make[1]: *** [CMakeFiles/taihen.skprx.dir/all] Error 2
make: *** [all] Error 2

Livetweet Bug

While TaiHenkaku Beta 8 (the December 15th build) is installed, LiveTweet for PS Vita will not work. Reboot to use it.

Missing file from release?

Not sure if this is a issue so sorry otherwise, but is the taihen.json file a needed file to compile against?

failed installation; C0-15008-4 and browser is unaccessible

During taiHenkaku installation, Vita crashed almost immediately with the following error: C2-14185-9:
'A problem occurred the last time the PS Vita system was used, and the system did not power off correctly'.

Error History also shows this, though I did not see this error appear: C1-6775-5
'An error occured'.

Now, opening the browser in any case gives this error: C0-15008-4
'A serious error has occured in the system software. This system will restart'.
Vita restarts in the safe mode with only two options: restart this system and restore this system.
Error History shows another error that occurs at the same time but isn't shown: C0-11478-1

Regular Henkaku is still accessible through the offline installer. Rebuilding the database didn't work and I don't want to risk formatting my system and be left without both browser and offline installer in case restoring doesn't fix the error.
There is no tai folder in ux0, so I assume it didn't install at all.

Allow loading modules with weak imports

Loading a suprx that is importing ScePgf for example (which isn't loaded yet either) will result in SCE_KERNEL_ERROR_MODULEMGR_NO_LIB. A workaround is to load the pgf module inside config.txt

Might be a bug with file system reading

I am using retroarch pcsx rearmed and it behaves differently between 'henkaku' and 'taihen'. With henkaku (go.henkaku.xyz), it loads game image files fine; but with 'taihen'(beta.henkaku.xyz) it is very unstable, retroarch always reports 'no items' when open a game image file. So i am 99% sure it might be a bug with 'taihen'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.