Skip to content

Commit dd1f707

Browse files
RootHideRootHide
authored andcommitted
version 0.0.3
1 parent bf50793 commit dd1f707

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ libroothide.dylib: roothideinit.dylib jbroot.c jbroot.cpp jbroot.m cache.c commo
1818
libvroot.h: vroot.h
1919
$(CPP) $< > $@
2020

21-
libvroot.dylib: libroothide.dylib vroot.c vroot_mktemp.c vroot.cpp vroot_rootfs.c vroot_exec.c vroot_dlfcn.c common.c
22-
$(CC) -arch arm64 -arch arm64e $(CFLAGS) $(LDFLAGS) -lstdc++ -lroothide -dynamiclib -install_name @loader_path/.jbroot/usr/lib/libvroot.dylib -o $@ $^
21+
libvroot.dylib: libroothide.dylib vroot.c vroot_mktemp.c vroot.cpp vroot_rootfs.c vroot_exec.c vroot_dlfcn.c common.c debug.m
22+
$(CC) -fobjc-arc -arch arm64 -arch arm64e $(CFLAGS) $(LDFLAGS) -lstdc++ -lroothide -dynamiclib -install_name @loader_path/.jbroot/usr/lib/libvroot.dylib -o $@ $^
2323
xcrun tapi stubify $@
2424

2525
libvrootapi.dylib: libvroot.dylib vrootapi.c

common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ extern const char* __roothideinit_JBROOT;
2020

2121
#define VROOT_LOG(...) {if(getenv("VROOTLOG")&&atoi(getenv("VROOTLOG"))) {printf(__VA_ARGS__);fflush(stdout);}}
2222

23+
char* backtrace();

debug.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <Foundation/Foundation.h>
2+
3+
4+
char* backtrace()
5+
{
6+
NSArray *csss = [NSThread callStackSymbols];
7+
return strdup([NSString stringWithFormat:@"%@", csss].UTF8String);
8+
}

vroot.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <fts.h>
2727
#include <glob.h>
2828
#include <mach-o/dyld.h>
29+
#include <libgen.h>
2930

3031
#include "roothide.h"
3132
#include "common.h"
@@ -194,11 +195,25 @@ int VROOT_API_NAME(symlink)(const char *name1, const char *name2)
194195
{
195196
VROOT_LOG("@%s\n",__FUNCTION__);
196197

197-
const char* newname1 = jbroot_alloc(name1);
198+
int ret = 0;
198199
const char* newname2 = jbroot_alloc(name2);
199-
int ret = symlink(newname1, newname2);
200-
if(newname1) free((void*)newname1);
200+
201+
char dname[PATH_MAX];
202+
int dfd = open(dirname_r(newname2, dname), O_RDONLY);
203+
if(dfd >= 0)
204+
{
205+
const char* newname1 = jbrootat_alloc(dfd, name1, 0);
206+
ret = symlink(newname1, newname2);
207+
if(newname1) free((void*)newname1);
208+
209+
close(dfd);
210+
211+
} else {
212+
ret = -1;
213+
}
214+
201215
if(newname2) free((void*)newname2);
216+
202217
return ret;
203218
}
204219

@@ -229,12 +244,24 @@ VROOT_LOG("@%s\n",__FUNCTION__);
229244

230245
int VROOTAT_API_NAME(symlinkat)(const char *name1, int fd, const char *name2)
231246
{
232-
VROOT_LOG("@%s\n",__FUNCTION__);
247+
VROOT_LOG("@%s %s %d %s\n",__FUNCTION__, name1, fd, name2);
233248

234-
const char* newname1 = jbroot_alloc(name1);
249+
int ret = 0;
235250
const char* newname2 = jbrootat_alloc(fd, name2, 0); //***********
236-
int ret = symlinkat(newname1, fd, newname2);
237-
if(newname1) free((void*)newname1);
251+
252+
char dname[PATH_MAX];
253+
int dfd = openat(fd, dirname_r(newname2, dname), O_RDONLY);
254+
if(dfd >= 0)
255+
{
256+
const char* newname1 = jbrootat_alloc(dfd, name1, 0);
257+
int ret = symlinkat(newname1, fd, newname2);
258+
if(newname1) free((void*)newname1);
259+
260+
close(dfd);
261+
} else {
262+
ret = -1;
263+
}
264+
238265
if(newname2) free((void*)newname2);
239266
return ret;
240267
}
@@ -366,7 +393,7 @@ VROOT_LOG("@%s\n",__FUNCTION__);
366393

367394
char* VROOT_API_NAME(realpath$DARWIN_EXTSN)(const char * path, char *resolved_path)
368395
{
369-
VROOT_LOG("@%s\n",__FUNCTION__);
396+
VROOT_LOG("@%s %s\n",__FUNCTION__, path);
370397

371398
char pathbuf[PATH_MAX]={0};
372399
const char* newpath = jbroot_alloc(path);

0 commit comments

Comments
 (0)