From e14e55edfafb81f2c51d588234edbda896ddb041 Mon Sep 17 00:00:00 2001 From: maxieds Date: Thu, 3 May 2018 21:44:03 -0400 Subject: [PATCH] More progress on the APDU tab (v3). --- .../chameleonminilivedebugger/ApduUtils.java | 30 ++++++++++++++++--- .../LiveLoggerActivity.java | 19 +++++++++--- .../LogEntryMetadataRecord.java | 1 + .../TabFragment.java | 2 ++ app/src/main/res/layout/apdu_tab.xml | 10 +++++-- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ApduUtils.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ApduUtils.java index a29b1e9..ac7d9c4 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/ApduUtils.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/ApduUtils.java @@ -1,6 +1,7 @@ package com.maxieds.chameleonminilivedebugger; import android.view.View; +import android.widget.TextView; import java.io.IOException; import java.util.ArrayList; @@ -222,6 +223,20 @@ public byte[] assembleAPDU() { return Utils.hexString2Bytes(apduCommand); } + public String assembleAPDUString() { + String apduCommand = CLA + INS + P1 + P2; + if(payloadData.length() == 0) { + LE = "00"; + LC = ""; + } + else { + LE = String.format("%02x", payloadData.length() / 2); + LC = "000000"; + } + apduCommand += LE + payloadData + LC; + return apduCommand; + } + public void clear() { CLA = INS = P1 = P2 = LE = LC = payloadData = "xx"; apduCmdDesc = ""; @@ -266,13 +281,15 @@ public int compareTo(APDUCommandData apdu) { } public String getSummary() { - String sstr = String.format("% 40s : %s %s %s %s %s", apduCmdDesc, CLA, INS, P1, P2, LE); + int numRHSSpaces = 45 - apduCmdDesc.length(); + String formatResp = "%s" + String.format("%" + numRHSSpaces + "s", "") + " : %s %s %s %s %s"; + String sstr = String.format(formatResp, apduCmdDesc, CLA, INS, P1, P2, LE); return sstr; } } - public static APDUCommandData apduTransceiveCmd; + public static APDUCommandData apduTransceiveCmd = new APDUCommandData(); public static APDUCommandData[] fullInsList; public static String[] fullInsDescList; public static View tabView; @@ -299,8 +316,13 @@ public static void buildFullInstructionsList() { //Arrays.sort(fullInsList); } - public static void processNewCommandSelection(View tabView) { - + public static void updateAssembledAPDUCmd() { + ((TextView) tabView.findViewById(R.id.apduCLA)).setText(apduTransceiveCmd.CLA); + ((TextView) tabView.findViewById(R.id.apduINS)).setText(apduTransceiveCmd.INS); + ((TextView) tabView.findViewById(R.id.apduP1)).setText(apduTransceiveCmd.P1); + ((TextView) tabView.findViewById(R.id.apduP2)).setText(apduTransceiveCmd.P2); + String payloadDataText = apduTransceiveCmd.payloadData.equals("") ? "NONE" : apduTransceiveCmd.payloadData; + ((TextView) tabView.findViewById(R.id.apduPayloadData)).setText(payloadDataText); } } \ No newline at end of file diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java index e7d9a88..750354c 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LiveLoggerActivity.java @@ -1461,13 +1461,24 @@ else if(selectedBytes) { } public void actionButtonApduCLA(View view) { - String CLA = ((Button) view).getText().toString(); - + String CLA = ((Button) view).getTag().toString(); + ApduUtils.apduTransceiveCmd.CLA = CLA; + ApduUtils.updateAssembledAPDUCmd(); } - public void actionButtonApduClear(View view) {} + public void actionButtonApduClear(View view) { + ApduUtils.apduTransceiveCmd.clear(); + ((TextView) ((ScrollView) ApduUtils.tabView.findViewById(R.id.apduSearchResultsScrollView)).getChildAt(0)).setText(""); + ApduUtils.updateAssembledAPDUCmd(); + } - public void actionButtonSendAPDU(View view) {} + public void actionButtonSendAPDU(View view) { + String apduCmd = ApduUtils.apduTransceiveCmd.assembleAPDUString(); + String chameleonCmd = "SEND " + apduCmd; + String respData = getSettingFromDevice(serialPort, chameleonCmd); + String logMsg = String.format("Sent %s as %s ... \nResponse: %s", ApduUtils.apduTransceiveCmd.apduCmdDesc, apduCmd, respData); + appendNewLog(LogEntryMetadataRecord.createDefaultEventRecord("APDU", logMsg)); + } public void actionButtonAPDUSearchCmd(View view) { String searchText = ((TextView) ApduUtils.tabView.findViewById(R.id.apduSearchText)).getText().toString().toLowerCase(); diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java index ab43869..f4c63c4 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/LogEntryMetadataRecord.java @@ -120,6 +120,7 @@ public View getLayoutContainer() { prefixIconMap.put("SEARCH", R.drawable.searchicon24); prefixIconMap.put("THEME", R.drawable.themecheck24); prefixIconMap.put("DUMP_MFU", R.drawable.phonebubble24); + prefixIconMap.put("APDU", R.drawable.sendarrow24v2); } /** diff --git a/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java b/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java index 8f00092..ba845ae 100644 --- a/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java +++ b/app/src/main/java/com/maxieds/chameleonminilivedebugger/TabFragment.java @@ -302,6 +302,8 @@ else if(tabNumber == TAB_APDU) { ApduUtils.tabView = inflatedView; ScrollView sv = (ScrollView) inflatedView.findViewById(R.id.apduSearchResultsScrollView); TextView tvSearchResults = new TextView(inflatedView.getContext()); + tvSearchResults.setTextSize((float) 10.0); + tvSearchResults.setTypeface(Typeface.MONOSPACE); sv.addView(tvSearchResults); } return inflatedView; diff --git a/app/src/main/res/layout/apdu_tab.xml b/app/src/main/res/layout/apdu_tab.xml index a41eb6c..019b778 100644 --- a/app/src/main/res/layout/apdu_tab.xml +++ b/app/src/main/res/layout/apdu_tab.xml @@ -149,6 +149,7 @@ android:textStyle="bold|italic" />