mirror of
https://github.com/RfidResearchGroup/RFIDtools.git
synced 2026-05-12 11:19:59 -07:00
PM3 simple terminal view recovered.
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import cn.rrg.rdv.R;
|
||||
import cn.rrg.rdv.activities.main.PM3FlasherMainActivity;
|
||||
import cn.rrg.rdv.activities.tools.DeviceConnectActivity;
|
||||
import cn.rrg.rdv.activities.tools.Proxmark3NewTerminalInitActivity;
|
||||
import cn.rrg.rdv.activities.proxmark3.rdv4_rrg.Proxmark3NewTerminalInitActivity;
|
||||
import cn.rrg.rdv.callback.ConnectFailedCtxCallback;
|
||||
import cn.rrg.rdv.models.AbstractDeviceModel;
|
||||
import cn.rrg.rdv.models.Proxmark3Rdv4SppModel;
|
||||
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package cn.rrg.rdv.activities.proxmark3.rdv4_rrg;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import cn.dxl.common.util.FileUtils;
|
||||
import cn.rrg.console.define.ICommandTools;
|
||||
import cn.rrg.console.define.ICommandType;
|
||||
import cn.rrg.freo.IORedirector;
|
||||
import cn.rrg.rdv.R;
|
||||
import cn.rrg.rdv.activities.tools.BaseConsoleActivity;
|
||||
import cn.rrg.rdv.implement.EntryICommandType;
|
||||
import cn.rrg.rdv.util.Paths;
|
||||
|
||||
public abstract class Proxmark3ConsoleActivity
|
||||
extends BaseConsoleActivity
|
||||
implements View.OnClickListener,
|
||||
CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
//滞留一个视图实例,可用如GUI,子控件实现!
|
||||
protected View guiView = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//重定向!
|
||||
IORedirector.setStdEO(Paths.PM3_FORWARD_O, IORedirector.STD_OUT);
|
||||
IORedirector.setStdEO(Paths.PM3_FORWARD_E, IORedirector.STD_ERR);
|
||||
IORedirector.setStdIN(Paths.COMMON_FORWARD_I);
|
||||
}
|
||||
}).start();
|
||||
|
||||
//父类先初初始化!
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//默认关闭错误消息输出区域(用不上...)
|
||||
ckBoxOpenOutputError.setChecked(false);
|
||||
//覆盖父类的停止按钮点击实例
|
||||
btnStop.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.btnStop) {//判断当前是否有客户端可终止的任务在执行,是的话则终止!
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//TODO 此处进行IO,模拟键盘输入!
|
||||
stopPM3Client4KeyBorad();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
//通过键盘输入结束任务!
|
||||
protected void stopPM3Client4KeyBorad() {
|
||||
FileUtils.writeString(new File(Paths.COMMON_FORWARD_I), "\n", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
//非常有必要进行相关的结束操作!
|
||||
stopPM3Client4KeyBorad();
|
||||
mCMD.stopExecute();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/*
|
||||
* 重写视图实例寻找,方便进行控制!
|
||||
* */
|
||||
@Override
|
||||
public <T extends View> T findViewById(int id) {
|
||||
T view = super.findViewById(id);
|
||||
return view != null ? view : guiView != null ? guiView.findViewById(id) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
//don't need process!!!
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getCommandGUI() {
|
||||
return guiView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File initOutTarget() {
|
||||
return new File(Paths.PM3_FORWARD_O);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File initErrTarget() {
|
||||
return new File(Paths.PM3_FORWARD_E);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int startTest(ICommandTools cmd) {
|
||||
mDefaultCMD = "help";
|
||||
if (edtInputCmd.getText().toString().length() > 0) {
|
||||
mDefaultCMD = edtInputCmd.getText().toString();
|
||||
}
|
||||
//此处做出多行执行优化!
|
||||
int ret = -2;
|
||||
//优化,如果是多行命令的操作!
|
||||
if (mDefaultCMD.contains("\n")) {
|
||||
//包含换行,则当作多行处理!
|
||||
String[] cmds = mDefaultCMD.split("\n");
|
||||
Log.d(LOG_TAG, "警告,当前执行的是多行处理操作!");
|
||||
for (String c : cmds) {
|
||||
Log.d(LOG_TAG, "当前执行的命令: " + c);
|
||||
mCMD.startExecute(c);
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
//直接执行命令并且在执行命令完成后进行回调!
|
||||
ret = cmd.startExecute(mDefaultCMD);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewOutLine(String line) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewErrLine(String line) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ICommandType initType() {
|
||||
return new EntryICommandType();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTestEnd() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTesting() {
|
||||
return super.isTesting();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stopTest() {
|
||||
//super.stopTest();
|
||||
//TODO 无必要停止PM3的底层线程!
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package cn.rrg.rdv.activities.proxmark3.rdv4_rrg;
|
||||
|
||||
import cn.rrg.console.define.ICommandTools;
|
||||
import cn.rrg.natives.Proxmark3RRGRdv4Tools;
|
||||
|
||||
public class Proxmark3Rdv4RRGConsoleActivity
|
||||
extends Proxmark3ConsoleActivity {
|
||||
|
||||
@Override
|
||||
protected ICommandTools initCMD() {
|
||||
//替换为rdv4的工具类!
|
||||
return new Proxmark3RRGRdv4Tools();
|
||||
}
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
package cn.rrg.rdv.activities.proxmark3.rdv4_rrg;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import cn.rrg.freo.IORedirector;
|
||||
import cn.rrg.rdv.R;
|
||||
import cn.rrg.rdv.adapter.EasyBtnAdapter;
|
||||
import cn.rrg.rdv.javabean.EasyCMDEntry;
|
||||
import cn.rrg.rdv.util.EasyBtnUtil;
|
||||
import cn.dxl.common.widget.DoubleInputDialog;
|
||||
import cn.dxl.common.util.ArrayUtils;
|
||||
import cn.dxl.common.widget.ToastUtil;
|
||||
import cn.dxl.common.util.ViewUtil;
|
||||
import cn.rrg.rdv.util.Paths;
|
||||
|
||||
public class Proxmark3Rdv4RRGRedTeamConsoleActivity
|
||||
extends Proxmark3Rdv4RRGConsoleActivity {
|
||||
|
||||
private GridView gridViewShowEasyButton;
|
||||
private EasyBtnAdapter adapter;
|
||||
private List<EasyCMDEntry> easyCMDEntries = new ArrayList<>();
|
||||
|
||||
//构造一个简单的对话框,用于提示需要的操作!
|
||||
private AlertDialog operaDialog;
|
||||
//显示添加按钮!
|
||||
private TextView txtAddEasyBtn;
|
||||
//缓存当前要操作的项目!
|
||||
private int operaPosition;
|
||||
//配置文件操作工具
|
||||
private EasyBtnUtil easyBtnUtil = new EasyBtnUtil();
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
btnGui.setText(getString(R.string.console_dynamic_btn));
|
||||
//隐藏不需要的区域!
|
||||
skBarConsoleViewScale.setProgress(10);
|
||||
//设置pm3的输入提示
|
||||
edtInputCmd.setHint(getString(R.string.pm3_hint));
|
||||
|
||||
//不能让用户关闭通讯!
|
||||
btnStop.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stopPM3Client4KeyBorad();
|
||||
}
|
||||
});
|
||||
|
||||
initViews();
|
||||
initActions();
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 更改工作目录!
|
||||
IORedirector.chdir(Paths.PM3_DIRECTORY);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
//先初始化视图!
|
||||
guiView = ViewUtil.inflate(this, R.layout.easy_button_container);
|
||||
|
||||
gridViewShowEasyButton = findViewById(R.id.gridViewShowEasyButton);
|
||||
adapter = new EasyBtnAdapter(this, R.layout.item_easy__btn, easyCMDEntries);
|
||||
gridViewShowEasyButton.setAdapter(adapter);
|
||||
|
||||
//添加数据!
|
||||
EasyCMDEntry[] buttons = getCMDs();
|
||||
if (buttons != null) {
|
||||
easyCMDEntries.addAll(Arrays.asList(getCMDs()));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
txtAddEasyBtn = findViewById(R.id.txtAddEasyBtn);
|
||||
}
|
||||
|
||||
private void initActions() {
|
||||
//列表项单击时执行相应的命令!
|
||||
gridViewShowEasyButton.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
//点击了对应项时,取出对应的实体,进行命令发送!
|
||||
EasyCMDEntry entry = easyCMDEntries.get(position);
|
||||
if (entry != null) {
|
||||
String cmd = entry.getCommand();
|
||||
if (cmd != null) {
|
||||
//先提交命令到输入框
|
||||
putCMDAndClosePop(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
//列表项长按时显示相关的操作项!
|
||||
gridViewShowEasyButton.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
operaDialog.show();
|
||||
operaPosition = position;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
//构建一个用于显示操作的对话框!
|
||||
operaDialog = new AlertDialog.Builder(this).setItems(new String[]{getString(R.string.delete), getString(R.string.modify)}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final EasyCMDEntry entry = easyCMDEntries.get(operaPosition);
|
||||
if (which == 0) {
|
||||
new AlertDialog.Builder(context).setTitle(R.string.warning).setMessage(getString(R.string.enter_delete)
|
||||
+ "\n\nItem name: " + entry.getCmdName())
|
||||
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//做出删除操作!
|
||||
easyCMDEntries.remove(operaPosition);
|
||||
adapter.notifyDataSetChanged();
|
||||
//TODO 本地配置删除!
|
||||
if (easyBtnUtil.deleteButton(0, operaPosition)) {
|
||||
ToastUtil.show(context, getString(R.string.success), false);
|
||||
} else {
|
||||
ToastUtil.show(context, getString(R.string.failed), false);
|
||||
}
|
||||
}
|
||||
}).setNegativeButton(getString(R.string.no), null).show();
|
||||
} else {
|
||||
//做出修改操作,先取出原来的数据!
|
||||
DoubleInputDialog inputDialog = new DoubleInputDialog(context);
|
||||
inputDialog.setTitle(R.string.button_edit);
|
||||
inputDialog.getHint1().setText(R.string.title_input);
|
||||
inputDialog.getHint2().setText(R.string.command_input);
|
||||
//设置到视图上!
|
||||
inputDialog.getEdtInput1().setText(entry.getCmdName());
|
||||
inputDialog.getEdtInput2().setText(entry.getCommand());
|
||||
//然后设置操作回调并且显示!
|
||||
inputDialog.setSaveListener(new DoubleInputDialog.OnSaveListener() {
|
||||
@Override
|
||||
public void onSave(String[] content) {
|
||||
//操作成功,进行内存更新!
|
||||
entry.setCmdName(content[0]);
|
||||
entry.setCommand(content[1]);
|
||||
adapter.notifyDataSetChanged();
|
||||
//TODO 然后进行本地更新!
|
||||
if (easyBtnUtil.updateButton(0, operaPosition, entry.getCmdName(), entry.getCommand())) {
|
||||
//现在的话已经更新成功
|
||||
ToastUtil.show(context, getString(R.string.success), false);
|
||||
} else {
|
||||
ToastUtil.show(context, getString(R.string.failed), false);
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
}).create();
|
||||
//设置添加按钮的动作!
|
||||
txtAddEasyBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//做出增加操作,构建一个实体用于保存!
|
||||
EasyCMDEntry entry = new EasyCMDEntry();
|
||||
DoubleInputDialog inputDialog = new DoubleInputDialog(context);
|
||||
inputDialog.setTitle(R.string.btn_add);
|
||||
inputDialog.getHint1().setText(R.string.title_input);
|
||||
inputDialog.getHint2().setText(R.string.command_input);
|
||||
//然后设置操作回调并且显示!
|
||||
inputDialog.setSaveListener(new DoubleInputDialog.OnSaveListener() {
|
||||
@Override
|
||||
public void onSave(String[] content) {
|
||||
//操作成功,进行内存更新!
|
||||
entry.setCmdName(content[0]);
|
||||
entry.setCommand(content[1]);
|
||||
easyCMDEntries.add(entry);
|
||||
adapter.notifyDataSetChanged();
|
||||
//TODO 然后进行本地更新!
|
||||
if (easyBtnUtil.inertButton(0, entry.getCmdName(), entry.getCommand())) {
|
||||
//现在的话已经更新成功
|
||||
ToastUtil.show(context, getString(R.string.success), false);
|
||||
} else {
|
||||
ToastUtil.show(context, getString(R.string.failed), false);
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private EasyCMDEntry[] getCMDs() {
|
||||
//默认先拿0组的按钮,以后做多组分页的时候再做其他组的处理!
|
||||
List<EasyCMDEntry> btns = easyBtnUtil.getButtons(0);
|
||||
if (btns == null) return null;
|
||||
return ArrayUtils.list2Arr(btns);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user