Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
25efdd3d
Commit
25efdd3d
authored
Aug 02, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use code generator for jni_hooks
parent
00a1e189
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
542 additions
and
419 deletions
+542
-419
gen_jni_hooks.py
native/jni/inject/gen_jni_hooks.py
+201
-0
hook.cpp
native/jni/inject/hook.cpp
+89
-77
jni_hooks.hpp
native/jni/inject/jni_hooks.hpp
+252
-342
No files found.
native/jni/inject/gen_jni_hooks.py
0 → 100755
View file @
25efdd3d
#!/usr/bin/env python3
primitives
=
[
'jint'
,
'jboolean'
,
'jlong'
]
class
JType
:
def
__init__
(
self
,
name
,
sig
)
->
None
:
self
.
name
=
name
self
.
sig
=
sig
class
JArray
(
JType
):
def
__init__
(
self
,
type
)
->
None
:
if
type
.
name
in
primitives
:
name
=
type
.
name
+
'Array'
else
:
name
=
'jobjectArray'
super
()
.
__init__
(
name
,
'['
+
type
.
sig
)
class
Argument
:
def
__init__
(
self
,
name
,
type
,
set_arg
=
False
)
->
None
:
self
.
name
=
name
self
.
type
=
type
self
.
set_arg
=
set_arg
def
cpp
(
self
):
return
f
'{self.type.name} {self.name}'
class
Method
:
def
__init__
(
self
,
name
,
args
)
->
None
:
self
.
name
=
name
self
.
args
=
args
def
cpp
(
self
):
return
', '
.
join
(
map
(
lambda
a
:
a
.
cpp
(),
self
.
args
))
def
name_list
(
self
):
return
', '
.
join
(
map
(
lambda
a
:
a
.
name
,
self
.
args
))
def
jni
(
self
):
return
''
.
join
(
map
(
lambda
a
:
a
.
type
.
sig
,
self
.
args
))
# Common types
jint
=
JType
(
'jint'
,
'I'
)
jintArray
=
JArray
(
jint
)
jstring
=
JType
(
'jstring'
,
'Ljava/lang/String;'
)
jboolean
=
JType
(
'jboolean'
,
'Z'
)
jlong
=
JType
(
'jlong'
,
'J'
)
# Common args
uid
=
Argument
(
'uid'
,
jint
)
gid
=
Argument
(
'gid'
,
jint
)
gids
=
Argument
(
'gids'
,
jintArray
)
runtime_flags
=
Argument
(
'runtime_flags'
,
jint
)
rlimits
=
Argument
(
'rlimits'
,
JArray
(
jintArray
))
mount_external
=
Argument
(
'mount_external'
,
jint
)
se_info
=
Argument
(
'se_info'
,
jstring
)
nice_name
=
Argument
(
'nice_name'
,
jstring
)
fds_to_close
=
Argument
(
'fds_to_close'
,
jintArray
)
instruction_set
=
Argument
(
'instruction_set'
,
jstring
)
app_data_dir
=
Argument
(
'app_data_dir'
,
jstring
)
# o
fds_to_ignore
=
Argument
(
'fds_to_ignore'
,
jintArray
)
# p
is_child_zygote
=
Argument
(
'is_child_zygote'
,
jboolean
,
True
)
# q_alt
is_top_app
=
Argument
(
'is_top_app'
,
jboolean
,
True
)
# r
pkg_data_info_list
=
Argument
(
'pkg_data_info_list'
,
JArray
(
jstring
),
True
)
whitelisted_data_info_list
=
Argument
(
'whitelisted_data_info_list'
,
JArray
(
jstring
),
True
)
mount_data_dirs
=
Argument
(
'mount_data_dirs'
,
jboolean
,
True
)
mount_storage_dirs
=
Argument
(
'mount_storage_dirs'
,
jboolean
,
True
)
# samsung (non-standard arguments)
i1
=
Argument
(
'i1'
,
jint
)
i2
=
Argument
(
'i2'
,
jint
)
i3
=
Argument
(
'i3'
,
jint
)
# server
permitted_capabilities
=
Argument
(
'permitted_capabilities'
,
jlong
)
effective_capabilities
=
Argument
(
'effective_capabilities'
,
jlong
)
# Method definitions
fork_m
=
Method
(
'm'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
fds_to_close
,
instruction_set
,
app_data_dir
])
fork_o
=
Method
(
'o'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
fds_to_close
,
fds_to_ignore
,
instruction_set
,
app_data_dir
])
fork_p
=
Method
(
'p'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
fds_to_close
,
fds_to_ignore
,
is_child_zygote
,
instruction_set
,
app_data_dir
])
fork_q_alt
=
Method
(
'q_alt'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
fds_to_close
,
fds_to_ignore
,
is_child_zygote
,
instruction_set
,
app_data_dir
,
is_top_app
])
fork_r
=
Method
(
'r'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
fds_to_close
,
fds_to_ignore
,
is_child_zygote
,
instruction_set
,
app_data_dir
,
is_top_app
,
pkg_data_info_list
,
whitelisted_data_info_list
,
mount_data_dirs
,
mount_storage_dirs
])
fork_samsung_m
=
Method
(
'samsung_m'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
i1
,
i2
,
nice_name
,
fds_to_close
,
instruction_set
,
app_data_dir
])
fork_samsung_n
=
Method
(
'samsung_n'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
i1
,
i2
,
nice_name
,
fds_to_close
,
instruction_set
,
app_data_dir
,
i3
])
fork_samsung_o
=
Method
(
'samsung_o'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
i1
,
i2
,
nice_name
,
fds_to_close
,
fds_to_ignore
,
instruction_set
,
app_data_dir
])
fork_samsung_p
=
Method
(
'samsung_p'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
i1
,
i2
,
nice_name
,
fds_to_close
,
fds_to_ignore
,
is_child_zygote
,
instruction_set
,
app_data_dir
])
spec_q
=
Method
(
'q'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
is_child_zygote
,
instruction_set
,
app_data_dir
])
spec_q_alt
=
Method
(
'q_alt'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
is_child_zygote
,
instruction_set
,
app_data_dir
,
is_top_app
])
spec_r
=
Method
(
'r'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
nice_name
,
is_child_zygote
,
instruction_set
,
app_data_dir
,
is_top_app
,
pkg_data_info_list
,
whitelisted_data_info_list
,
mount_data_dirs
,
mount_storage_dirs
])
spec_samsung_q
=
Method
(
'samsung_q'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
i1
,
i2
,
nice_name
,
is_child_zygote
,
instruction_set
,
app_data_dir
])
server_m
=
Method
(
'm'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
permitted_capabilities
,
effective_capabilities
])
server_samsung_q
=
Method
(
'samsung_q'
,
[
uid
,
gid
,
gids
,
runtime_flags
,
i1
,
i2
,
rlimits
,
permitted_capabilities
,
effective_capabilities
])
def
ind
(
i
):
return
'
\n
'
+
' '
*
i
def
gen_definitions
(
methods
,
base_name
):
decl
=
''
if
base_name
!=
'nativeSpecializeAppProcess'
:
ret_stat
=
ind
(
1
)
+
'return ctx.pid;'
cpp_ret
=
'jint'
jni_ret
=
'I'
else
:
ret_stat
=
''
cpp_ret
=
'void'
jni_ret
=
'V'
for
m
in
methods
:
func_name
=
f
'{base_name}_{m.name}'
decl
+=
ind
(
0
)
+
f
'static {cpp_ret} {func_name}(JNIEnv *env, jclass clazz, {m.cpp()}) {{'
decl
+=
ind
(
1
)
+
'HookContext ctx{};'
if
base_name
==
'nativeForkSystemServer'
:
decl
+=
ind
(
1
)
+
'ForkSystemServerArgs args(uid, gid, gids, runtime_flags, permitted_capabilities, effective_capabilities);'
else
:
decl
+=
ind
(
1
)
+
'SpecializeAppProcessArgs args(uid, gid, gids, runtime_flags, mount_external, se_info, nice_name, instruction_set, app_data_dir);'
for
a
in
m
.
args
:
if
a
.
set_arg
:
decl
+=
ind
(
1
)
+
f
'args.{a.name} = &{a.name};'
decl
+=
ind
(
1
)
+
'ctx.raw_args = &args;'
decl
+=
ind
(
1
)
+
f
'{base_name}_pre(&ctx, env, clazz);'
decl
+=
ind
(
1
)
+
f
'reinterpret_cast<decltype(&{func_name})>({base_name}_orig)('
decl
+=
ind
(
2
)
+
f
'env, clazz, {m.name_list()}'
decl
+=
ind
(
1
)
+
');'
decl
+=
ind
(
1
)
+
f
'{base_name}_post(&ctx, env, clazz);'
decl
+=
ret_stat
decl
+=
ind
(
0
)
+
'}'
decl
+=
ind
(
0
)
+
'namespace {'
decl
+=
ind
(
0
)
+
f
'const JNINativeMethod {base_name}_methods[] = {{'
for
m
in
methods
:
decl
+=
ind
(
1
)
+
'{'
decl
+=
ind
(
2
)
+
f
'"{base_name}",'
decl
+=
ind
(
2
)
+
f
'"({m.jni()}){jni_ret}",'
decl
+=
ind
(
2
)
+
f
'(void *) &{base_name}_{m.name}'
decl
+=
ind
(
1
)
+
'},'
decl
+=
ind
(
0
)
+
'};'
decl
+=
ind
(
0
)
+
f
'const int {base_name}_methods_num = std::size({base_name}_methods);'
decl
+=
ind
(
0
)
+
'} // namespace'
decl
+=
ind
(
0
)
return
decl
def
gen_fork
():
methods
=
[
fork_m
,
fork_o
,
fork_p
,
fork_q_alt
,
fork_r
,
fork_samsung_m
,
fork_samsung_n
,
fork_samsung_o
,
fork_samsung_p
]
return
gen_definitions
(
methods
,
'nativeForkAndSpecialize'
)
def
gen_spec
():
methods
=
[
spec_q
,
spec_q_alt
,
spec_r
,
spec_samsung_q
]
return
gen_definitions
(
methods
,
'nativeSpecializeAppProcess'
)
def
gen_server
():
methods
=
[
server_m
,
server_samsung_q
]
return
gen_definitions
(
methods
,
'nativeForkSystemServer'
)
with
open
(
'jni_hooks.hpp'
,
'w'
)
as
f
:
f
.
write
(
'// Generated by gen_jni_hooks.py
\n
'
)
f
.
write
(
gen_fork
())
f
.
write
(
gen_spec
())
f
.
write
(
gen_server
())
native/jni/inject/hook.cpp
View file @
25efdd3d
...
@@ -11,9 +11,58 @@ using jni_hook::hash_map;
...
@@ -11,9 +11,58 @@ using jni_hook::hash_map;
using
jni_hook
::
tree_map
;
using
jni_hook
::
tree_map
;
using
xstring
=
jni_hook
::
string
;
using
xstring
=
jni_hook
::
string
;
struct
SpecializeAppProcessArgs
{
jint
&
uid
;
jint
&
gid
;
jintArray
&
gids
;
jint
&
runtime_flags
;
jint
&
mount_external
;
jstring
&
se_info
;
jstring
&
nice_name
;
jstring
&
instruction_set
;
jstring
&
app_data_dir
;
/* Optional */
jboolean
*
is_child_zygote
=
nullptr
;
jboolean
*
is_top_app
=
nullptr
;
jobjectArray
*
pkg_data_info_list
=
nullptr
;
jobjectArray
*
whitelisted_data_info_list
=
nullptr
;
jboolean
*
mount_data_dirs
=
nullptr
;
jboolean
*
mount_storage_dirs
=
nullptr
;
SpecializeAppProcessArgs
(
jint
&
uid
,
jint
&
gid
,
jintArray
&
gids
,
jint
&
runtime_flags
,
jint
&
mount_external
,
jstring
&
se_info
,
jstring
&
nice_name
,
jstring
&
instruction_set
,
jstring
&
app_data_dir
)
:
uid
(
uid
),
gid
(
gid
),
gids
(
gids
),
runtime_flags
(
runtime_flags
),
mount_external
(
mount_external
),
se_info
(
se_info
),
nice_name
(
nice_name
),
instruction_set
(
instruction_set
),
app_data_dir
(
app_data_dir
)
{}
};
struct
ForkSystemServerArgs
{
jint
&
uid
;
jint
&
gid
;
jintArray
&
gids
;
jint
&
runtime_flags
;
jlong
&
permitted_capabilities
;
jlong
&
effective_capabilities
;
ForkSystemServerArgs
(
jint
&
uid
,
jint
&
gid
,
jintArray
&
gids
,
jint
&
runtime_flags
,
jlong
&
permitted_capabilities
,
jlong
&
effective_capabilities
)
:
uid
(
uid
),
gid
(
gid
),
gids
(
gids
),
runtime_flags
(
runtime_flags
),
permitted_capabilities
(
permitted_capabilities
),
effective_capabilities
(
effective_capabilities
)
{}
};
struct
HookContext
{
struct
HookContext
{
int
pid
;
int
pid
;
bool
do_hide
;
bool
do_hide
;
union
{
SpecializeAppProcessArgs
*
args
;
ForkSystemServerArgs
*
server_args
;
void
*
raw_args
;
};
};
};
static
vector
<
tuple
<
const
char
*
,
const
char
*
,
void
**>>
*
xhook_list
;
static
vector
<
tuple
<
const
char
*
,
const
char
*
,
void
**>>
*
xhook_list
;
...
@@ -21,7 +70,6 @@ static vector<JNINativeMethod> *jni_hook_list;
...
@@ -21,7 +70,6 @@ static vector<JNINativeMethod> *jni_hook_list;
static
hash_map
<
xstring
,
tree_map
<
xstring
,
tree_map
<
xstring
,
void
*>>>
*
jni_method_map
;
static
hash_map
<
xstring
,
tree_map
<
xstring
,
tree_map
<
xstring
,
void
*>>>
*
jni_method_map
;
static
JavaVM
*
g_jvm
;
static
JavaVM
*
g_jvm
;
static
int
prev_fork_pid
=
-
1
;
static
HookContext
*
current_ctx
;
static
HookContext
*
current_ctx
;
#define DCL_HOOK_FUNC(ret, func, ...) \
#define DCL_HOOK_FUNC(ret, func, ...) \
...
@@ -29,10 +77,7 @@ static HookContext *current_ctx;
...
@@ -29,10 +77,7 @@ static HookContext *current_ctx;
static ret new_##func(__VA_ARGS__)
static ret new_##func(__VA_ARGS__)
#define DCL_JNI_FUNC(name) \
#define DCL_JNI_FUNC(name) \
static int name##_orig_idx; \
static void *name##_orig; \
static inline JNINativeMethod &name##_orig() { \
return (*jni_hook_list)[name##_orig_idx]; \
} \
extern const JNINativeMethod name##_methods[]; \
extern const JNINativeMethod name##_methods[]; \
extern const int name##_methods_num;
extern const int name##_methods_num;
...
@@ -44,9 +89,9 @@ DCL_JNI_FUNC(nativeForkSystemServer)
...
@@ -44,9 +89,9 @@ DCL_JNI_FUNC(nativeForkSystemServer)
}
}
#define HOOK_JNI(method) \
#define HOOK_JNI(method) \
if (
hooked < 3 &&
methods[i].name == #method##sv) { \
if (methods[i].name == #method##sv) { \
jni_hook_list->push_back(methods[i]); \
jni_hook_list->push_back(methods[i]); \
method##_orig
_idx = jni_hook_list->size() - 1;
\
method##_orig
= methods[i].fnPtr;
\
for (int j = 0; j < method##_methods_num; ++j) { \
for (int j = 0; j < method##_methods_num; ++j) { \
if (strcmp(methods[i].signature, method##_methods[j].signature) == 0) { \
if (strcmp(methods[i].signature, method##_methods[j].signature) == 0) { \
newMethods[i] = method##_methods[j]; \
newMethods[i] = method##_methods[j]; \
...
@@ -78,22 +123,18 @@ DCL_HOOK_FUNC(int, jniRegisterNativeMethods,
...
@@ -78,22 +123,18 @@ DCL_HOOK_FUNC(int, jniRegisterNativeMethods,
auto
&
class_map
=
(
*
jni_method_map
)[
className
];
auto
&
class_map
=
(
*
jni_method_map
)[
className
];
for
(
int
i
=
0
;
i
<
numMethods
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numMethods
;
++
i
)
{
class_map
[
methods
[
i
].
name
][
methods
[
i
].
signature
]
=
methods
[
i
].
fnPtr
;
class_map
[
methods
[
i
].
name
][
methods
[
i
].
signature
]
=
methods
[
i
].
fnPtr
;
HOOK_JNI
(
nativeForkAndSpecialize
);
if
(
hooked
<
3
)
{
HOOK_JNI
(
nativeSpecializeAppProcess
);
HOOK_JNI
(
nativeForkAndSpecialize
);
HOOK_JNI
(
nativeForkSystemServer
);
HOOK_JNI
(
nativeSpecializeAppProcess
);
HOOK_JNI
(
nativeForkSystemServer
);
}
}
}
return
old_jniRegisterNativeMethods
(
env
,
className
,
newMethods
.
get
()
?:
methods
,
numMethods
);
return
old_jniRegisterNativeMethods
(
env
,
className
,
newMethods
.
get
()
?:
methods
,
numMethods
);
}
}
DCL_HOOK_FUNC
(
int
,
fork
)
{
DCL_HOOK_FUNC
(
int
,
fork
)
{
if
(
prev_fork_pid
<
0
)
return
current_ctx
?
current_ctx
->
pid
:
old_fork
();
return
old_fork
();
// Skip an actual fork and return the previous fork result
int
pid
=
prev_fork_pid
;
prev_fork_pid
=
-
1
;
return
pid
;
}
}
DCL_HOOK_FUNC
(
int
,
selinux_android_setcontext
,
DCL_HOOK_FUNC
(
int
,
selinux_android_setcontext
,
...
@@ -114,103 +155,73 @@ static int sigmask(int how, int signum) {
...
@@ -114,103 +155,73 @@ static int sigmask(int how, int signum) {
return
sigprocmask
(
how
,
&
set
,
nullptr
);
return
sigprocmask
(
how
,
&
set
,
nullptr
);
}
}
static
int
pre_specialize_fork
()
{
// First block SIGCHLD, unblock after original fork is done
sigmask
(
SIG_BLOCK
,
SIGCHLD
);
prev_fork_pid
=
old_fork
();
return
prev_fork_pid
;
}
// -----------------------------------------------------------------
// -----------------------------------------------------------------
static
void
nativeSpecializeAppProcess_pre
(
HookContext
*
ctx
,
static
void
nativeSpecializeAppProcess_pre
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
JNIEnv
*
env
,
jclass
clazz
,
jint
&
uid
,
jint
&
gid
,
jintArray
&
gids
,
jint
&
runtime_flags
,
jobjectArray
&
rlimits
,
jint
&
mount_external
,
jstring
&
se_info
,
jstring
&
nice_name
,
jboolean
&
is_child_zygote
,
jstring
&
instruction_set
,
jstring
&
app_data_dir
,
jboolean
&
is_top_app
,
jobjectArray
&
pkg_data_info_list
,
jobjectArray
&
whitelisted_data_info_list
,
jboolean
&
mount_data_dirs
,
jboolean
&
mount_storage_dirs
)
{
current_ctx
=
ctx
;
current_ctx
=
ctx
;
const
char
*
process
=
env
->
GetStringUTFChars
(
ctx
->
args
->
nice_name
,
nullptr
);
const
char
*
process
=
env
->
GetStringUTFChars
(
nice_name
,
nullptr
);
LOGD
(
"hook: %s %s
\n
"
,
__FUNCTION__
,
process
);
LOGD
(
"hook: %s %s
\n
"
,
__FUNCTION__
,
process
);
if
(
mount_external
!=
0
/* TODO: Handle MOUNT_EXTERNAL_NONE cases */
if
(
ctx
->
args
->
mount_external
!=
0
/* TODO: Handle MOUNT_EXTERNAL_NONE cases */
&&
remote_check_hide
(
uid
,
process
))
{
&&
remote_check_hide
(
ctx
->
args
->
uid
,
process
))
{
ctx
->
do_hide
=
true
;
ctx
->
do_hide
=
true
;
LOGI
(
"hook: [%s] should be hidden
\n
"
,
process
);
LOGI
(
"hook: [%s] should be hidden
\n
"
,
process
);
}
}
env
->
ReleaseStringUTFChars
(
nice_name
,
process
);
env
->
ReleaseStringUTFChars
(
ctx
->
args
->
nice_name
,
process
);
}
}
static
void
nativeSpecializeAppProcess_post
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
static
void
nativeSpecializeAppProcess_post
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
current_ctx
=
nullptr
;
LOGD
(
"hook: %s
\n
"
,
__FUNCTION__
);
LOGD
(
"hook: %s
\n
"
,
__FUNCTION__
);
if
(
ctx
->
do_hide
)
if
(
ctx
->
do_hide
)
self_unload
();
self_unload
();
current_ctx
=
nullptr
;
}
}
// -----------------------------------------------------------------
// -----------------------------------------------------------------
static
void
nativeForkAndSpecialize_pre
(
HookContext
*
ctx
,
// Do our own fork before loading any 3rd party code
JNIEnv
*
env
,
jclass
clazz
,
jint
&
uid
,
jint
&
gid
,
jintArray
&
gids
,
jint
&
runtime_flags
,
// First block SIGCHLD, unblock after original fork is done
jobjectArray
&
rlimits
,
jint
&
mount_external
,
jstring
&
se_info
,
jstring
&
nice_name
,
#define PRE_FORK() \
jintArray
fds_to_close
,
jintArray
fds_to_ignore
,
/* These 2 arguments are unique to fork */
current_ctx = ctx; \
jboolean
&
is_child_zygote
,
jstring
&
instruction_set
,
jstring
&
app_data_dir
,
sigmask(SIG_BLOCK, SIGCHLD); \
jboolean
&
is_top_app
,
jobjectArray
&
pkg_data_info_list
,
ctx->pid = old_fork(); \
jobjectArray
&
whitelisted_data_info_list
,
jboolean
&
mount_data_dirs
,
if (ctx->pid != 0) \
jboolean
&
mount_storage_dirs
)
{
// Do our own fork before loading any 3rd party code
ctx
->
pid
=
pre_specialize_fork
();
if
(
ctx
->
pid
!=
0
)
return;
return;
nativeSpecializeAppProcess_pre
(
// Unblock SIGCHLD in case the original method didn't
ctx
,
env
,
clazz
,
uid
,
gid
,
gids
,
runtime_flags
,
rlimits
,
mount_external
,
se_info
,
#define POST_FORK() \
nice_name
,
is_child_zygote
,
instruction_set
,
app_data_dir
,
is_top_app
,
current_ctx = nullptr; \
pkg_data_info_list
,
whitelisted_data_info_list
,
mount_data_dirs
,
mount_storage_dirs
);
sigmask(SIG_UNBLOCK, SIGCHLD); \
if (ctx->pid != 0)\
return;
static
void
nativeForkAndSpecialize_pre
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
PRE_FORK
();
nativeSpecializeAppProcess_pre
(
ctx
,
env
,
clazz
);
}
}
static
void
nativeForkAndSpecialize_post
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
static
void
nativeForkAndSpecialize_post
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
// Unblock SIGCHLD in case the original method didn't
POST_FORK
();
sigmask
(
SIG_UNBLOCK
,
SIGCHLD
);
if
(
ctx
->
pid
!=
0
)
return
;
nativeSpecializeAppProcess_post
(
ctx
,
env
,
clazz
);
nativeSpecializeAppProcess_post
(
ctx
,
env
,
clazz
);
}
}
// -----------------------------------------------------------------
// -----------------------------------------------------------------
static
void
nativeForkSystemServer_pre
(
HookContext
*
ctx
,
static
void
nativeForkSystemServer_pre
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
JNIEnv
*
env
,
jclass
clazz
,
uid_t
&
uid
,
gid_t
&
gid
,
jintArray
&
gids
,
jint
&
runtime_flags
,
PRE_FORK
();
jobjectArray
&
rlimits
,
jlong
&
permitted_capabilities
,
jlong
&
effective_capabilities
)
{
// Do our own fork before loading any 3rd party code
ctx
->
pid
=
pre_specialize_fork
();
if
(
ctx
->
pid
!=
0
)
return
;
current_ctx
=
ctx
;
LOGD
(
"hook: %s
\n
"
,
__FUNCTION__
);
LOGD
(
"hook: %s
\n
"
,
__FUNCTION__
);
}
}
static
void
nativeForkSystemServer_post
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
static
void
nativeForkSystemServer_post
(
HookContext
*
ctx
,
JNIEnv
*
env
,
jclass
clazz
)
{
// Unblock SIGCHLD in case the original method didn't
POST_FORK
();
sigmask
(
SIG_UNBLOCK
,
SIGCHLD
);
if
(
ctx
->
pid
!=
0
)
return
;
LOGD
(
"hook: %s
\n
"
,
__FUNCTION__
);
LOGD
(
"hook: %s
\n
"
,
__FUNCTION__
);
current_ctx
=
nullptr
;
}
}
#undef PRE_FORK
#undef POST_FORK
// -----------------------------------------------------------------
// -----------------------------------------------------------------
static
bool
hook_refresh
()
{
static
bool
hook_refresh
()
{
...
@@ -282,4 +293,5 @@ bool unhook_functions() {
...
@@ -282,4 +293,5 @@ bool unhook_functions() {
return
hook_refresh
();
return
hook_refresh
();
}
}
// JNI method definitions, include all method signatures of past Android versions
#include "jni_hooks.hpp"
#include "jni_hooks.hpp"
native/jni/inject/jni_hooks.hpp
View file @
25efdd3d
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment