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
499a1579
Commit
499a1579
authored
Jun 09, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update snet extension
parent
c5a7ab24
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
66 deletions
+73
-66
snet.apk
snet.apk
+0
-0
MagiskFragment.java
src/full/java/com/topjohnwu/magisk/MagiskFragment.java
+7
-14
CheckSafetyNet.java
...full/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
+19
-26
FlavorActivity.java
.../java/com/topjohnwu/magisk/components/FlavorActivity.java
+23
-23
ISafetyNetHelper.java
...ull/java/com/topjohnwu/magisk/utils/ISafetyNetHelper.java
+22
-0
Const.java
src/main/java/com/topjohnwu/magisk/utils/Const.java
+2
-3
No files found.
snet.apk
deleted
100644 → 0
View file @
c5a7ab24
This diff was suppressed by a .gitattributes entry.
src/full/java/com/topjohnwu/magisk/MagiskFragment.java
View file @
499a1579
...
...
@@ -23,6 +23,7 @@ import com.topjohnwu.magisk.asyncs.CheckUpdates;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
import
com.topjohnwu.magisk.components.ExpandableView
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.utils.ISafetyNetHelper
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.RootUtils
;
import
com.topjohnwu.magisk.utils.ShowUI
;
...
...
@@ -39,14 +40,6 @@ import butterknife.Unbinder;
public
class
MagiskFragment
extends
Fragment
implements
Topic
.
Subscriber
,
SwipeRefreshLayout
.
OnRefreshListener
,
ExpandableView
{
private
static
final
int
CAUSE_SERVICE_DISCONNECTED
=
0x01
;
private
static
final
int
CAUSE_NETWORK_LOST
=
0x02
;
private
static
final
int
RESPONSE_ERR
=
0x04
;
private
static
final
int
CONNECTION_FAIL
=
0x08
;
private
static
final
int
BASIC_PASS
=
0x10
;
private
static
final
int
CTS_PASS
=
0x20
;
private
Container
expandableContainer
=
new
Container
();
private
MagiskManager
mm
;
...
...
@@ -285,12 +278,12 @@ public class MagiskFragment extends Fragment
safetyNetStatusText
.
setText
(
R
.
string
.
safetyNet_check_success
);
boolean
b
;
b
=
(
response
&
CTS_PASS
)
!=
0
;
b
=
(
response
&
ISafetyNetHelper
.
CTS_PASS
)
!=
0
;
ctsStatusText
.
setText
(
"ctsProfile: "
+
b
);
ctsStatusIcon
.
setImageResource
(
b
?
R
.
drawable
.
ic_check_circle
:
R
.
drawable
.
ic_cancel
);
ctsStatusIcon
.
setColorFilter
(
b
?
colorOK
:
colorBad
);
b
=
(
response
&
BASIC_PASS
)
!=
0
;
b
=
(
response
&
ISafetyNetHelper
.
BASIC_PASS
)
!=
0
;
basicStatusText
.
setText
(
"basicIntegrity: "
+
b
);
basicStatusIcon
.
setImageResource
(
b
?
R
.
drawable
.
ic_check_circle
:
R
.
drawable
.
ic_cancel
);
basicStatusIcon
.
setColorFilter
(
b
?
colorOK
:
colorBad
);
...
...
@@ -299,16 +292,16 @@ public class MagiskFragment extends Fragment
}
else
{
@StringRes
int
resid
;
switch
(
response
)
{
case
CAUSE_SERVICE_DISCONNECTED:
case
ISafetyNetHelper
.
CAUSE_SERVICE_DISCONNECTED
:
resid
=
R
.
string
.
safetyNet_network_loss
;
break
;
case
CAUSE_NETWORK_LOST:
case
ISafetyNetHelper
.
CAUSE_NETWORK_LOST
:
resid
=
R
.
string
.
safetyNet_service_disconnected
;
break
;
case
RESPONSE_ERR:
case
ISafetyNetHelper
.
RESPONSE_ERR
:
resid
=
R
.
string
.
safetyNet_res_invalid
;
break
;
case
CONNECTION_FAIL:
case
ISafetyNetHelper
.
CONNECTION_FAIL
:
default
:
resid
=
R
.
string
.
safetyNet_api_error
;
break
;
...
...
src/full/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
View file @
499a1579
...
...
@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.asyncs;
import
android.app.Activity
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.ISafetyNetHelper
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -15,7 +16,6 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Proxy
;
import
java.net.HttpURLConnection
;
import
dalvik.system.DexClassLoader
;
...
...
@@ -24,32 +24,33 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
public
static
final
File
dexPath
=
new
File
(
MagiskManager
.
get
().
getFilesDir
().
getParent
()
+
"/snet"
,
"snet.apk"
);
private
DexClassLoader
loader
;
private
Class
<?>
helperClazz
,
callbackClazz
;
private
ISafetyNetHelper
helper
;
public
CheckSafetyNet
(
Activity
activity
)
{
super
(
activity
);
}
private
void
dlSnet
()
throws
IO
Exception
{
private
void
dlSnet
()
throws
Exception
{
Shell
.
Sync
.
sh
(
"rm -rf "
+
dexPath
.
getParent
());
HttpURLConnection
conn
=
WebService
.
request
(
Const
.
Url
.
SNET_URL
,
null
);
dexPath
.
getParentFile
().
mkdir
();
HttpURLConnection
conn
=
WebService
.
request
(
Const
.
Url
.
SNET_URL
,
null
);
try
(
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
dexPath
));
InputStream
in
=
new
BufferedInputStream
(
conn
.
getInputStream
()))
{
ShellUtils
.
pump
(
in
,
out
);
}
}
finally
{
conn
.
disconnect
();
}
}
private
void
dyload
()
throws
Exception
{
loader
=
new
DexClassLoader
(
dexPath
.
getPath
(),
dexPath
.
getParent
(),
null
,
ClassLoader
.
getSystemClassLoader
());
helperClazz
=
loader
.
loadClass
(
Const
.
SNET_PKG
+
".SafetyNetHelper"
);
callbackClazz
=
loader
.
loadClass
(
Const
.
SNET_PKG
+
".SafetyNetCallback"
);
int
snet_ver
=
(
int
)
helperClazz
.
getMethod
(
"getVersion"
).
invoke
(
null
);
if
(
snet_ver
!=
Const
.
SNET_VER
)
{
DexClassLoader
loader
=
new
DexClassLoader
(
dexPath
.
getPath
(),
dexPath
.
getParent
(),
null
,
ISafetyNetHelper
.
class
.
getClassLoader
());
Class
<?>
clazz
=
loader
.
loadClass
(
"com.topjohnwu.snet.SafetyNetHelper"
);
helper
=
(
ISafetyNetHelper
)
clazz
.
getConstructors
()[
0
]
.
newInstance
(
getActivity
(),
(
ISafetyNetHelper
.
Callback
)
code
->
MagiskManager
.
get
().
safetyNetDone
.
publish
(
false
,
code
));
if
(
helper
.
getVersion
()
!=
Const
.
SNET_VER
)
{
throw
new
Exception
();
}
}
...
...
@@ -72,21 +73,13 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
}
@Override
protected
void
onPostExecute
(
Exception
err
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
try
{
if
(
err
!=
null
)
throw
err
;
Object
helper
=
helperClazz
.
getConstructors
()[
0
].
newInstance
(
getActivity
(),
dexPath
.
getPath
(),
Proxy
.
newProxyInstance
(
loader
,
new
Class
[]
{
callbackClazz
},
(
proxy
,
method
,
args
)
->
{
mm
.
safetyNetDone
.
publish
(
false
,
args
[
0
]);
return
null
;
}));
helperClazz
.
getMethod
(
"attest"
).
invoke
(
helper
);
}
catch
(
Exception
e
)
{
protected
void
onPostExecute
(
Exception
e
)
{
if
(
e
==
null
)
{
helper
.
attest
();
}
else
{
e
.
printStackTrace
();
mm
.
safetyNetDone
.
publish
(
false
,
-
1
);
MagiskManager
.
get
()
.
safetyNetDone
.
publish
(
false
,
-
1
);
}
super
.
onPostExecute
(
e
rr
);
super
.
onPostExecute
(
e
);
}
}
src/full/java/com/topjohnwu/magisk/components/FlavorActivity.java
View file @
499a1579
...
...
@@ -17,7 +17,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
private
AssetManager
swappedAssetManager
=
null
;
private
Resources
swappedResources
=
null
;
private
Resources
.
Theme
swapped
Theme
=
null
;
private
Resources
.
Theme
backup
Theme
=
null
;
@StyleRes
public
int
getDarkTheme
()
{
...
...
@@ -25,7 +25,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
}
public
MagiskManager
getMagiskManager
()
{
return
(
MagiskManager
)
super
.
getApplication
Context
();
return
(
MagiskManager
)
super
.
getApplication
();
}
@Override
...
...
@@ -48,17 +48,6 @@ public abstract class FlavorActivity extends AppCompatActivity {
super
.
onDestroy
();
}
private
static
AssetManager
getAssets
(
String
apk
)
{
try
{
AssetManager
asset
=
AssetManager
.
class
.
newInstance
();
AssetManager
.
class
.
getMethod
(
"addAssetPath"
,
String
.
class
).
invoke
(
asset
,
apk
);
return
asset
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
protected
void
setFloating
()
{
boolean
isTablet
=
getResources
().
getBoolean
(
R
.
bool
.
isTablet
);
if
(
isTablet
)
{
...
...
@@ -75,7 +64,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
@Override
public
Resources
.
Theme
getTheme
()
{
return
swappedTheme
==
null
?
super
.
getTheme
()
:
swapped
Theme
;
return
backupTheme
==
null
?
super
.
getTheme
()
:
backup
Theme
;
}
@Override
...
...
@@ -83,26 +72,37 @@ public abstract class FlavorActivity extends AppCompatActivity {
return
swappedAssetManager
==
null
?
super
.
getAssets
()
:
swappedAssetManager
;
}
private
AssetManager
getAssets
(
String
apk
)
{
try
{
AssetManager
asset
=
AssetManager
.
class
.
newInstance
();
AssetManager
.
class
.
getMethod
(
"addAssetPath"
,
String
.
class
).
invoke
(
asset
,
apk
);
return
asset
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
@Override
public
Resources
getResources
()
{
return
swappedResources
==
null
?
super
.
getResources
()
:
swappedResources
;
}
@Keep
public
void
swapResources
(
String
dexPath
,
int
resId
)
{
swappedAssetManager
=
getAssets
(
dexPath
);
if
(
swappedAssetManager
==
null
)
return
;
public
void
swapResources
(
String
dexPath
)
{
AssetManager
asset
=
getAssets
(
dexPath
);
if
(
asset
!=
null
)
{
backupTheme
=
super
.
getTheme
()
;
Resources
res
=
super
.
getResources
();
swappedResources
=
new
Resources
(
swappedAssetManager
,
res
.
getDisplayMetrics
(),
res
.
getConfiguration
());
swappedTheme
=
swappedResources
.
newTheme
()
;
swappedTheme
.
applyStyle
(
resId
,
true
);
swappedResources
=
new
Resources
(
asset
,
res
.
getDisplayMetrics
(),
res
.
getConfiguration
());
swappedAssetManager
=
asset
;
}
}
@Keep
public
void
restoreResources
()
{
swappedAssetManager
=
null
;
swappedResources
=
null
;
swapped
Theme
=
null
;
backup
Theme
=
null
;
}
}
src/full/java/com/topjohnwu/magisk/utils/ISafetyNetHelper.java
0 → 100644
View file @
499a1579
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.support.annotation.Keep
;
public
interface
ISafetyNetHelper
{
int
CAUSE_SERVICE_DISCONNECTED
=
0x01
;
int
CAUSE_NETWORK_LOST
=
0x02
;
int
RESPONSE_ERR
=
0x04
;
int
CONNECTION_FAIL
=
0x08
;
int
BASIC_PASS
=
0x10
;
int
CTS_PASS
=
0x20
;
void
attest
();
int
getVersion
();
interface
Callback
{
@Keep
void
onResponse
(
int
responseCode
);
}
}
src/main/java/com/topjohnwu/magisk/utils/Const.java
View file @
499a1579
...
...
@@ -14,7 +14,6 @@ public class Const {
public
static
final
String
DEBUG_TAG
=
"MagiskManager"
;
public
static
final
String
ORIG_PKG_NAME
=
BuildConfig
.
APPLICATION_ID
;
public
static
final
String
SNET_PKG
=
"com.topjohnwu.snet"
;
public
static
final
String
MAGISKHIDE_PROP
=
"persist.magisk.hide"
;
// APK content
...
...
@@ -37,7 +36,7 @@ public class Const {
// Versions
public
static
final
int
UPDATE_SERVICE_VER
=
1
;
public
static
final
int
SNET_VER
=
7
;
public
static
final
int
SNET_VER
=
8
;
public
static
int
MIN_MODULE_VER
()
{
return
MagiskManager
.
get
().
magiskVersionCode
>=
MAGISK_VER
.
REMOVE_LEGACY_LINK
?
1500
:
1400
;
...
...
@@ -81,7 +80,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/
a82a5e5a49285df65da91d2e8b24f4783841b515
/snet.apk"
;
public
static
final
String
SNET_URL
=
"https://github.com/topjohnwu/MagiskManager/raw/
788f01f499714471949613820d43bc364786e85d
/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"
;
...
...
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