diff --git a/.idea/modules.xml b/.idea/modules.xml
index 9e303b9c..f6ab9e10 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -4,20 +4,35 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index c40279fb..37740d42 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ Download and flash [Compiled FW 12 August](https://www.dropbox.com/s/416lsrqpr2l
## App core implementation
-If you want to join our project, you must comply with the following development specifications to some extent, including macro architecture and micro implementation. Let us have fun time coding.
+If you want to join our project, you must comply with the following development specifications to some extent, including macro architecture and micro implementation. Let us have target time coding.
- Communication implementation: using JNI mapping C & Java communication, encapsulating posix-compliant UART library, using Google API in the upper layer (Java) and posix-compliant UART in the lower layer (C/C+++).
diff --git a/app_main/build.gradle b/app_main/build.gradle
index 8f3242ce..77f1c503 100644
--- a/app_main/build.gradle
+++ b/app_main/build.gradle
@@ -8,8 +8,8 @@ android {
minSdkVersion 19
targetSdkVersion 29
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
- versionCode 6
- versionName "1.3.3"
+ versionCode 13
+ versionName "1.4"
}
buildTypes {
release {
diff --git a/app_main/src/main/AndroidManifest.xml b/app_main/src/main/AndroidManifest.xml
index 77361d1e..8ac19efb 100644
--- a/app_main/src/main/AndroidManifest.xml
+++ b/app_main/src/main/AndroidManifest.xml
@@ -109,7 +109,7 @@
-
+
diff --git a/app_main/src/main/assets/bootrom.elf b/app_main/src/main/assets/bootrom.elf
new file mode 100644
index 00000000..b39c35a8
Binary files /dev/null and b/app_main/src/main/assets/bootrom.elf differ
diff --git a/app_main/src/main/assets/fullimage.elf b/app_main/src/main/assets/fullimage.elf
new file mode 100644
index 00000000..7189512e
Binary files /dev/null and b/app_main/src/main/assets/fullimage.elf differ
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 f7005de5..dc5c01f4 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
@@ -2,6 +2,8 @@ package cn.rrg.rdv.activities.connect;
import android.Manifest;
import android.app.Activity;
+import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
@@ -12,6 +14,7 @@ import android.widget.TextView;
import cn.dxl.common.util.DisplayUtil;
import cn.rrg.rdv.R;
+import cn.rrg.rdv.activities.main.PM3FlasherMainActivity;
import cn.rrg.rdv.activities.main.Proxmark3Rdv4RRGMain;
import cn.rrg.rdv.activities.tools.DeviceConnectActivity;
import cn.rrg.rdv.callback.ConnectFailedCtxCallback;
@@ -43,9 +46,7 @@ public class Proxmark3Rdv4RRGConnectActivity
@Override
public AbstractDeviceModel[] getModels() {
return new AbstractDeviceModel[]{
- //RDV4支持SPP数据源,因此提供SPP的通信!
new Proxmark3Rdv4SppModel(),
- //RDV4还支持USB的数据源,同样提供USB的通信!
new Proxmark3Rdv4UsbModel()
};
}
@@ -76,14 +77,17 @@ public class Proxmark3Rdv4RRGConnectActivity
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
- int paddingValue = DisplayUtil.dip2px(activity, 16);
- TextView msg = new TextView(activity);
- msg.setTextIsSelectable(true);
- msg.setPadding(paddingValue, paddingValue, paddingValue, paddingValue);
- msg.setText(Html.fromHtml(activity.getString(R.string.connect_errr_msg_1)));
new AlertDialog.Builder(activity)
.setTitle(R.string.connect_faild)
- .setView(msg).show();
+ .setMessage(R.string.connect_errr_msg_1)
+ .setPositiveButton(getString(R.string.flash) + "(OTG)", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ startActivity(new Intent(context, PM3FlasherMainActivity.class));
+ }
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .show();
}
});
}
diff --git a/app_main/src/main/java/cn/rrg/rdv/activities/main/AppMain.java b/app_main/src/main/java/cn/rrg/rdv/activities/main/AppMain.java
index d8d86cf7..721701c3 100644
--- a/app_main/src/main/java/cn/rrg/rdv/activities/main/AppMain.java
+++ b/app_main/src/main/java/cn/rrg/rdv/activities/main/AppMain.java
@@ -1,6 +1,5 @@
package cn.rrg.rdv.activities.main;
-import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
@@ -42,9 +41,6 @@ public class AppMain extends BaseActivity {
initActions();
gotoFragment(appMainDevicesFragment);
-
- startActivity(new Intent(context, FlasherMainActivity.class));
- finish();
}
private void initViews() {
diff --git a/app_main/src/main/java/cn/rrg/rdv/activities/main/FlasherMainActivity.java b/app_main/src/main/java/cn/rrg/rdv/activities/main/FlasherMainActivity.java
deleted file mode 100644
index 5961ad9f..00000000
--- a/app_main/src/main/java/cn/rrg/rdv/activities/main/FlasherMainActivity.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package cn.rrg.rdv.activities.main;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.view.View;
-
-import androidx.annotation.Nullable;
-
-import com.proxgrind.pm3flasher.Proxmark3Flasher;
-
-import cn.dxl.com.Com;
-import cn.dxl.common.util.LogUtils;
-import cn.dxl.common.widget.ToastUtil;
-import cn.rrg.com.ContextCallback;
-import cn.rrg.com.DevCallback;
-import cn.rrg.com.UsbSerialControl;
-import cn.rrg.devices.EmptyDeivce;
-import cn.rrg.rdv.R;
-
-public class FlasherMainActivity extends BaseActivity {
-
- private UsbSerialControl control = UsbSerialControl.get();
- private Proxmark3Flasher flasher = Proxmark3Flasher.getFlasher();
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.act_pm3_flasher);
-
- Com.initCom(control, new EmptyDeivce());
-
- control.setContextCallback(new ContextCallback() {
- @Override
- public Context getContext() {
- return context;
- }
- });
-
- control.register(this, new DevCallback() {
- @Override
- public void onAttach(String dev) {
-
- }
-
- @Override
- public void onDetach(String dev) {
- flasher.closeProxmark3();
- }
- });
-
- findViewById(R.id.btnStatusCheck).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- flasher.isBootloaderMode();
- }
- }).start();
- }
- });
-
- findViewById(R.id.btnClientClose).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- flasher.closeProxmark3();
- }
- }).start();
- }
- });
-
- findViewById(R.id.btnClientOpen).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- flasher.openProxmark3();
- }
- }).start();
- }
- });
-
- findViewById(R.id.btnDeviceConnect).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- if (control.connect(null)) {
- ToastUtil.show(context, "连接成功", false);
- } else {
- ToastUtil.show(context, "连接失败", false);
- }
- }
- }).start();
- }
- });
-
- findViewById(R.id.btnFlashStart).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- String bootrom = "/storage/emulated/0/Download/bootrom.elf";
- String fullimg = "/storage/emulated/0/Download/fullimage.elf";
- if (!flasher.isPM3Opened()) {
- if (!flasher.openProxmark3()) {
- LogUtils.d("PM3打开失败!");
- return;
- } else {
- LogUtils.d("PM3打开成功!");
- }
- }
- // 如果没有在Bootloader模式下,我们需要先重启设备使其进入Bootloader模式下!
- if (flasher.isBootloaderMode()) {
- LogUtils.d("当前处于Bootloader模式下,将会开始刷机!");
- if (flasher.flashBootRom(bootrom)) {
- LogUtils.d("PM3刷写BootRom成功!");
- } else {
- LogUtils.d("PM3刷写BootRom失败!");
- }
- if (flasher.flashFullImg(fullimg)) {
- LogUtils.d("PM3刷写BootRom成功!");
- } else {
- LogUtils.d("PM3刷写BootRom失败!");
- }
- flasher.flashModeClose();
- flasher.closeProxmark3();
- } else {
- if (!flasher.enterBootloader()) {
- LogUtils.d("PM3进入刷写模式失败!");
- }
- }
- }
- }).start();
- }
- });
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- control.unregister(this);
- }
-}
diff --git a/app_main/src/main/java/cn/rrg/rdv/activities/main/PM3FlasherMainActivity.java b/app_main/src/main/java/cn/rrg/rdv/activities/main/PM3FlasherMainActivity.java
new file mode 100644
index 00000000..c8d7cd3f
--- /dev/null
+++ b/app_main/src/main/java/cn/rrg/rdv/activities/main/PM3FlasherMainActivity.java
@@ -0,0 +1,166 @@
+package cn.rrg.rdv.activities.main;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import androidx.annotation.Nullable;
+
+import com.bumptech.glide.Glide;
+import com.proxgrind.pm3flasher.Proxmark3Flasher;
+import com.proxgrind.pm3flasher.Target;
+
+import cn.dxl.com.Com;
+import cn.dxl.common.util.LogUtils;
+import cn.dxl.common.widget.ToastUtil;
+import cn.rrg.com.DevCallback;
+import cn.rrg.com.UsbSerialControl;
+import cn.rrg.devices.EmptyDeivce;
+import cn.rrg.rdv.R;
+import cn.rrg.rdv.util.Paths;
+
+public class PM3FlasherMainActivity extends BaseActivity implements DevCallback {
+
+ private enum MODE {
+ BOOT, OS
+ }
+
+ private UsbSerialControl control = UsbSerialControl.get();
+ private Proxmark3Flasher flasher = Proxmark3Flasher.getFlasher();
+
+ //在程序执行读卡,写卡操作时的程序后台交互性提醒对话框
+ private AlertDialog mDialogWorkingState = null;
+
+ private Button btnFlash;
+
+ private MODE mode = MODE.BOOT;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.act_pm3_flasher);
+
+ // init and try to connect.
+ control.register(this, this);
+ Com.initCom(control, new EmptyDeivce());
+
+ initViews();
+ initActions();
+
+ setStatus(true);
+ }
+
+ private void initViews() {
+ mDialogWorkingState = new AlertDialog.Builder(context).create();
+ View _workingStateMsgView = View.inflate(context, R.layout.dialog_working_msg, null);
+ mDialogWorkingState.setView(_workingStateMsgView);
+ mDialogWorkingState.setTitle(R.string.tips);
+ mDialogWorkingState.setCancelable(false);
+
+ btnFlash = findViewById(R.id.btnFlash);
+ }
+
+ private void initActions() {
+ btnFlash.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mode = MODE.BOOT;
+ if (control.connect(null)) {
+ flashDefaultFW();
+ } else {
+ ToastUtil.show(context, getString(R.string.tips_device_no_found), false);
+ }
+ }
+ });
+ }
+
+ private void flashDefaultFW() {
+ if (!mDialogWorkingState.isShowing())
+ mDialogWorkingState.show();
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ if (!flasher.isStart(Target.CLIENT)) {
+ if (!flasher.start(Target.CLIENT)) {
+ return;
+ }
+ }
+ // 如果没有在Bootloader模式下,我们需要先重启设备使其进入Bootloader模式下!
+ if (flasher.isStart(Target.BOOT)) {
+ switch (mode) {
+ case BOOT:
+ if (flasher.flashBootRom(Paths.PM3_IMAGE_BOOT_FILE)) {
+ ToastUtil.show(context, getString(R.string.tips_boot_flash_success), false);
+ } else {
+ ToastUtil.show(context, getString(R.string.tips_boot_flash_failed), false);
+ }
+ finishFlash();
+ // 开启下一轮!
+ mode = MODE.OS;
+ break;
+
+ case OS:
+ if (flasher.flashFullImg(Paths.PM3_IMAGE_OS_FILE)) {
+ ToastUtil.show(context, getString(R.string.tips_os_flash_success), false);
+ } else {
+ ToastUtil.show(context, getString(R.string.tips_os_flash_failed), false);
+ }
+ finishFlash();
+ ToastUtil.show(context, getString(R.string.finish), false);
+ finish();
+ break;
+ }
+ } else {
+ if (!flasher.start(Target.BOOT)) {
+ ToastUtil.show(context, getString(R.string.tips_pm3_enter_failed), false);
+ }
+ }
+ }
+ }).start();
+ }
+
+ private void finishFlash() {
+ flasher.close(Target.BOOT);
+ flasher.close(Target.CLIENT);
+ }
+
+ private void closeClient() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ flasher.close(Target.CLIENT);
+ }
+ }).start();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mDialogWorkingState.dismiss();
+ control.unregister(this);
+ closeClient();
+ }
+
+ @Override
+ public void onAttach(String dev) {
+ // 自动连接设备!
+ control.connect(dev);
+ flashDefaultFW();
+ }
+
+ @Override
+ public void onDetach(String dev) {
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ // LogUtils.d("X: " + event.getRawX());
+ // LogUtils.d("Y: " + event.getRawY());
+ return super.onTouchEvent(event);
+ }
+}
diff --git a/app_main/src/main/java/cn/rrg/rdv/activities/tools/BaseConsoleActivity.java b/app_main/src/main/java/cn/rrg/rdv/activities/tools/BaseConsoleActivity.java
index 9892e871..0be26482 100644
--- a/app_main/src/main/java/cn/rrg/rdv/activities/tools/BaseConsoleActivity.java
+++ b/app_main/src/main/java/cn/rrg/rdv/activities/tools/BaseConsoleActivity.java
@@ -454,7 +454,6 @@ public abstract class BaseConsoleActivity extends BaseActivity {
// 我们需要单独处理其中的每个/r,进行视觉更新!
for (String s : newLineReturnArr) {
arr[arr.length - 1] = s;
- Log.d(LOG_TAG, "当前被newLineReturnArr拼接的行: " + arr[arr.length - 1]);
// 拼接回去!
StringBuilder sb = new StringBuilder();
for (int j = 0; j < arr.length; ++j) {
@@ -466,7 +465,6 @@ public abstract class BaseConsoleActivity extends BaseActivity {
}
} else {
arr[arr.length - 1] = line;
- Log.d(LOG_TAG, "当前被arr拼接的行: " + arr[arr.length - 1]);
// 拼接回去!
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arr.length; ++i) {
diff --git a/app_main/src/main/java/cn/rrg/rdv/activities/tools/DeviceConnectActivity.java b/app_main/src/main/java/cn/rrg/rdv/activities/tools/DeviceConnectActivity.java
index 503040ec..ecc98388 100644
--- a/app_main/src/main/java/cn/rrg/rdv/activities/tools/DeviceConnectActivity.java
+++ b/app_main/src/main/java/cn/rrg/rdv/activities/tools/DeviceConnectActivity.java
@@ -46,7 +46,7 @@ public abstract class DeviceConnectActivity
public abstract ConnectFailedCtxCallback getCallback();
//数据源承载数组!
- AbstractDeviceModel[] models;
+ public AbstractDeviceModel[] models;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -62,16 +62,8 @@ public abstract class DeviceConnectActivity
model.register(this);
}
- Bundle data = new Bundle();
- data.putSerializable("models", models);
- data.putSerializable("target", getTarget());
- data.putSerializable("callback", getCallback());
- data.putString("msg", getConnectingMsg());
-
Fragment newDevFragment = new DeviceConnectNewFragment();
Fragment allDevFragment = new DeviceConnectAllFragment();
- newDevFragment.setArguments(data);
- allDevFragment.setArguments(data);
//初始化分页适配器!
FragmentPagerAdapter mAdapter =
diff --git a/app_main/src/main/java/cn/rrg/rdv/fragment/connect/DeviceConnectFragment.java b/app_main/src/main/java/cn/rrg/rdv/fragment/connect/DeviceConnectFragment.java
index a9d8ace1..b2947fff 100644
--- a/app_main/src/main/java/cn/rrg/rdv/fragment/connect/DeviceConnectFragment.java
+++ b/app_main/src/main/java/cn/rrg/rdv/fragment/connect/DeviceConnectFragment.java
@@ -15,6 +15,7 @@ import android.widget.TextView;
import java.util.ArrayList;
import cn.rrg.rdv.R;
+import cn.rrg.rdv.activities.tools.DeviceConnectActivity;
import cn.rrg.rdv.callback.ConnectFailedCtxCallback;
import cn.rrg.rdv.fragment.base.AppMainDevicesFragment;
import cn.rrg.rdv.models.AbstractDeviceModel;
@@ -33,12 +34,13 @@ public abstract class DeviceConnectFragment
@Override
protected void initResource() {
- Bundle data = getArguments();
- if (data != null) {
- this.models = (AbstractDeviceModel[]) data.getSerializable("models");
- this.target = (Class) data.getSerializable("target");
- this.connectCallback = (ConnectFailedCtxCallback) data.getSerializable("callback");
+ Activity activity = getActivity();
+ if (activity == null) return;
+ if (activity instanceof DeviceConnectActivity) {
+ this.models = ((DeviceConnectActivity) activity).models;
if (models != null) {
+ this.target = ((DeviceConnectActivity) activity).getTarget();
+ this.connectCallback = ((DeviceConnectActivity) activity).getCallback();
for (AbstractDeviceModel m : models) {
//初始化中介者并且绑定视图!
DevicePresenter presenter = new DevicePresenter<>(m);
@@ -46,15 +48,13 @@ public abstract class DeviceConnectFragment
presenter.attachView(this);
presenters.add(presenter);
}
+ String msg = ((DeviceConnectActivity) activity).getConnectingMsg();
+ if (msg != null) {
+ ((TextView) (msgView.findViewById(R.id.text1))).setText(msg);
+ }
} else {
- throw new RuntimeException("Models container null exception!");
+ throw new RuntimeException("Models not init exception!");
}
- String msg = data.getString("msg");
- if (msg != null) {
- ((TextView) (msgView.findViewById(R.id.text1))).setText(msg);
- }
- } else {
- throw new RuntimeException("Models not init exception!");
}
}
diff --git a/app_main/src/main/java/cn/rrg/rdv/models/AbsUsb2UartModel.java b/app_main/src/main/java/cn/rrg/rdv/models/AbsUsb2UartModel.java
index 449a4a64..8071a109 100644
--- a/app_main/src/main/java/cn/rrg/rdv/models/AbsUsb2UartModel.java
+++ b/app_main/src/main/java/cn/rrg/rdv/models/AbsUsb2UartModel.java
@@ -19,18 +19,7 @@ public abstract class AbsUsb2UartModel extends AbstractDeviceModel getDriverInterface() {
- DriverInterface di = DriverSource.driverMap.get(0x04);
- if (di != null) {
- ContextHandle contextHandle = (ContextHandle) di;
- contextHandle.setContextCallback(new ContextCallback() {
- @Override
- public Context getContext() {
- return AppUtil.getInstance().getApp();
- }
- });
- return di;
- }
- return null;
+ return DriverSource.driverMap.get(0x04);
}
@Override
diff --git a/app_main/src/main/java/cn/rrg/rdv/models/AbstractDeviceModel.java b/app_main/src/main/java/cn/rrg/rdv/models/AbstractDeviceModel.java
index ec40801b..5f44e2a0 100644
--- a/app_main/src/main/java/cn/rrg/rdv/models/AbstractDeviceModel.java
+++ b/app_main/src/main/java/cn/rrg/rdv/models/AbstractDeviceModel.java
@@ -3,10 +3,12 @@ package cn.rrg.rdv.models;
import android.content.Context;
import android.util.Log;
+import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import cn.dxl.common.util.LogUtils;
import cn.rrg.com.DevCallback;
import cn.rrg.com.DriverInterface;
@@ -172,6 +174,13 @@ public abstract class AbstractDeviceModel
if (Com.initCom(mDI, mDevice)) {
callback.onInitSuccess();
} else {
+ try {
+ LogUtils.d("初始化失败,将会调用设备封装类关闭设备!");
+ // close device!
+ mDevice.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
callback.onInitFail();
}
}
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 9014cd9e..93c9295b 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
@@ -18,10 +18,8 @@ import cn.dxl.common.util.DiskKVUtil;
public class InitUtil {
- //短称路径
public static final String LOG_TAG = InitUtil.class.getSimpleName();
- //初始化dump文件目录
public static void initApplicationResource(Context context) {
AssetsUtil au = new AssetsUtil(context);
File dump_dir = new File(Paths.DUMP_DIRECTORY);
@@ -74,11 +72,13 @@ public class InitUtil {
if (!pm3_dir.mkdirs()) {
Log.d(LOG_TAG, "init pm3 dir fail!");
} else {
+ initProxmark3RDV4ImageFile(au);
initEasyButtonFile(au);
initPM3ForwardFile();
initHardnestedFile(au);
}
} else {
+ initProxmark3RDV4ImageFile(au);
initEasyButtonFile(au);
initPM3ForwardFile();
initHardnestedFile(au);
@@ -99,17 +99,28 @@ public class InitUtil {
}
}
+ private static void initProxmark3RDV4ImageFile(AssetsUtil au) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ //初始化标准输入的文件!
+ File boot = new File(Paths.PM3_IMAGE_BOOT_FILE);
+ File os = new File(Paths.PM3_IMAGE_OS_FILE);
+ au.moveFile(Paths.PM3_BOOT_FILE_NAME, boot.getAbsolutePath());
+ au.moveFile(Paths.PM3_OS_FILE_NAME, os.getAbsolutePath());
+ }
+ }).start();
+ }
+
private static void initMfInfoMapsFile(AssetsUtil au) {
File f1 = new File(Paths.COMMON_DIRECTORY + "/" + "template_mifare_info_en.html");
File f2 = new File(Paths.COMMON_DIRECTORY + "/" + "template_tag_info_en.html");
//移动两个标签信息HTML文件到指定目录!
- if (/*!f1.exists()*/true)
- au.moveFile("template_mifare_info_en.html",
- new File(Paths.COMMON_DIRECTORY + "/" + "template_mifare_info_en.html").getAbsolutePath());
- if (/*!f2.exists()*/true)
- au.moveFile("template_tag_info_en.html",
- new File(Paths.COMMON_DIRECTORY + "/" + "template_tag_info_en.html").getAbsolutePath());
+ au.moveFile("template_mifare_info_en.html",
+ new File(Paths.COMMON_DIRECTORY + "/" + "template_mifare_info_en.html").getAbsolutePath());
+ au.moveFile("template_tag_info_en.html",
+ new File(Paths.COMMON_DIRECTORY + "/" + "template_tag_info_en.html").getAbsolutePath());
}
private static void initDumpFile(AssetsUtil au) {
@@ -230,7 +241,6 @@ public class InitUtil {
}
}
- //进行日志记录开始!
public static void startLogcat(boolean open) {
//拼接名字
String name = "log.txt";
@@ -257,7 +267,6 @@ public class InitUtil {
}
}
- //初始化必须要的设置!
public static void initSettings() throws IOException {
File dir = new File(Paths.SETTINGS_DIRECTORY);
if (dir.exists()) {
@@ -269,7 +278,6 @@ public class InitUtil {
}
}
- //私有初始化函数!
private static void initSets() throws IOException {
File file = new File(Paths.SETTINGS_FILE);
if (!file.exists())
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 7f70b946..3646a5fa 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
@@ -4,7 +4,6 @@ import android.os.Environment;
public interface Paths {
- //常用的相对路径文件夹 | 文件名定义!
String EXTERNAL_STORAGE_DIRECTORY = Environment.getExternalStorageDirectory().getPath();
String TOOLS_PATH = "NfcTools";
String SETTINGS_PATH = "Settings";
@@ -26,7 +25,6 @@ public interface Paths {
String DEFAULT_DUMP_NAME = "BLANK(空白).dump";
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;
@@ -53,11 +51,15 @@ public interface Paths {
String SETTINGS_DIRECTORY = TOOLS_DIRECTORY + "/" + SETTINGS_PATH;
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";
- //PM3的RDV4动态按钮
+ //PM3 Easy Button
String PM3_CMD_FILE = PM3_DIRECTORY + "/" + DEFAULT_CMD_NAME;
+ // PM3 Image
+ String PM3_IMAGE_BOOT_FILE = Paths.PM3_DIRECTORY + "/" + PM3_BOOT_FILE_NAME;
+ String PM3_IMAGE_OS_FILE = Paths.PM3_DIRECTORY + "/" + PM3_OS_FILE_NAME;
String PN53X_FORWARD_O = PN53X_DIRRECTORY + "/" + "pn53x_forward_o.txt";
String PN53X_FORWARD_E = PN53X_DIRRECTORY + "/" + "pn53x_forward_e.txt";
diff --git a/app_main/src/main/res/drawable-hdpi/usb_connect.gif b/app_main/src/main/res/drawable-hdpi/usb_connect.gif
new file mode 100644
index 00000000..52392336
Binary files /dev/null and b/app_main/src/main/res/drawable-hdpi/usb_connect.gif differ
diff --git a/app_main/src/main/res/layout/act_pm3_flasher.xml b/app_main/src/main/res/layout/act_pm3_flasher.xml
index efb3f1cb..5b48021c 100644
--- a/app_main/src/main/res/layout/act_pm3_flasher.xml
+++ b/app_main/src/main/res/layout/act_pm3_flasher.xml
@@ -1,46 +1,25 @@
-
-
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true"
+ android:src="@drawable/rdv4_2" />
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/app_main/src/main/res/layout/item_usb_device_connecting.xml b/app_main/src/main/res/layout/item_usb_device_connecting.xml
new file mode 100644
index 00000000..ca5d6bff
--- /dev/null
+++ b/app_main/src/main/res/layout/item_usb_device_connecting.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app_main/src/main/res/values-en/strings.xml b/app_main/src/main/res/values-en/strings.xml
index 8d076064..0ef9e4da 100644
--- a/app_main/src/main/res/values-en/strings.xml
+++ b/app_main/src/main/res/values-en/strings.xml
@@ -170,11 +170,9 @@
<p style="color:black;"><big>Powered</big></p><p>By: ProxGrind</p><p><small>Click go to web site</small></p>
<p style="color:black;"><big>Distributed</big></p><p>By: RFID Research Group (RRG)</p><p><small>Click go to web site</small></p>
NFC not turned on
- <p>1、To ensure that firmware versions are consistent, please login at</p>
-<p style="color:green">http://proxgrind.com/free-sdk/</p>
-<p>download the corresponding version.</p>
-<p>2.Make sure the battery has sufficient voltage.</p>
-<p>3.Restart the device and APP, reconnect.</p>
+ 1. Confirm that the firmware version is the same as the app client. You can log in "http://proxgrind.com/free-sdk/" to download the corresponding version, or directly click the button below to flash\n
+2. Make sure the battery has enough voltage\n
+3. Restart the external device and app and try to connect again
Connection failed
Your NFC is not open and cannot use this function. Please open your NFC first.
open
@@ -270,5 +268,12 @@
List
Share
Some permission requests failed.
+ Device no found(Proxmark3 CDC)
+ 1. Firmware flash only support proxmark3 driver by usb-cdc\n \n 2. Only rdv4 is supported (RRG firmware supported by app is needed)\n \n 3. In order to be compatible, flasher need to write boot first and then OS\n \n 4. Please make sure the USB link is stable work during the process of writing\n \n 5. PM3 will be restarted repeatedly during the flash process. In case of usb permission request, please click allow.\n \n 6. This Activity will be automatically closed after all flash are completed
+ BootRom flash successful.
+ BootRom flash failed.
+ OS flash successful.
+ OS flash failed.
+ PM3 failed to enter flash mode!
\ 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 7c259f3f..7ac1f98b 100644
--- a/app_main/src/main/res/values-zh/strings.xml
+++ b/app_main/src/main/res/values-zh/strings.xml
@@ -166,11 +166,9 @@
<p style="color:black;"><big>技术</big></p><p>By: ProxGrind</p><p><small>点击前往主页</small></p>
<p style="color:black;"><big>发布</big></p><p>By: RFID Research Group (RRG)</p><p><small>点击前往主页</small></p>
NFC 未开启
- <p>1、为确保固件版本一致,请登录</p>
-<p style="color:green">http://proxgrind.com/free-sdk/</p>
-<p>下载相应的版本。</p>
-<p>2.确保电池有足够的电压.</p>
-<p>3.重启外置设备和APP, 重新连接</p>
+ 1、确认固件版本与APP客户端一致,可以登录 http://proxgrind.com/free-sdk/ 下载相应的版本,或直接点击下方按钮刷写
+2、确保电池有足够的电压电量
+3、重启外置设备和APP并且重新尝试连接
连接失败
您的NFC未打开,无法使用该功能,请先打开您的NFC
打开
@@ -266,5 +264,22 @@
列表
共享
部分权限请求失败。
+ 设备未插入(Proxmark3 CDC)
+ 1、固件烧写只支持USB-CDC驱动的Proxmark3\n
+\n
+2、只支持RDV4(内置了APP支持的RRG固件)\n
+\n
+3、为了兼容性需要先刷写BOOT,然后刷OS\n
+\n
+4、刷写过程中请保证USB链接稳定\n
+\n
+5、刷写过程中会反复重启PM3,如果出现授权申请请点击允许。\n
+\n
+6、全部刷写完成后将会自动关闭此页面\n
+ 引导器刷写成功.
+ 引导器刷写失败.
+ 操作系统刷写成功
+ 操作系统刷写失败
+ PM3进入刷写模式失败!
\ 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 c12bd42c..b73cd991 100644
--- a/app_main/src/main/res/values/strings.xml
+++ b/app_main/src/main/res/values/strings.xml
@@ -169,11 +169,9 @@
<p style="color:black;"><big>Powered</big></p><p>By: ProxGrind</p><p><small>Click go to web site</small></p>
<p style="color:black;"><big>Distributed</big></p><p>By: RFID Research Group (RRG)</p><p><small>Click go to web site</small></p>
NFC not turned on
- <p>1.To ensure that firmware versions are consistent, please login at</p>
-<p style="color:green">http://proxgrind.com/free-sdk/</p>
-<p>download the corresponding version.</p>
-<p>2.Make sure the battery has sufficient voltage.</p>
-<p>3.Restart the device and APP, reconnect.</p>
+ 1. Confirm that the firmware version is the same as the app client. You can log in "http://proxgrind.com/free-sdk/" to download the corresponding version, or directly click the button below to flash\n
+2. Make sure the battery has enough voltage\n
+3. Restart the external device and app and try to connect again
Connection failed
Your NFC is not open and cannot use this function. Please open your NFC first.
open
@@ -269,5 +267,12 @@
List
Share
Some permission requests failed.
+ Device no found(Proxmark3 CDC)
+ 1. Firmware flash only support proxmark3 driver by usb-cdc\n \n 2. Only rdv4 is supported (RRG firmware supported by app is needed)\n \n 3. In order to be compatible, flasher need to write boot first and then OS\n \n 4. Please make sure the USB link is stable work during the process of writing\n \n 5. PM3 will be restarted repeatedly during the flash process. In case of usb permission request, please click allow.\n \n 6. This Activity will be automatically closed after all flash are completed
+ BootRom flash successful.
+ BootRom flash failed.
+ OS flash successful.
+ OS flash failed.
+ PM3 failed to enter flash mode!
\ No newline at end of file
diff --git a/app_main/src/main/res/values/styles.xml b/app_main/src/main/res/values/styles.xml
index f112bf59..c64b469d 100644
--- a/app_main/src/main/res/values/styles.xml
+++ b/app_main/src/main/res/values/styles.xml
@@ -32,4 +32,19 @@
- @drawable/bg_circular_grey_radius_16dp
+
+
\ No newline at end of file
diff --git a/communication/src/main/java/cn/dxl/com/Com.java b/communication/src/main/java/cn/dxl/com/Com.java
index 0108d51b..7fa4425f 100644
--- a/communication/src/main/java/cn/dxl/com/Com.java
+++ b/communication/src/main/java/cn/dxl/com/Com.java
@@ -75,6 +75,7 @@ public final class Com implements Serializable {
* @throws IOException IOException in write error.
*/
private static int write() throws IOException {
+ if (mCommunication == null) return -1;
//加上偏移值
//try {
return mCommunication.write(send_buffer.array(),
@@ -92,6 +93,7 @@ public final class Com implements Serializable {
* @throws IOException IOException in read error.
*/
private static int read() throws IOException {
+ if (mCommunication == null) return -1;
//try {
return mCommunication.read(recv_buffer.array(),
recv_buffer.arrayOffset(), syncLength() +
@@ -105,6 +107,7 @@ public final class Com implements Serializable {
* flush data, clear buffer!
*/
private static void flush() throws IOException {
+ if (mCommunication == null) return;
//try {
mCommunication.flush();
//} catch (IOException e) {
@@ -114,7 +117,7 @@ public final class Com implements Serializable {
/**
* close devices, clear buffer and break communication!
- * TODO don't need close, because some communication can't close() in c layer.
+ * TODO don't close, because some communication can't close() in c layer.
*/
private static void close() throws IOException {
//try {
diff --git a/communication/src/main/java/cn/rrg/com/UsbSerialControl.java b/communication/src/main/java/cn/rrg/com/UsbSerialControl.java
index e3cc2984..7d4736e4 100644
--- a/communication/src/main/java/cn/rrg/com/UsbSerialControl.java
+++ b/communication/src/main/java/cn/rrg/com/UsbSerialControl.java
@@ -27,7 +27,7 @@ import cn.dxl.common.util.HexUtil;
/*
* Usb 2 uart Serial implements
*/
-public class UsbSerialControl extends ContextHandle implements DriverInterface {
+public class UsbSerialControl implements DriverInterface {
// Application context, is global.
@SuppressLint("StaticFieldLeak")
@@ -43,7 +43,7 @@ public class UsbSerialControl extends ContextHandle implements DriverInterface recvBufQueue = new LinkedList<>();
//广播过滤!
private IntentFilter filter = new IntentFilter();
- // 波特率!
- private int baudRate = 115200;
/*私有化构造方法,懒汉单例模式*/
private UsbSerialControl() {
@@ -111,9 +109,7 @@ public class UsbSerialControl extends ContextHandle implements DriverInterface devList = new ArrayList<>(usbManager.getDeviceList().values());
+ if (devList.size() == 0) return false;
//取出第一个USB对象
UsbDevice usbDevice = devList.get(0);
//USB链接!
@@ -308,7 +304,7 @@ public class UsbSerialControl extends ContextHandle implements DriverInterfacerun a cross thread call?
while (connection->run) {
rxlen = 0;
@@ -556,10 +552,6 @@ __attribute__((force_align_arg_pointer))
uart_close(sp);
sp = NULL;
-#if defined(__MACH__) && defined(__APPLE__)
- enableAppNap();
-#endif
-
pthread_exit(NULL);
return NULL;
}
@@ -693,21 +685,27 @@ int TestProxmark(void) {
void CloseProxmark(void) {
conn.run = false;
+ LOGD("尝试释放资源!");
+
#ifdef __BIONIC__
if (communication_thread != 0) {
pthread_join(communication_thread, NULL);
}
#else
- pthread_join(communication_thread, NULL);
+ pthread_join(communication_thread, NULL);
#endif
+ LOGD("释放线程资源完成!");
+
if (sp) {
uart_close(sp);
}
// Clean up our state
sp = NULL;
- memset(&communication_thread, 0, sizeof(pthread_t));
+ if (communication_thread != 0) {
+ memset(&communication_thread, 0, sizeof(pthread_t));
+ }
session.pm3_present = false;
}
@@ -753,7 +751,6 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms
// Wait until the command is received
while (true) {
-
while (getReply(response)) {
if (cmd == CMD_UNKNOWN || response->cmd == cmd) {
return true;
diff --git a/pm3flasher/src/main/cpp/client/flash.c b/pm3flasher/src/main/cpp/client/flash.c
index 8b350f03..24202dd7 100644
--- a/pm3flasher/src/main/cpp/client/flash.c
+++ b/pm3flasher/src/main/cpp/client/flash.c
@@ -324,8 +324,8 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl, int flash_
static int get_proxmark_state(uint32_t *state) {
SendCommandBL(CMD_DEVICE_INFO, 0, 0, 0, NULL, 0);
PacketResponseNG resp;
- WaitForResponse(CMD_UNKNOWN, &resp); // wait for any response. No timeout.
- // WaitForResponseTimeout(CMD_UNKNOWN, &resp, 3000);
+ // WaitForResponse(CMD_UNKNOWN, &resp); // wait for any response. No timeout.
+ WaitForResponseTimeout(CMD_UNKNOWN, &resp, 3000);
// Three outcomes:
// 1. The old bootrom code will ignore CMD_DEVICE_INFO, but respond with an ACK
@@ -346,54 +346,10 @@ static int get_proxmark_state(uint32_t *state) {
return PM3_EFATAL;
}
LOGD("get_proxmark_state() Current state:%d", *state);
+ if (*state == 0) return get_proxmark_state(state);
return PM3_SUCCESS;
}
-// Enter the bootloader to be able to start flashing
-static int enter_bootloader(char *serial_port_name) {
- uint32_t state;
- int ret;
-
- if ((ret = get_proxmark_state(&state)) != PM3_SUCCESS)
- return ret;
-
- /* Already in flash state, we're done. */
- if (state & DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM)
- return PM3_SUCCESS;
-
- if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
- PrintAndLogEx(SUCCESS, _BLUE_("Entering bootloader..."));
-
- if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
- && (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
- // New style handover: Send CMD_START_FLASH, which will reset the board
- // and enter the bootrom on the next boot.
- SendCommandBL(CMD_START_FLASH, 0, 0, 0, NULL, 0);
- PrintAndLogEx(SUCCESS, "(Press and release the button only to " _YELLOW_("abort") ")");
- } else {
- // Old style handover: Ask the user to press the button, then reset the board
- SendCommandBL(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
- PrintAndLogEx(SUCCESS,
- "Press and hold down button NOW if your bootloader requires it.");
- }
- msleep(100);
- CloseProxmark();
- // Let time to OS to make the port disappear
- msleep(1000);
-
- if (OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
- PrintAndLogEx(NORMAL, " " _GREEN_("Found"));
- return PM3_SUCCESS;
- } else {
- PrintAndLogEx(ERR, _RED_("Error:") "Proxmark3 not found.");
- return PM3_ETIMEOUT;
- }
- }
-
- PrintAndLogEx(ERR, _RED_("Error:") "Unknown Proxmark3 mode");
- return PM3_EFATAL;
-}
-
static int wait_for_ack(PacketResponseNG *ack) {
WaitForResponse(CMD_UNKNOWN, ack);
@@ -419,112 +375,6 @@ static void flash_suggest_update_flasher(void) {
_YELLOW_("update your flasher")));
}
-// Go into flashing mode
-int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *max_allowed) {
- uint32_t state;
- uint32_t chipinfo = 0;
- int ret;
-
- ret = enter_bootloader(serial_port_name);
- if (ret != PM3_SUCCESS)
- return ret;
-
- ret = get_proxmark_state(&state);
- if (ret != PM3_SUCCESS)
- return ret;
-
- if (state & DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO) {
- SendCommandBL(CMD_CHIP_INFO, 0, 0, 0, NULL, 0);
- PacketResponseNG resp;
- WaitForResponse(CMD_CHIP_INFO, &resp);
- chipinfo = resp.oldarg[0];
- }
-
- int version = BL_VERSION_INVALID;
- if (state & DEVICE_INFO_FLAG_UNDERSTANDS_VERSION) {
- SendCommandBL(CMD_BL_VERSION, 0, 0, 0, NULL, 0);
- PacketResponseNG resp;
- WaitForResponse(CMD_BL_VERSION, &resp);
- version = resp.oldarg[0];
- if ((BL_VERSION_MAJOR(version) < BL_VERSION_FIRST_MAJOR) ||
- (BL_VERSION_MAJOR(version) > BL_VERSION_LAST_MAJOR)) {
- // version info seems fishy
- version = BL_VERSION_INVALID;
- PrintAndLogEx(ERR, _RED_("====================== OBS ! ==========================="));
- PrintAndLogEx(ERR, _RED_("Note: Your bootloader reported an invalid version number"));
- flash_suggest_update_bootloader();
- //
- } else if (BL_VERSION_MAJOR(version) < BL_VERSION_MAJOR(FLASHER_VERSION)) {
- PrintAndLogEx(ERR,
- _RED_("====================== OBS ! ==================================="));
- PrintAndLogEx(ERR,
- _RED_("Note: Your bootloader reported a version older than this flasher"));
- flash_suggest_update_bootloader();
- } else if (BL_VERSION_MAJOR(version) > BL_VERSION_MAJOR(FLASHER_VERSION)) {
- PrintAndLogEx(ERR, _RED_("====================== OBS ! ========================="));
- PrintAndLogEx(ERR, _RED_("Note: Your bootloader is more recent than this flasher"));
- flash_suggest_update_flasher();
- }
- } else {
- PrintAndLogEx(ERR,
- _RED_("====================== OBS ! ==========================================="));
- PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new "
- _YELLOW_("CMD_BL_VERSION")
- _RED_("command")));
- flash_suggest_update_bootloader();
- }
-
- uint32_t flash_end = FLASH_START + AT91C_IFLASH_PAGE_SIZE * AT91C_IFLASH_NB_OF_PAGES / 2;
- *max_allowed = 256;
-
- int mem_avail = chipid_to_mem_avail(chipinfo);
- if (mem_avail != 0) {
- PrintAndLogEx(INFO, "Available memory on this board: "_YELLOW_("%uK") "bytes\n", mem_avail);
- if (mem_avail > 256) {
- if (BL_VERSION_MAJOR(version) < BL_VERSION_MAJOR(BL_VERSION_1_0_0)) {
- PrintAndLogEx(ERR, _RED_("====================== OBS ! ======================"));
- PrintAndLogEx(ERR, _RED_("Your bootloader does not support writing above 256k"));
- flash_suggest_update_bootloader();
- } else {
- flash_end = FLASH_START + AT91C_IFLASH_PAGE_SIZE * AT91C_IFLASH_NB_OF_PAGES;
- *max_allowed = mem_avail;
- }
- }
- } else {
- PrintAndLogEx(INFO, "Available memory on this board: "_RED_("UNKNOWN")"\n");
- PrintAndLogEx(ERR,
- _RED_("====================== OBS ! ======================================"));
- PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new "
- _YELLOW_("CHIP_INFO")
- _RED_("command")));
- flash_suggest_update_bootloader();
- }
-
- if (enable_bl_writes) {
- PrintAndLogEx(INFO, "Permitted flash range: 0x%08x-0x%08x", FLASH_START, flash_end);
- } else {
- PrintAndLogEx(INFO, "Permitted flash range: 0x%08x-0x%08x", BOOTLOADER_END, flash_end);
- }
- if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
- PacketResponseNG resp;
-
- if (enable_bl_writes) {
- SendCommandBL(CMD_START_FLASH, FLASH_START, flash_end, START_FLASH_MAGIC, NULL, 0);
- } else {
- SendCommandBL(CMD_START_FLASH, BOOTLOADER_END, flash_end, 0, NULL, 0);
- }
- return wait_for_ack(&resp);
- } else {
- PrintAndLogEx(ERR,
- _RED_("====================== OBS ! ========================================"));
- PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new "
- _YELLOW_("START_FLASH")
- _RED_("command")));
- flash_suggest_update_bootloader();
- }
- return PM3_SUCCESS;
-}
-
static int write_block(uint32_t address, uint8_t *data, uint32_t length) {
uint8_t block_buf[BLOCK_SIZE];
memset(block_buf, 0xFF, BLOCK_SIZE);
@@ -599,7 +449,9 @@ void flash_free(flash_file_t *ctx) {
// just reset the unit
int flash_stop_flashing(void) {
- SendCommandBL(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
+ if (conn.run) {
+ SendCommandBL(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
+ }
return PM3_SUCCESS;
}
@@ -725,15 +577,10 @@ jboolean is_bootloader_mode(JNIEnv *env, jobject thiz) {
}
jboolean flash_implement(JNIEnv *env, jobject thiz, jstring file, jboolean is_boot_rom) {
-
jclass iae_clz = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (!conn.run) {
(*env)->ThrowNew(env, iae_clz, "The pm3 client is closed, please open first.");
- return false;
- }
- if (!is_bootloader_mode(env, thiz)) {
- (*env)->ThrowNew(env, iae_clz, "The pm3 is not bootloader mode, please enter into.");
- return false;
+ goto finish;
}
const char *file_path = (*env)->GetStringUTFChars(env, file, false);
@@ -767,9 +614,6 @@ jboolean flash_implement(JNIEnv *env, jobject thiz, jstring file, jboolean is_bo
flash_free(files);
finish:
- // don't close flash mode and communication.
- // ret = flash_stop_flashing();
- // CloseProxmark();
(*env)->DeleteLocalRef(env, iae_clz);
if (filepaths[0] != NULL) free(filepaths[0]);
if (ret == PM3_SUCCESS) LOGD("All done.");
@@ -780,8 +624,8 @@ jboolean flash_implement(JNIEnv *env, jobject thiz, jstring file, jboolean is_bo
void close_proxmkar3(JNIEnv *env, jobject thiz) {
if (conn.run) {
CloseProxmark();
- deatchThread();
}
+ LOGD("关闭完成.");
}
jboolean enter_bootloader_mode(JNIEnv *env, jobject thiz) {
@@ -817,11 +661,6 @@ jboolean enter_bootloader_mode(JNIEnv *env, jobject thiz) {
SendCommandBL(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
LOGD("Press and hold down button NOW if your bootloader requires it.");
}
- msleep(100);
- CloseProxmark();
- // Let time to OS to make the port disappear
- msleep(1000);
- deatchThread();
return true;
}
return false;
@@ -835,8 +674,9 @@ jboolean open_proxmark3(JNIEnv *env, jobject thiz) {
if (conn.run) {
LOGD("设备已经是打开状态,将会跳过打开!");
return true;
+ } else {
+ LOGD("开启完成.");
}
- clearCommandBuffer();
return (jboolean) OpenProxmark("dxl", false, 233, true, FLASHMODE_SPEED);
}
diff --git a/pm3flasher/src/main/java/com/proxgrind/pm3flasher/Proxmark3Flasher.java b/pm3flasher/src/main/java/com/proxgrind/pm3flasher/Proxmark3Flasher.java
index 1985ce04..283c28bc 100644
--- a/pm3flasher/src/main/java/com/proxgrind/pm3flasher/Proxmark3Flasher.java
+++ b/pm3flasher/src/main/java/com/proxgrind/pm3flasher/Proxmark3Flasher.java
@@ -14,15 +14,24 @@ import java.io.FileNotFoundException;
* 4. If you want to flash once, must to use the {@link Proxmark3Flasher#flashModeClose()} function to restart PM3 to os mode.
* Otherwise, you don't need to call the {@link Proxmark3Flasher#flashModeClose()} function to turn off PM3's flash mode, thus flash all the firmware in once.
* 5. Due to the differences in communication between different versions of the client, we cannot verify the client version!
+ * 6. All operations should be placed in the child thread
*
* @author DXL
* @version 1.0
*/
public class Proxmark3Flasher {
- private static Proxmark3Flasher flasher;
+ private static final Proxmark3Flasher flasher;
private static String LOG = "Proxmark3Flasher";
+ /**
+ * 警告!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * 使用刷写器的时候尽量不要频繁关闭Client
+ * openProxmark3() 请在Activity -> onCreate() 中执行
+ * closeProxmark3() 请求Activity -> onDestroy() 中执行
+ * 频繁关闭客户端可能会导致JNI Crash!!!!!!!!!!!!
+ * */
+
static {
//在静态块加载对应的模块
System.loadLibrary("pm3_flasher");
@@ -42,6 +51,43 @@ public class Proxmark3Flasher {
return flasher;
}
+ public boolean start(Target target) {
+ synchronized (flasher) {
+ switch (target) {
+ case CLIENT:
+ return openProxmark3();
+ case BOOT:
+ return enterBootloader();
+ }
+ return false;
+ }
+ }
+
+ public boolean isStart(Target target) {
+ synchronized (flasher) {
+ switch (target) {
+ case CLIENT:
+ return isPM3Opened();
+ case BOOT:
+ return isBootloaderMode();
+ }
+ return false;
+ }
+ }
+
+ public void close(Target target) {
+ synchronized (flasher) {
+ switch (target) {
+ case CLIENT:
+ closeProxmark3();
+ break;
+ case BOOT:
+ flashModeClose();
+ break;
+ }
+ }
+ }
+
/**
* The pm3 client state check!
* if client is close, the UART communication will error.
@@ -49,19 +95,19 @@ public class Proxmark3Flasher {
*
* @return status, true is open, false is close.
*/
- public native boolean isPM3Opened();
+ private native boolean isPM3Opened();
/**
* Open the client of pm3(Communication basic)
*
* @return true is opened, false is open failed!
*/
- public native boolean openProxmark3();
+ private native boolean openProxmark3();
/**
* Close clint of pm3(Communication basic)
*/
- public native void closeProxmark3();
+ private native void closeProxmark3();
/**
* Request to enter bootloader mode
@@ -74,27 +120,14 @@ public class Proxmark3Flasher {
*
* @return Request result, true is the request success, false is the request failure
*/
- public native boolean enterBootloader() throws IllegalStateException;
+ private native boolean enterBootloader() throws IllegalStateException;
/**
* Check if bootloader mode is currently available
*
* @return true is available, false is unavailable
*/
- public native boolean isBootloaderMode() throws IllegalStateException;
-
- // show warning
- private void printLog() {
- Log.w(LOG, "Try not to flash bootrom and fullmg at the same time");
- }
-
- // check file
- private void checkFile(File file) throws FileNotFoundException {
- boolean pass = file.exists() && file.isFile() && file.canRead();
- if (!pass) {
- throw new FileNotFoundException("The file is no exists or can't read.");
- }
- }
+ private native boolean isBootloaderMode() throws IllegalStateException;
/**
* flash BootRom, if flash once please invoke {@link Proxmark3Flasher#flashModeClose()} behind finished.
@@ -110,7 +143,9 @@ public class Proxmark3Flasher {
e.printStackTrace();
return false;
}
- return flash(file, true);
+ synchronized (flasher) {
+ return flash(file, true);
+ }
}
/**
@@ -127,7 +162,9 @@ public class Proxmark3Flasher {
e.printStackTrace();
return false;
}
- return flash(file, false);
+ synchronized (flasher) {
+ return flash(file, false);
+ }
}
/**
@@ -141,5 +178,18 @@ public class Proxmark3Flasher {
* if you flash bootrom and fullimage same time,
* please invoke this function at all operation finished.
*/
- public native void flashModeClose();
+ private native void flashModeClose();
+
+ // show warning
+ private void printLog() {
+ Log.w(LOG, "Try not to flash bootrom and fullmg at the same time");
+ }
+
+ // check file
+ private void checkFile(File file) throws FileNotFoundException {
+ boolean pass = file.exists() && file.isFile() && file.canRead();
+ if (!pass) {
+ throw new FileNotFoundException("The file is no exists or can't read.");
+ }
+ }
}
diff --git a/pm3flasher/src/main/java/com/proxgrind/pm3flasher/Target.java b/pm3flasher/src/main/java/com/proxgrind/pm3flasher/Target.java
new file mode 100644
index 00000000..814b288c
--- /dev/null
+++ b/pm3flasher/src/main/java/com/proxgrind/pm3flasher/Target.java
@@ -0,0 +1,5 @@
+package com.proxgrind.pm3flasher;
+
+public enum Target {
+ BOOT, CLIENT
+}
diff --git a/pm3iceman/src/main/cpp/client/scripts/tnp3clone.lua b/pm3iceman/src/main/cpp/client/scripts/tnp3clone.lua
index 2e1ee701..f620ab60 100644
--- a/pm3iceman/src/main/cpp/client/scripts/tnp3clone.lua
+++ b/pm3iceman/src/main/cpp/client/scripts/tnp3clone.lua
@@ -28,7 +28,7 @@ Arguments:
-t : toytype id, 4hex symbols
-s : subtype id, 4hex symbols
- For fun, try the following subtype id:
+ For target, try the following subtype id:
0612 - Lightcore
0118 - Series 1
0138 - Series 2
diff --git a/pm3official/src/main/cpp/client/scripts/tnp3clone.lua b/pm3official/src/main/cpp/client/scripts/tnp3clone.lua
index 9441559b..3e64b092 100644
--- a/pm3official/src/main/cpp/client/scripts/tnp3clone.lua
+++ b/pm3official/src/main/cpp/client/scripts/tnp3clone.lua
@@ -28,7 +28,7 @@ Arguments:
-t : toytype id, 4hex symbols
-s : subtype id, 4hex symbols
- For fun, try the following subtype id:
+ For target, try the following subtype id:
0612 - Lightcore
0118 - Series 1
0138 - Series 2
diff --git a/pm3rdv4rrg/src/main/cpp/client/comms.c b/pm3rdv4rrg/src/main/cpp/client/comms.c
index 0f521aca..767346f4 100644
--- a/pm3rdv4rrg/src/main/cpp/client/comms.c
+++ b/pm3rdv4rrg/src/main/cpp/client/comms.c
@@ -708,7 +708,9 @@ void CloseProxmark(void) {
// Clean up our state
sp = NULL;
- memset(&communication_thread, 0, sizeof(pthread_t));
+ if (communication_thread != 0) {
+ memset(&communication_thread, 0, sizeof(pthread_t));
+ }
session.pm3_present = false;
}
diff --git a/pm3rdv4rrg/src/main/cpp/client/luascripts/tnp3clone.lua b/pm3rdv4rrg/src/main/cpp/client/luascripts/tnp3clone.lua
index 58bb5d33..f0f0f922 100644
--- a/pm3rdv4rrg/src/main/cpp/client/luascripts/tnp3clone.lua
+++ b/pm3rdv4rrg/src/main/cpp/client/luascripts/tnp3clone.lua
@@ -32,7 +32,7 @@ Arguments:
-t : toytype id, 4hex symbols
-s : subtype id, 4hex symbols
- For fun, try the following subtype id:
+ For target, try the following subtype id:
0612 - Lightcore
0118 - Series 1
0138 - Series 2
diff --git a/pm3rdv4rrg/src/main/cpp/client/proxmark3.c b/pm3rdv4rrg/src/main/cpp/client/proxmark3.c
index 88427258..160f4d22 100644
--- a/pm3rdv4rrg/src/main/cpp/client/proxmark3.c
+++ b/pm3rdv4rrg/src/main/cpp/client/proxmark3.c
@@ -998,7 +998,8 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
{"isExecuting", "()Z", (void *) isExecuting}
};
JNINativeMethod methods1[] = {
- {"testPm3", "()Z", (void *) testPm3}
+ {"testPm3", "()Z", (void *) testPm3},
+ {"closePm3", "()V", stopPm3}
};
//构建和初始化函数结构体,分别是java层的函数名称,签名,对应的函数指针
JNINativeMethod methods2[] = {
diff --git a/pm3rdv4rrg/src/main/java/cn/rrg/devices/Proxmark3RRGRdv4.java b/pm3rdv4rrg/src/main/java/cn/rrg/devices/Proxmark3RRGRdv4.java
index be593765..649bab88 100644
--- a/pm3rdv4rrg/src/main/java/cn/rrg/devices/Proxmark3RRGRdv4.java
+++ b/pm3rdv4rrg/src/main/java/cn/rrg/devices/Proxmark3RRGRdv4.java
@@ -5,6 +5,7 @@ import java.io.IOException;
import cn.rrg.com.Device;
public class Proxmark3RRGRdv4 implements Device {
+
static {
System.loadLibrary("pm3rrg_rdv4");
}
@@ -16,8 +17,11 @@ public class Proxmark3RRGRdv4 implements Device {
@Override
public boolean close() throws IOException {
- return false;
+ closePm3();
+ return true;
}
- public native boolean testPm3() throws IOException;
+ private native boolean testPm3() throws IOException;
+
+ private native void closePm3();
}