From 777c8028061695080ba3d5dd2130879bc69f0966 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Tue, 21 Jul 2020 11:44:41 +0800 Subject: [PATCH 01/13] some chinese comments removed --- .../cn/proxgrind/com/AbsUsbBulkTransfer.java | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java b/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java index 0fb8ebe2..6e2fa9c2 100644 --- a/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java +++ b/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java @@ -28,37 +28,23 @@ public abstract class AbsUsbBulkTransfer implements DriverInterface mCallback = null; - //广播接收器,在设备插入和移除时使用 private BroadcastReceiver mReceiver; - //主页状态! private boolean isRegister = false; - //广播过滤器! private IntentFilter filter = new IntentFilter(); - //缓存设备管理器 private UsbManager mUsbManger = null; - //缓存插入的设备 private UsbDevice mDevice = null; - //缓存设备链接(实际上等同于串口port) private UsbDeviceConnection mCon = null; - //USB接口 private UsbInterface mUi = null; - //USB读端点 private UsbEndpoint mEpIn = null; - //USB写端点 private UsbEndpoint mEpOut = null; - // 流实现! private BulkOutputStream outputStream; private BulkInputStream inputStream; - - //私有构造方法,避免被直接调用 protected AbsUsbBulkTransfer() { final String act = getDeviceDiscoveryAction(); final String name = getDeviceNameOnFound(); - //建立意图过滤数组 filter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); @@ -73,7 +59,6 @@ public void onReceive(Context context, Intent intent) { return; } switch (_action) { - //在设备插入的时候初始化 case UsbManager.ACTION_USB_DEVICE_ATTACHED: initAndCall(name); break; @@ -97,10 +82,8 @@ private void initAndCall(String name) { private void register1() { unRegister(); try { - //注册广播事件 mContext.registerReceiver(mReceiver, filter); isRegister = true; - Log.d(LOG_TAG, "注册广播成功!"); } catch (Exception ignored) { } } @@ -108,7 +91,6 @@ private void register1() { private void unRegister() { try { if (isRegister) { - //注册广播事件 mContext.unregisterReceiver(mReceiver); isRegister = false; } @@ -132,31 +114,22 @@ private boolean init() { Log.d(LOG_TAG, "USB管理器为空!"); return false; } - //得到设备集 HashMap _hmDevs = mUsbManger.getDeviceList(); if (_hmDevs == null || _hmDevs.size() <= 0) return false; List _devs = new ArrayList<>(_hmDevs.values()); - //判断插入的设备集是否存在设备 if (_devs.size() <= 0) return false; - //判断是否是ACR122 mDevice = _devs.get(0); if (mDevice == null) return false; - //判断设备厂商和设备型号 if (isRawDevice(mDevice.getProductId(), mDevice.getVendorId())) { if (!mUsbManger.hasPermission(mDevice)) { - //如果没有权限,则需要申请! mCon = mUsbManger.openDevice(mDevice); - //空链接,可能需要申请权限! if (mCon == null) { - //发送广播申请权限 PendingIntent intent = PendingIntent.getBroadcast(mContext, 0, new Intent(getDeviceDiscoveryAction()), 0); Log.d(LOG_TAG, "trying get usb permission!"); mUsbManger.requestPermission(mDevice, intent); - //当没有权限的时候应当直接返回 return false; } } else { - //如果有权限,可以直接打开! mCon = mUsbManger.openDevice(mDevice); } } else { @@ -169,7 +142,6 @@ private boolean init() { @Override public void register(final DevCallback callback) { mCallback = callback; - //初始化USB管理器资源 mUsbManger = (UsbManager) mContext.getSystemService(Context.USB_SERVICE); // register driver register1(); @@ -181,7 +153,6 @@ public boolean connect(String t) { Log.e(LOG_TAG, "devices is null!"); return false; } - //再一次判断设备正确性 if (isRawDevice(mDevice.getProductId(), mDevice.getVendorId())) { for (int iIndex = 0; iIndex < mDevice.getInterfaceCount(); ++iIndex) { UsbInterface tmpUi = mDevice.getInterface(iIndex); @@ -200,11 +171,9 @@ public boolean connect(String t) { return false; } } - //端点初始化 Log.d(LOG_TAG, "connect: Endpoint count: " + mUi.getEndpointCount()); for (int i = 0; i < mUi.getEndpointCount(); ++i) { UsbEndpoint _ue = mUi.getEndpoint(i); - //判断端点的类型 if (_ue.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) { Log.d(LOG_TAG, "connect: Found interrupt endpoint: " + i); continue; @@ -224,7 +193,6 @@ public boolean connect(String t) { Log.d(LOG_TAG, "Invalid endpoint!"); return false; } - //全部链接初始化成功,返回TRUE告诉调用者可以开始尝试通信 inputStream = new BulkInputStream(mCon, mEpIn); outputStream = new BulkOutputStream(mCon, mEpOut); return true; From 033fc34aff6130b8088badd70979b335aca428ac Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Tue, 21 Jul 2020 12:48:23 +0800 Subject: [PATCH 02/13] some chinese comments removed --- .../src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java b/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java index 6e2fa9c2..d18ad13d 100644 --- a/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java +++ b/communication/src/main/java/cn/proxgrind/com/AbsUsbBulkTransfer.java @@ -213,7 +213,9 @@ public String getDevice() { @Override public void disconect() { - mCon.releaseInterface(mUi); + if (mCon != null && mUi != null) { + mCon.releaseInterface(mUi); + } } @Override From e6607cad6cdd5218da5fd6db75bb5c9e8470f1e2 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 17:55:54 +0800 Subject: [PATCH 03/13] add some string --- app_main/src/main/res/values-en/strings.xml | 2 + app_main/src/main/res/values-zh/strings.xml | 2 + app_main/src/main/res/values/strings.xml | 3 +- termux-app/build.gradle | 2 +- .../java/com/termux/app/TermuxActivity.java | 6 +- .../java/com/termux/app/TermuxService.java | 26 ++++---- .../java/cn/dxl/common/util/FileUtils.java | 59 +++++++++++-------- 7 files changed, 60 insertions(+), 40 deletions(-) diff --git a/app_main/src/main/res/values-en/strings.xml b/app_main/src/main/res/values-en/strings.xml index d3d05295..37816397 100644 --- a/app_main/src/main/res/values-en/strings.xml +++ b/app_main/src/main/res/values-en/strings.xml @@ -328,5 +328,7 @@ The complete terminal view is suitable for developers or masters, while the simple terminal view is suitable for novice users. Unselected 请稍等 + select + Proxmark3 External Work Directory \ No newline at end of file diff --git a/app_main/src/main/res/values-zh/strings.xml b/app_main/src/main/res/values-zh/strings.xml index 7b99e2e7..c5fa6597 100644 --- a/app_main/src/main/res/values-zh/strings.xml +++ b/app_main/src/main/res/values-zh/strings.xml @@ -334,5 +334,7 @@ 完整的终端视图适合开发人员或大师,而简单终端视图适合新手用户。 未选择 请稍等。 + 选择 + Proxmark3 外部工作目录 \ No newline at end of file diff --git a/app_main/src/main/res/values/strings.xml b/app_main/src/main/res/values/strings.xml index 43923b0c..9335ef84 100644 --- a/app_main/src/main/res/values/strings.xml +++ b/app_main/src/main/res/values/strings.xml @@ -299,7 +299,6 @@ Custom firmware Select BootRom Select FullImage - Will use TERMUX implement UI 1. Your FW can\'t than for client version too low or high , you need go flash FW. 2. Check \'Auto Go\', it will auto go to terminal view. Auto Go @@ -328,5 +327,7 @@ The complete terminal view is suitable for developers or masters, while the simple terminal view is suitable for novice users. Unselected Please wait. + select + Proxmark3 External Work Directory \ No newline at end of file diff --git a/termux-app/build.gradle b/termux-app/build.gradle index 62665010..79e20fbc 100644 --- a/termux-app/build.gradle +++ b/termux-app/build.gradle @@ -15,7 +15,7 @@ android { defaultConfig { // applicationId "com.termux" - minSdkVersion 24 + minSdkVersion 21 targetSdkVersion 28 versionCode 95 versionName "0.95" diff --git a/termux-app/src/main/java/com/termux/app/TermuxActivity.java b/termux-app/src/main/java/com/termux/app/TermuxActivity.java index b157e364..ed525dd6 100644 --- a/termux-app/src/main/java/com/termux/app/TermuxActivity.java +++ b/termux-app/src/main/java/com/termux/app/TermuxActivity.java @@ -67,6 +67,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.content.PermissionChecker; import androidx.drawerlayout.widget.DrawerLayout; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; @@ -198,10 +200,10 @@ void updateBackgroundColor() { * For processes to access shared internal storage (/sdcard) we need this permission. */ public boolean ensureStoragePermissionGranted() { - if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + if (PermissionChecker.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED) { return true; } else { - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUESTCODE_PERMISSION_STORAGE); + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUESTCODE_PERMISSION_STORAGE); return false; } } diff --git a/termux-app/src/main/java/com/termux/app/TermuxService.java b/termux-app/src/main/java/com/termux/app/TermuxService.java index 64bcf5b9..b8ec27a3 100644 --- a/termux-app/src/main/java/com/termux/app/TermuxService.java +++ b/termux-app/src/main/java/com/termux/app/TermuxService.java @@ -56,6 +56,7 @@ public final class TermuxService extends Service implements SessionChangedCallba public static final String FILES_PATH = "/data/data/" + packageName + "/files"; public static final String PREFIX_PATH = FILES_PATH + "/usr"; public static final String HOME_PATH = FILES_PATH + "/home"; + public static String PM3_CWD = null; private static final int NOTIFICATION_ID = 1337; @@ -122,7 +123,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { if (mWakeLock == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, EmulatorDebug.LOG_TAG); - mWakeLock.acquire(); + mWakeLock.acquire(10 * 60 * 1000L /*10 minutes*/); // http://tools.android.com/tech-docs/lint-in-studio-2-3#TOC-WifiManager-Leak WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); @@ -130,16 +131,18 @@ public int onStartCommand(Intent intent, int flags, int startId) { mWifiLock.acquire(); String packageName = getPackageName(); - if (!pm.isIgnoringBatteryOptimizations(packageName)) { - Intent whitelist = new Intent(); - whitelist.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); - whitelist.setData(Uri.parse("package:" + packageName)); - whitelist.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - try { - startActivity(whitelist); - } catch (ActivityNotFoundException e) { - Log.e(EmulatorDebug.LOG_TAG, "Failed to call ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", e); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!pm.isIgnoringBatteryOptimizations(packageName)) { + Intent whitelist = new Intent(); + whitelist.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + whitelist.setData(Uri.parse("package:" + packageName)); + whitelist.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + try { + startActivity(whitelist); + } catch (ActivityNotFoundException e) { + Log.e(EmulatorDebug.LOG_TAG, "Failed to call ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", e); + } } } @@ -299,6 +302,7 @@ public List getSessions() { TerminalSession createTermSession(String executablePath, String[] arguments, String cwd, boolean failSafe) { new File(HOME_PATH).mkdirs(); + if (PM3_CWD != null) cwd = PM3_CWD; if (cwd == null) cwd = HOME_PATH; String[] env = BackgroundJob.buildEnvironment(failSafe, cwd); diff --git a/utils/src/main/java/cn/dxl/common/util/FileUtils.java b/utils/src/main/java/cn/dxl/common/util/FileUtils.java index c106cca8..84b65468 100644 --- a/utils/src/main/java/cn/dxl/common/util/FileUtils.java +++ b/utils/src/main/java/cn/dxl/common/util/FileUtils.java @@ -354,43 +354,52 @@ public static String getFilePathByUri(Uri uri) { private static String getFilePathByUri_BELOWAPI11(Uri uri) { // 以 content:// 开头的,比如 content://media/extenral/images/media/17766 - if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { - String path = null; - String[] projection = new String[]{MediaStore.Images.Media.DATA}; - Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); - if (cursor != null) { - if (cursor.moveToFirst()) { - try { - int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); - if (columnIndex > -1) { - path = cursor.getString(columnIndex); + try { + if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { + String path = null; + String[] projection = new String[]{MediaStore.Images.Media.DATA}; + Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); + if (cursor != null) { + if (cursor.moveToFirst()) { + try { + int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + if (columnIndex > -1) { + path = cursor.getString(columnIndex); + } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); } + cursor.close(); } - cursor.close(); + return path; } - return path; + } catch (Exception e) { + return null; } return null; } private static String getFilePathByUri_API11to18(Uri contentUri) { - String[] projection = {MediaStore.Images.Media.DATA}; String result = null; - CursorLoader cursorLoader = new CursorLoader(context, contentUri, projection, null, null, null); - Cursor cursor = cursorLoader.loadInBackground(); - if (cursor != null) { - if (cursor.moveToFirst()) { - try { - int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); - result = cursor.getString(column_index); - } catch (Exception e) { - e.printStackTrace(); + try { + String[] projection = {MediaStore.Images.Media.DATA}; + + CursorLoader cursorLoader = new CursorLoader(context, contentUri, projection, null, null, null); + Cursor cursor = cursorLoader.loadInBackground(); + if (cursor != null) { + if (cursor.moveToFirst()) { + try { + int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + result = cursor.getString(column_index); + } catch (Exception e) { + e.printStackTrace(); + } } + cursor.close(); } - cursor.close(); + } catch (Exception e) { + return null; } return result; } From 44a2c2e57781e5b0b0f92ea4aee460ac54267348 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 17:56:25 +0800 Subject: [PATCH 04/13] Minimum support to SDK 21. --- app_main/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_main/build.gradle b/app_main/build.gradle index 6cc0a466..89815cf1 100644 --- a/app_main/build.gradle +++ b/app_main/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "29.0.2" defaultConfig { applicationId "com.rfidresearchgroup.rfidtools" - minSdkVersion 24 + minSdkVersion 21 targetSdkVersion 28 testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' versionCode 25 From de7a4db7353f32bbde41998f397c31e929af2849 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 17:57:08 +0800 Subject: [PATCH 05/13] add pm3 cwd save and get function. --- .../main/java/cn/rrg/rdv/util/Commons.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app_main/src/main/java/cn/rrg/rdv/util/Commons.java b/app_main/src/main/java/cn/rrg/rdv/util/Commons.java index 8c258808..c01223dc 100644 --- a/app_main/src/main/java/cn/rrg/rdv/util/Commons.java +++ b/app_main/src/main/java/cn/rrg/rdv/util/Commons.java @@ -283,4 +283,25 @@ public static int getTerminalType() { return getPrivatePreferences() .getInt(Properties.k_terminal_type, -1); } + + public static void setPM3ExternalWorkDirectoryEnable(boolean enable) { + getPrivatePreferences().edit() + .putBoolean(Properties.k_pm3_externl_cwd_enable, enable) + .apply(); + } + + public static boolean isPM3ExternalWorkDirectoryEnable() { + return getPrivatePreferences() + .getBoolean(Properties.k_pm3_externl_cwd_enable, false); + } + + public static void updatePM3Cwd() { + // init pm3 cwd + if (Commons.isPM3ExternalWorkDirectoryEnable()) { + TermuxService.PM3_CWD = Paths.PM3_CWD; + new File(TermuxService.PM3_CWD).mkdirs(); + } else { + Paths.PM3_CWD = TermuxService.HOME_PATH; + } + } } From eef75b8b3abd68c6e0d1ba3e6f3f2c71e20119ca Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 17:57:29 +0800 Subject: [PATCH 06/13] add pm3 cwd path def. --- .../src/main/java/cn/rrg/rdv/util/Paths.java | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/app_main/src/main/java/cn/rrg/rdv/util/Paths.java b/app_main/src/main/java/cn/rrg/rdv/util/Paths.java index 97a5bea0..706c6ab5 100644 --- a/app_main/src/main/java/cn/rrg/rdv/util/Paths.java +++ b/app_main/src/main/java/cn/rrg/rdv/util/Paths.java @@ -6,71 +6,73 @@ import java.io.File; -public interface Paths { +public class Paths { - String EXTERNAL_STORAGE_DIRECTORY = Environment.getExternalStorageDirectory().getPath(); - String TOOLS_PATH = "NfcTools"; - String SETTINGS_PATH = "Settings"; - String MCT_PATH = "MifareClassicTool"; - String MTools_PATH = "MTools"; - String HARDNESTED_PATH = "hardnested"; - String LOG_PATH = "log"; - String PM3_PATH = "proxmark3"; - String COMMON_PATH = "common"; - String PN53X_PATH = "pn53x"; - String DRIVER_PATH = "driver"; - String TENCENT_PATH = "tencent"; - String WECAT_PATH = "MicroMsg/Download"; - String QQ_PATH = "QQfile_recv"; - String KEY_PATH = "keyFile"; - String DUMP_PATH = "dumpFile"; - String DEFAULT_KEYS_NAME = "default_keys.txt"; - String DEFAULT_DUMP_NAME = "BLANK(空白).dump"; - String DEFAULT_CMD_NAME = "cmd.json"; + public static String EXTERNAL_STORAGE_DIRECTORY = Environment.getExternalStorageDirectory().getPath(); + public static String TOOLS_PATH = "NfcTools"; + public static String SETTINGS_PATH = "Settings"; + public static String MCT_PATH = "MifareClassicTool"; + public static String MTools_PATH = "MTools"; + public static String HARDNESTED_PATH = "hardnested"; + public static String LOG_PATH = "log"; + public static String PM3_PATH = "proxmark3"; + public static String COMMON_PATH = "common"; + public static String PN53X_PATH = "pn53x"; + public static String DRIVER_PATH = "driver"; + public static String TENCENT_PATH = "tencent"; + public static String WECAT_PATH = "MicroMsg/Download"; + public static String QQ_PATH = "QQfile_recv"; + public static String KEY_PATH = "keyFile"; + public static String DUMP_PATH = "dumpFile"; + public static String DEFAULT_KEYS_NAME = "default_keys.txt"; + public static String DEFAULT_DUMP_NAME = "BLANK(空白).dump"; + public static String DEFAULT_CMD_NAME = "cmd.json"; - String TOOLS_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + TOOLS_PATH; - String KEY_DIRECTORY = TOOLS_DIRECTORY + "/" + KEY_PATH; - String LOG_DIRECTORY = TOOLS_DIRECTORY + "/" + LOG_PATH; + public static String TOOLS_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + TOOLS_PATH; + public static String KEY_DIRECTORY = TOOLS_DIRECTORY + "/" + KEY_PATH; + public static String LOG_DIRECTORY = TOOLS_DIRECTORY + "/" + LOG_PATH; - String MCT_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + MCT_PATH; - String MCT_DUMP_DIRECTORY = MCT_DIRECTORY + "/" + "dump-files"; - String MCT_KEYS_DIRECTORY = MCT_DIRECTORY + "/" + "key-files"; + public static String MCT_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + MCT_PATH; + public static String MCT_DUMP_DIRECTORY = MCT_DIRECTORY + "/" + "dump-files"; + public static String MCT_KEYS_DIRECTORY = MCT_DIRECTORY + "/" + "key-files"; - String MTools_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + MTools_PATH; - String MTools_DUMP_DIRECTORY = MTools_DIRECTORY + "/" + "dump"; - String MTools_KEYS_DIRECTORY = MTools_DIRECTORY + "/" + "key"; + public static String MTools_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + MTools_PATH; + public static String MTools_DUMP_DIRECTORY = MTools_DIRECTORY + "/" + "dump"; + public static String MTools_KEYS_DIRECTORY = MTools_DIRECTORY + "/" + "key"; - String COMMON_DIRECTORY = TOOLS_DIRECTORY + "/" + COMMON_PATH; - String DUMP_DIRECTORY = TOOLS_DIRECTORY + "/" + DUMP_PATH; + public static String COMMON_DIRECTORY = TOOLS_DIRECTORY + "/" + COMMON_PATH; + public static String DUMP_DIRECTORY = TOOLS_DIRECTORY + "/" + DUMP_PATH; - String PM3_DIRECTORY = TOOLS_DIRECTORY + "/" + PM3_PATH; - String PN53X_DIRRECTORY = TOOLS_DIRECTORY + "/" + PN53X_PATH; + public static String PM3_DIRECTORY = TOOLS_DIRECTORY + "/" + PM3_PATH; + public static String PN53X_DIRRECTORY = TOOLS_DIRECTORY + "/" + PN53X_PATH; - String WECAT_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + TENCENT_PATH + "/" + WECAT_PATH; - String QQ_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + TENCENT_PATH + "/" + QQ_PATH; + public static String WECAT_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + TENCENT_PATH + "/" + WECAT_PATH; + public static String QQ_DIRECTORY = EXTERNAL_STORAGE_DIRECTORY + "/" + TENCENT_PATH + "/" + QQ_PATH; - String SETTINGS_DIRECTORY = TOOLS_DIRECTORY + "/" + SETTINGS_PATH; - String SETTINGS_FILE = SETTINGS_DIRECTORY + "/" + "set.dat"; + public static String SETTINGS_DIRECTORY = TOOLS_DIRECTORY + "/" + SETTINGS_PATH; + public static String SETTINGS_FILE = SETTINGS_DIRECTORY + "/" + "set.dat"; - String PM3_BOOT_FILE_NAME = "bootrom.elf"; - String PM3_OS_FILE_NAME = "fullimage.elf"; - String PM3_FORWARD_O = PM3_DIRECTORY + "/" + "pm3_forward_o.txt"; - String PM3_FORWARD_E = PM3_DIRECTORY + "/" + "pm3_forward_e.txt"; + public static String PM3_BOOT_FILE_NAME = "bootrom.elf"; + public static String PM3_OS_FILE_NAME = "fullimage.elf"; + public static String PM3_FORWARD_O = PM3_DIRECTORY + "/" + "pm3_forward_o.txt"; + public static String PM3_FORWARD_E = PM3_DIRECTORY + "/" + "pm3_forward_e.txt"; //PM3 Easy Button - String PM3_CMD_FILE = PM3_DIRECTORY + "/" + DEFAULT_CMD_NAME; + public static String PM3_CMD_FILE = PM3_DIRECTORY + "/" + DEFAULT_CMD_NAME; // PM3 Image - String PM3_IMAGE_BOOT_FILE = TermuxService.HOME_PATH + File.separator + PM3_PATH + File.separator + PM3_BOOT_FILE_NAME; - String PM3_IMAGE_OS_FILE = TermuxService.HOME_PATH + File.separator + PM3_PATH + File.separator + PM3_OS_FILE_NAME; + public static String PM3_IMAGE_BOOT_FILE = TermuxService.HOME_PATH + File.separator + PM3_PATH + File.separator + PM3_BOOT_FILE_NAME; + public static String PM3_IMAGE_OS_FILE = TermuxService.HOME_PATH + File.separator + PM3_PATH + File.separator + PM3_OS_FILE_NAME; + // pm3 cwd -> sdcard + public static String PM3_CWD = PM3_DIRECTORY + File.separator + "home"; - String PN53X_FORWARD_O = PN53X_DIRRECTORY + "/" + "pn53x_forward_o.txt"; - String PN53X_FORWARD_E = PN53X_DIRRECTORY + "/" + "pn53x_forward_e.txt"; - String PN53X_FORWARD_MF_O = PN53X_DIRRECTORY + "/" + "pn53x_forward_mf_o.txt"; - String PN53X_FORWARD_MF_E = PN53X_DIRRECTORY + "/" + "pn53x_forward_mf_e.txt"; - String COMMON_FORWARD_O = COMMON_DIRECTORY + "/" + "common_forward_o.txt"; - String COMMON_FORWARD_E = COMMON_DIRECTORY + "/" + "common_forward_e.txt"; - String COMMON_FORWARD_I = COMMON_DIRECTORY + "/" + "common_forward_i.txt"; + public static String PN53X_FORWARD_O = PN53X_DIRRECTORY + "/" + "pn53x_forward_o.txt"; + public static String PN53X_FORWARD_E = PN53X_DIRRECTORY + "/" + "pn53x_forward_e.txt"; + public static String PN53X_FORWARD_MF_O = PN53X_DIRRECTORY + "/" + "pn53x_forward_mf_o.txt"; + public static String PN53X_FORWARD_MF_E = PN53X_DIRRECTORY + "/" + "pn53x_forward_mf_e.txt"; + public static String COMMON_FORWARD_O = COMMON_DIRECTORY + "/" + "common_forward_o.txt"; + public static String COMMON_FORWARD_E = COMMON_DIRECTORY + "/" + "common_forward_e.txt"; + public static String COMMON_FORWARD_I = COMMON_DIRECTORY + "/" + "common_forward_i.txt"; - String DEFAULT_KEYS_FILE = KEY_DIRECTORY + "/" + DEFAULT_KEYS_NAME; - String DEFAULT_DUMP_FILE = DUMP_DIRECTORY + "/" + DEFAULT_DUMP_NAME; - String DRIVER_DIRECTORY = TOOLS_DIRECTORY + "/" + DRIVER_PATH; + public static String DEFAULT_KEYS_FILE = KEY_DIRECTORY + "/" + DEFAULT_KEYS_NAME; + public static String DEFAULT_DUMP_FILE = DUMP_DIRECTORY + "/" + DEFAULT_DUMP_NAME; + public static String DRIVER_DIRECTORY = TOOLS_DIRECTORY + "/" + DRIVER_PATH; } From 8a6e4389f115dca62d74c6bf96a947c2d63d1486 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 17:58:01 +0800 Subject: [PATCH 07/13] init pm3 cwd if enable. --- app_main/src/main/java/cn/rrg/rdv/util/InitUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app_main/src/main/java/cn/rrg/rdv/util/InitUtil.java b/app_main/src/main/java/cn/rrg/rdv/util/InitUtil.java index 86b40f7b..42d76239 100644 --- a/app_main/src/main/java/cn/rrg/rdv/util/InitUtil.java +++ b/app_main/src/main/java/cn/rrg/rdv/util/InitUtil.java @@ -3,6 +3,9 @@ import android.content.Context; import android.util.Log; +import com.termux.app.TermuxActivity; +import com.termux.app.TermuxService; + import java.io.File; import java.io.IOException; @@ -75,6 +78,7 @@ public static void initApplicationResource(Context context) { initEasyButtonFile(au); initPM3ForwardFile(); } + Commons.updatePM3Cwd(); } private static void initCommonInFile() { From 408b63108567576c7393f7ce2cdcb167f77dd2be Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 18:02:10 +0800 Subject: [PATCH 08/13] add a setting to change pm3 cwd. --- .../fragment/tools/MainSettingsFragment.java | 86 +++++++++++++------ 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java b/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java index cc3214c2..cf66af04 100644 --- a/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java +++ b/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java @@ -8,6 +8,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import androidx.annotation.NonNull; @@ -21,6 +22,8 @@ import android.view.ViewGroup; import cn.dxl.common.util.AppUtil; +import cn.dxl.common.util.FileUtils; +import cn.dxl.common.util.LogUtils; import cn.dxl.common.util.RestartUtils; import cn.rrg.rdv.R; import cn.rrg.rdv.binder.ItemSingleTextBean; @@ -31,10 +34,13 @@ import cn.rrg.rdv.javabean.ItemToggleBean; import cn.rrg.rdv.javabean.TitleBean; import cn.rrg.rdv.util.Commons; +import cn.rrg.rdv.util.Paths; import cn.rrg.rdv.util.Proxmark3Installer; import me.drakeet.multitype.Items; import me.drakeet.multitype.MultiTypeAdapter; +import static android.app.Activity.RESULT_OK; + /* * 主设置活动! * */ @@ -119,35 +125,51 @@ public void onClick(View view, int pos) { pm3Res.setMessage(Commons.isPM3ResInitialled() ? getString(R.string.initialized) : getString(R.string.uninitialized)); items.add(pm3Res); - ItemToggleBean pm3AutoGo = new ItemToggleBean(getString(R.string.title_pm3_autogo_setting)) { - @Override - public void onChange(View view, int pos, boolean checked) { - Commons.setAutoGoToTerminal(checked); - } - }; - pm3AutoGo.setSubTitle(getString(R.string.title_sub_pm3_autogo_setting)); - pm3AutoGo.setChecked(Commons.getAutoGoToTerminal()); - items.add(pm3AutoGo); + // 只有SDK版本大于等于24的时候才使能PM3的高级视图 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + + ItemToggleBean pm3AutoGo = new ItemToggleBean(getString(R.string.title_pm3_autogo_setting)) { + @Override + public void onChange(View view, int pos, boolean checked) { + Commons.setAutoGoToTerminal(checked); + } + }; + pm3AutoGo.setSubTitle(getString(R.string.title_sub_pm3_autogo_setting)); + pm3AutoGo.setChecked(Commons.getAutoGoToTerminal()); + items.add(pm3AutoGo); + + ItemTextBean pm3TerminalTypeItem = new ItemTextBean(getString(R.string.title_terminal_type_setting)) { + @Override + public void onClick(View view, int pos) { + String[] languages = new String[]{getString(R.string.item_full_terminal_view), getString(R.string.item_simple_terminal_view)}; + new AlertDialog.Builder(view.getContext()) + .setTitle(R.string.tips_terminal_select_like) + .setItems(languages, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Commons.setTerminalType(which); + setMessage(currentTerminalType()); + multiTypeAdapter.notifyDataSetChanged(); + } + }).show(); + } + }; + pm3TerminalTypeItem.setSubTitle(getString(R.string.title_sub_terminal_type_setting)); + pm3TerminalTypeItem.setMessage(currentTerminalType()); + items.add(pm3TerminalTypeItem); + } - ItemTextBean pm3TerminalTypeItem = new ItemTextBean(getString(R.string.title_terminal_type_setting)) { + // PM3 work directory select + ItemToggleBean pm3HomePathItem = new ItemToggleBean(getString(R.string.title_pm3_home)) { @Override - public void onClick(View view, int pos) { - String[] languages = new String[]{getString(R.string.item_full_terminal_view), getString(R.string.item_simple_terminal_view)}; - new AlertDialog.Builder(view.getContext()) - .setTitle(R.string.tips_terminal_select_like) - .setItems(languages, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Commons.setTerminalType(which); - setMessage(currentTerminalType()); - multiTypeAdapter.notifyDataSetChanged(); - } - }).show(); + public void onChange(View view, int pos, boolean checked) { + Commons.setPM3ExternalWorkDirectoryEnable(checked); + Commons.updatePM3Cwd(); } }; - pm3TerminalTypeItem.setSubTitle(getString(R.string.title_sub_terminal_type_setting)); - pm3TerminalTypeItem.setMessage(currentTerminalType()); - items.add(pm3TerminalTypeItem); + pm3HomePathItem.setSubTitle(Paths.PM3_CWD); + pm3HomePathItem.setChecked(Commons.isPM3ExternalWorkDirectoryEnable()); + items.add(pm3HomePathItem); items.add(new TitleBean(getString(R.string.other))); @@ -166,6 +188,20 @@ public void onClick(View view, int pos) { multiTypeAdapter.notifyDataSetChanged(); } + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == 0x77 && resultCode == RESULT_OK && data != null) { + Uri uri = data.getData(); + if (uri != null) { + // get file path + String path = FileUtils.getFilePathByUri(uri); + // save + LogUtils.d("获取到的路径: " + path); + } + } + } + public static String getVersion(Context context) { if (context == null) return "unknown"; try { From ad03472da5699657e7439c29b0177082ce83a0fd Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 18:02:32 +0800 Subject: [PATCH 09/13] add pm3 cwd key. --- app_main/src/main/java/cn/rrg/rdv/application/Properties.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app_main/src/main/java/cn/rrg/rdv/application/Properties.java b/app_main/src/main/java/cn/rrg/rdv/application/Properties.java index 52c82227..5820eb65 100644 --- a/app_main/src/main/java/cn/rrg/rdv/application/Properties.java +++ b/app_main/src/main/java/cn/rrg/rdv/application/Properties.java @@ -19,4 +19,6 @@ public class Properties { public static String k_auto_goto_terminal = "autoGotoTermuxView"; // The type of terminal public static String k_terminal_type = "terminal_type"; + // The enable status of p3m external work directory + public static String k_pm3_externl_cwd_enable = "pm3_cwd_external_enable"; } From 74525544d1608ee07de3ef4097c7371be98b26de Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 18:03:12 +0800 Subject: [PATCH 10/13] set cwd. --- .../Proxmark3Rdv4RRGRedTeamConsoleActivity.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app_main/src/main/java/cn/rrg/rdv/activities/proxmark3/rdv4_rrg/Proxmark3Rdv4RRGRedTeamConsoleActivity.java b/app_main/src/main/java/cn/rrg/rdv/activities/proxmark3/rdv4_rrg/Proxmark3Rdv4RRGRedTeamConsoleActivity.java index 4d989748..ed6e7987 100644 --- a/app_main/src/main/java/cn/rrg/rdv/activities/proxmark3/rdv4_rrg/Proxmark3Rdv4RRGRedTeamConsoleActivity.java +++ b/app_main/src/main/java/cn/rrg/rdv/activities/proxmark3/rdv4_rrg/Proxmark3Rdv4RRGRedTeamConsoleActivity.java @@ -11,9 +11,6 @@ import android.widget.GridView; import android.widget.TextView; -import com.termux.app.TermuxService; - -import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -66,13 +63,8 @@ public void onClick(View v) { initViews(); initActions(); - new Thread(new Runnable() { - @Override - public void run() { - // 更改工作目录! - IORedirector.chdir(TermuxService.HOME_PATH + File.separator + Paths.PM3_PATH); - } - }).start(); + // 更改工作目录! + IORedirector.chdir(Paths.PM3_CWD); } private void initViews() { From 0541bc0b2ce4c0de43688ecc23cf2d433bac8630 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 18:04:09 +0800 Subject: [PATCH 11/13] Select the advanced view of enabling PM3 according to the SDK version. --- .../connect/Proxmark3Rdv4RRGConnectActivity.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app_main/src/main/java/cn/rrg/rdv/activities/connect/Proxmark3Rdv4RRGConnectActivity.java b/app_main/src/main/java/cn/rrg/rdv/activities/connect/Proxmark3Rdv4RRGConnectActivity.java index c646c323..46349153 100644 --- a/app_main/src/main/java/cn/rrg/rdv/activities/connect/Proxmark3Rdv4RRGConnectActivity.java +++ b/app_main/src/main/java/cn/rrg/rdv/activities/connect/Proxmark3Rdv4RRGConnectActivity.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import androidx.annotation.Nullable; @@ -11,6 +12,7 @@ import cn.rrg.rdv.R; import cn.rrg.rdv.activities.main.PM3FlasherMainActivity; +import cn.rrg.rdv.activities.proxmark3.rdv4_rrg.Proxmark3Rdv4RRGRedTeamConsoleActivity; import cn.rrg.rdv.activities.tools.DeviceConnectActivity; import cn.rrg.rdv.activities.proxmark3.rdv4_rrg.Proxmark3NewTerminalInitActivity; import cn.rrg.rdv.callback.ConnectFailedCtxCallback; @@ -20,9 +22,6 @@ import cn.dxl.common.util.PermissionUtil; /** - * 专供RDV4连接设备 - * 可以使用USB 与 SPP两种方式连接设备 - * * @author DXL */ public class Proxmark3Rdv4RRGConnectActivity @@ -48,7 +47,11 @@ public AbstractDeviceModel[] getModels() { @Override public Class getTarget() { - return Proxmark3NewTerminalInitActivity.class; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + return Proxmark3NewTerminalInitActivity.class; + } else { + return Proxmark3Rdv4RRGRedTeamConsoleActivity.class; + } } @Override From dcd2ec58ace75c61228fbe052a3ddba631935157 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 18:25:16 +0800 Subject: [PATCH 12/13] version updated. --- app_main/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app_main/build.gradle b/app_main/build.gradle index 89815cf1..d79e7afb 100644 --- a/app_main/build.gradle +++ b/app_main/build.gradle @@ -8,8 +8,8 @@ android { minSdkVersion 21 targetSdkVersion 28 testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - versionCode 25 - versionName "1.4.7 Termux and SimpleView" + versionCode 26 + versionName "1.4.8 SDK21 && PM3 CWD" } buildTypes { release { From 556d071c2acf6c883ee97535912f9887912b2ae2 Mon Sep 17 00:00:00 2001 From: dxl <64101226@qq.com> Date: Thu, 13 Aug 2020 18:54:25 +0800 Subject: [PATCH 13/13] cwd invalid bug fixed. --- .../cn/rrg/rdv/fragment/tools/MainSettingsFragment.java | 6 +++++- app_main/src/main/java/cn/rrg/rdv/util/Commons.java | 9 ++++++--- app_main/src/main/java/cn/rrg/rdv/util/Paths.java | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java b/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java index cf66af04..e8d3297a 100644 --- a/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java +++ b/app_main/src/main/java/cn/rrg/rdv/fragment/tools/MainSettingsFragment.java @@ -21,6 +21,8 @@ import android.view.View; import android.view.ViewGroup; +import com.termux.app.TermuxService; + import cn.dxl.common.util.AppUtil; import cn.dxl.common.util.FileUtils; import cn.dxl.common.util.LogUtils; @@ -164,7 +166,9 @@ public void onClick(DialogInterface dialog, int which) { @Override public void onChange(View view, int pos, boolean checked) { Commons.setPM3ExternalWorkDirectoryEnable(checked); - Commons.updatePM3Cwd(); + setSubTitle(Commons.updatePM3Cwd()); + setChecked(checked); + multiTypeAdapter.notifyDataSetChanged(); } }; pm3HomePathItem.setSubTitle(Paths.PM3_CWD); diff --git a/app_main/src/main/java/cn/rrg/rdv/util/Commons.java b/app_main/src/main/java/cn/rrg/rdv/util/Commons.java index c01223dc..620412dd 100644 --- a/app_main/src/main/java/cn/rrg/rdv/util/Commons.java +++ b/app_main/src/main/java/cn/rrg/rdv/util/Commons.java @@ -295,13 +295,16 @@ public static boolean isPM3ExternalWorkDirectoryEnable() { .getBoolean(Properties.k_pm3_externl_cwd_enable, false); } - public static void updatePM3Cwd() { + public static String updatePM3Cwd() { // init pm3 cwd if (Commons.isPM3ExternalWorkDirectoryEnable()) { - TermuxService.PM3_CWD = Paths.PM3_CWD; - new File(TermuxService.PM3_CWD).mkdirs(); + TermuxService.PM3_CWD = Paths.PM3_CWD_FINAL; + Paths.PM3_CWD = TermuxService.PM3_CWD; + new File(Paths.PM3_CWD).mkdirs(); } else { Paths.PM3_CWD = TermuxService.HOME_PATH; + TermuxService.PM3_CWD = null; } + return Paths.PM3_CWD; } } diff --git a/app_main/src/main/java/cn/rrg/rdv/util/Paths.java b/app_main/src/main/java/cn/rrg/rdv/util/Paths.java index 706c6ab5..51da52fb 100644 --- a/app_main/src/main/java/cn/rrg/rdv/util/Paths.java +++ b/app_main/src/main/java/cn/rrg/rdv/util/Paths.java @@ -63,6 +63,7 @@ public class Paths { public static String PM3_IMAGE_OS_FILE = TermuxService.HOME_PATH + File.separator + PM3_PATH + File.separator + PM3_OS_FILE_NAME; // pm3 cwd -> sdcard public static String PM3_CWD = PM3_DIRECTORY + File.separator + "home"; + public static final String PM3_CWD_FINAL = PM3_DIRECTORY + File.separator + "home"; public static String PN53X_FORWARD_O = PN53X_DIRRECTORY + "/" + "pn53x_forward_o.txt"; public static String PN53X_FORWARD_E = PN53X_DIRRECTORY + "/" + "pn53x_forward_e.txt";