Skip to content

Instantly share code, notes, and snippets.

@opa334
Last active May 22, 2023 02:17
Show Gist options
  • Save opa334/b14fa4a593bbb79f025cda6113e8b81b to your computer and use it in GitHub Desktop.
Save opa334/b14fa4a593bbb79f025cda6113e8b81b to your computer and use it in GitHub Desktop.
Macros to support rootless jailbreaks in your packages
#import <Foundation/Foundation.h>
#include <unistd.h>
// Use for NSString literals or variables
#define ROOT_PATH_NS(path)([[NSFileManager defaultManager] fileExistsAtPath:path] ? path : [@"/var/jb" stringByAppendingPathComponent:path])
// Use for C string literals
#define ROOT_PATH_C(cPath) (access(cPath, F_OK) == 0) ? cPath : "/var/jb" cPath
// Use for C string variables
// The string returned by this will get freed when your function exits
// If you want to keep it, use strdup
#define ROOT_PATH_C_VAR(cPath)(ROOT_PATH_NS([NSString stringWithUTF8String:cPath]).fileSystemRepresentation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment