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
1c61feb3
Commit
1c61feb3
authored
Jan 26, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update native su connect broadcast code
Use -p <pkg> for supported platforms
parent
d32b7889
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
42 deletions
+37
-42
connect.cpp
native/jni/su/connect.cpp
+37
-42
No files found.
native/jni/su/connect.cpp
View file @
1c61feb3
...
...
@@ -17,8 +17,10 @@
#include "utils.h"
#include "su.h"
#define AM_PATH "/system/bin/app_process", "/system/bin", "com.android.commands.am.Am"
#define RECEIVER "a.h"
#define BROADCAST_BOOT_COMPLETED \
"/system/bin/app_process", "/system/bin", "com.android.commands.am.Am", \
"broadcast", nullptr, nullptr, "-a", "android.intent.action.BOOT_COMPLETED", \
"-f", "0x00000020"
static
inline
const
char
*
get_command
(
const
struct
su_request
*
to
)
{
if
(
to
->
command
[
0
])
...
...
@@ -28,18 +30,27 @@ static inline const char *get_command(const struct su_request *to) {
return
DEFAULT_SHELL
;
}
static
void
silent_run
(
const
char
*
args
[])
{
if
(
fork_dont_care
())
return
;
int
zero
=
open
(
"/dev/zero"
,
O_RDONLY
|
O_CLOEXEC
);
xdup2
(
zero
,
0
);
int
null
=
open
(
"/dev/null"
,
O_WRONLY
|
O_CLOEXEC
);
xdup2
(
null
,
1
);
xdup2
(
null
,
2
);
static
void
silent_run
(
const
char
**
args
,
struct
su_info
*
info
)
{
char
component
[
128
];
if
(
SDK_INT
>=
22
)
{
args
[
4
]
=
"-p"
;
args
[
5
]
=
info
->
str
[
SU_MANAGER
];
}
else
{
sprintf
(
component
,
"%s/a.h"
,
info
->
str
[
SU_MANAGER
]);
args
[
4
]
=
"-n"
;
args
[
5
]
=
component
;
}
exec_t
exec
{
.
pre_exec
=
[]()
->
void
{
int
null
=
xopen
(
"/dev/null"
,
O_WRONLY
|
O_CLOEXEC
);
dup2
(
null
,
STDOUT_FILENO
);
dup2
(
null
,
STDERR_FILENO
);
setenv
(
"CLASSPATH"
,
"/system/framework/am.jar"
,
1
);
execv
(
args
[
0
],
(
char
**
)
args
);
PLOGE
(
"exec am"
);
_exit
(
EXIT_FAILURE
);
},
.
fork
=
fork_dont_care
,
.
argv
=
args
};
exec_command
(
exec
);
}
static
void
setup_user
(
char
*
user
,
struct
su_info
*
info
)
{
...
...
@@ -72,14 +83,8 @@ void app_log(struct su_context *ctx) {
char
policy
[
2
];
sprintf
(
policy
,
"%d"
,
ctx
->
info
->
access
.
policy
);
char
component
[
128
];
sprintf
(
component
,
"%s/"
RECEIVER
,
ctx
->
info
->
str
[
SU_MANAGER
]);
const
char
*
cmd
[]
=
{
AM_PATH
,
"broadcast"
,
"-a"
,
"android.intent.action.BOOT_COMPLETED"
,
"-n"
,
component
,
"-f"
,
"0x00000020"
,
BROADCAST_BOOT_COMPLETED
,
"--user"
,
user
,
"--es"
,
"action"
,
"log"
,
"--ei"
,
"from.uid"
,
fromUid
,
...
...
@@ -90,7 +95,7 @@ void app_log(struct su_context *ctx) {
"--ez"
,
"notify"
,
ctx
->
info
->
access
.
notify
?
"true"
:
"false"
,
nullptr
};
silent_run
(
cmd
);
silent_run
(
cmd
,
ctx
->
info
);
}
void
app_notify
(
struct
su_context
*
ctx
)
{
...
...
@@ -105,39 +110,29 @@ void app_notify(struct su_context *ctx) {
char
policy
[
2
];
sprintf
(
policy
,
"%d"
,
ctx
->
info
->
access
.
policy
);
char
component
[
128
];
sprintf
(
component
,
"%s/"
RECEIVER
,
ctx
->
info
->
str
[
SU_MANAGER
]);
const
char
*
cmd
[]
=
{
AM_PATH
,
"broadcast"
,
"-a"
,
"android.intent.action.BOOT_COMPLETED"
,
"-n"
,
component
,
"-f"
,
"0x00000020"
,
BROADCAST_BOOT_COMPLETED
,
"--user"
,
user
,
"--es"
,
"action"
,
"notify"
,
"--ei"
,
"from.uid"
,
fromUid
,
"--ei"
,
"policy"
,
policy
,
nullptr
};
silent_run
(
cmd
);
silent_run
(
cmd
,
ctx
->
info
);
}
void
app_connect
(
const
char
*
socket
,
struct
su_info
*
info
)
{
char
user
[
8
];
setup_user
(
user
,
info
);
char
component
[
128
];
sprintf
(
component
,
"%s/"
RECEIVER
,
info
->
str
[
SU_MANAGER
]);
const
char
*
cmd
[]
=
{
AM_PATH
,
"broadcast"
,
"-a"
,
"android.intent.action.BOOT_COMPLETED"
,
"-n"
,
component
,
"-f"
,
"0x00000020"
,
BROADCAST_BOOT_COMPLETED
,
"--user"
,
user
,
"--es"
,
"action"
,
"request"
,
"--es"
,
"socket"
,
socket
,
nullptr
};
silent_run
(
cmd
);
silent_run
(
cmd
,
info
);
}
void
socket_send_request
(
int
fd
,
struct
su_info
*
info
)
{
...
...
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