Skip to content

Instantly share code, notes, and snippets.

@asdfugil
Last active April 14, 2022 01:43
Show Gist options
  • Save asdfugil/760419ece9667bc3e106cff43b83933d to your computer and use it in GitHub Desktop.
Save asdfugil/760419ece9667bc3e106cff43b83933d to your computer and use it in GitHub Desktop.
TRFP0 test
/*A lot of this code is copied from libkrw */
/*
clang -miphoneos-version-min=14.5 -DPRIVATE trfp0.c -o trfp0
ldid -Stfp0.xml trfp0
*/
/*
The MIT License (MIT)
Copyright (c) 2021 Siguza
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <mach/mach.h>
#include <sys/proc.h>
#include <errno.h>
#include <stdio.h>
int get_tfp0 () {
static task_t gKernelTask = MACH_PORT_NULL;
task_t port = MACH_PORT_NULL;
int ret;
ret = task_for_pid(mach_task_self(), 0, &port);
if(ret == KERN_SUCCESS) {
if(MACH_PORT_VALID(port)) {
gKernelTask = port;
printf("got tfp0!\n%d\n", port);
return 0;
}
return EDEVERR;
} else {
printf("unable to get tfp0!\n");
}
return -ret;
}
int get_trfp0 () {
static task_t gKernelTask = MACH_PORT_NULL;
task_t port = MACH_PORT_NULL;
int ret;
ret = task_read_for_pid(mach_task_self(), 0, &port);
if(ret == KERN_SUCCESS) {
if(MACH_PORT_VALID(port)) {
gKernelTask = port;
printf("got trfp0!\n%d\n", port);
return 0;
}
return EDEVERR;
} else {
printf("unable to get trfp0!\n");
}
return -ret;
}
int main () {
printf("%d\n",get_tfp0());
printf("%d\n",get_trfp0());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment