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
039be65a
Commit
039be65a
authored
Dec 31, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Magisk Manager hiding after using WorkManager
parent
570ecd99
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
33 deletions
+32
-33
DownloadApp.java
...src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java
+1
-2
PatchAPK.java
app/src/full/java/com/topjohnwu/magisk/utils/PatchAPK.java
+30
-30
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-1
No files found.
app/src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java
View file @
039be65a
...
@@ -72,8 +72,7 @@ public class DownloadApp {
...
@@ -72,8 +72,7 @@ public class DownloadApp {
progress
.
update
();
progress
.
update
();
patched
=
new
File
(
apk
.
getParent
(),
"patched.apk"
);
patched
=
new
File
(
apk
.
getParent
(),
"patched.apk"
);
try
{
try
{
JarMap
jarMap
=
new
JarMap
(
apk
);
JarMap
jarMap
=
PatchAPK
.
patch
(
apk
.
getPath
(),
app
.
getPackageName
());
PatchAPK
.
patch
(
jarMap
,
app
.
getPackageName
());
SignAPK
.
sign
(
jarMap
,
new
BufferedOutputStream
(
new
FileOutputStream
(
patched
)));
SignAPK
.
sign
(
jarMap
,
new
BufferedOutputStream
(
new
FileOutputStream
(
patched
)));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
;
return
;
...
...
app/src/full/java/com/topjohnwu/magisk/utils/PatchAPK.java
View file @
039be65a
...
@@ -23,10 +23,11 @@ import java.nio.ByteOrder;
...
@@ -23,10 +23,11 @@ import java.nio.ByteOrder;
import
java.nio.CharBuffer
;
import
java.nio.CharBuffer
;
import
java.nio.IntBuffer
;
import
java.nio.IntBuffer
;
import
java.security.SecureRandom
;
import
java.security.SecureRandom
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarEntry
;
import
androidx.core.app.NotificationCompat
;
import
androidx.core.app.NotificationCompat
;
import
androidx.core.app.NotificationManagerCompat
;
public
class
PatchAPK
{
public
class
PatchAPK
{
...
@@ -42,7 +43,7 @@ public class PatchAPK {
...
@@ -42,7 +43,7 @@ public class PatchAPK {
builder
.
append
(
prefix
);
builder
.
append
(
prefix
);
length
-=
prefix
.
length
();
length
-=
prefix
.
length
();
SecureRandom
random
=
new
SecureRandom
();
SecureRandom
random
=
new
SecureRandom
();
char
next
,
prev
=
'.'
;
char
next
,
prev
=
prefix
.
charAt
(
prefix
.
length
()
-
1
)
;
for
(
int
i
=
0
;
i
<
length
;
++
i
)
{
for
(
int
i
=
0
;
i
<
length
;
++
i
)
{
if
(
prev
==
'.'
||
i
==
length
-
1
)
{
if
(
prev
==
'.'
||
i
==
length
-
1
)
{
next
=
ALPHA
.
charAt
(
random
.
nextInt
(
ALPHA
.
length
()));
next
=
ALPHA
.
charAt
(
random
.
nextInt
(
ALPHA
.
length
()));
...
@@ -55,30 +56,30 @@ public class PatchAPK {
...
@@ -55,30 +56,30 @@ public class PatchAPK {
return
builder
.
toString
();
return
builder
.
toString
();
}
}
private
static
boolean
findAndPatch
(
byte
xml
[],
String
a
,
String
b
)
{
private
static
boolean
findAndPatch
(
byte
xml
[],
String
from
,
String
to
)
{
if
(
a
.
length
()
!=
b
.
length
())
if
(
from
.
length
()
!=
to
.
length
())
return
false
;
return
false
;
char
[]
from
=
a
.
toCharArray
(),
to
=
b
.
toCharArray
();
CharBuffer
buf
=
ByteBuffer
.
wrap
(
xml
).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asCharBuffer
();
CharBuffer
buf
=
ByteBuffer
.
wrap
(
xml
).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
asCharBuffer
();
int
offset
=
-
1
;
List
<
Integer
>
offList
=
new
ArrayList
<>()
;
for
(
int
i
=
0
;
i
<
buf
.
length
()
-
from
.
length
;
++
i
)
{
for
(
int
i
=
0
;
i
<
buf
.
length
()
-
from
.
length
()
;
++
i
)
{
boolean
match
=
true
;
boolean
match
=
true
;
for
(
int
j
=
0
;
j
<
from
.
length
;
++
j
)
{
for
(
int
j
=
0
;
j
<
from
.
length
()
;
++
j
)
{
if
(
buf
.
get
(
i
+
j
)
!=
from
[
j
]
)
{
if
(
buf
.
get
(
i
+
j
)
!=
from
.
charAt
(
j
)
)
{
match
=
false
;
match
=
false
;
break
;
break
;
}
}
}
}
// Make sure it is null terminated
if
(
match
)
{
if
(
match
&&
buf
.
get
(
i
+
from
.
length
)
==
'\0'
)
{
offList
.
add
(
i
);
offset
=
i
;
i
+=
from
.
length
();
break
;
}
}
}
}
if
(
off
set
<
0
)
if
(
off
List
.
isEmpty
()
)
return
false
;
return
false
;
buf
.
position
(
offset
);
for
(
int
off
:
offList
)
{
buf
.
put
(
to
);
buf
.
position
(
off
);
buf
.
put
(
to
);
}
return
true
;
return
true
;
}
}
...
@@ -102,8 +103,8 @@ public class PatchAPK {
...
@@ -102,8 +103,8 @@ public class PatchAPK {
String
pkg
=
genPackageName
(
"com."
,
BuildConfig
.
APPLICATION_ID
.
length
());
String
pkg
=
genPackageName
(
"com."
,
BuildConfig
.
APPLICATION_ID
.
length
());
try
{
try
{
JarMap
apk
=
new
JarMap
(
app
.
getPackageCodePath
())
;
JarMap
apk
;
if
(
!
patch
(
apk
,
pkg
)
)
if
(
(
apk
=
patch
(
app
.
getPackageCodePath
(),
pkg
))
==
null
)
return
false
;
return
false
;
SignAPK
.
sign
(
apk
,
new
BufferedOutputStream
(
new
FileOutputStream
(
repack
)));
SignAPK
.
sign
(
apk
,
new
BufferedOutputStream
(
new
FileOutputStream
(
repack
)));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -113,7 +114,7 @@ public class PatchAPK {
...
@@ -113,7 +114,7 @@ public class PatchAPK {
// Install the application
// Install the application
repack
.
setReadable
(
true
,
false
);
repack
.
setReadable
(
true
,
false
);
if
(!
ShellUtils
.
fastCmdResult
(
"pm install "
+
repack
))
if
(!
ShellUtils
.
fastCmdResult
(
"pm install "
+
repack
))
return
false
;
;
return
false
;
app
.
mDB
.
setStrings
(
Const
.
Key
.
SU_MANAGER
,
pkg
);
app
.
mDB
.
setStrings
(
Const
.
Key
.
SU_MANAGER
,
pkg
);
Data
.
exportPrefs
();
Data
.
exportPrefs
();
...
@@ -122,23 +123,23 @@ public class PatchAPK {
...
@@ -122,23 +123,23 @@ public class PatchAPK {
return
true
;
return
true
;
}
}
public
static
boolean
patch
(
JarMap
apk
,
String
pkg
)
{
public
static
JarMap
patch
(
String
apk
,
String
pkg
)
{
try
{
try
{
JarEntry
je
=
apk
.
getJarEntry
(
Const
.
ANDROID_MANIFEST
);
JarMap
jar
=
new
JarMap
(
apk
);
byte
xml
[]
=
apk
.
getRawData
(
je
);
JarEntry
je
=
jar
.
getJarEntry
(
Const
.
ANDROID_MANIFEST
);
byte
xml
[]
=
jar
.
getRawData
(
je
);
if
(!
findAndPatch
(
xml
,
BuildConfig
.
APPLICATION_ID
,
pkg
)
||
if
(!
findAndPatch
(
xml
,
BuildConfig
.
APPLICATION_ID
,
pkg
)
||
!
findAndPatch
(
xml
,
BuildConfig
.
APPLICATION_ID
+
".provider"
,
pkg
+
".provider"
)
||
!
findAndPatch
(
xml
,
R
.
string
.
app_name
,
R
.
string
.
re_app_name
))
!
findAndPatch
(
xml
,
R
.
string
.
app_name
,
R
.
string
.
re_app_name
))
return
false
;
return
null
;
// Write in changes
// Write in changes
apk
.
getOutputStream
(
je
).
write
(
xml
);
jar
.
getOutputStream
(
je
).
write
(
xml
);
return
jar
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
false
;
return
null
;
}
}
return
true
;
}
}
public
static
void
hideManager
()
{
public
static
void
hideManager
()
{
...
@@ -146,10 +147,9 @@ public class PatchAPK {
...
@@ -146,10 +147,9 @@ public class PatchAPK {
App
app
=
App
.
self
;
App
app
=
App
.
self
;
NotificationCompat
.
Builder
progress
=
NotificationCompat
.
Builder
progress
=
Notifications
.
progress
(
app
.
getString
(
R
.
string
.
hide_manager_title
));
Notifications
.
progress
(
app
.
getString
(
R
.
string
.
hide_manager_title
));
NotificationManagerCompat
mgr
=
NotificationManagerCompat
.
from
(
app
);
Notifications
.
mgr
.
notify
(
Const
.
ID
.
HIDE_MANAGER_NOTIFICATION_ID
,
progress
.
build
());
mgr
.
notify
(
Const
.
ID
.
HIDE_MANAGER_NOTIFICATION_ID
,
progress
.
build
());
boolean
b
=
patchAndHide
();
boolean
b
=
patchAndHide
();
mgr
.
cancel
(
Const
.
ID
.
HIDE_MANAGER_NOTIFICATION_ID
);
Notifications
.
mgr
.
cancel
(
Const
.
ID
.
HIDE_MANAGER_NOTIFICATION_ID
);
if
(!
b
)
Utils
.
toast
(
R
.
string
.
hide_manager_fail_toast
,
Toast
.
LENGTH_LONG
);
if
(!
b
)
Utils
.
toast
(
R
.
string
.
hide_manager_fail_toast
,
Toast
.
LENGTH_LONG
);
});
});
}
}
...
...
app/src/main/AndroidManifest.xml
View file @
039be65a
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
<provider
<provider
android:name=
"androidx.core.content.FileProvider"
android:name=
"androidx.core.content.FileProvider"
android:authorities=
"
com.topjohnwu.magisk
.provider"
android:authorities=
"
${applicationId}
.provider"
android:exported=
"false"
android:exported=
"false"
android:grantUriPermissions=
"true"
>
android:grantUriPermissions=
"true"
>
<meta-data
<meta-data
...
...
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