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
b2483ba4
Commit
b2483ba4
authored
Dec 25, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add version check within binary
parent
a82a5e5a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
22 deletions
+38
-22
CheckSafetyNet.java
...main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
+36
-20
Const.java
src/main/java/com/topjohnwu/magisk/utils/Const.java
+2
-2
No files found.
src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
View file @
b2483ba4
...
...
@@ -12,6 +12,7 @@ import java.io.BufferedInputStream;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Proxy
;
...
...
@@ -23,50 +24,65 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
private
File
dexPath
;
private
DexClassLoader
loader
;
private
Class
<?>
helperClazz
,
callbackClazz
;
public
CheckSafetyNet
(
Activity
activity
)
{
super
(
activity
);
dexPath
=
new
File
(
activity
.
getCacheDir
().
getParent
()
+
"/snet"
,
"snet.apk"
);
}
@Override
protected
void
onPreExecute
()
{
MagiskManager
mm
=
MagiskManager
.
get
();
if
(
mm
.
snetVersion
!=
Const
.
Value
.
SNET_VER
)
{
Shell
.
sh
(
"rm -rf "
+
dexPath
.
getParent
());
private
void
dlSnet
()
throws
IOException
{
Shell
.
sh
(
"rm -rf "
+
dexPath
.
getParent
());
HttpURLConnection
conn
=
WebService
.
request
(
Const
.
Url
.
SNET_URL
,
null
);
dexPath
.
getParentFile
().
mkdir
();
try
(
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
dexPath
));
InputStream
in
=
new
BufferedInputStream
(
conn
.
getInputStream
()))
{
Utils
.
inToOut
(
in
,
out
);
}
mm
.
snetVersion
=
Const
.
Value
.
SNET_VER
;
mm
.
prefs
.
edit
().
putInt
(
Const
.
Key
.
SNET_VER
,
Const
.
Value
.
SNET_VER
).
apply
();
conn
.
disconnect
();
}
private
void
loadClasses
()
throws
ClassNotFoundException
{
loader
=
new
DexClassLoader
(
dexPath
.
toString
(),
dexPath
.
getParent
(),
null
,
ClassLoader
.
getSystemClassLoader
());
helperClazz
=
loader
.
loadClass
(
Const
.
SNET_PKG
+
".SafetyNetHelper"
);
callbackClazz
=
loader
.
loadClass
(
Const
.
SNET_PKG
+
".SafetyNetCallback"
);
}
@Override
protected
Exception
doInBackground
(
Void
...
voids
)
{
int
snet_ver
=
-
1
;
try
{
if
(!
dexPath
.
exists
())
{
HttpURLConnection
conn
=
WebService
.
request
(
Const
.
Url
.
SNET_URL
,
null
);
dexPath
.
getParentFile
().
mkdir
();
try
(
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
dexPath
));
InputStream
in
=
new
BufferedInputStream
(
conn
.
getInputStream
()))
{
Utils
.
inToOut
(
in
,
out
);
}
conn
.
disconnect
();
if
(!
dexPath
.
exists
())
dlSnet
();
loadClasses
();
try
{
snet_ver
=
(
int
)
helperClazz
.
getMethod
(
"getVersion"
).
invoke
(
null
);
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
if
(
snet_ver
!=
Const
.
Value
.
SNET_VER
)
{
dlSnet
();
loadClasses
();
}
loader
=
new
DexClassLoader
(
dexPath
.
toString
(),
dexPath
.
getParent
(),
null
,
ClassLoader
.
getSystemClassLoader
());
}
catch
(
Exception
e
)
{
return
e
;
}
return
null
;
}
@Override
protected
void
onPostExecute
(
Exception
err
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
mm
.
snetVersion
=
Const
.
Value
.
SNET_VER
;
mm
.
prefs
.
edit
().
putInt
(
Const
.
Key
.
SNET_VER
,
Const
.
Value
.
SNET_VER
).
apply
();
try
{
if
(
err
!=
null
)
throw
err
;
Class
<?>
helperClazz
=
loader
.
loadClass
(
Const
.
SNET_PKG
+
".SafetyNetHelper"
);
Class
<?>
callbackClazz
=
loader
.
loadClass
(
Const
.
SNET_PKG
+
".SafetyNetCallback"
);
Object
helper
=
helperClazz
.
getConstructors
()[
0
].
newInstance
(
getActivity
(),
dexPath
.
getPath
(),
Proxy
.
newProxyInstance
(
loader
,
new
Class
[]
{
callbackClazz
},
(
proxy
,
method
,
args
)
->
{
...
...
src/main/java/com/topjohnwu/magisk/utils/Const.java
View file @
b2483ba4
...
...
@@ -84,7 +84,7 @@ public class Const {
public
static
class
Url
{
public
static
final
String
STABLE_URL
=
"https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json"
;
public
static
final
String
BETA_URL
=
"https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json"
;
public
static
final
String
SNET_URL
=
"https://github.com/topjohnwu/MagiskManager/raw/a
fff3c0a49cec8d797e486be3092e256b4bf537
5/snet.apk"
;
public
static
final
String
SNET_URL
=
"https://github.com/topjohnwu/MagiskManager/raw/a
82a5e5a49285df65da91d2e8b24f4783841b51
5/snet.apk"
;
public
static
final
String
REPO_URL
=
"https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d"
;
public
static
final
String
FILE_URL
=
"https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s"
;
public
static
final
String
ZIP_URL
=
"https://github.com/Magisk-Modules-Repo/%s/archive/master.zip"
;
...
...
@@ -159,7 +159,7 @@ public class Const {
public
static
final
String
FLASH_MAGISK
=
"magisk"
;
public
static
final
int
[]
timeoutList
=
{
0
,
-
1
,
10
,
20
,
30
,
60
};
public
static
final
int
UPDATE_SERVICE_VER
=
1
;
public
static
final
int
SNET_VER
=
6
;
public
static
final
int
SNET_VER
=
7
;
public
static
final
int
MIN_MODULE_VER
=
1400
;
}
}
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