-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinit.c
58 lines (42 loc) · 1.39 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <libgen.h>
#include <dlfcn.h>
#include <sys/param.h>
#include "common.h"
EXPORT
const char* __roothideinit_JBRAND=NULL;
EXPORT
const char* __roothideinit_JBROOT=NULL;
#define BOOTSTRAP_LIBRARY_PATH "/usr/lib/roothideinit.dylib"
int bootstrap()
{
struct dl_info di={0};
assert(dladdr((void*)bootstrap, &di) != 0);
char* librealpath = strdup(di.dli_fname);
assert(strlen(librealpath) >= (sizeof(BOOTSTRAP_LIBRARY_PATH)-1));
char* plib = librealpath + strlen(librealpath) - (sizeof(BOOTSTRAP_LIBRARY_PATH)-1);
assert(strcmp(plib, BOOTSTRAP_LIBRARY_PATH) == 0);
*plib = '\0';
const char* jbroot = librealpath;
char bname[PATH_MAX];
basename_r(jbroot, bname);
assert(is_jbroot_name(bname));
uint64_t randvalue = resolve_jbrand_value(bname);
assert(randvalue != 0);
char jbrand[32]={0};
snprintf(jbrand, sizeof(jbrand), "%016llX", randvalue);
char jbroot_standardized[PATH_MAX]={0};
snprintf(jbroot_standardized, sizeof(jbroot_standardized), "%s/%s%s", JB_ROOT_PARENT, JB_ROOT_PREFIX, jbrand);
__roothideinit_JBRAND = strdup(jbrand);
__roothideinit_JBROOT = strdup(jbroot_standardized);
free(librealpath);
return 0;
}
static void __attribute__((__constructor__)) _roothide_init()
{
assert(bootstrap() == 0);
}