Created
July 1, 2020 13:03
-
-
Save kaedea/2f9184168c9e720228e5435baee81e33 to your computer and use it in GitHub Desktop.
Utility to trigger native crash in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NativeCrashUtils { | |
public static void crashNatively() { | |
try { | |
Class<?> clazz = Class.forName("dalvik.system.VMDebug"); | |
Method method = reflectMethod(clazz, "crash"); | |
method.setAccessible(true); | |
method.invoke(null); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static Method reflectMethod(Class<?> clazz, String methodName, Class... args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { | |
Method getDeclaredMethod = Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class); | |
getDeclaredMethod.setAccessible(true); | |
return (Method) getDeclaredMethod.invoke(clazz, methodName, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment