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
e11508f8
Commit
e11508f8
authored
May 07, 2022
by
vvb2060
Committed by
John Wu
May 17, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respond deny when pkg name not found
parent
0772f6dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
23 deletions
+22
-23
SuRequestHandler.kt
...ain/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
+22
-23
No files found.
app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
View file @
e11508f8
...
@@ -12,7 +12,6 @@ import com.topjohnwu.superuser.Shell
...
@@ -12,7 +12,6 @@ import com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
timber.log.Timber
import
timber.log.Timber
import
java.io.Closeable
import
java.io.DataOutputStream
import
java.io.DataOutputStream
import
java.io.FileOutputStream
import
java.io.FileOutputStream
import
java.io.IOException
import
java.io.IOException
...
@@ -21,11 +20,10 @@ import java.util.concurrent.TimeUnit
...
@@ -21,11 +20,10 @@ import java.util.concurrent.TimeUnit
class
SuRequestHandler
(
class
SuRequestHandler
(
val
pm
:
PackageManager
,
val
pm
:
PackageManager
,
private
val
policyDB
:
PolicyDao
private
val
policyDB
:
PolicyDao
)
:
Closeable
{
)
{
private
lateinit
var
output
:
DataOutputStream
private
lateinit
var
output
:
DataOutputStream
lateinit
var
policy
:
SuPolicy
private
lateinit
var
policy
:
SuPolicy
private
set
lateinit
var
pkgInfo
:
PackageInfo
lateinit
var
pkgInfo
:
PackageInfo
private
set
private
set
...
@@ -54,35 +52,36 @@ class SuRequestHandler(
...
@@ -54,35 +52,36 @@ class SuRequestHandler(
return
true
return
true
}
}
overrid
e
fun
close
()
{
privat
e
fun
close
()
{
if
(
::
output
.
isInitialized
)
if
(
::
output
.
isInitialized
)
runCatching
{
output
.
close
()
}
runCatching
{
output
.
close
()
}
}
}
private
class
SuRequestError
:
IOException
()
private
suspend
fun
init
(
intent
:
Intent
)
=
withContext
(
Dispatchers
.
IO
)
{
private
suspend
fun
init
(
intent
:
Intent
)
=
withContext
(
Dispatchers
.
IO
)
{
try
{
try
{
val
fifo
=
intent
.
getStringExtra
(
"fifo"
)
?:
throw
SuRequestError
()
val
fifo
=
intent
.
getStringExtra
(
"fifo"
)
?:
throw
IOException
(
"fifo == null"
)
val
uid
=
intent
.
getIntExtra
(
"uid"
,
-
1
).
also
{
if
(
it
<
0
)
throw
SuRequestError
()
}
output
=
DataOutputStream
(
FileOutputStream
(
fifo
))
val
pid
=
intent
.
getIntExtra
(
"pid"
,
-
1
)
val
uid
=
intent
.
getIntExtra
(
"uid"
,
-
1
)
pkgInfo
=
pm
.
getPackageInfo
(
uid
,
pid
)
?:
PackageInfo
().
apply
{
if
(
uid
<=
0
)
{
val
name
=
pm
.
getNameForUid
(
uid
)
?:
throw
SuRequestError
()
throw
IOException
(
"uid == $uid"
)
// We only fill in sharedUserId and leave other fields uninitialized
sharedUserId
=
name
.
split
(
":"
)[
0
]
}
}
output
=
DataOutputStream
(
FileOutputStream
(
fifo
).
buffered
())
policy
=
SuPolicy
(
uid
)
policy
=
SuPolicy
(
uid
)
true
val
pid
=
intent
.
getIntExtra
(
"pid"
,
-
1
)
}
catch
(
e
:
Exception
)
{
try
{
when
(
e
)
{
pkgInfo
=
pm
.
getPackageInfo
(
uid
,
pid
)
?:
PackageInfo
().
apply
{
is
IOException
,
is
PackageManager
.
NameNotFoundException
->
{
val
name
=
pm
.
getNameForUid
(
uid
)
?:
throw
PackageManager
.
NameNotFoundException
()
Timber
.
e
(
e
)
// We only fill in sharedUserId and leave other fields uninitialized
close
()
sharedUserId
=
name
.
split
(
":"
)[
0
]
false
}
}
else
->
throw
e
// Unexpected error
return
@withContext
true
}
catch
(
e
:
PackageManager
.
NameNotFoundException
)
{
respond
(
SuPolicy
.
DENY
,
-
1
)
return
@withContext
false
}
}
}
catch
(
e
:
IOException
)
{
Timber
.
e
(
e
)
close
()
return
@withContext
false
}
}
}
}
...
...
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