Skip to content

Commit 8502d20

Browse files
RootHideRootHide
authored andcommitted
fix rootfs bug
1 parent 5679bb1 commit 8502d20

File tree

8 files changed

+189
-55
lines changed

8 files changed

+189
-55
lines changed

common.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
#define JB_ROOT_PREFIX ".jbroot-"
44
#define JB_RAND_LENGTH (sizeof(uint64_t)*sizeof(char)*2)
55

6-
#define ROOTFS_PREFIX "/rootfs"
7-
8-
#define LOG(...)
9-
10-
//#define LOG(...) {char* jbpathlog = getenv("JBROOTLOG"); if((jbpathlog && *jbpathlog)||access("/var/.jbrootlog", F_OK)==0) {printf(__VA_ARGS__);fflush(stdout);}}
6+
#define ROOTFS_NAME "rootfs"
117

128
#include <sys/syslog.h>
13-
//#define LOG(...) {openlog("roothide",LOG_PID,LOG_AUTH);syslog(LOG_DEBUG, __VA_ARGS__);closelog();}
9+
#define SYSLOG(...) {openlog("roothide",LOG_PID,LOG_AUTH);syslog(LOG_DEBUG, __VA_ARGS__);closelog();}
1410

1511
int is_jbroot_name(const char* name);
1612

1713
#define EXPORT __attribute__ ((visibility ("default")))
1814

15+
#define JBPATH_LOG(...) {if(getenv("JBPATHLOG")&&atoi(getenv("JBPATHLOG"))) {printf(__VA_ARGS__);fflush(stdout);}}
16+
17+
#define VROOT_LOG(...) {if(getenv("VROOTLOG")&&atoi(getenv("VROOTLOG")))printf(__VA_ARGS__);fflush(stdout);}
18+

control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Package: com.roothide.libroothide
1+
Package: roothide
22
Name: roothide
33
Version: 0.0.1
44
Architecture: iphoneos-arm64e
5-
Description: roothide core library
5+
Description: roothide core
66
Maintainer: roothide
77
Author: roothide
88
Section: System

control.procursus

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Package: com.roothide.core
1+
Package: roothide
22
Name: roothide
33
Version: @DEB_ROOTHIDE_V@
44
Architecture: @DEB_ARCH@
5-
Description: roothide core library
5+
Description: roothide core
66
Maintainer: roothide
77
Author: roothide
88
Section: System

jbroot.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,7 @@ unsigned long long jbrand() {
2222
}
2323

2424
static void __attribute__((__constructor__)) _jbroot_init()
25-
{
26-
if(access("/var/.jbroottest", F_OK)==0||getenv("JBROOTTEST"))
27-
{
28-
setenv("JBRAND", "1234567890ABCDEF", 1);
29-
//setenv("JBROOT", "/private/var/.jbroot-1234567890ABCDEF", 1);
30-
// use /var/ instead of /private/var/ because stringByResolvingSymlinksInPath won't resolve /var/
31-
setenv("JBROOT", "/var/.jbroot-1234567890ABCDEF", 1);
32-
}
33-
25+
{
3426
JBRAND = getenv("JBRAND");
3527
JBROOT = getenv("JBROOT");
3628

@@ -77,11 +69,14 @@ static void __attribute__((__constructor__)) _jbroot_init()
7769
//free after use
7870
static const char* __private_jbrootat_alloc(int fd, const char* path)
7971
{
72+
int olderr = errno;
73+
8074
char atdir[PATH_MAX]={0};
8175
fd==AT_FDCWD ? (long)getcwd(atdir,sizeof(atdir)) : fcntl(fd, F_GETPATH, atdir, sizeof(atdir));
82-
LOG(" **jbrootat_alloc (%d)%s %s\n", fd, atdir, path);
76+
JBPATH_LOG(" **jbrootat_alloc (%d)%s %s\n", fd, atdir, path);
8377

8478
if(!path || !*path) {
79+
errno = olderr;
8580
return NULL;
8681
}
8782

@@ -195,8 +190,9 @@ static const char* __private_jbrootat_alloc(int fd, const char* path)
195190
resolved[resolved_len - 1] = '\0';
196191

197192

198-
LOG("*resolved:%ld %s\n", resolved_len, resolved);
193+
JBPATH_LOG("*resolved:%ld %s\n", resolved_len, resolved);
199194

195+
errno = olderr;
200196
return strdup(resolved);
201197
}
202198

@@ -214,21 +210,20 @@ const char* jbrootat_alloc(int fd, const char* path)
214210
if(fixedpath[0] != '/') return fixedpath;
215211

216212
//its necessary for symlink /rootfs/xxx -> /rootfs/yyy
217-
if(strlen(fixedpath)>=(sizeof("/rootfs")-1)
218-
&& strncmp(fixedpath, "/rootfs", sizeof("/rootfs")-1)==0)
213+
if(strlen(fixedpath)>=(sizeof("/"ROOTFS_NAME)-1)
214+
&& strncmp(fixedpath, "/"ROOTFS_NAME, sizeof("/"ROOTFS_NAME)-1)==0)
219215
{
216+
// char atdir[PATH_MAX]={0};
217+
// fd==AT_FDCWD ? (long)getcwd(atdir,sizeof(atdir)) : fcntl(fd, F_GETPATH, atdir, sizeof(atdir));
218+
// printf(" **rootfs--> (%d)%s\n\t%s : %s\n", fd, atdir, path, fixedpath);
220219

221-
// char atdir[PATH_MAX]={0};
222-
// fd==AT_FDCWD ? (long)getcwd(atdir,sizeof(atdir)) : fcntl(fd, F_GETPATH, atdir, sizeof(atdir));
223-
// printf(" **rootfs--> (%d)%s\n\t%s\n\t%s\n", fd, atdir, path, fixedpath);
224-
225-
if(fixedpath[sizeof("/rootfs")-1]=='/') {
226-
char* newpath = strdup(&fixedpath[sizeof("/rootfs")-1]);
220+
if(fixedpath[sizeof("/"ROOTFS_NAME)-1]=='/') {
221+
char* newpath = strdup(&fixedpath[sizeof("/"ROOTFS_NAME)-1]);
227222
free((void*)fixedpath);
228223
return newpath;
229224
}
230-
//break find / ???
231-
if(fixedpath[sizeof("/rootfs")-1]=='\0') {
225+
//break find / and cd rootfs;realpath . ??? caused by lstat(jbroot("/rootfs")) in vroot module
226+
if(fixedpath[sizeof("/"ROOTFS_NAME)-1]=='\0') {
232227
free((void*)fixedpath);
233228
return strdup("/");
234229
}
@@ -254,9 +249,12 @@ const char* jbroot_alloc(const char* path)
254249
//free after use
255250
static const char* __private_rootfs_alloc(const char* path)
256251
{
257-
LOG(" **rootfs_alloc %s\n", path);
252+
int olderr = errno;
253+
254+
JBPATH_LOG(" **rootfs_alloc %s\n", path);
258255

259256
if(!path || !*path) {
257+
errno = olderr;
260258
return NULL;
261259
}
262260

@@ -352,15 +350,16 @@ static const char* __private_rootfs_alloc(const char* path)
352350
char* retval = NULL;
353351
if(jbroot_based==0 && path[0] == '/') { //revert a path out of jbroot?
354352
assert(resolved[0] == '/');
355-
retval = malloc(sizeof(ROOTFS_PREFIX)-1 + strlen(resolved) + 1);
356-
strcpy(retval, ROOTFS_PREFIX);//just add ROOTFS_PREFIX prefix
353+
retval = malloc(sizeof("/"ROOTFS_NAME)-1 + strlen(resolved) + 1);
354+
strcpy(retval, "/"ROOTFS_NAME);//just add rootfs prefix
357355
strcat(retval, resolved);
358356
} else {
359357
retval = strdup(resolved);
360358
}
361359

362-
LOG("*resolved:%ld %s\n", resolved_len, retval);
360+
JBPATH_LOG("*resolved:%ld %s\n", resolved_len, retval);
363361

362+
errno = olderr;
364363
return retval;
365364
}
366365

symredirect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ std::vector<std::string> g_shim_apis = {
3434
#include "vroot.h"
3535
};
3636

37-
const char* g_shim_install_name = "@loader_path/.jbroot/usr/lib/libroothide.dylib";
37+
const char* g_shim_install_name = "@loader_path/.jbroot/usr/lib/libvrootapi.dylib";
3838

3939
char* getLibraryByOrdinal(struct mach_header_64* header, int ordinal)
4040
{

0 commit comments

Comments
 (0)