From 03242c8aa5b85cff58543c9205549bfd5a530e99 Mon Sep 17 00:00:00 2001 From: simonpunk Date: Fri, 15 Feb 2019 04:39:23 +0800 Subject: [PATCH 01/14] updated .gitignore --- .gitignore | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index a14101e6c..be193326d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,36 @@ -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries +#built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Windows thumbnail db +Thumbs.db + +# OSX files .DS_Store -/build + +# Android Studio *.iml -/.idea/.name -/.idea/gradle.xml -/.idea/misc.xml -/.idea/modules.xml -/term/term-release.apk -/term/Term-nh.apk -release +.idea +#.idea/workspace.xml - remove # and delete .idea if it better suit your needs. +.gradle +build/ +.navigation +captures/ +output.json + +#NDK +obj/ +.externalNativeBuild From 47b2804fc891e19a65b5ad7f20672aad63f0aa83 Mon Sep 17 00:00:00 2001 From: simonpunk Date: Fri, 15 Feb 2019 04:41:40 +0800 Subject: [PATCH 02/14] updated gradle and properties. --- build.gradle | 9 ++------- emulatorview/build.gradle | 5 ++--- gradle/wrapper/gradle-wrapper.properties | 4 ++-- libtermexec/build.gradle | 12 ++++++------ term/build.gradle | 11 +++++------ 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 474fe2aa8..4345ad0aa 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,3 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -task wrapper (type:Wrapper) { - gradleVersion = '4.1' - distributionUrl = 'https://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip' -} - buildscript { repositories { jcenter() @@ -13,12 +7,13 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-beta3' + classpath 'com.android.tools.build:gradle:3.4.0-alpha09' } } allprojects { repositories { jcenter() + google() } } \ No newline at end of file diff --git a/emulatorview/build.gradle b/emulatorview/build.gradle index f3ba04aef..b9f5c3e87 100644 --- a/emulatorview/build.gradle +++ b/emulatorview/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25" + compileSdkVersion 28 defaultConfig { minSdkVersion 4 - targetSdkVersion 25 + targetSdkVersion 28 } buildTypes { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f83a6793..a0545d350 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Aug 31 21:08:59 CDT 2017 +#Thu Feb 14 02:14:00 CST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/libtermexec/build.gradle b/libtermexec/build.gradle index 34ed3dddb..198674c0a 100644 --- a/libtermexec/build.gradle +++ b/libtermexec/build.gradle @@ -1,9 +1,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.4.0-alpha09' } } apply plugin: 'com.android.library' @@ -13,18 +14,17 @@ repositories { } android { - compileSdkVersion 25 - buildToolsVersion "26.0.1" + compileSdkVersion 28 defaultConfig { minSdkVersion 14 - targetSdkVersion 25 + targetSdkVersion 28 versionCode 2 versionName "2.0" ndk { moduleName 'libjackpal-termexec2' - abiFilters 'armeabi', 'arm64-v8a', 'armeabi-v7a', 'x86' + abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86' ldLibs 'log', 'c' } } @@ -63,5 +63,5 @@ android.libraryVariants.all { variant -> dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:support-annotations:26+' + implementation 'com.android.support:support-annotations:28.0.0' } \ No newline at end of file diff --git a/term/build.gradle b/term/build.gradle index e4ef9de1d..c82b91a2b 100644 --- a/term/build.gradle +++ b/term/build.gradle @@ -1,16 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 26 - buildToolsVersion '26.0.1' + compileSdkVersion 28 defaultConfig { applicationId 'com.offsec.nhterm' - minSdkVersion 14 - targetSdkVersion 26 + minSdkVersion 26 + targetSdkVersion 28 ndk { moduleName "libjackpal-androidterm5nhj1" - abiFilters 'armeabi', 'arm64-v8a', 'armeabi-v7a', 'x86' + abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86' ldLibs 'log', 'c' } } @@ -44,5 +43,5 @@ android { dependencies { implementation project(':emulatorview') implementation project(':libtermexec') - implementation "com.android.support:support-v4:+" + implementation 'com.android.support:support-v4:+' } From d66e636fb59a37ed9da062ffdf8d6300ff4e4747 Mon Sep 17 00:00:00 2001 From: simonpunk Date: Fri, 15 Feb 2019 04:48:39 +0800 Subject: [PATCH 03/14] Fixed foreground being killed, keep the code updated. --- .idea/compiler.xml | 22 ----------- .idea/copyright/profiles_settings.xml | 3 -- .idea/encodings.xml | 4 +- .idea/inspectionProfiles/Project_Default.xml | 7 ---- .../inspectionProfiles/profiles_settings.xml | 7 ---- .idea/scopes/scope_settings.xml | 5 --- Android.mk | 2 +- emulatorview/src/main/AndroidManifest.xml | 1 - .../nhterm/emulatorview/TermSession.java | 17 ++++---- libtermexec/src/main/jni/Application.mk | 2 +- libtermexec/src/main/jni/process.cpp | 5 ++- term/src/main/AndroidManifest.xml | 4 +- .../src/main/java/com/offsec/nhterm/Term.java | 7 ++-- .../java/com/offsec/nhterm/TermService.java | 39 ++++++++++++------- .../compat/ServiceForegroundCompat.java | 1 + term/src/main/jni/Application.mk | 2 +- term/src/main/res/values/strings.xml | 4 +- 17 files changed, 52 insertions(+), 80 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/scopes/scope_settings.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 9a8b7e5c4..000000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf337..000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 97626ba45..15a15b218 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,4 @@ - - - + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index e503882fa..000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 3b312839b..000000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b84..000000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/Android.mk b/Android.mk index 633ef4ec7..6fb4ff640 100644 --- a/Android.mk +++ b/Android.mk @@ -25,4 +25,4 @@ LOCAL_SRC_FILES := $(nhterm_dir)/$(nhterm_apk) LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) -include $(BUILD_PREBUILT) \ No newline at end of file +include $(BUILD_PREBUILT) diff --git a/emulatorview/src/main/AndroidManifest.xml b/emulatorview/src/main/AndroidManifest.xml index 61513aa83..601d55941 100644 --- a/emulatorview/src/main/AndroidManifest.xml +++ b/emulatorview/src/main/AndroidManifest.xml @@ -3,5 +3,4 @@ package="com.offsec.nhterm.emulatorview" android:versionCode="43" android:versionName="1.0.42"> - diff --git a/emulatorview/src/main/java/com/offsec/nhterm/emulatorview/TermSession.java b/emulatorview/src/main/java/com/offsec/nhterm/emulatorview/TermSession.java index f98e4f5b2..2cfe4688e 100644 --- a/emulatorview/src/main/java/com/offsec/nhterm/emulatorview/TermSession.java +++ b/emulatorview/src/main/java/com/offsec/nhterm/emulatorview/TermSession.java @@ -112,11 +112,12 @@ public interface FinishCallback { private FinishCallback mFinishCallback; private boolean mIsRunning = false; - private final Handler mMsgHandler = new Handler() { + + private final Handler mMsgHandler = new Handler(new Handler.Callback() { @Override - public void handleMessage(Message msg) { + public boolean handleMessage(Message msg) { if (!mIsRunning) { - return; + return false; } if (msg.what == NEW_INPUT) { readFromProcess(); @@ -128,8 +129,9 @@ public void run() { } }); } + return true; } - }; + }); private UpdateCallback mTitleChangedListener; @@ -186,16 +188,17 @@ public void run() { Looper.prepare(); Log.d("TermSession.java: ", "new Handler"); - mWriterHandler = new Handler() { + mWriterHandler = new Handler(new Handler.Callback() { @Override - public void handleMessage(Message msg) { + public boolean handleMessage(Message msg) { if (msg.what == NEW_OUTPUT) { writeToOutput(); } else if (msg.what == FINISH) { Looper.myLooper().quit(); } + return true; } - }; + }); // Drain anything in the queue from before we started Log.d("TermSession.java: ", "writeToOutput()"); diff --git a/libtermexec/src/main/jni/Application.mk b/libtermexec/src/main/jni/Application.mk index 35ab62887..c29f1d41f 100644 --- a/libtermexec/src/main/jni/Application.mk +++ b/libtermexec/src/main/jni/Application.mk @@ -1,2 +1,2 @@ # Build for ARMv5TE, mips and x86 architectures. -APP_ABI := armeabi mips x86 arm64-v8a armeabi-v7a +APP_ABI := mips x86 arm64-v8a armeabi-v7a diff --git a/libtermexec/src/main/jni/process.cpp b/libtermexec/src/main/jni/process.cpp index 65c505e7f..2e4a8bcd6 100644 --- a/libtermexec/src/main/jni/process.cpp +++ b/libtermexec/src/main/jni/process.cpp @@ -26,8 +26,9 @@ #include #include #include +#include -typedef unsigned short char16_t; +typedef unsigned short uint_least16_t; class String8 { public: @@ -41,7 +42,7 @@ class String8 { } } - void set(const char16_t* o, size_t numChars) { + void set(const uint_least16_t* o, size_t numChars) { if (mString) { free(mString); } diff --git a/term/src/main/AndroidManifest.xml b/term/src/main/AndroidManifest.xml index f03738761..ae0acd229 100644 --- a/term/src/main/AndroidManifest.xml +++ b/term/src/main/AndroidManifest.xml @@ -10,6 +10,8 @@ + + - + diff --git a/term/src/main/java/com/offsec/nhterm/Term.java b/term/src/main/java/com/offsec/nhterm/Term.java index fd47f8e8f..a9d27a43a 100644 --- a/term/src/main/java/com/offsec/nhterm/Term.java +++ b/term/src/main/java/com/offsec/nhterm/Term.java @@ -15,7 +15,6 @@ */ package com.offsec.nhterm; - import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; @@ -35,6 +34,7 @@ import android.content.res.Resources; import android.net.Uri; import android.net.wifi.WifiManager; +import android.nfc.Tag; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -376,7 +376,7 @@ public void onCreate(Bundle icicle) { Intent broadcast = new Intent(ACTION_PATH_BROADCAST); if (AndroidCompat.SDK >= 12) { - broadcast.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES); + broadcast.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); } mPendingPathBroadcasts++; sendOrderedBroadcast(broadcast, PERMISSION_PATH_BROADCAST, mPathReceiver, null, RESULT_OK, null, null); @@ -388,7 +388,6 @@ public void onCreate(Bundle icicle) { TSIntent = new Intent(this, TermService.class); startService(TSIntent); - if (AndroidCompat.SDK >= 11) { int actionBarMode = mSettings.actionBarMode(); mActionBarMode = actionBarMode; @@ -411,7 +410,7 @@ public void onCreate(Bundle icicle) { setFunctionKeyListener(); PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE); - mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TermDebug.LOG_TAG); + mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.offsec.nhterm:TermDebug.LOG_TAG"); WifiManager wm = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE); int wifiLockMode = WifiManager.WIFI_MODE_FULL; if (AndroidCompat.SDK >= 12) { diff --git a/term/src/main/java/com/offsec/nhterm/TermService.java b/term/src/main/java/com/offsec/nhterm/TermService.java index 42a968311..e513923b3 100644 --- a/term/src/main/java/com/offsec/nhterm/TermService.java +++ b/term/src/main/java/com/offsec/nhterm/TermService.java @@ -15,7 +15,7 @@ */ package com.offsec.nhterm; - +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.Service; import android.content.Context; @@ -31,14 +31,11 @@ import android.support.v4.app.TaskStackBuilder; import android.text.TextUtils; import android.util.Log; -import android.app.Notification; + import android.support.v4.app.NotificationCompat; import android.app.PendingIntent; - -import com.offsec.nhterm.R; import com.offsec.nhterm.emulatorview.TermSession; - import com.offsec.nhterm.compat.ServiceForegroundCompat; import com.offsec.nhterm.libtermexec.v1.*; import com.offsec.nhterm.util.SessionList; @@ -51,9 +48,9 @@ public class TermService extends Service implements TermSession.FinishCallback /* Parallels the value of START_STICKY on API Level >= 5 */ private static final int COMPAT_START_STICKY = 1; - private NotificationManager mNotificationManager; - private final int notifyID = 1; - + private NotificationManager notificationManager; + private static final int notifyID = 1; + private static final String NH_TERM_CHANNEL_ID = "NH_TERM_CHANNEL"; private static final int RUNNING_NOTIFICATION = 1; private ServiceForegroundCompat compat; @@ -102,14 +99,28 @@ public void onCreate() { //compat = new ServiceForegroundCompat(this); mTermSessions = new SessionList(); - mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // Create the NotificationChannel + CharSequence name = getString(R.string.nh_term_notification_channel); + String description = getString(R.string.nh_term_notification_channel); + int importance = NotificationManager.IMPORTANCE_LOW; + NotificationChannel mChannel = new NotificationChannel(NH_TERM_CHANNEL_ID, name, importance); + mChannel.setDescription(description); + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this + notificationManager = (NotificationManager) getSystemService( + NOTIFICATION_SERVICE); + if (notificationManager != null) { + notificationManager.createNotificationChannel(mChannel); + } + } // Building the notification - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NH_TERM_CHANNEL_ID) .setSmallIcon(R.drawable.ic_stat_service_notification_icon) // notification icon .setContentTitle(getText(R.string.application_terminal)) // main title of the notification .setContentText(getText(R.string.service_notify_text)); // notification text - //.setContentIntent(pendingIntent); // notification intent + //.setContentIntent(pendingIntent); // notification intent Intent notifyIntent = new Intent(this, Term.class); @@ -133,16 +144,16 @@ public void onCreate() { mBuilder.setContentIntent(resultPendingIntent); // mId allows you to update the notification later on. - mNotificationManager.notify(notifyID, mBuilder.build()); + //notificationManager.notify(notifyID, mBuilder.build()); + startForeground(notifyID, mBuilder.build()); - //compat.startForeground(RUNNING_NOTIFICATION, notification); Log.d(TermDebug.LOG_TAG, "TermService started"); } @Override public void onDestroy() { // Remove notification - mNotificationManager.cancel(notifyID); + notificationManager.cancel(notifyID); for (TermSession session : mTermSessions) { /* Don't automatically remove from list of sessions -- we clear the diff --git a/term/src/main/java/com/offsec/nhterm/compat/ServiceForegroundCompat.java b/term/src/main/java/com/offsec/nhterm/compat/ServiceForegroundCompat.java index 28b4bd15f..af566a654 100644 --- a/term/src/main/java/com/offsec/nhterm/compat/ServiceForegroundCompat.java +++ b/term/src/main/java/com/offsec/nhterm/compat/ServiceForegroundCompat.java @@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException; import android.app.Service; import android.util.Log; + import android.app.Notification; import android.app.NotificationManager; import android.content.Context; diff --git a/term/src/main/jni/Application.mk b/term/src/main/jni/Application.mk index 35ab62887..c29f1d41f 100644 --- a/term/src/main/jni/Application.mk +++ b/term/src/main/jni/Application.mk @@ -1,2 +1,2 @@ # Build for ARMv5TE, mips and x86 architectures. -APP_ABI := armeabi mips x86 arm64-v8a armeabi-v7a +APP_ABI := mips x86 arm64-v8a armeabi-v7a diff --git a/term/src/main/res/values/strings.xml b/term/src/main/res/values/strings.xml index 0b1aa7ab3..adcd381da 100644 --- a/term/src/main/res/values/strings.xml +++ b/term/src/main/res/values/strings.xml @@ -46,7 +46,9 @@ Terminal session is running Terminal session finished - + + nh_term + Notification for nh_term Screen From 8e7751d59defe8464817d7ac49dada07c9b6909a Mon Sep 17 00:00:00 2001 From: Christian B Date: Thu, 14 Feb 2019 23:20:43 +0100 Subject: [PATCH 04/14] Update build.gradle --- emulatorview/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/emulatorview/build.gradle b/emulatorview/build.gradle index b9f5c3e87..84948f94e 100644 --- a/emulatorview/build.gradle +++ b/emulatorview/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 28 + buildToolsVersion "28.0.3" defaultConfig { minSdkVersion 4 From 102dcfc2b2e9993740405fbecc7ef8eca77cf479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bremv=C3=A5g?= Date: Sat, 23 Feb 2019 13:35:42 +0100 Subject: [PATCH 05/14] build.gradle: Add required repositories and bump min/target SDK version --- emulatorview/build.gradle | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/emulatorview/build.gradle b/emulatorview/build.gradle index 84948f94e..d87f7cd1a 100644 --- a/emulatorview/build.gradle +++ b/emulatorview/build.gradle @@ -1,12 +1,17 @@ apply plugin: 'com.android.library' +repositories { + jcenter() + google() +} + android { compileSdkVersion 28 buildToolsVersion "28.0.3" defaultConfig { - minSdkVersion 4 - targetSdkVersion 28 + minSdkVersion 14 + targetSdkVersion 27 } buildTypes { From f491036658cf292100fc164c3823be1673b4d3cc Mon Sep 17 00:00:00 2001 From: Re4son Date: Tue, 26 Feb 2019 20:01:27 +1100 Subject: [PATCH 06/14] Consolidate properties at project level Define common properties at project level: compileSdkVersion=28 minSdkVersion=14 targetSdkVersion=28 versionName="2019.2-rc1" Downgrade gradle version requirements to 3.2 --- .idea/encodings.xml | 4 ---- build.gradle | 13 +++++++++++-- emulatorview/build.gradle | 7 ++++--- gradle.properties | 1 + libtermexec/build.gradle | 10 +++++----- term/build.gradle | 8 +++++--- 6 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 .idea/encodings.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 15a15b218..000000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4345ad0aa..0ff358c98 100644 --- a/build.gradle +++ b/build.gradle @@ -7,13 +7,22 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0-alpha09' + classpath 'com.android.tools.build:gradle:3.2.0' } } + allprojects { repositories { jcenter() google() } -} \ No newline at end of file +} + +ext { + compileSdkVersion=28 + minSdkVersion=14 + targetSdkVersion=28 + versionName="2019.2-rc1" +} + diff --git a/emulatorview/build.gradle b/emulatorview/build.gradle index b9f5c3e87..5a9ea2a49 100644 --- a/emulatorview/build.gradle +++ b/emulatorview/build.gradle @@ -1,11 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 28 + compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { - minSdkVersion 4 - targetSdkVersion 28 + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionName rootProject.ext.versionName } buildTypes { diff --git a/gradle.properties b/gradle.properties index e0b6a5fed..004c59039 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,4 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true #Fri Sep 16 18:00:52 CDT 2016 + diff --git a/libtermexec/build.gradle b/libtermexec/build.gradle index 198674c0a..98ed4c4a2 100644 --- a/libtermexec/build.gradle +++ b/libtermexec/build.gradle @@ -14,13 +14,13 @@ repositories { } android { - compileSdkVersion 28 + compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { - minSdkVersion 14 - targetSdkVersion 28 - versionCode 2 - versionName "2.0" + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionName rootProject.ext.versionName + ndk { moduleName 'libjackpal-termexec2' diff --git a/term/build.gradle b/term/build.gradle index c82b91a2b..4bdb40da4 100644 --- a/term/build.gradle +++ b/term/build.gradle @@ -1,11 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion rootProject.ext.compileSdkVersion + defaultConfig { applicationId 'com.offsec.nhterm' - minSdkVersion 26 - targetSdkVersion 28 + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionName rootProject.ext.versionName ndk { moduleName "libjackpal-androidterm5nhj1" From 1014d0622e93ae0dbad540727beed54c0accd37b Mon Sep 17 00:00:00 2001 From: Re4son Date: Wed, 27 Feb 2019 20:34:33 +1100 Subject: [PATCH 07/14] Restart NotificationManager on exit if required Closing the application on Android Nougat and older causes a null pointer exception so we check if the NotificatiionManager Service exists and start it if it doesn't --- term/src/main/java/com/offsec/nhterm/TermService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/term/src/main/java/com/offsec/nhterm/TermService.java b/term/src/main/java/com/offsec/nhterm/TermService.java index e513923b3..5129895d9 100644 --- a/term/src/main/java/com/offsec/nhterm/TermService.java +++ b/term/src/main/java/com/offsec/nhterm/TermService.java @@ -152,6 +152,9 @@ public void onCreate() { @Override public void onDestroy() { + // invoking notificationManager.cancel on Android < 8 causes a null pointer exception so we should check first + if (notificationManager == null) + notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Remove notification notificationManager.cancel(notifyID); From e1c6cebcfd5d4004eb74b1f38f2a1535ff88f52a Mon Sep 17 00:00:00 2001 From: Re4son Date: Wed, 27 Feb 2019 20:39:46 +1100 Subject: [PATCH 08/14] Add versionCode and bump version to 2019.2-rc2 --- build.gradle | 4 +++- emulatorview/build.gradle | 1 + libtermexec/build.gradle | 3 ++- term/build.gradle | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0ff358c98..087f69faf 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,8 @@ ext { compileSdkVersion=28 minSdkVersion=14 targetSdkVersion=28 - versionName="2019.2-rc1" + //version=YYYYMMVVRR (Either "VV" for stable version OR "RR" for pre-release candidate (e.g. 0001 for rc1) + versionCode=2019020002 + versionName="2019.2-rc2" } diff --git a/emulatorview/build.gradle b/emulatorview/build.gradle index 5a9ea2a49..c5e409902 100644 --- a/emulatorview/build.gradle +++ b/emulatorview/build.gradle @@ -6,6 +6,7 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion + versionCode rootProject.ext.versionCode versionName rootProject.ext.versionName } diff --git a/libtermexec/build.gradle b/libtermexec/build.gradle index 98ed4c4a2..e899b6c97 100644 --- a/libtermexec/build.gradle +++ b/libtermexec/build.gradle @@ -4,7 +4,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0-alpha09' + classpath 'com.android.tools.build:gradle:3.2.0' } } apply plugin: 'com.android.library' @@ -19,6 +19,7 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion + versionCode rootProject.ext.versionCode versionName rootProject.ext.versionName diff --git a/term/build.gradle b/term/build.gradle index 4bdb40da4..ec2f2c9d9 100644 --- a/term/build.gradle +++ b/term/build.gradle @@ -7,6 +7,7 @@ android { applicationId 'com.offsec.nhterm' minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion + versionCode rootProject.ext.versionCode versionName rootProject.ext.versionName ndk { From 431c2d6d73724a35a80d03d6a84d033c995198e3 Mon Sep 17 00:00:00 2001 From: Re4son Kernel <12821486+Re4son@users.noreply.github.com> Date: Wed, 27 Feb 2019 22:09:33 +1100 Subject: [PATCH 09/14] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 50f7a58f8..cc8857810 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ -#NetHunter Terminal Emulator +# NetHunter Terminal Emulator -This is a new fork of the Android Terminal Emulator so we can adapt it to our neeeds for Kali Linux Nethunter. +This is a new fork of the Android Terminal Emulator so we can adapt it to our neeeds for Kali NetHunter. Dependencies running the terminal: - Nedds a full instalation (included the chroot install) of Kali Nethunter + Needs a full installation of Kali NetHunter (including chroot) -Buiding from sources: +Building from sources: (Todo) see: https://github.com/jmingov/NetHunter-Terminal-Emulator/blob/master/docs/Building.md -Since the original proyect is "ended" we left here the credits an licenses: +Since the original project has "ended" we'll include the credits and licenses below: Original author: https://github.com/jackpal -Original proyect: https://github.com/jackpal/Android-Terminal-Emulator +Original project: https://github.com/jackpal/Android-Terminal-Emulator -License: The same as the original proyect. (Thouse files are [included](https://github.com/jmingov/NetHunter-Terminal-Emulator/blob/master/NOTICE) in this proyect too.) +License: The same as the original project. (Thouse files are [included](https://github.com/jmingov/NetHunter-Terminal-Emulator/blob/master/NOTICE) in this project too.) From 324b11b4460dcf90c78bb53072a1af01468bffac Mon Sep 17 00:00:00 2001 From: simonpunk Date: Fri, 1 Mar 2019 22:32:09 +0800 Subject: [PATCH 10/14] Fixed some typos in string.xml --- term/src/main/java/com/offsec/nhterm/Term.java | 2 +- term/src/main/res/values-ro/strings.xml | 2 +- term/src/main/res/values/strings.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/term/src/main/java/com/offsec/nhterm/Term.java b/term/src/main/java/com/offsec/nhterm/Term.java index a9d27a43a..97dc00f0f 100644 --- a/term/src/main/java/com/offsec/nhterm/Term.java +++ b/term/src/main/java/com/offsec/nhterm/Term.java @@ -198,7 +198,7 @@ public View getView(int position, View convertView, ViewGroup parent) { Log.d("mPendingPathBroadcasts","Tamano = " + mTermService.getSessions().size()); Log.d("mPendingPathBroadcasts","Tamano = " + oldLength); TextView label = new TextView(Term.this); - @SuppressLint("StringFormatInvalid") String title = getSessionTitle(position, getString(R.string.window_title, position + 1)); + String title = getSessionTitle(position, getString(R.string.window_title, position + 1)); label.setText(title); if (AndroidCompat.SDK >= 13) { label.setTextAppearance(Term.this, TextAppearance_Holo_Widget_ActionBar_Title); diff --git a/term/src/main/res/values-ro/strings.xml b/term/src/main/res/values-ro/strings.xml index 3c7ea069f..3795fa050 100644 --- a/term/src/main/res/values-ro/strings.xml +++ b/term/src/main/res/values-ro/strings.xml @@ -34,7 +34,7 @@ "Trimiteţi tasta Control" "Trimiteţi tasta Fn" - "Fereastră" + "Fereastră %1$d" "Sesiune de terminal se execută" diff --git a/term/src/main/res/values/strings.xml b/term/src/main/res/values/strings.xml index adcd381da..6eb15151a 100644 --- a/term/src/main/res/values/strings.xml +++ b/term/src/main/res/values/strings.xml @@ -41,7 +41,7 @@ Send control key Send fn key - %1$d) + Window %1$d Terminal session is running From df9135d4461eb3fedd525ae2fcc8cb4e4cbd633c Mon Sep 17 00:00:00 2001 From: simonpunk Date: Fri, 1 Mar 2019 22:33:50 +0800 Subject: [PATCH 11/14] Fixed missing hostname --- .../com/offsec/nhterm/ShellTermSession.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/term/src/main/java/com/offsec/nhterm/ShellTermSession.java b/term/src/main/java/com/offsec/nhterm/ShellTermSession.java index d20fb7cd1..84c83ad39 100644 --- a/term/src/main/java/com/offsec/nhterm/ShellTermSession.java +++ b/term/src/main/java/com/offsec/nhterm/ShellTermSession.java @@ -96,13 +96,29 @@ private void initializeSession(String mShell) throws IOException { if (settings.verifyPath()) { path = checkPath(path); } - String[] env = new String[3]; + String[] env = new String[4]; env[0] = "TERM=" + settings.getTermType(); env[1] = "PATH=" + path + ":/data/data/com.offsec.nethunter/files/scripts/"; env[2] = "HOME=" + settings.getHomePath(); + // Seems the $HOSTNAME is not defined in the file /system/etc/mkshrc on android 9, + // so the workaround is to set the $HOSTNAME manually by running getprop net.hostname, but shoud getprop be fine to use here? + env[3] = "HOSTNAME=" + getSystemProperty("net.hostname"); // Log.d("Initialize Sess", settings.getShell()); mProcId = createSubprocess(mShell, env); } + // Copied from stack overflow..https://stackoverflow.com/questions/16944494/system-getpropertyparam-returns-wrong-value-android by @Muzikant + private String getSystemProperty(String propertyName) { + String propertyValue = "";// let's default empty + try { + Process getPropProcess = Runtime.getRuntime().exec("getprop " + propertyName); + BufferedReader osRes = new BufferedReader(new InputStreamReader(getPropProcess.getInputStream())); + propertyValue = osRes.readLine(); + osRes.close(); + } catch (Exception e) { + Log.d(": Get hostname: ", "Failed to get hostname by $(getprop net.hostname)"); + } + return propertyValue; + } private String checkPath(String path) { String[] dirs = path.split(":"); From f92b07e45360c60fe1d17fb98bf059d288e4061c Mon Sep 17 00:00:00 2001 From: simonpunk Date: Mon, 11 Mar 2019 15:40:46 +0800 Subject: [PATCH 12/14] Fixed hostname again, changed to get the hostname from ro.product.name as somehow the net.hostname can go missing. Also fixed the mount namespace issue by changing the su command to su --mount-master, that it won't isolate the mount space from nethunter app and terminal app, I think this will prevent the filesystem corruption in kali chroot, but still we need to keep monitoring the status. --- term/src/main/java/com/offsec/nhterm/ShellTermSession.java | 2 +- term/src/main/java/com/offsec/nhterm/ShellType.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/term/src/main/java/com/offsec/nhterm/ShellTermSession.java b/term/src/main/java/com/offsec/nhterm/ShellTermSession.java index 84c83ad39..d5d50445c 100644 --- a/term/src/main/java/com/offsec/nhterm/ShellTermSession.java +++ b/term/src/main/java/com/offsec/nhterm/ShellTermSession.java @@ -102,7 +102,7 @@ private void initializeSession(String mShell) throws IOException { env[2] = "HOME=" + settings.getHomePath(); // Seems the $HOSTNAME is not defined in the file /system/etc/mkshrc on android 9, // so the workaround is to set the $HOSTNAME manually by running getprop net.hostname, but shoud getprop be fine to use here? - env[3] = "HOSTNAME=" + getSystemProperty("net.hostname"); + env[3] = "HOSTNAME=" + getSystemProperty("ro.product.name"); // Log.d("Initialize Sess", settings.getShell()); mProcId = createSubprocess(mShell, env); } diff --git a/term/src/main/java/com/offsec/nhterm/ShellType.java b/term/src/main/java/com/offsec/nhterm/ShellType.java index 235e76686..51bcbf05b 100644 --- a/term/src/main/java/com/offsec/nhterm/ShellType.java +++ b/term/src/main/java/com/offsec/nhterm/ShellType.java @@ -11,9 +11,9 @@ class ShellType { static final String ANDROID_SHELL = whichCMD("sh") + " -"; - static final String ANDROID_SU_SHELL = whichCMD("su"); - static final String KALI_SHELL = whichCMD("su") + " -c /data/data/com.offsec.nethunter/files/scripts/bootkali"; - static final String KALI_LOGIN_SHELL = whichCMD("su") +" -c /data/data/com.offsec.nethunter/files/scripts/bootkali_login"; + static final String ANDROID_SU_SHELL = whichCMD("su") + " --mount-master"; + static final String KALI_SHELL = whichCMD("su") + " --mount-master -c /data/data/com.offsec.nethunter/files/scripts/bootkali"; + static final String KALI_LOGIN_SHELL = whichCMD("su") + " --mount-master -c /data/data/com.offsec.nethunter/files/scripts/bootkali_login"; private static String whichCMD(String theCmd){ String output = null; From 774125fd7a24e5ead3448f3aa06c13887b87d134 Mon Sep 17 00:00:00 2001 From: simonpunk Date: Thu, 23 May 2019 23:36:40 +0800 Subject: [PATCH 13/14] Add setting for configuring Chroot Path, and default chroot path is set to /data/local/nhsystem/kali-arm64 --- .../src/main/java/com/offsec/nhterm/Term.java | 41 +++++++++++++++---- .../com/offsec/nhterm/util/TermSettings.java | 15 +++++++ term/src/main/res/layout/menu_chroot_path.xml | 24 +++++++++++ term/src/main/res/menu/main.xml | 2 + term/src/main/res/values/strings.xml | 2 + 5 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 term/src/main/res/layout/menu_chroot_path.xml diff --git a/term/src/main/java/com/offsec/nhterm/Term.java b/term/src/main/java/com/offsec/nhterm/Term.java index 97dc00f0f..ec9589e10 100644 --- a/term/src/main/java/com/offsec/nhterm/Term.java +++ b/term/src/main/java/com/offsec/nhterm/Term.java @@ -58,6 +58,7 @@ import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.Button; +import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; @@ -776,6 +777,8 @@ public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_preferences) { doPreferences(); + } else if (id == R.id.menu_chroot_path) { + doConfigChrootPath(); } else if (id == R.id.menu_new_window) { doCreateNewWindow(); } else if (id == R.id.menu_close_window) { @@ -896,7 +899,7 @@ public void onClick(DialogInterface dialog, int id) { if(CheckRoot.isDeviceRooted()){ Log.d("isDeviceRooted","Device is rooted!"); - String chroot_dir = "/data/local/nhsystem/kali-armhf"; // Not sure if I can wildcard this + String chroot_dir = mSettings.getChrootDir(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (!dir_exists(chroot_dir)){ @@ -991,13 +994,13 @@ public boolean dir_exists(String dir_path) @TargetApi(Build.VERSION_CODES.KITKAT) private void NotFound(String text){ - String msg = ""; + String msg = "Please config a proper Chroot Container Path in Settings."; - if (Objects.equals(text, "/data/data/com.offsec.nethunter/files/scripts/bootkali")){ - msg = "Please run Nethunter Application to generate!"; - } else if (Objects.equals(text, "/data/local/nhsystem/kali-armhf")){ - msg = "Missing chroot. You need to install from Chroot Manager"; - } + //if (Objects.equals(text, "/data/data/com.offsec.nethunter/files/scripts/bootkali")){ + // msg = "Please run Nethunter Application to generate!"; + //} else if (Objects.equals(text, "/data/local/nhsystem/kali-armhf")){ + //msg = "Missing chroot. You need to install from Chroot Manager"; + //} /// Do something for not found text (alertDialog) alertDialogBuilder = new AlertDialog.Builder(this); //alertDialogBuilder.setView(promptsView); @@ -1079,6 +1082,30 @@ private void sendKeyStrings(String str, boolean esc) { } } + private void doConfigChrootPath(){ + final View promptView = getLayoutInflater().inflate(R.layout.menu_chroot_path, null); + final EditText chrootpathEditText = promptView.findViewById(R.id.menu_chroot_path_et); + chrootpathEditText.setText(mSettings.getChrootDir()); + final AlertDialog.Builder adbConfigChrootPath = new AlertDialog.Builder(this); + adbConfigChrootPath.setView(promptView); + adbConfigChrootPath.setCancelable(false); + adbConfigChrootPath.setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mSettings.setChrootDir(getApplicationContext(), chrootpathEditText.getText().toString()); + } + }); + adbConfigChrootPath.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + adbConfigChrootPath.create().show(); + + + + } private void doCreateNewWindow() { if (mTermSessions == null) { Log.w(TermDebug.LOG_TAG, "Couldn't create new window because mTermSessions == null"); diff --git a/term/src/main/java/com/offsec/nhterm/util/TermSettings.java b/term/src/main/java/com/offsec/nhterm/util/TermSettings.java index cbc7a1539..46173a2b0 100644 --- a/term/src/main/java/com/offsec/nhterm/util/TermSettings.java +++ b/term/src/main/java/com/offsec/nhterm/util/TermSettings.java @@ -18,8 +18,10 @@ import com.offsec.nhterm.R; +import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; +import android.preference.PreferenceManager; import android.view.KeyEvent; /** @@ -28,6 +30,7 @@ public class TermSettings { private SharedPreferences mPrefs; + private String mChrootPath; private int mStatusBar; private boolean mFunctionBar; private int mActionBarMode; @@ -71,6 +74,7 @@ public class TermSettings { private boolean mUseKeyboardShortcuts; + private static final String CHROOT_DIR = "chroot_dir"; private static final String STATUSBAR_KEY = "statusbar"; private static final String FUNCTIONBAR_KEY = "functionbar"; private static final String ACTIONBAR_KEY = "actionbar"; @@ -183,6 +187,8 @@ public TermSettings(Resources res, SharedPreferences prefs) { } private void readDefaultPrefs(Resources res) { + + mChrootPath = res.getString(R.string.chroot_dir); mStatusBar = Integer.parseInt(res.getString(R.string.pref_statusbar_default)); mFunctionBar = res.getBoolean(R.bool.pref_functionbar_default); mActionBarMode = res.getInteger(R.integer.pref_actionbar_default); @@ -223,6 +229,8 @@ private void readDefaultPrefs(Resources res) { public void readPrefs(SharedPreferences prefs) { mPrefs = prefs; + + mChrootPath = readStringPref(CHROOT_DIR, mChrootPath); mStatusBar = readIntPref(STATUSBAR_KEY, mStatusBar, 1); mFunctionBar = readBooleanPref(FUNCTIONBAR_KEY, mFunctionBar); mActionBarMode = readIntPref(ACTIONBAR_KEY, mActionBarMode, ACTION_BAR_MODE_MAX); @@ -284,6 +292,13 @@ private boolean readBooleanPref(String key, boolean defaultValue) { return mPrefs.getBoolean(key, defaultValue); } + public String getChrootDir() { return mChrootPath; } + + public void setChrootDir(Context context, String chrootDir) { + mPrefs = PreferenceManager.getDefaultSharedPreferences(context); + mPrefs.edit().putString(CHROOT_DIR, chrootDir).apply(); + mPrefs = null; + } public boolean showStatusBar() { return true; } diff --git a/term/src/main/res/layout/menu_chroot_path.xml b/term/src/main/res/layout/menu_chroot_path.xml new file mode 100644 index 000000000..b99aa8dab --- /dev/null +++ b/term/src/main/res/layout/menu_chroot_path.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/term/src/main/res/menu/main.xml b/term/src/main/res/menu/main.xml index 166245a9e..29dc8be1a 100644 --- a/term/src/main/res/menu/main.xml +++ b/term/src/main/res/menu/main.xml @@ -16,6 +16,8 @@ --> + diff --git a/term/src/main/res/values/strings.xml b/term/src/main/res/values/strings.xml index 6eb15151a..44264a514 100644 --- a/term/src/main/res/values/strings.xml +++ b/term/src/main/res/values/strings.xml @@ -50,6 +50,8 @@ nh_term Notification for nh_term + + /data/local/nhsystem/kali-arm64 Screen Status bar From d5cd2cef4b341e896c2f07e0fc72e37c3e15bfa7 Mon Sep 17 00:00:00 2001 From: simonpunk Date: Sun, 9 Jun 2019 21:08:11 +0800 Subject: [PATCH 14/14] Added /sbin/.magisk/busybox to PATH evn --- term/src/main/java/com/offsec/nhterm/ShellTermSession.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/term/src/main/java/com/offsec/nhterm/ShellTermSession.java b/term/src/main/java/com/offsec/nhterm/ShellTermSession.java index d5d50445c..a0b4f7438 100644 --- a/term/src/main/java/com/offsec/nhterm/ShellTermSession.java +++ b/term/src/main/java/com/offsec/nhterm/ShellTermSession.java @@ -98,7 +98,7 @@ private void initializeSession(String mShell) throws IOException { } String[] env = new String[4]; env[0] = "TERM=" + settings.getTermType(); - env[1] = "PATH=" + path + ":/data/data/com.offsec.nethunter/files/scripts/"; + env[1] = "PATH=" + path + ":/data/data/com.offsec.nethunter/files/scripts" + ":/sbin/.magisk/busybox"; env[2] = "HOME=" + settings.getHomePath(); // Seems the $HOSTNAME is not defined in the file /system/etc/mkshrc on android 9, // so the workaround is to set the $HOSTNAME manually by running getprop net.hostname, but shoud getprop be fine to use here?