Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Signed-off-by: tiann <[email protected]>
  • Loading branch information
tiann committed Apr 8, 2021
1 parent 4035cf4 commit 21797a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ publish {
userOrg = 'twsxtd'
groupId = 'me.weishu'
artifactId = 'free_reflection'
publishVersion = '3.0.1'
publishVersion = '3.0.2'
desc = 'Use Relection above Android P without any restriction'
website = 'https://github.com/tiann/FreeRelfection'
}
25 changes: 22 additions & 3 deletions library/src/main/java/me/weishu/reflection/Reflection.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.weishu.reflection;

import android.content.Context;
import android.text.TextUtils;
import android.util.Base64;

import java.io.File;
Expand Down Expand Up @@ -43,18 +44,21 @@ public static int unseal(Context context) {

private static boolean unsealByDexFile(Context context) {
byte[] bytes = Base64.decode(DEX, Base64.NO_WRAP);
File codeCacheDir = context.getCodeCacheDir();
File codeCacheDir = getCodeCacheDir(context);
if (codeCacheDir == null) {
return false;
}
File code = new File(codeCacheDir, System.currentTimeMillis() + ".dex");
try {

try(FileOutputStream fos = new FileOutputStream(code)) {
try (FileOutputStream fos = new FileOutputStream(code)) {
fos.write(bytes);
}

DexFile dexFile = new DexFile(code);
Class<?> bootstrapClass = dexFile.loadClass(BootstrapClass.class.getCanonicalName(), null);
Method exemptAll = bootstrapClass.getDeclaredMethod("exemptAll");
return (boolean) exemptAll.invoke(null);
return (boolean) exemptAll.invoke(null);
} catch (Throwable e) {
e.printStackTrace();
return false;
Expand All @@ -65,4 +69,19 @@ private static boolean unsealByDexFile(Context context) {
}
}
}

private static File getCodeCacheDir(Context context) {
if (context != null) {
return context.getCodeCacheDir();
}
String tmpDir = System.getProperty("java.io.tmpdir");
if (TextUtils.isEmpty(tmpDir)) {
return null;
}
File tmp = new File(tmpDir);
if (!tmp.exists()) {
return null;
}
return tmp;
}
}

1 comment on commit 21797a4

@TheMelody
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改了内容能添加个注释吗?没有怎么看懂这次的提交

Please sign in to comment.