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
cdc66c1a
Commit
cdc66c1a
authored
Aug 26, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move patching logic out of AXML
parent
e9af7739
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
22 deletions
+23
-22
HideAPK.kt
app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt
+12
-2
AXML.kt
app/src/main/java/com/topjohnwu/magisk/core/utils/AXML.kt
+11
-20
No files found.
app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt
View file @
cdc66c1a
...
...
@@ -71,14 +71,24 @@ object HideAPK {
pkg
:
String
,
label
:
CharSequence
):
Boolean
{
val
info
=
context
.
packageManager
.
getPackageArchiveInfo
(
apk
.
path
,
0
)
?:
return
false
val
name
=
info
.
applicationInfo
.
nonLocalizedLabel
.
toString
()
val
origLabel
=
info
.
applicationInfo
.
nonLocalizedLabel
.
toString
()
try
{
JarMap
.
open
(
apk
,
true
).
use
{
jar
->
val
je
=
jar
.
getJarEntry
(
ANDROID_MANIFEST
)
val
xml
=
AXML
(
jar
.
getRawData
(
je
))
if
(!
xml
.
findAndPatch
(
APPLICATION_ID
to
pkg
,
name
to
label
.
toString
()))
if
(!
xml
.
patchStrings
{
for
(
i
in
it
.
indices
)
{
val
s
=
it
[
i
]
if
(
s
.
contains
(
APPLICATION_ID
))
{
it
[
i
]
=
s
.
replace
(
APPLICATION_ID
,
pkg
)
}
else
if
(
s
==
origLabel
)
{
it
[
i
]
=
label
.
toString
()
}
}
})
{
return
false
}
// Write apk changes
jar
.
getOutputStream
(
je
).
use
{
it
.
write
(
xml
.
bytes
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/utils/AXML.kt
View file @
cdc66c1a
...
...
@@ -29,7 +29,7 @@ class AXML(b: ByteArray) {
* Followed by an array of uint32_t with size = number of strings
* Each entry points to an offset into the string data
*/
fun
findAndPatch
(
vararg
patterns
:
Pair
<
String
,
String
>
):
Boolean
{
fun
patchStrings
(
patchFn
:
(
Array
<
String
>)
->
Unit
):
Boolean
{
val
buffer
=
ByteBuffer
.
wrap
(
bytes
).
order
(
LITTLE_ENDIAN
)
fun
findStringPool
():
Int
{
...
...
@@ -42,7 +42,6 @@ class AXML(b: ByteArray) {
return
-
1
}
var
patch
=
false
val
start
=
findStringPool
()
if
(
start
<
0
)
return
false
...
...
@@ -57,34 +56,26 @@ class AXML(b: ByteArray) {
val
dataOff
=
start
+
intBuf
.
get
()
intBuf
.
get
()
val
str
ings
=
ArrayList
<
String
>(
count
)
//
Read and patch all strings
loop
@
for
(
i
in
0
until
count
)
{
val
str
List
=
ArrayList
<
String
>(
count
)
//
Collect all strings in the pool
for
(
i
in
0
until
count
)
{
val
off
=
dataOff
+
intBuf
.
get
()
val
len
=
buffer
.
getShort
(
off
)
val
str
=
String
(
bytes
,
off
+
2
,
len
*
2
,
UTF_16LE
)
for
((
from
,
to
)
in
patterns
)
{
if
(
str
.
contains
(
from
))
{
strings
.
add
(
str
.
replace
(
from
,
to
))
patch
=
true
continue
@loop
}
}
strings
.
add
(
str
)
strList
.
add
(
String
(
bytes
,
off
+
2
,
len
*
2
,
UTF_16LE
))
}
if
(!
patch
)
return
false
val
strArr
=
strList
.
toTypedArray
(
)
patchFn
(
strArr
)
// Write everything before string data, will patch values later
val
baos
=
RawByteStream
()
baos
.
write
(
bytes
,
0
,
dataOff
)
// Write string data
val
str
List
=
IntArray
(
count
)
val
off
List
=
IntArray
(
count
)
for
(
i
in
0
until
count
)
{
str
List
[
i
]
=
baos
.
size
()
-
dataOff
val
str
=
str
ings
[
i
]
off
List
[
i
]
=
baos
.
size
()
-
dataOff
val
str
=
str
Arr
[
i
]
baos
.
write
(
str
.
length
.
toShortBytes
())
baos
.
write
(
str
.
toByteArray
(
UTF_16LE
))
// Null terminate
...
...
@@ -103,7 +94,7 @@ class AXML(b: ByteArray) {
// Patch index table
newBuffer
.
position
(
start
+
STRING_INDICES_OFF
)
val
newIntBuf
=
newBuffer
.
asIntBuffer
()
str
List
.
forEach
{
newIntBuf
.
put
(
it
)
}
off
List
.
forEach
{
newIntBuf
.
put
(
it
)
}
// Write the rest of the chunks
val
nextOff
=
start
+
size
...
...
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