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
2793d209
Commit
2793d209
authored
May 07, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow requesting root from non app process
parent
71e9c044
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
9 deletions
+29
-9
SuRequestHandler.kt
...ain/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
+5
-1
RootUtils.kt
...rc/main/java/com/topjohnwu/magisk/core/utils/RootUtils.kt
+9
-3
SuRequestViewModel.kt
...a/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt
+15
-5
No files found.
app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
View file @
2793d209
...
@@ -66,7 +66,11 @@ class SuRequestHandler(
...
@@ -66,7 +66,11 @@ class SuRequestHandler(
val
fifo
=
intent
.
getStringExtra
(
"fifo"
)
?:
throw
SuRequestError
()
val
fifo
=
intent
.
getStringExtra
(
"fifo"
)
?:
throw
SuRequestError
()
val
uid
=
intent
.
getIntExtra
(
"uid"
,
-
1
).
also
{
if
(
it
<
0
)
throw
SuRequestError
()
}
val
uid
=
intent
.
getIntExtra
(
"uid"
,
-
1
).
also
{
if
(
it
<
0
)
throw
SuRequestError
()
}
val
pid
=
intent
.
getIntExtra
(
"pid"
,
-
1
)
val
pid
=
intent
.
getIntExtra
(
"pid"
,
-
1
)
pkgInfo
=
pm
.
getPackageInfo
(
uid
,
pid
)
?:
throw
SuRequestError
()
pkgInfo
=
pm
.
getPackageInfo
(
uid
,
pid
)
?:
PackageInfo
().
apply
{
val
name
=
pm
.
getNameForUid
(
uid
)
?:
throw
SuRequestError
()
// We only fill in sharedUserId and leave other fields uninitialized
sharedUserId
=
name
.
split
(
":"
)[
0
]
}
output
=
DataOutputStream
(
FileOutputStream
(
fifo
).
buffered
())
output
=
DataOutputStream
(
FileOutputStream
(
fifo
).
buffered
())
policy
=
SuPolicy
(
uid
)
policy
=
SuPolicy
(
uid
)
true
true
...
...
app/src/main/java/com/topjohnwu/magisk/core/utils/RootUtils.kt
View file @
2793d209
...
@@ -12,6 +12,7 @@ import com.topjohnwu.superuser.ipc.RootService
...
@@ -12,6 +12,7 @@ import com.topjohnwu.superuser.ipc.RootService
import
com.topjohnwu.superuser.nio.FileSystemManager
import
com.topjohnwu.superuser.nio.FileSystemManager
import
timber.log.Timber
import
timber.log.Timber
import
java.io.File
import
java.io.File
import
java.io.IOException
import
java.util.concurrent.locks.AbstractQueuedSynchronizer
import
java.util.concurrent.locks.AbstractQueuedSynchronizer
class
RootUtils
(
stub
:
Any
?)
:
RootService
()
{
class
RootUtils
(
stub
:
Any
?)
:
RootService
()
{
...
@@ -55,9 +56,14 @@ class RootUtils(stub: Any?) : RootService() {
...
@@ -55,9 +56,14 @@ class RootUtils(stub: Any?) : RootService() {
if
(
proc
!=
null
)
if
(
proc
!=
null
)
return
proc
return
proc
// Find PPID
// Find PPID
File
(
"/proc/$pid/status"
).
useLines
{
try
{
val
s
=
it
.
find
{
line
->
line
.
startsWith
(
"PPid:"
)
}
File
(
"/proc/$pid/status"
).
useLines
{
pid
=
s
?.
substring
(
5
)
?.
trim
()
?.
toInt
()
?:
-
1
val
line
=
it
.
find
{
l
->
l
.
startsWith
(
"PPid:"
)
}
?:
return
null
pid
=
line
.
substring
(
5
).
trim
().
toInt
()
}
}
catch
(
e
:
IOException
)
{
// The process died unexpectedly
return
null
}
}
}
}
return
null
return
null
...
...
app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt
View file @
2793d209
...
@@ -110,11 +110,21 @@ class SuRequestViewModel(
...
@@ -110,11 +110,21 @@ class SuRequestViewModel(
private
fun
showDialog
()
{
private
fun
showDialog
()
{
val
pm
=
handler
.
pm
val
pm
=
handler
.
pm
val
info
=
handler
.
pkgInfo
val
info
=
handler
.
pkgInfo
val
prefix
=
if
(
info
.
sharedUserId
==
null
)
""
else
"[SharedUID] "
val
app
=
info
.
applicationInfo
if
(
app
==
null
)
{
// The request is not coming from an app process, and the UID is a
// shared UID. We have no way to know where this request comes from.
icon
=
pm
.
defaultActivityIcon
title
=
"[SharedUID] ${info.sharedUserId}"
packageName
=
info
.
sharedUserId
}
else
{
val
prefix
=
if
(
info
.
sharedUserId
==
null
)
""
else
"[SharedUID] "
icon
=
app
.
loadIcon
(
pm
)
title
=
"$prefix${app.getLabel(pm)}"
packageName
=
info
.
packageName
}
icon
=
info
.
applicationInfo
.
loadIcon
(
pm
)
title
=
"$prefix${info.applicationInfo.getLabel(pm)}"
packageName
=
info
.
packageName
selectedItemPosition
=
timeoutPrefs
.
getInt
(
packageName
,
0
)
selectedItemPosition
=
timeoutPrefs
.
getInt
(
packageName
,
0
)
// Set timer
// Set timer
...
@@ -135,7 +145,7 @@ class SuRequestViewModel(
...
@@ -135,7 +145,7 @@ class SuRequestViewModel(
timer
.
cancel
()
timer
.
cancel
()
val
pos
=
selectedItemPosition
val
pos
=
selectedItemPosition
timeoutPrefs
.
edit
().
putInt
(
handler
.
pkgInfo
.
packageName
,
pos
).
apply
()
timeoutPrefs
.
edit
().
putInt
(
packageName
,
pos
).
apply
()
viewModelScope
.
launch
{
viewModelScope
.
launch
{
handler
.
respond
(
action
,
Config
.
Value
.
TIMEOUT_LIST
[
pos
])
handler
.
respond
(
action
,
Config
.
Value
.
TIMEOUT_LIST
[
pos
])
...
...
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