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
f5374a02
Commit
f5374a02
authored
Oct 29, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve dynamic loading snet package
parent
4956d826
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
97 additions
and
75 deletions
+97
-75
build.gradle
app/build.gradle
+5
-4
MagiskFragment.java
app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java
+11
-9
CheckSafetyNet.java
...main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
+8
-7
Activity.java
...c/main/java/com/topjohnwu/magisk/components/Activity.java
+37
-1
build.gradle
build.gradle
+0
-10
build.gradle
snet/build.gradle
+6
-3
SafetyNetHelper.java
snet/src/main/java/com/topjohnwu/snet/SafetyNetHelper.java
+30
-41
No files found.
app/build.gradle
View file @
f5374a02
apply
plugin:
'com.android.application'
android
{
compileSdkVersion
2
6
buildToolsVersion
"2
6.0.2
"
compileSdkVersion
2
7
buildToolsVersion
"2
7.0.0
"
defaultConfig
{
applicationId
"com.topjohnwu.magisk"
minSdkVersion
21
targetSdkVersion
2
6
targetSdkVersion
2
7
versionCode
57
versionName
"5.4.0"
ndk
{
...
...
@@ -45,10 +45,11 @@ android {
disable
'MissingTranslation'
}
}
repositories
{
jcenter
()
google
()
maven
{
url
"https://jitpack.io"
}
maven
{
url
"https://maven.google.com"
}
}
dependencies
{
...
...
app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java
View file @
f5374a02
...
...
@@ -43,12 +43,13 @@ import butterknife.Unbinder;
public
class
MagiskFragment
extends
Fragment
implements
Topic
.
Subscriber
,
SwipeRefreshLayout
.
OnRefreshListener
,
ExpandableView
{
public
static
final
int
CAUSE_SERVICE_DISCONNECTED
=
0x00001
;
public
static
final
int
CAUSE_NETWORK_LOST
=
0x00010
;
public
static
final
int
RESPONSE_ERR
=
0x00100
;
public
static
final
int
CAUSE_SERVICE_DISCONNECTED
=
0x01
;
public
static
final
int
CAUSE_NETWORK_LOST
=
0x02
;
public
static
final
int
RESPONSE_ERR
=
0x04
;
public
static
final
int
CONNECTION_FAIL
=
0x08
;
public
static
final
int
BASIC_PASS
=
0x
0100
0
;
public
static
final
int
CTS_PASS
=
0x
1000
0
;
public
static
final
int
BASIC_PASS
=
0x
1
0
;
public
static
final
int
CTS_PASS
=
0x
2
0
;
private
Container
expandableContainer
=
new
Container
();
...
...
@@ -331,9 +332,7 @@ public class MagiskFragment extends Fragment
private
void
updateSafetyNetUI
(
int
response
)
{
safetyNetProgress
.
setVisibility
(
View
.
GONE
);
safetyNetRefreshIcon
.
setVisibility
(
View
.
VISIBLE
);
if
(
response
<
0
)
{
safetyNetStatusText
.
setText
(
R
.
string
.
safetyNet_api_error
);
}
else
if
((
response
&
0x111
)
==
0
)
{
if
((
response
&
0x0F
)
==
0
)
{
safetyNetStatusText
.
setText
(
R
.
string
.
safetyNet_check_success
);
boolean
b
;
...
...
@@ -358,9 +357,12 @@ public class MagiskFragment extends Fragment
resid
=
R
.
string
.
safetyNet_service_disconnected
;
break
;
case
RESPONSE_ERR:
default
:
resid
=
R
.
string
.
safetyNet_res_invalid
;
break
;
case
CONNECTION_FAIL:
default
:
resid
=
R
.
string
.
safetyNet_api_error
;
break
;
}
safetyNetStatusText
.
setText
(
resid
);
}
...
...
app/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
View file @
f5374a02
package
com
.
topjohnwu
.
magisk
.
asyncs
;
import
android.
support.v4.app.Fragment
Activity
;
import
android.
app.
Activity
;
import
com.topjohnwu.jarsigner.ByteArrayStream
;
import
com.topjohnwu.magisk.MagiskManager
;
...
...
@@ -18,15 +18,15 @@ import dalvik.system.DexClassLoader;
public
class
CheckSafetyNet
extends
ParallelTask
<
Void
,
Void
,
Exception
>
{
public
static
final
int
SNET_VER
=
2
;
public
static
final
int
SNET_VER
=
3
;
private
static
final
String
SNET_URL
=
"https://
github.com/topjohnwu/MagiskManager/releases/download/v5.4.0/snet.apk
"
;
private
static
final
String
SNET_URL
=
"https://
www.dropbox.com/s/jg2yhcrn3l9fckc/snet.apk?dl=1
"
;
private
static
final
String
PKG
=
"com.topjohnwu.snet"
;
private
File
dexPath
;
private
DexClassLoader
loader
;
public
CheckSafetyNet
(
Fragment
Activity
activity
)
{
public
CheckSafetyNet
(
Activity
activity
)
{
super
(
activity
);
dexPath
=
new
File
(
activity
.
getCacheDir
().
getParent
()
+
"/snet"
,
"snet.apk"
);
}
...
...
@@ -65,20 +65,21 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
@Override
protected
void
onPostExecute
(
Exception
err
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
try
{
if
(
err
!=
null
)
throw
err
;
Class
<?>
helperClazz
=
loader
.
loadClass
(
PKG
+
".SafetyNetHelper"
);
Class
<?>
callbackClazz
=
loader
.
loadClass
(
PKG
+
".SafetyNetCallback"
);
Object
helper
=
helperClazz
.
getConstructors
()[
0
].
newInstance
(
getActivity
(),
Proxy
.
newProxyInstance
(
getActivity
(),
dexPath
.
getPath
(),
Proxy
.
newProxyInstance
(
loader
,
new
Class
[]
{
callbackClazz
},
(
proxy
,
method
,
args
)
->
{
MagiskManager
.
get
()
.
safetyNetDone
.
publish
(
false
,
args
[
0
]);
mm
.
safetyNetDone
.
publish
(
false
,
args
[
0
]);
return
null
;
}));
helperClazz
.
getMethod
(
"attest"
).
invoke
(
helper
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
MagiskManager
.
get
()
.
safetyNetDone
.
publish
(
false
,
-
1
);
mm
.
safetyNetDone
.
publish
(
false
,
-
1
);
}
super
.
onPostExecute
(
err
);
}
...
...
app/src/main/java/com/topjohnwu/magisk/components/Activity.java
View file @
f5374a02
package
com
.
topjohnwu
.
magisk
.
components
;
import
android.content.pm.PackageManager
;
import
android.content.res.AssetManager
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.os.Bundle
;
import
android.support.annotation.Keep
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.v7.app.AppCompatActivity
;
...
...
@@ -14,7 +17,9 @@ import com.topjohnwu.magisk.utils.Topic;
public
class
Activity
extends
AppCompatActivity
{
private
Runnable
permissionGrantCallback
;
private
Runnable
permissionGrantCallback
=
null
;
private
AssetManager
mAssetManager
=
null
;
private
Resources
mResources
=
null
;
public
Activity
()
{
super
();
...
...
@@ -49,6 +54,16 @@ public class Activity extends AppCompatActivity {
permissionGrantCallback
=
null
;
}
@Override
public
AssetManager
getAssets
()
{
return
mAssetManager
==
null
?
super
.
getAssets
()
:
mAssetManager
;
}
@Override
public
Resources
getResources
()
{
return
mResources
==
null
?
super
.
getResources
()
:
mResources
;
}
public
void
setPermissionGrantCallback
(
Runnable
callback
)
{
permissionGrantCallback
=
callback
;
}
...
...
@@ -71,4 +86,25 @@ public class Activity extends AppCompatActivity {
}
}
@Keep
public
void
swapResources
(
String
dexPath
)
{
try
{
AssetManager
asset
=
AssetManager
.
class
.
newInstance
();
AssetManager
.
class
.
getMethod
(
"addAssetPath"
,
String
.
class
).
invoke
(
asset
,
dexPath
);
mAssetManager
=
asset
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
;
}
Resources
res
=
super
.
getResources
();
mResources
=
new
Resources
(
mAssetManager
,
res
.
getDisplayMetrics
(),
res
.
getConfiguration
());
mResources
.
newTheme
().
setTo
(
super
.
getTheme
());
}
@Keep
public
void
restoreResources
()
{
mAssetManager
=
null
;
mResources
=
null
;
}
}
build.gradle
View file @
f5374a02
...
...
@@ -3,8 +3,6 @@
buildscript
{
repositories
{
jcenter
()
mavenCentral
()
maven
{
url
"https://maven.google.com"
}
google
()
}
dependencies
{
...
...
@@ -15,14 +13,6 @@ buildscript {
}
}
allprojects
{
repositories
{
jcenter
()
maven
{
url
"https://jitpack.io"
}
google
()
}
}
task
clean
(
type:
Delete
)
{
delete
rootProject
.
buildDir
}
snet/build.gradle
View file @
f5374a02
apply
plugin:
'com.android.application'
android
{
compileSdkVersion
2
6
buildToolsVersion
"2
6.0.2
"
compileSdkVersion
2
7
buildToolsVersion
"2
7.0.0
"
defaultConfig
{
applicationId
"com.topjohnwu.snet"
minSdkVersion
21
targetSdkVersion
2
6
targetSdkVersion
2
7
versionCode
1
versionName
"1.0"
}
...
...
@@ -18,7 +18,10 @@ android {
proguardFiles
getDefaultProguardFile
(
'proguard-android.txt'
),
'proguard-rules.pro'
}
}
}
repositories
{
google
()
}
dependencies
{
...
...
snet/src/main/java/com/topjohnwu/snet/SafetyNetHelper.java
View file @
f5374a02
package
com
.
topjohnwu
.
snet
;
import
android.
content.Context
;
import
android.
app.Activity
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.Base64
;
import
com.google.android.gms.common.ConnectionResult
;
import
com.google.android.gms.common.GoogleApiAvailability
;
import
com.google.android.gms.common.api.GoogleApiClient
;
import
com.google.android.gms.common.api.ResultCallback
;
import
com.google.android.gms.common.api.Status
;
...
...
@@ -16,49 +17,40 @@ import com.google.android.gms.safetynet.SafetyNetApi;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.lang.reflect.Method
;
import
java.security.SecureRandom
;
public
class
SafetyNetHelper
implements
GoogleApiClient
.
ConnectionCallbacks
,
GoogleApiClient
.
OnConnectionFailedListener
{
public
static
final
int
CONNECTION_FAIL
=
-
1
;
public
static
final
int
CAUSE_SERVICE_DISCONNECTED
=
0x01
;
public
static
final
int
CAUSE_NETWORK_LOST
=
0x02
;
public
static
final
int
RESPONSE_ERR
=
0x04
;
public
static
final
int
CONNECTION_FAIL
=
0x08
;
public
static
final
int
CAUSE_SERVICE_DISCONNECTED
=
0x00001
;
public
static
final
int
CAUSE_NETWORK_LOST
=
0x00010
;
public
static
final
int
RESPONSE_ERR
=
0x00100
;
public
static
final
int
BASIC_PASS
=
0x01000
;
public
static
final
int
CTS_PASS
=
0x10000
;
public
static
final
int
BASIC_PASS
=
0x10
;
public
static
final
int
CTS_PASS
=
0x20
;
private
GoogleApiClient
mGoogleApiClient
;
private
Context
mActivity
;
private
Activity
mActivity
;
private
int
responseCode
;
private
SafetyNetCallback
cb
;
private
String
dexPath
;
public
SafetyNetHelper
(
Context
context
,
SafetyNetCallback
cb
)
{
mActivity
=
context
;
public
SafetyNetHelper
(
Activity
activity
,
String
dexPath
,
SafetyNetCallback
cb
)
{
mActivity
=
activity
;
this
.
cb
=
cb
;
this
.
dexPath
=
dexPath
;
responseCode
=
0
;
}
// Entry point to start test
public
void
attest
()
{
// Connect Google Service
GoogleApiClient
.
Builder
builder
=
new
GoogleApiClient
.
Builder
(
mActivity
);
try
{
// Use reflection to workaround FragmentActivity crap
Class
<?>
clazz
=
Class
.
forName
(
"com.google.android.gms.common.api.GoogleApiClient$Builder"
);
for
(
Method
m
:
clazz
.
getMethods
())
{
if
(
m
.
getName
().
equals
(
"enableAutoManage"
))
{
m
.
invoke
(
builder
,
mActivity
,
this
);
break
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
mGoogleApiClient
=
builder
.
addApi
(
SafetyNet
.
API
).
addConnectionCallbacks
(
this
).
build
();
mGoogleApiClient
=
new
GoogleApiClient
.
Builder
(
mActivity
)
.
addApi
(
SafetyNet
.
API
)
.
addOnConnectionFailedListener
(
this
)
.
addConnectionCallbacks
(
this
)
.
build
();
mGoogleApiClient
.
connect
();
}
...
...
@@ -68,7 +60,16 @@ public class SafetyNetHelper
}
@Override
public
void
onConnectionFailed
(
@NonNull
ConnectionResult
connectionResult
)
{
public
void
onConnectionFailed
(
@NonNull
ConnectionResult
result
)
{
Class
<?
extends
Activity
>
clazz
=
mActivity
.
getClass
();
try
{
// Use external resources
clazz
.
getMethod
(
"swapResources"
,
String
.
class
).
invoke
(
mActivity
,
dexPath
);
GoogleApiAvailability
.
getInstance
().
getErrorDialog
(
mActivity
,
result
.
getErrorCode
(),
0
).
show
();
clazz
.
getMethod
(
"restoreResources"
).
invoke
(
mActivity
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
cb
.
onResponse
(
CONNECTION_FAIL
);
}
...
...
@@ -92,22 +93,10 @@ public class SafetyNetHelper
responseCode
|=
decoded
.
getBoolean
(
"ctsProfileMatch"
)
?
CTS_PASS
:
0
;
responseCode
|=
decoded
.
getBoolean
(
"basicIntegrity"
)
?
BASIC_PASS
:
0
;
}
catch
(
JSONException
e
)
{
cb
.
onResponse
(
RESPONSE_ERR
);
return
;
responseCode
=
RESPONSE_ERR
;
}
// Disconnect
try
{
// Use reflection to workaround FragmentActivity crap
Class
<?>
clazz
=
Class
.
forName
(
"com.google.android.gms.common.api.GoogleApiClient"
);
for
(
Method
m
:
clazz
.
getMethods
())
{
if
(
m
.
getName
().
equals
(
"stopAutoManage"
))
{
m
.
invoke
(
mGoogleApiClient
,
mActivity
,
this
);
break
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
mGoogleApiClient
.
disconnect
();
// Return results
...
...
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