Skip to content

Commit

Permalink
support switch hookDump
Browse files Browse the repository at this point in the history
  • Loading branch information
nnjun committed Jul 4, 2021
1 parent 5f12474 commit 05ccd24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Bcore/src/main/java/top/niunaijun/blackbox/BlackBoxCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public boolean isFixCodeItem() {
return mClientConfiguration.isFixCodeItem();
}

@Override
public boolean isEnableHookDump() {
return mClientConfiguration.isEnableHookDump();
}

private void startLogcat() {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), getContext().getPackageName() + "_logcat.txt");
FileUtils.deleteDir(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public String getDexDumpDir() {
public boolean isFixCodeItem() {
return false;
}

public boolean isEnableHookDump() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ private void checkHCallback() {
@Override
public Application newApplication(ClassLoader cl, String className, Context context) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
ContextCompat.fix(context);
String absolutePath = new File(BlackBoxCore.get().getDexDumpDir(), context.getPackageName()).getAbsolutePath();
FileUtils.mkdirs(absolutePath);
Class<?> aClass = cl.loadClass(VMCore.class.getName());
try {
Method initDumpDex = aClass.getDeclaredMethod("hookDumpDex", String.class);
initDumpDex.setAccessible(true);
initDumpDex.invoke(null, absolutePath);
} catch (Throwable e) {
e.printStackTrace();
if (BlackBoxCore.get().isEnableHookDump()) {
String absolutePath = new File(BlackBoxCore.get().getDexDumpDir(), context.getPackageName()).getAbsolutePath();
FileUtils.mkdirs(absolutePath);
Class<?> aClass = cl.loadClass(VMCore.class.getName());
try {
Method initDumpDex = aClass.getDeclaredMethod("hookDumpDex", String.class);
initDumpDex.setAccessible(true);
initDumpDex.invoke(null, absolutePath);
} catch (Throwable e) {
e.printStackTrace();
}
}
return super.newApplication(cl, className, context);
}
Expand Down

0 comments on commit 05ccd24

Please sign in to comment.