From 3b59d513b532063e532dd010633fe1109228575e Mon Sep 17 00:00:00 2001 From: Tim Wright Date: Fri, 13 Mar 2015 23:29:42 +0000 Subject: [PATCH] Fix AndroidMeterpreter when running on Main thread --- .../meterpreter/AndroidMeterpreter.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java b/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java index be3db315..ccd83309 100644 --- a/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java +++ b/java/androidpayload/library/src/com/metasploit/meterpreter/AndroidMeterpreter.java @@ -49,6 +49,19 @@ public class AndroidMeterpreter extends Meterpreter { private static String writeableDir; private static Context context; + private void startExecutingOnThread() { + new Thread() { + @Override + public void run() { + try { + startExecuting(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }.start(); + } + private void findContext() throws Exception { final Class activityThreadClass = Class.forName("android.app.ActivityThread"); final Method currentApplication = activityThreadClass.getMethod("currentApplication"); @@ -63,11 +76,7 @@ public class AndroidMeterpreter extends Meterpreter { } catch (Exception e) { e.printStackTrace(); } - try { - startExecuting(); - } catch (Exception e) { - e.printStackTrace(); - } + startExecutingOnThread(); } }); } else {