forked from android-rooting-tools/android_run_root_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cred.c
104 lines (80 loc) · 2.34 KB
/
cred.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <errno.h>
#include <stdio.h>
#include "cred.h"
#include "mm.h"
#include "kallsyms.h"
#include "device_database/device_database.h"
prepare_kernel_cred_t prepare_kernel_cred;
commit_creds_t commit_creds;
bool
setup_prepare_kernel_cred_address(void)
{
if (prepare_kernel_cred) {
return true;
}
prepare_kernel_cred = (prepare_kernel_cred_t)device_get_symbol_address(DEVICE_SYMBOL(prepare_kernel_cred));
if (!prepare_kernel_cred && kallsyms_exist()) {
prepare_kernel_cred = kallsyms_get_symbol_address("prepare_kernel_cred");
}
return !!prepare_kernel_cred;
}
bool
setup_commit_creds_address(void)
{
if (commit_creds) {
return true;
}
commit_creds = (commit_creds_t)device_get_symbol_address(DEVICE_SYMBOL(commit_creds));
if (!commit_creds && kallsyms_exist()) {
commit_creds = kallsyms_get_symbol_address("commit_creds");
}
return !!commit_creds;
}
static uint32_t prepare_kernel_cred_asm[] = { 0xe59f30bc, 0xe3a010d0, 0xe92d4070, 0xe1a04000 };
static size_t prepare_kernel_cred_asm_length = sizeof(prepare_kernel_cred_asm);
static bool
find_prepare_kernel_cred_address_in_memory(void *mem, size_t length)
{
void *address;
if (prepare_kernel_cred) {
return true;
}
address = (prepare_kernel_cred_t)memmem(mem, length, &prepare_kernel_cred_asm, prepare_kernel_cred_asm_length);
if (!address) {
return false;
}
prepare_kernel_cred = (prepare_kernel_cred_t)convert_to_kernel_address(address, mem);
return true;
}
static uint32_t commit_creds_asm[] = { 0xe92d4070, 0xe1a0200d, 0xe3c23d7f, 0xe1a05000 };
static size_t commit_creds_asm_length = sizeof(prepare_kernel_cred_asm);
static bool
find_commit_creds_address_in_memory(void *mem, size_t length)
{
void *address;
if (commit_creds) {
return true;
}
address = (commit_creds_t)memmem(mem, length, &commit_creds_asm, commit_creds_asm_length);
if (!address) {
return false;
}
commit_creds = (commit_creds_t)convert_to_kernel_address(address, mem);
return true;
}
bool
setup_prepare_kernel_cred_address_in_memory(void *mem, size_t length)
{
if (prepare_kernel_cred) {
return true;
}
return find_prepare_kernel_cred_address_in_memory(mem, length);
}
bool
setup_commit_creds_address_in_memory(void *mem, size_t length)
{
if (commit_creds) {
return true;
}
return find_commit_creds_address_in_memory(mem, length);
}