Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
More progress on the APDU tab (v3).
Browse files Browse the repository at this point in the history
  • Loading branch information
maxieds committed May 4, 2018
1 parent 3398aed commit e14e55e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxieds.chameleonminilivedebugger;

import android.view.View;
import android.widget.TextView;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/res/layout/apdu_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
android:textStyle="bold|italic" />

<TextView
android:id="@+id/apduCLA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
Expand All @@ -172,6 +173,7 @@
android:textStyle="bold|italic" />

<TextView
android:id="@+id/apduINS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
Expand All @@ -196,6 +198,7 @@
android:textStyle="bold|italic" />

<TextView
android:id="@+id/apduP1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
Expand All @@ -220,6 +223,7 @@
android:textStyle="bold|italic" />

<TextView
android:id="@+id/apduP2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
Expand All @@ -245,6 +249,7 @@
android:textStyle="bold|italic" />

<TextView
android:id="@+id/apduPayloadData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
Expand Down Expand Up @@ -309,6 +314,7 @@
android:background="?colorPrimaryDark" />

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
Expand All @@ -322,7 +328,7 @@
android:layout_gravity="right"
android:background="?colorAccent"
android:hint="Search by Text or Byte Strings ..."
android:paddingLeft="1dp"
android:paddingLeft="5dp"
android:singleLine="true"
android:textAllCaps="true"
android:textSize="14sp"
Expand All @@ -333,7 +339,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/searchapdu24"
android:drawablePadding="0dp"
android:drawablePadding="5dp"
android:onClick="actionButtonAPDUSearchCmd"
android:text="" />

Expand Down

0 comments on commit e14e55e

Please sign in to comment.