Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
SingulartSdk
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2.interfaces;
public interface CommandListener {
void onHeadsetPlugged();
void onHeadsetUnplug();
void onInitialSuccess();
void onGetVersion(String var1, String var2);
void onGetReaderSN(String var1, String var2);
void onSetReaderSN(String var1);
void onGetNextPackage();
void onGiveUpAction(String var1);
void onDetectBattery(String var1, String var2);
void onSetSleepTimer(String var1);
void onWriteCustomerInformation(String var1);
void onReadCustomerInformation(String var1, String var2);
void onDetectICCStatus(String var1, String var2);
void onPowerOnICC(String var1, String var2);
void onPowerOffICC(String var1);
void onAccessICC(String var1, String var2);
void onGetICCCardholderInfo(String var1, String var2);
void onGetEMVData(String var1, String var2);
void onVerifyPIN(String var1, String var2);
void onSelectEncrptMethod(String var1);
void onResetWholeKey(String var1);
void onLockWholeKey(String var1);
void onRestoreandUnlock(String var1);
void onUpdateMainKey(String var1);
void onUpdateWorkingKey(String var1);
void onSelectWorkingKey(String var1);
void onLoadInitialKeyDUKPT(String var1);
void onMagneticCardRead(String var1, String var2);
void onPICCActive(String var1, String var2);
void onPICCDeactive(String var1);
void onPICCRate(String var1, String var2);
void onPICCAccess(String var1, String var2);
void onMifareAuth(String var1);
void onMifareReadBlock(String var1, String var2);
void onMifareWriteBlock(String var1);
void onMifareIncrement(String var1);
void onMifareDecrement(String var1);
void onSetPinpadMode(String var1);
void onGetPINPress(String var1, String var2);
void onGetPINBlock(String var1, String var2);
void onGetPINBlockwithPAN(String var1, String var2);
void onGetPINBlockwithPAN12(String var1, String var2);
void onLoadRSAPublicKey(String var1);
void onMagneticCardRSARead(String var1, String var2);
void onGetMagCardholderInfo(String var1, String var2);
void onSelectICC(String var1);
void onSelectPSAM(String var1);
void onMagneticCardReadInfo(String var1, String var2);
void onReaderPowerDown(String var1);
void onGetUId(String var1, String var2);
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2.interfaces;
public interface DataListener {
void onDataReceived();
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2.interfaces;
public interface NextListener {
void onBoardReadyReceiveNext();
void onSDKReadyReceiveNext();
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.media.AudioTrack;
import android.os.SystemClock;
import android.util.Log;
import tw.com.android.singularsdk.lib2.MainPlayer;
class MainPlayer$PlayAllShorts implements Runnable {
private short[] s;
private MainPlayer$PlayAllShorts(MainPlayer var1, short[] s) {
this.this$0 = var1;
this.s = null;
this.s = s;
}
public void run() {
if(MainPlayer.access$0(this.this$0) != null) {
this.this$0.stopPlay();
}
MainPlayer.access$2(this.this$0, new AudioTrack(3, MainPlayer.SAMPLE_RATE, 12, 2, MainPlayer.access$1(this.this$0), 1));
this.this$0.setVolumeMax();
SystemClock.sleep(50L);
MainPlayer.access$0(this.this$0).play();
int sent = MainPlayer.access$0(this.this$0).write(this.s, 0, MainPlayer.access$1(this.this$0));
if(MainPlayer.access$3()) {
Log.d("JsLib", "Short sent: " + sent);
}
MainPlayer.access$0(this.this$0).flush();
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.media.AudioTrack;
import android.os.SystemClock;
import android.util.Log;
import tw.com.android.singularsdk.lib2.interfaces.NextListener;
import tw.com.android.singularsdk.lib2.util.Util;
public class MainPlayer implements NextListener {
private static boolean IS_DEBUG = false;
public static final int FREQUENCY_MODE_44 = 44100;
public static final int FREQUENCY_MODE_22 = 22050;
public static final int FREQUENCY_MODE_11 = 11025;
public static int SAMPLE_RATE = '걄';
private final int FORMAT = 2;
private final int CHANNEL = 12;
private final float MAX_VOLUME = 1.0F;
private final int CYCLE_TIME = 4;
private int CURRENT_SENT_COUNT = 0;
private String[] SEND_DATA = null;
private int BUFFER_SIZE = 0;
private AudioTrack player = null;
public MainPlayer() {
this.BUFFER_SIZE = AudioTrack.getMinBufferSize(SAMPLE_RATE, 12, 2) * 4;
if(IS_DEBUG) {
Log.d("JsLib", "Got audio focus, buffer size: " + this.BUFFER_SIZE);
}
int count = this.BUFFER_SIZE / 4;
int mod = this.BUFFER_SIZE % 4;
if(mod > 0) {
++count;
}
this.BUFFER_SIZE = count * 4;
if(IS_DEBUG) {
Log.d("JsLib", "Buffer size adjusted: " + this.BUFFER_SIZE);
}
}
public boolean setVolumeMax() {
boolean b = false;
if(this.player != null) {
try {
this.player.setStereoVolume(1.0F, 1.0F);
b = true;
} catch (Exception var3) {
var3.printStackTrace();
if(IS_DEBUG) {
Log.w("JsLib", "Set audio output to maximum volume failed, " + var3.toString());
}
b = false;
}
} else {
b = false;
}
return b;
}
public void play(String hex, boolean isCRC) {
if(isCRC) {
this.play(Util.hexStringToByteArray(Util.getCommandCRC(hex)));
} else {
this.play(Util.hexStringToByteArray(hex));
}
}
public void play(String[] str) {
this.SEND_DATA = str;
this.CURRENT_SENT_COUNT = 0;
this.playNextCommand();
}
private void playNextCommand() {
this.play(this.SEND_DATA[this.CURRENT_SENT_COUNT], true);
++this.CURRENT_SENT_COUNT;
if(this.CURRENT_SENT_COUNT >= this.SEND_DATA.length) {
this.CURRENT_SENT_COUNT = 0;
}
}
public void onBoardReadyReceiveNext() {
if(IS_DEBUG) {
Log.d("JsLib", "Sending next package..." + this.CURRENT_SENT_COUNT);
}
this.playNextCommand();
}
public void onSDKReadyReceiveNext() {
this.play("1B0003252600", true);
}
private void play(byte[] command) {
String manchesterCode = Util.manchesterEncodeToString(command);
String manchesterSyncCode = Util.addManchesterSyncCode(manchesterCode);
short[] squareWave = Util.wrapToShortSquareWave(manchesterSyncCode, this.BUFFER_SIZE);
this.play(squareWave);
}
private void play(short[] s) {
(new Thread(new MainPlayer.PlayAllShorts(s, (MainPlayer.PlayAllShorts)null))).start();
}
public void stopPlay() {
try {
this.player.flush();
this.player.stop();
this.player.release();
} catch (Exception var2) {
var2.printStackTrace();
}
}
public int getSampleRate() {
return SAMPLE_RATE;
}
public void setSampleRate(int samplerate) {
SAMPLE_RATE = samplerate;
}
private class PlayAllShorts implements Runnable {
private short[] s;
private PlayAllShorts(short[] s) {
this.s = null;
this.s = s;
}
public void run() {
if(MainPlayer.this.player != null) {
MainPlayer.this.stopPlay();
}
MainPlayer.this.player = new AudioTrack(3, MainPlayer.SAMPLE_RATE, 12, 2, MainPlayer.this.BUFFER_SIZE, 1);
MainPlayer.this.setVolumeMax();
SystemClock.sleep(50L);
MainPlayer.this.player.play();
int sent = MainPlayer.this.player.write(this.s, 0, MainPlayer.this.BUFFER_SIZE);
if(MainPlayer.IS_DEBUG) {
Log.d("JsLib", "Short sent: " + sent);
}
MainPlayer.this.player.flush();
}
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.os.Handler;
import android.os.Message;
import java.lang.ref.WeakReference;
import tw.com.android.singularsdk.lib2.MainRecorder;
class MainRecorder$DataReceiveHandler extends Handler {
WeakReference<MainRecorder> mainAct;
MainRecorder$DataReceiveHandler(MainRecorder main) {
this.mainAct = new WeakReference(main);
}
public void handleMessage(Message msg) {
MainRecorder me = (MainRecorder)this.mainAct.get();
MainRecorder.access$9(me).onDataReceived();
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.media.AudioRecord;
import android.os.Build;
import android.os.SystemClock;
import android.util.Log;
import java.util.Arrays;
import tw.com.android.singularsdk.lib2.MainRecorder;
class MainRecorder$RecClass implements Runnable {
boolean ok;
boolean run;
private MainRecorder$RecClass(MainRecorder var1) {
this.this$0 = var1;
this.ok = false;
this.run = true;
}
public void run() {
if(Build.MODEL.equalsIgnoreCase("SHV-E270L") || Build.MODEL.equalsIgnoreCase("SHV-E270K") || Build.MODEL.equalsIgnoreCase("SHV-E270S") || Build.MODEL.equalsIgnoreCase("Hol-T00") || Build.MODEL.equalsIgnoreCase("vivo Y13") || Build.MODEL.equalsIgnoreCase("vivo X3t") || Build.MODEL.equalsIgnoreCase("HUAWEI G630-T00") || Build.MODEL.equalsIgnoreCase("ZTE M901C") || Build.MODEL.equalsIgnoreCase("LNV-Lenovo A380e") || Build.MODEL.equalsIgnoreCase("XM50t")) {
MainRecorder.access$0(this.this$0, (short)1000);
}
if(MainRecorder.access$1()) {
Log.d("JsLib", "Recorder starting...");
}
try {
SystemClock.sleep(10L);
MainRecorder.access$2(this.this$0).startRecording();
this.ok = true;
} catch (Exception var8) {
var8.printStackTrace();
this.ok = false;
if(MainRecorder.access$1()) {
Log.d("JsLib", "Unable to start recorder !");
}
}
if(this.ok) {
if(MainRecorder.access$1()) {
Log.d("JsLib", "Recorder started.");
}
StringBuilder sb = new StringBuilder();
boolean sample = false;
int sampleLast = 0;
int count = 0;
boolean val = false;
boolean len = false;
while(this.run) {
Arrays.fill(MainRecorder.access$3(this.this$0), (short)0);
val = false;
len = false;
sb.delete(0, sb.length());
int var11 = MainRecorder.access$2(this.this$0).read(MainRecorder.access$3(this.this$0), 0, MainRecorder.access$4(this.this$0));
for(int i = 0; i < var11; ++i) {
short var10 = MainRecorder.access$3(this.this$0)[i];
if(Math.abs(var10) >= MainRecorder.access$5(this.this$0)) {
int var9 = var10 >= MainRecorder.access$6(this.this$0)?0:1;
if(var9 != sampleLast) {
if(count >= 5 - MainRecorder.access$7(this.this$0) && count <= 5 + MainRecorder.access$7(this.this$0)) {
sb.append(String.valueOf(sampleLast));
}
sampleLast = var9;
count = 1;
} else {
++count;
if(count == 5) {
sb.append(String.valueOf(var9));
count = 0;
}
}
}
}
if(sb.length() > 0) {
this.this$0.pushData(sb.toString());
}
}
if(MainRecorder.access$2(this.this$0) != null) {
MainRecorder.access$2(this.this$0).stop();
MainRecorder.access$2(this.this$0).release();
MainRecorder.access$8(this.this$0, (AudioRecord)null);
}
}
}
public boolean isOk() {
return this.ok;
}
public boolean isRun() {
return this.run;
}
public void setRun(boolean run) {
this.run = run;
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.media.AudioRecord;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import tw.com.android.singularsdk.lib2.MainPlayer;
import tw.com.android.singularsdk.lib2.interfaces.DataListener;
import tw.com.android.singularsdk.lib2.util.Util;
public class MainRecorder {
private static boolean IS_DEBUG = false;
private final int FORMAT = 2;
private final int CHANNEL = 16;
private final int SOURCE = 1;
private final int BUFFER_SIZE;
public static final String SYNC_MODE_POSITIVE = "01";
public static final String SYNC_MODE_NEGATIVE = "10";
private String syncMode;
private final String START_BIT_POSITIVE;
private final String START_BIT_NEGATIVE;
private final String END_BIT_POSITIVE;
private final String END_BIT_NEGATIVE;
private String COMMAND_TEMPLATE_START_BIT;
private String COMMAND_TEMPLATE_END_BIT;
private final String SYNC_END_POSITIVE;
private final String SYNC_END_NEGATIVE;
private String COMMAND_TEMPLATE_SYNC_END;
private String PATTERN_END;
private int SYNC_COUNT;
private String DATA_PATTERN;
private static final int HALF_BIT_TIME_IN = 5;
private short V_RANG;
private short V_ZERO;
private int TOLERANCE_TIME;
private StringBuilder data;
private DataListener listener;
private StringBuilder command;
private short[] buffers;
private AudioRecord recorder;
private MainRecorder.RecClass rec;
private boolean tracking;
private MainRecorder.DataReceiveHandler handDataRecv;
public MainRecorder(DataListener listener) {
this.BUFFER_SIZE = AudioRecord.getMinBufferSize(MainPlayer.SAMPLE_RATE, 16, 2);
this.syncMode = "01";
this.START_BIT_POSITIVE = "10";
this.START_BIT_NEGATIVE = "01";
this.END_BIT_POSITIVE = "01";
this.END_BIT_NEGATIVE = "10";
this.COMMAND_TEMPLATE_START_BIT = "10";
this.COMMAND_TEMPLATE_END_BIT = "01";
this.SYNC_END_POSITIVE = "111";
this.SYNC_END_NEGATIVE = "000";
this.COMMAND_TEMPLATE_SYNC_END = "111";
this.PATTERN_END = "10(.*?)01111";
this.SYNC_COUNT = 80;
this.DATA_PATTERN = "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" + this.PATTERN_END;
this.V_RANG = 1000;
this.V_ZERO = 0;
this.TOLERANCE_TIME = 2;
this.data = new StringBuilder();
this.listener = null;
this.command = null;
this.buffers = new short[this.BUFFER_SIZE];
this.recorder = null;
this.rec = null;
this.tracking = false;
this.handDataRecv = new MainRecorder.DataReceiveHandler(this);
this.listener = listener;
this.command = new StringBuilder();
}
public void setTracking(boolean tracking) {
this.tracking = tracking;
}
public String getBitMode() {
return this.syncMode;
}
public void setBitMode(String bitMode) {
this.syncMode = bitMode;
if("01".equals(bitMode)) {
this.COMMAND_TEMPLATE_START_BIT = "10";
this.COMMAND_TEMPLATE_END_BIT = "01";
this.COMMAND_TEMPLATE_SYNC_END = "111";
this.PATTERN_END = "10(.*?)01111";
this.DATA_PATTERN = "";
}
if("10".equals(bitMode)) {
this.COMMAND_TEMPLATE_START_BIT = "01";
this.COMMAND_TEMPLATE_END_BIT = "10";
this.COMMAND_TEMPLATE_SYNC_END = "000";
this.PATTERN_END = "01(.*?)10000";
}
this.setSyncCount(80);
if(IS_DEBUG) {
Log.i("JsLib", "TempStert: " + this.COMMAND_TEMPLATE_START_BIT);
Log.i("JsLib", "TempEnd: " + this.COMMAND_TEMPLATE_END_BIT);
Log.i("JsLib", "TempSyncEnd: " + this.COMMAND_TEMPLATE_SYNC_END);
Log.i("JsLib", "PatternEnd: " + this.PATTERN_END);
Log.i("JsLib", "Pattern: " + this.DATA_PATTERN);
}
}
public short getVRange() {
return this.V_RANG;
}
public void setVRange(short s) {
this.V_RANG = s;
}
public int getSyncCount() {
return this.SYNC_COUNT;
}
public void setSyncCount(int count) {
String patternStart = "";
int i;
if("01".equals(this.syncMode)) {
for(i = 0; i < count; ++i) {
patternStart = patternStart + "01";
}
}
if("10".equals(this.syncMode)) {
for(i = 0; i < count; ++i) {
patternStart = patternStart + "10";
}
}
this.DATA_PATTERN = patternStart + this.PATTERN_END;
}
public boolean init() {
boolean b = false;
try {
this.recorder = new AudioRecord(1, MainPlayer.SAMPLE_RATE, 16, 2, this.BUFFER_SIZE);
b = true;
this.rec = new MainRecorder.RecClass((MainRecorder.RecClass)null);
} catch (Exception var5) {
var5.printStackTrace();
try {
this.recorder.release();
} catch (Exception var4) {
var4.printStackTrace();
}
b = false;
}
return b;
}
public void startRecord() {
if(this.rec != null) {
(new Thread(this.rec)).start();
}
}
public void stopRecord() {
this.rec.setRun(false);
}
public boolean isRecording() {
return this.rec != null?this.rec.isOk() && this.rec.isRun():false;
}
public synchronized void pushData(String d) {
if(!d.equals("")) {
this.data.append(d);
if(IS_DEBUG && this.tracking) {
Log.d("JsLib", "Data in queue: " + this.data.toString());
}
int endBit = this.data.indexOf(new String(this.COMMAND_TEMPLATE_END_BIT + this.COMMAND_TEMPLATE_SYNC_END));
if(endBit != -1) {
this.parseData(this.data.toString());
this.data.delete(0, this.data.length());
}
}
}
private void parseData(String str) {
Pattern p = Pattern.compile(this.DATA_PATTERN);
Matcher m = p.matcher(str);
if(m.find()) {
String str2 = new String(this.COMMAND_TEMPLATE_START_BIT + m.group(1) + this.COMMAND_TEMPLATE_END_BIT);
String tmp = "";
String start = "";
String end = "";
for(int i = 0; i < str2.length(); i += 20) {
try {
tmp = str2.substring(i, i + 20);
} catch (IndexOutOfBoundsException var12) {
tmp = str2.substring(i, str2.length());
}
start = tmp.substring(0, 2);
end = tmp.substring(tmp.length() - 2, tmp.length());
if(this.COMMAND_TEMPLATE_START_BIT.equals(start) && this.COMMAND_TEMPLATE_END_BIT.equals(end)) {
String data = tmp.substring(2, tmp.length() - 2);
try {
String obe = Util.binaryToHex(Util.manchesterToBin(data, this.syncMode));
this.command.append(obe);
} catch (StringIndexOutOfBoundsException var11) {
var11.printStackTrace();
}
}
}
this.handDataRecv.sendEmptyMessage(0);
}
}
public String getCommand() {
return this.command.toString().toUpperCase();
}
public void clearCommand() {
this.command.delete(0, this.command.length());
}
static class DataReceiveHandler extends Handler {
WeakReference<MainRecorder> mainAct;
DataReceiveHandler(MainRecorder main) {
this.mainAct = new WeakReference(main);
}
public void handleMessage(Message msg) {
MainRecorder me = (MainRecorder)this.mainAct.get();
me.listener.onDataReceived();
}
}
private class RecClass implements Runnable {
boolean ok;
boolean run;
private RecClass() {
this.ok = false;
this.run = true;
}
public void run() {
if(Build.MODEL.equalsIgnoreCase("SHV-E270L") || Build.MODEL.equalsIgnoreCase("SHV-E270K") || Build.MODEL.equalsIgnoreCase("SHV-E270S") || Build.MODEL.equalsIgnoreCase("Hol-T00") || Build.MODEL.equalsIgnoreCase("vivo Y13") || Build.MODEL.equalsIgnoreCase("vivo X3t") || Build.MODEL.equalsIgnoreCase("HUAWEI G630-T00") || Build.MODEL.equalsIgnoreCase("ZTE M901C") || Build.MODEL.equalsIgnoreCase("LNV-Lenovo A380e") || Build.MODEL.equalsIgnoreCase("XM50t")) {
MainRecorder.this.V_RANG = 1000;
}
if(MainRecorder.IS_DEBUG) {
Log.d("JsLib", "Recorder starting...");
}
try {
SystemClock.sleep(10L);
MainRecorder.this.recorder.startRecording();
this.ok = true;
} catch (Exception var8) {
var8.printStackTrace();
this.ok = false;
if(MainRecorder.IS_DEBUG) {
Log.d("JsLib", "Unable to start recorder !");
}
}
if(this.ok) {
if(MainRecorder.IS_DEBUG) {
Log.d("JsLib", "Recorder started.");
}
StringBuilder sb = new StringBuilder();
boolean sample = false;
int sampleLast = 0;
int count = 0;
boolean val = false;
boolean len = false;
while(this.run) {
Arrays.fill(MainRecorder.this.buffers, (short)0);
val = false;
len = false;
sb.delete(0, sb.length());
int var11 = MainRecorder.this.recorder.read(MainRecorder.this.buffers, 0, MainRecorder.this.BUFFER_SIZE);
for(int i = 0; i < var11; ++i) {
short var10 = MainRecorder.this.buffers[i];
if(Math.abs(var10) >= MainRecorder.this.V_RANG) {
int var9 = var10 >= MainRecorder.this.V_ZERO?0:1;
if(var9 != sampleLast) {
if(count >= 5 - MainRecorder.this.TOLERANCE_TIME && count <= 5 + MainRecorder.this.TOLERANCE_TIME) {
sb.append(String.valueOf(sampleLast));
}
sampleLast = var9;
count = 1;
} else {
++count;
if(count == 5) {
sb.append(String.valueOf(var9));
count = 0;
}
}
}
}
if(sb.length() > 0) {
MainRecorder.this.pushData(sb.toString());
}
}
if(MainRecorder.this.recorder != null) {
MainRecorder.this.recorder.stop();
MainRecorder.this.recorder.release();
MainRecorder.this.recorder = null;
}
}
}
public boolean isOk() {
return this.ok;
}
public boolean isRun() {
return this.run;
}
public void setRun(boolean run) {
this.run = run;
}
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import tw.com.android.singularsdk.lib2.SingularLib;
class SingularLib$HeadsetIntentReceiver extends BroadcastReceiver {
private SingularLib$HeadsetIntentReceiver(SingularLib var1) {
this.this$0 = var1;
}
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.intent.action.HEADSET_PLUG")) {
int state = intent.getIntExtra("state", -1);
switch(state) {
case 0:
if(SingularLib.access$0(this.this$0) != null) {
SingularLib.access$0(this.this$0).onHeadsetUnplug();
}
break;
case 1:
if(SingularLib.access$0(this.this$0) != null) {
SingularLib.access$0(this.this$0).onHeadsetPlugged();
}
break;
default:
if(SingularLib.access$1()) {
Log.d("JsLib", "No idea what the headset state is...");
}
}
}
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.os.SystemClock;
import android.util.Log;
import tw.com.android.singularsdk.lib2.MainPlayer;
import tw.com.android.singularsdk.lib2.MainRecorder;
import tw.com.android.singularsdk.lib2.interfaces.CommandListener;
import tw.com.android.singularsdk.lib2.interfaces.DataListener;
import tw.com.android.singularsdk.lib2.interfaces.NextListener;
import tw.com.android.singularsdk.lib2.util.Commands;
import tw.com.android.singularsdk.lib2.util.DESUtil;
import tw.com.android.singularsdk.lib2.util.Util;
public class SingularLib implements DataListener, OnAudioFocusChangeListener {
private static boolean IS_DEBUG = false;
private String BDK = "0123456789ABCDEFFEDCBA9876543210";
private String KSN = "FFFF9876543210E00000";
public static final String PASSWORD_ENCRYPT_NONE = "00";
public static final String PASSWORD_ENCRYPT_DES = "10";
public static final String PASSWORD_ENCRYPT_3DES_16_Byte = "20";
public static final String PASSWORD_ENCRYPT_3DES_24_Byte = "21";
public static final String PASSWORD_ENCRYPT_AES_16_Byte = "30";
public static final String PASSWORD_ENCRYPT_AES_24_Byte = "31";
public static final String PASSWORD_ENCRYPT_AES_32_Byte = "32";
public static final String PASSWORD_ENCRYPT_DUKPT = "40";
public static final String PASSWORD_ENCRYPT_RSA = "50";
public static final String DATA_CRC_ERROR = "CRC_ERROR";
private int MAX_COMMAND_LENGTH = 54;
public static final String TAG = "JsLib";
private Context context = null;
private SingularLib.HeadsetIntentReceiver headRec = null;
private boolean listenHeadset = false;
private MainPlayer player = null;
private MainRecorder recorder = null;
private AudioManager audioManager;
private CommandListener cmdCall = null;
private NextListener nextCall = null;
private String currentAction = "";
private StringBuilder sb = new StringBuilder();
public SingularLib(Context context_lib, boolean listenHeadset, int samplerate) throws Exception {
this.player = new MainPlayer();
this.player.setSampleRate(samplerate);
this.nextCall = this.player;
this.context = context_lib;
this.listenHeadset = listenHeadset;
if(listenHeadset) {
this.resumeListenHeadset();
}
}
public boolean getAudioFocus() {
this.audioManager = (AudioManager)this.context.getSystemService("audio");
int result = this.audioManager.requestAudioFocus(this, 3, 1);
if(result != 1) {
if(IS_DEBUG) {
Log.d("JsLib", "Can\'t get audio focus !!");
}
return false;
} else {
return true;
}
}
public void resumeListenHeadset() {
this.headRec = new SingularLib.HeadsetIntentReceiver((SingularLib.HeadsetIntentReceiver)null);
IntentFilter filter = new IntentFilter("android.intent.action.HEADSET_PLUG");
this.context.registerReceiver(this.headRec, filter);
}
public void pauseListenHeadset() {
try {
this.context.unregisterReceiver(this.headRec);
} catch (Exception var2) {
var2.printStackTrace();
if(IS_DEBUG) {
Log.w("JsLib", "Headset listener is null or didn\'t enable.");
}
}
}
public void setCommandListener(CommandListener commandListener) {
this.cmdCall = commandListener;
}
public void initRecord() throws Exception {
this.recorder = new MainRecorder(this);
if(this.recorder.init()) {
if(IS_DEBUG) {
Log.d("JsLib", "Recorder init. ok !");
}
this.recorder.startRecord();
} else {
throw new Exception("Init record error!");
}
}
public void stop() {
try {
this.player.stopPlay();
this.recorder.stopRecord();
this.player = null;
} catch (Exception var3) {
var3.printStackTrace();
}
if(this.listenHeadset) {
try {
this.context.unregisterReceiver(this.headRec);
} catch (Exception var2) {
var2.printStackTrace();
}
}
}
public String getSyncMode() throws IllegalStateException {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
return this.recorder.getBitMode();
}
}
public void setSyncMode(String syncMode) throws IllegalStateException {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
this.recorder.setBitMode(syncMode);
}
}
public void startTracking() {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
this.recorder.setTracking(true);
}
}
public void stopTracking() {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
this.recorder.setTracking(false);
}
}
public short getRecorderVRange() {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
return this.recorder.getVRange();
}
}
public void setRecorderVRange(short s) {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
this.recorder.setVRange(s);
}
}
public int getCommandLength() {
return this.MAX_COMMAND_LENGTH + 12;
}
public int setCommandLength(int length) {
if(length > 32 || length < 6) {
length = 32;
}
this.MAX_COMMAND_LENGTH = length * 2 - 10;
return length;
}
public int getSyncCount() {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
return this.recorder.getSyncCount();
}
}
public int setSyncCount(int count) {
if(this.recorder == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
if(count > 80 || count < 40) {
count = 80;
}
this.recorder.setSyncCount(count);
return count;
}
}
public int getSampleRate() {
if(this.player == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
return this.player.getSampleRate();
}
}
public int setSampleRate(int samplerate) {
if(this.player == null) {
throw new IllegalStateException("JsLib recorder is null, you should call initRecord() at first.");
} else {
this.player.setSampleRate(samplerate);
Log.d("lib_samplerate()", Integer.toString(samplerate));
return samplerate;
}
}
public String getLibraryVersion() {
String version = "SComboReaderII_Lib_V1.4";
return version;
}
public boolean requestAudioFocus() {
try {
return 1 == this.audioManager.requestAudioFocus(this, 3, 1);
} catch (Exception var2) {
var2.printStackTrace();
return false;
}
}
public boolean abandonAudioFocus() {
try {
return 1 == this.audioManager.abandonAudioFocus(this);
} catch (Exception var2) {
var2.printStackTrace();
return false;
}
}
public void onAudioFocusChange(int focusChange) {
switch(focusChange) {
case -3:
case -2:
case -1:
case 0:
case 1:
default:
}
}
public void cmdInitial() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[0].split(";")[2];
this.player.play(Commands.COPMMANDS[0].split(";")[0], false);
}
public void cmdGetVer() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[1].split(";")[2];
this.player.play(Commands.COPMMANDS[1].split(";")[0], true);
}
public void cmdGetReaderSN() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[2].split(";")[2];
this.player.play(Commands.COPMMANDS[2].split(";")[0], true);
}
public void cmdSetReaderSN(String sn) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[3].split(";")[2];
String cmd = Commands.COPMMANDS[3].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex(sn.length() / 2 + 2));
cmd = cmd.replaceAll("<DATA>", sn);
this.player.play(cmd, true);
}
public void cmdGiveUpAction() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[4].split(";")[2];
this.player.play(Commands.COPMMANDS[4].split(";")[0], true);
}
public void cmdDetectBattery() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[5].split(";")[2];
this.player.play(Commands.COPMMANDS[5].split(";")[0], true);
}
public void cmdSetSleepTimer(int time) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[6].split(";")[2];
String cmd = Commands.COPMMANDS[6].split(";")[0];
cmd = cmd.replaceAll("TT", Util.intToHex(time));
this.player.play(cmd, true);
}
public void cmdWriteCustomerInformation(String index, String information) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[7].split(";")[2];
String cmd = Commands.COPMMANDS[7].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((index.length() + information.length()) / 2 + 2));
cmd = cmd.replaceAll("II", index);
cmd = cmd.replaceAll("<DATA>", information);
this.player.play(cmd, true);
}
public void cmdReadCustomerInformation(String index) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[8].split(";")[2];
String cmd = Commands.COPMMANDS[8].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex(index.length() / 2 + 2));
cmd = cmd.replaceAll("II", index);
this.player.play(cmd, true);
}
public void cmdDetectICCStatus() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[9].split(";")[2];
this.player.play(Commands.COPMMANDS[9].split(";")[0], true);
}
public void cmdPowerOnICC() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[10].split(";")[2];
this.player.play(Commands.COPMMANDS[10].split(";")[0], true);
}
public void cmdPowerOffICC() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[11].split(";")[2];
this.player.play(Commands.COPMMANDS[11].split(";")[0], true);
}
public void cmdAccessICC(String c_apdu) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[12].split(";")[2];
String cmd = Commands.COPMMANDS[12].split(";")[0];
String[] strA = Util.splitCommandInLength(cmd, c_apdu, this.MAX_COMMAND_LENGTH);
this.player.play(strA);
}
public void cmdGetICCCardholderInfo() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[13].split(";")[2];
this.player.play(Commands.COPMMANDS[13].split(";")[0], true);
}
public void cmdGetEMVData() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[14].split(";")[2];
this.player.play(Commands.COPMMANDS[14].split(";")[0], true);
}
public void cmdVerifyPIN() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[15].split(";")[2];
this.player.play(Commands.COPMMANDS[15].split(";")[0], true);
}
public void cmdSelectEncrptMethod(String encrypt_method) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[16].split(";")[2];
String cmd = Commands.COPMMANDS[16].split(";")[0];
cmd = cmd.replaceAll("EE", encrypt_method);
this.player.play(cmd, true);
}
public void cmdResetWholeKey() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[17].split(";")[2];
this.player.play(Commands.COPMMANDS[17].split(";")[0], true);
}
public void cmdLockWholeKey() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[18].split(";")[2];
this.player.play(Commands.COPMMANDS[18].split(";")[0], true);
}
public void cmdRestoreandUnlock(String verify_mkey) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[19].split(";")[2];
String cmd = Commands.COPMMANDS[19].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex(verify_mkey.length() / 2 + 2));
cmd = cmd.replaceAll("<DATA>", verify_mkey);
this.player.play(cmd, true);
}
public void cmdUpdateMainKey(String mlndex, String verify_mkey, String update_mkey) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[20].split(";")[2];
String cmd = Commands.COPMMANDS[20].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((mlndex.length() + verify_mkey.length() + update_mkey.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", mlndex + verify_mkey + update_mkey);
this.player.play(cmd, true);
}
public void cmdUpdateWorkingKey(String mlndex, String wlndex, String verify_mkey, String update_wkey) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[21].split(";")[2];
String cmd = Commands.COPMMANDS[21].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((mlndex.length() + wlndex.length() + verify_mkey.length() + update_wkey.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", mlndex + wlndex + verify_mkey + update_wkey);
this.player.play(cmd, true);
}
public void cmdSelectWorkingKey(String mlndex, String wlndex) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[22].split(";")[2];
String cmd = Commands.COPMMANDS[22].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((mlndex.length() + wlndex.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", mlndex + wlndex);
this.player.play(cmd, true);
}
public void cmdLoadInitialKeyDUKPT(String ksn, String ipek) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[23].split(";")[2];
String cmd = Commands.COPMMANDS[23].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((ksn.length() + ipek.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", ksn + ipek);
this.player.play(cmd, true);
}
public void cmdMagneticCardRead() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[24].split(";")[2];
this.player.play(Commands.COPMMANDS[24].split(";")[0], true);
}
public void cmdPICCActive() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[25].split(";")[2];
this.player.play(Commands.COPMMANDS[25].split(";")[0], true);
}
public void cmdPICCDeactive() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[26].split(";")[2];
this.player.play(Commands.COPMMANDS[26].split(";")[0], true);
}
public void cmdPICCRate() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[27].split(";")[2];
this.player.play(Commands.COPMMANDS[27].split(";")[0], true);
}
public void cmdPICCAccess(String c_apdu) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[28].split(";")[2];
String cmd = Commands.COPMMANDS[28].split(";")[0];
String[] strA = Util.splitCommandInLength(cmd, c_apdu, this.MAX_COMMAND_LENGTH);
this.player.play(strA);
}
public void cmdMifareAuth(String ktype, String sector, String key) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[29].split(";")[2];
String cmd = Commands.COPMMANDS[29].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((ktype.length() + sector.length() + key.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", ktype + sector + key);
this.player.play(cmd, true);
}
public void cmdMifareReadBlock(String block) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[30].split(";")[2];
String cmd = Commands.COPMMANDS[30].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex(block.length() / 2 + 2));
cmd = cmd.replaceAll("<DATA>", block);
this.player.play(cmd, true);
}
public void cmdMifareWriteBlock(String block, String mifare_data) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[31].split(";")[2];
String cmd = Commands.COPMMANDS[31].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((block.length() + mifare_data.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", block + mifare_data);
this.player.play(cmd, true);
}
public void cmdMifareIncrement(String block, String inc_data) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[32].split(";")[2];
String cmd = Commands.COPMMANDS[32].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((block.length() + inc_data.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", block + inc_data);
this.player.play(cmd, true);
}
public void cmdMifareDecrement(String block, String dec_data) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[33].split(";")[2];
String cmd = Commands.COPMMANDS[33].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex((block.length() + dec_data.length()) / 2 + 2));
cmd = cmd.replaceAll("<DATA>", block + dec_data);
this.player.play(cmd, true);
}
public void cmdSetPinpadMode(int length, int timeout) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[34].split(";")[2];
String cmd = Commands.COPMMANDS[34].split(";")[0];
cmd = cmd.replaceAll("LL", Util.intToHex(length));
cmd = cmd.replaceAll("TT", Util.intToHex(timeout));
this.player.play(cmd, true);
}
public void cmdGetPINPress() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[35].split(";")[2];
this.player.play(Commands.COPMMANDS[35].split(";")[0], true);
}
public void cmdGetPINBlock() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[36].split(";")[2];
this.player.play(Commands.COPMMANDS[36].split(";")[0], true);
}
public void cmdGetPINBlockwithPAN(String pin) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[37].split(";")[2];
String cmd = Commands.COPMMANDS[37].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex(pin.length() / 2 + 2));
cmd = cmd.replaceAll("<DATA>", pin);
this.player.play(cmd, true);
}
public void cmdGetPINBlockwithPAN12(String pin) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[38].split(";")[2];
String cmd = Commands.COPMMANDS[38].split(";")[0];
cmd = cmd.replaceAll("NN", Util.intToHex(pin.length() / 2 + 2));
cmd = cmd.replaceAll("<DATA>", pin);
this.player.play(cmd, true);
}
public void cmdLoadRSAPublicKey(String exponent, String modulus) {
this.clearAll();
String pindex_pkey = "00A10" + exponent + "A2" + modulus;
this.currentAction = Commands.COPMMANDS[39].split(";")[2];
String cmd = Commands.COPMMANDS[39].split(";")[0];
String[] strA = Util.splitCommandInLength(cmd, pindex_pkey, this.MAX_COMMAND_LENGTH);
this.player.play(strA);
}
public void cmdMagneticCardRSARead() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[40].split(";")[2];
this.player.play(Commands.COPMMANDS[40].split(";")[0], true);
}
public void cmdGetMagCardholderInfo() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[41].split(";")[2];
this.player.play(Commands.COPMMANDS[41].split(";")[0], true);
}
public void cmdSelectICC() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[42].split(";")[2];
this.player.play(Commands.COPMMANDS[42].split(";")[0], true);
}
public void cmdSelectPSAM() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[43].split(";")[2];
this.player.play(Commands.COPMMANDS[43].split(";")[0], true);
}
public void cmdMagneticCardReadInfo(String data) {
this.clearAll();
this.currentAction = Commands.COPMMANDS[44].split(";")[2];
String cmd = Commands.COPMMANDS[44].split(";")[0];
String[] strA = Util.splitCommandInLength(cmd, data, this.MAX_COMMAND_LENGTH);
this.player.play(strA);
}
public void cmdGetUID() {
this.clearAll();
this.currentAction = Commands.COPMMANDS[46].split(";")[2];
this.player.play(Commands.COPMMANDS[46].split(";")[0], true);
}
public void SetBDK(String bdk_b) {
this.BDK = bdk_b;
}
public String GetBDK() {
return this.BDK;
}
public void SetKSN(String ksn_b) {
this.KSN = ksn_b;
}
public String GetKSN() {
return this.KSN;
}
public String GenerateIPEK(String bdk_b, String ksn_b) {
String bdk = bdk_b.replace(" ", "");
String ksn = ksn_b.replace(" ", "");
String ipek0 = ksn.substring(0, 16);
if(IS_DEBUG) {
Log.v("JsLib", " ipek0 =" + ipek0);
}
ipek0 = DESUtil.encryptionTriDes(bdk, ipek0);
if(IS_DEBUG) {
Log.v("JsLib", " ipek0 =" + ipek0);
}
String ipek8 = ksn.substring(0, 16);
if(IS_DEBUG) {
Log.v("JsLib", " ipek8 =" + ipek8);
}
byte[] nk = Util.hexStringToByteArray(bdk);
for(int ipek = 0; ipek < 4; ++ipek) {
nk[ipek] = (byte)(nk[ipek] ^ 192);
nk[ipek + 8] = (byte)(nk[ipek + 8] ^ 192);
}
ipek8 = DESUtil.encryptionTriDes(Util.bytesToHexString(nk), ipek8);
if(IS_DEBUG) {
Log.v("JsLib", " ipek8 =" + ipek8);
Log.v("JsLib", " Util.bytesToHexString(nk) =" + Util.bytesToHexString(nk));
}
String var9 = ipek0.substring(0, 2) + " " + ipek0.substring(2, 4) + " " + ipek0.substring(4, 6) + " " + ipek0.substring(6, 8) + " " + ipek0.substring(8, 10) + " " + ipek0.substring(10, 12) + " " + ipek0.substring(12, 14) + " " + ipek0.substring(14, 16) + " " + ipek8.substring(0, 2) + " " + ipek8.substring(2, 4) + " " + ipek8.substring(4, 6) + " " + ipek8.substring(6, 8) + " " + ipek8.substring(8, 10) + " " + ipek8.substring(10, 12) + " " + ipek8.substring(12, 14) + " " + ipek8.substring(14, 16);
return var9;
}
public String GenerateCTKey(String ipek, String ksn) {
String ipek2 = ipek.replace(" ", "");
byte[] current_key = Util.hexStringToByteArray(ipek2);
String r8 = ksn.substring(0, 16);
byte[] b_r8 = Util.hexStringToByteArray(r8);
b_r8[6] = b_r8[7] = 0;
b_r8[5] = (byte)(b_r8[5] & 224);
byte[] b_ksn = Util.hexStringToByteArray(ksn);
long R3 = (long)(b_ksn[7] | (b_ksn[6] & 255) << 8 | (b_ksn[5] & 31) << 16);
long SR = 1048576L;
byte[] R8A = new byte[8];
byte[] R8B = new byte[8];
do {
if((SR & R3) != 0L) {
b_r8[5] = (byte)((int)((long)b_r8[5] | SR >>> 16 & 31L));
b_r8[6] = (byte)((int)((long)b_r8[6] | SR >>> 8 & 255L));
b_r8[7] = (byte)((int)((long)b_r8[7] | SR & 255L));
for(int s_R8A = 0; s_R8A < 8; ++s_R8A) {
R8A[s_R8A] = (byte)(current_key[8 + s_R8A] ^ b_r8[s_R8A]);
}
String var17 = DESUtil.encryptionDes(Util.bytesToHexString(current_key), Util.bytesToHexString(R8A));
R8A = Util.hexStringToByteArray(var17);
int s_R8B;
for(s_R8B = 0; s_R8B < 8; ++s_R8B) {
R8A[s_R8B] = (byte)(R8A[s_R8B] & 255 ^ current_key[8 + s_R8B] & 255);
}
for(s_R8B = 0; s_R8B < 4; ++s_R8B) {
current_key[s_R8B] = (byte)(current_key[s_R8B] ^ 192);
current_key[s_R8B + 8] = (byte)(current_key[s_R8B + 8] ^ 192);
}
for(s_R8B = 0; s_R8B < 8; ++s_R8B) {
R8B[s_R8B] = (byte)(current_key[8 + s_R8B] & 255 ^ b_r8[s_R8B] & 255);
}
String var18 = DESUtil.encryptionDes(Util.bytesToHexString(current_key), Util.bytesToHexString(R8B));
R8B = Util.hexStringToByteArray(var18);
int i;
for(i = 0; i < 8; ++i) {
R8B[i] = (byte)(R8B[i] ^ current_key[i + 8] & 255);
}
for(i = 0; i < 8; ++i) {
current_key[i + 8] = R8A[i];
}
for(i = 0; i < 8; ++i) {
current_key[i] = R8B[i];
}
}
SR >>= 1;
} while(SR > 0L);
current_key[7] = (byte)(current_key[7] ^ 255);
current_key[15] = (byte)(current_key[15] ^ 255);
return Util.bytesToHexString(current_key);
}
public String[] splitMagneticCardData(String data) {
String[] ret = new String[4];
ret[0] = data;
if(IS_DEBUG) {
Log.d("JsLib", "data" + Util.hexToASCII(data));
}
data = new String(data);
data = data.replaceAll("A1", "").replaceAll("A2", ";").replaceAll("A3", ";");
try {
String[] e = data.split(";", 3);
if(!e[0].equals("") && !e[0].equals("F5")) {
if(!e[0].equals("F1") && !e[0].equals("F2") && !e[0].equals("F3") && !e[0].equals("F4")) {
ret[1] = Util.hexToASCII(e[0]);
} else {
ret[1] = "T1 Error";
}
} else {
ret[1] = "T1 Empty";
}
if(!e[1].equals("") && !e[1].equals("F5")) {
if(!e[1].equals("F1") && !e[1].equals("F2") && !e[1].equals("F3") && !e[1].equals("F4")) {
ret[2] = Util.hexToASCII(e[1]);
} else {
ret[2] = "T2 Error";
}
} else {
ret[2] = "T2 Empty";
}
if(!e[2].equals("") && !e[2].equals("F5")) {
if(!e[2].equals("F1") && !e[2].equals("F2") && !e[2].equals("F3") && !e[2].equals("F4")) {
ret[3] = Util.hexToASCII(e[2]);
} else {
ret[3] = "T3 Error";
}
} else {
ret[3] = "T3 Empty";
}
return ret;
} catch (Exception var4) {
var4.printStackTrace();
return new String[]{""};
}
}
private void clearAll() {
this.sb.delete(0, this.sb.length());
this.recorder.clearCommand();
}
public void onDataReceived() {
String s = this.recorder.getCommand();
if(IS_DEBUG) {
Log.d("JsLib", "Command received: " + this.recorder.getCommand());
}
int count;
int maxLen;
if(Commands.COPMMANDS[0].split(";")[2].equals(this.currentAction)) {
if(Commands.COPMMANDS[0].split(";")[1].equals(s)) {
this.cmdCall.onInitialSuccess();
this.clearAll();
}
} else if(Commands.COPMMANDS[1].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetVersion(Commands.getResponseMessage(s), Util.hexToASCII(Commands.getDataParameters(s)));
this.clearAll();
} else {
this.cmdCall.onGetVersion(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetVersion(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[2].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetReaderSN(Commands.getResponseMessage(s), Commands.getDataParameters(s));
if(IS_DEBUG) {
Log.d("JsLib", "GetReaderSN received: " + Commands.getResponseMessage(s) + Commands.getDataParameters(s));
}
this.clearAll();
} else {
this.cmdCall.onGetReaderSN(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetReaderSN(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[3].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onSetReaderSN(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[4].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onGiveUpAction(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[5].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onDetectBattery(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onDetectBattery(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onDetectBattery(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[6].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onSetSleepTimer(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[7].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onWriteCustomerInformation(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[8].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onReadCustomerInformation(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onReadCustomerInformation(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onReadCustomerInformation(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[9].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onDetectICCStatus(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onDetectICCStatus(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onDetectICCStatus(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[10].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onPowerOnICC(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onPowerOnICC(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onPowerOnICC(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[11].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onPowerOffICC(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[12].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
if(Util.haveNextPackageToSend(s)) {
SystemClock.sleep(500L);
this.nextCall.onBoardReadyReceiveNext();
this.clearAll();
} else if(Util.isPackageFinished(s)) {
this.sb.append(Commands.getDataParameters(s));
this.cmdCall.onAccessICC(Commands.getResponseMessage(s), this.sb.toString());
this.clearAll();
} else {
this.sb.append(Commands.getDataParameters(s));
this.nextCall.onSDKReadyReceiveNext();
this.cmdCall.onGetNextPackage();
this.recorder.clearCommand();
}
} else {
this.cmdCall.onAccessICC(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onAccessICC(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[13].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetICCCardholderInfo(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetICCCardholderInfo(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetICCCardholderInfo(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[14].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(2, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetEMVData(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetEMVData(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetEMVData(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[15].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onVerifyPIN(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onVerifyPIN(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onVerifyPIN(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[16].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onSelectEncrptMethod(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[17].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onResetWholeKey(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[18].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onLockWholeKey(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[19].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onRestoreandUnlock(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[20].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onUpdateMainKey(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[21].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onUpdateWorkingKey(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[22].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onSelectWorkingKey(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[23].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onLoadInitialKeyDUKPT(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[24].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
if(Util.haveNextPackageToSend(s)) {
this.nextCall.onBoardReadyReceiveNext();
this.clearAll();
} else if(Util.isPackageFinished(s)) {
this.sb.append(Commands.getDataParameters(s));
this.cmdCall.onMagneticCardRead(Commands.getResponseMessage(s), this.sb.toString());
this.clearAll();
} else {
this.sb.append(Commands.getDataParameters(s));
this.nextCall.onSDKReadyReceiveNext();
this.cmdCall.onGetNextPackage();
this.recorder.clearCommand();
}
} else {
this.cmdCall.onMagneticCardRead(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onMagneticCardRead(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[25].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onPICCActive(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onPICCActive(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onPICCActive(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[26].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onPICCDeactive(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[27].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onPICCRate(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onPICCRate(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onPICCRate(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[28].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
if(Util.haveNextPackageToSend(s)) {
SystemClock.sleep(500L);
this.nextCall.onBoardReadyReceiveNext();
this.clearAll();
} else if(Util.isPackageFinished(s)) {
this.sb.append(Commands.getDataParameters(s));
this.cmdCall.onPICCAccess(Commands.getResponseMessage(s), this.sb.toString());
this.clearAll();
} else {
this.sb.append(Commands.getDataParameters(s));
this.nextCall.onSDKReadyReceiveNext();
this.cmdCall.onGetNextPackage();
this.recorder.clearCommand();
}
} else {
this.cmdCall.onPICCAccess(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onPICCAccess(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[29].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onMifareAuth(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[30].split(";")[2].equals(this.currentAction) && s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onMifareReadBlock(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onMifareReadBlock(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onMifareReadBlock(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
if(Commands.COPMMANDS[31].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onMifareWriteBlock(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[32].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onMifareIncrement(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[33].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onMifareDecrement(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[34].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onSetPinpadMode(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[35].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetPINPress(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetPINPress(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetPINPress(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[36].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetPINBlock(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetPINBlock(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetPINBlock(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[37].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetPINBlockwithPAN(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetPINBlockwithPAN(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetPINBlockwithPAN(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[38].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetPINBlockwithPAN12(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetPINBlockwithPAN12(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetPINBlockwithPAN12(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[39].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
if(Util.haveNextPackageToSend(s)) {
SystemClock.sleep(500L);
this.nextCall.onBoardReadyReceiveNext();
this.clearAll();
} else if(Util.isPackageFinished(s)) {
this.sb.append(Commands.getDataParameters(s));
this.cmdCall.onLoadRSAPublicKey(Commands.getResponseMessage(s));
this.clearAll();
} else {
this.sb.append(Commands.getDataParameters(s));
this.nextCall.onSDKReadyReceiveNext();
this.cmdCall.onGetNextPackage();
this.recorder.clearCommand();
}
} else {
this.cmdCall.onLoadRSAPublicKey(Commands.getCRCErrorMessage());
this.clearAll();
}
} else {
this.cmdCall.onLoadRSAPublicKey(Commands.getReceiveLengthErrorMessage());
this.clearAll();
}
}
} else if(Commands.COPMMANDS[40].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
if(Util.haveNextPackageToSend(s)) {
this.nextCall.onBoardReadyReceiveNext();
this.clearAll();
} else if(Util.isPackageFinished(s)) {
this.sb.append(Commands.getDataParameters(s));
this.cmdCall.onMagneticCardRSARead(Commands.getResponseMessage(s), this.sb.toString());
this.clearAll();
} else {
this.sb.append(Commands.getDataParameters(s));
this.nextCall.onSDKReadyReceiveNext();
this.cmdCall.onGetNextPackage();
this.recorder.clearCommand();
}
} else {
this.cmdCall.onMagneticCardRSARead(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onMagneticCardRSARead(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[41].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetMagCardholderInfo(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetMagCardholderInfo(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetMagCardholderInfo(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(Commands.COPMMANDS[42].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onSelectICC(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[43].split(";")[2].equals(this.currentAction)) {
this.cmdCall.onSelectPSAM(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[44].split(";")[2].equals(this.currentAction)) {
if(s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
if(Util.haveNextPackageToSend(s)) {
SystemClock.sleep(500L);
this.nextCall.onBoardReadyReceiveNext();
this.clearAll();
} else if(Util.isPackageFinished(s)) {
this.sb.append(Commands.getDataParameters(s));
this.cmdCall.onMagneticCardReadInfo(Commands.getResponseMessage(s), this.sb.toString());
this.clearAll();
} else {
this.sb.append(Commands.getDataParameters(s));
this.nextCall.onSDKReadyReceiveNext();
this.cmdCall.onGetNextPackage();
this.recorder.clearCommand();
}
} else {
this.cmdCall.onMagneticCardReadInfo(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onMagneticCardReadInfo(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
} else if(s.equals("1C00010C11")) {
this.cmdCall.onReaderPowerDown(Commands.getResponseMessage(s));
this.clearAll();
} else if(Commands.COPMMANDS[46].split(";")[2].equals(this.currentAction) && s.length() >= 6) {
count = Util.hexToInt(s.substring(4, 6));
maxLen = count * 2 + 8;
if(s.length() >= maxLen) {
if(Util.isCRCCorrect(s)) {
this.cmdCall.onGetUId(Commands.getResponseMessage(s), Commands.getDataParameters(s));
this.clearAll();
} else {
this.cmdCall.onGetUId(Commands.getCRCErrorMessage(), "");
this.clearAll();
}
} else {
this.cmdCall.onGetUId(Commands.getReceiveLengthErrorMessage(), "");
this.clearAll();
}
}
}
private class HeadsetIntentReceiver extends BroadcastReceiver {
private HeadsetIntentReceiver() {
}
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.intent.action.HEADSET_PLUG")) {
int state = intent.getIntExtra("state", -1);
switch(state) {
case 0:
if(SingularLib.this.cmdCall != null) {
SingularLib.this.cmdCall.onHeadsetUnplug();
}
break;
case 1:
if(SingularLib.this.cmdCall != null) {
SingularLib.this.cmdCall.onHeadsetPlugged();
}
break;
default:
if(SingularLib.IS_DEBUG) {
Log.d("JsLib", "No idea what the headset state is...");
}
}
}
}
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2.util;
import android.util.Log;
public class Commands {
private static final String RECEIVE_ERROR_TEXT = "Receiver length error";
private static boolean IS_DEBUG = false;
public static final String RESPONSE_CAN_SEND_NEXT = "1C00010A17";
public static final String COMMAND_PLEASE_SEND_NEXT = "1B0003252600";
public static final String[] COPMMANDS = new String[]{"AA;AA;Initial;00", "1B00022521;1C00NNSW;GetVersion;01", "1B00022524;1C00NNSW;GetReaderSN;02", "1B00NN2525<DATA>;1C0001001D;SetReaderSN;03", "1B00022527;1C000200001E;GiveUpAction;04", "1B0002252B;1C00NNSW;DetectBattery;05", "1B0003252CTT;1C0001001D;SetSleepTimer;06", "1B00NN25A1II<DATA>;1C0001001D;WriteCustomerInformation;07", "1B00NN25A2II;1C00NNSW;ReadCustomerInformation;08", "1B00022535;1C00NNSW;DetectICCStatus;09", "1B00022536;1C0001001D;PowerOnICC;10", "1B00022537;1C0001001D;PowerOffICC;11", "1BNDNN2538<DATA>;1CNDNNSW;AccessICC;12", "1B00022540;1C00NNSW;GetICCCardholderInfo;13", "1B00022541;1CNDNNSW;GetEMVData;14", "1B00022542;1C00NNSW;VerifyPIN;15", "1B00032570EE;1C0001001D;SelectEncrptMethod;16", "1B00022571;1C0001001D;ResetWholeKey;17", "1B00022572;1C0001001D;LockWholeKey;18", "1B00NN2573<DATA>;1C0001001D;RestoreandUnlock;19", "1B00NN2574<DATA>;1C0001001D;UpdateMainKey;20", "1B00NN2575<DATA>;1C0001001D;UpdateWorkingKey;21", "1B00042576<DATA>;1C0001001D;SelectWorkingKey;22", "1B00NN2577<DATA>;1C0001001D;LoadInitialKeyDUKPT;23", "1B00021011;1CNDNNSW;MagneticCardRead ;24", "1B00023511;1C00NNSW;PICCActive;25", "1B00023512;1C0001001D;PICCDeactive;26", "1B00023513;1C00NNSW;PICCRate;27", "1BNDNN3514<DATA>;1CNDNNSW;PICCAccess;28", "1B00NN3515<DATA>;1C0001001D;MifareAuth;29", "1B00NN3516<DATA>;1C0001001D;MifareReadBlock;30", "1B00NN3517<DATA>;1C0001001D;MifareWriteBlock;31", "1B00073518<DATA>;1C0001001D;MifareIncrement;32", "1B00073519<DATA>;1C0001001D;MifareDecrement;33", "1B00044511LLTT;1C0001001D;SetPinpadMode;34", "1B00024512;1C00NNSW;GetPINPress;35", "1B00024513;1C00NNSW;GetPINBlock;36", "1B00NN4514<DATA>;1C00NNSW;GetPINBlockwithPAN;37", "1B00NN4515<DATA>;1C00NNSW;GetPINBlockwithPAN12;38", "1BNDNN2578<DATA>;1CNDNNSW;LoadRSAPublicKey;39", "1B00021012;1CNDNNSW;MagneticCardRSARead;40", "1B00021020;1C00NNSW;GetMagCardholderInfo;41", "1B00022530;1C0001001D;SelectICC;42", "1B00022532;1C0001001D;SelectPSAM;43", "1BNDNN5012<DATA>;1CNDNNSW;MagneticCardReadInfo;44", "1B;1C0001001D;ReaderPowerDown;45", "1B00022523;1C00NNSW;GetUID;46"};
public static final String[] RESPONSE = new String[]{"00;PASS", "01;Command error", "02;Parameter error", "03;CRC error", "04;Time-out", "05;MagCard not swipe", "06;Passwords not pressed", "0A;Next Package", "0B;Re-send Package", "0C;Entry Sleep Mode", "10;Magnetic data error", "11;Can\'t found RSA Key", "12;SmartCard Removed", "13;SmartCard Power On Error", "14;SmartCard APDU Error", "15;SmartCard Power Off Error", "16;SmartCard Type Not Support", "17;CardReader Lock", "18;Non Encrypt", "19;Encrypt Mode Error", "20;20", "21;21", "22;22", "23;23", "24;24"};
public Commands() {
}
public static void LogCommand(byte[] command) {
StringBuffer hexString = new StringBuffer();
for(int i = 0; i < command.length; ++i) {
hexString.append(String.format("%02x", new Object[]{Byte.valueOf(command[i])}));
if((i + 1) % 4 == 0) {
hexString.append(",");
} else {
hexString.append(" ");
}
}
if(IS_DEBUG) {
Log.d("JsLib", "Command(HEX): " + hexString);
}
}
public static String getResponseMessage(String data) {
String ret = "";
try {
String iofe = data.substring(6, 8).toUpperCase().trim();
for(int i = 0; i < RESPONSE.length; ++i) {
String[] s = RESPONSE[i].split(";");
if(s[0].equals(iofe)) {
ret = s[1];
break;
}
}
} catch (IndexOutOfBoundsException var5) {
ret = RESPONSE[1].split(";")[1];
}
return ret;
}
public static String getReceiveLengthErrorMessage() {
return "Receiver length error";
}
public static String getCRCErrorMessage() {
return RESPONSE[3].split(";")[1];
}
public static String getDataParameters(String data) {
return data.substring(8, data.length() - 2);
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2.util;
import android.util.Log;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.SecretKeySpec;
import tw.com.android.singularsdk.lib2.util.Util;
public class DESUtil {
private static boolean IS_DEBUG = false;
public DESUtil() {
}
public static String encryptionDes(String enc_key, String unenc_data) {
byte[] en_key = Util.hexStringToByteArray(enc_key);
if(en_key == null) {
if(IS_DEBUG) {
Log.e("JsLib", "Encryption_data key is null!!!");
}
return null;
} else {
SecureRandom sr = null;
SecretKey secretKey = null;
try {
sr = new SecureRandom();
DESKeySpec e = new DESKeySpec(en_key);
SecretKeyFactory enc = SecretKeyFactory.getInstance("DES");
secretKey = enc.generateSecret(e);
} catch (Exception var10) {
var10.printStackTrace();
return null;
}
try {
Cipher e1 = Cipher.getInstance("DES/ECB/NoPadding");
e1.init(1, secretKey, sr);
byte[] enc1 = Util.hexStringToByteArray(unenc_data);
byte[] en_b = e1.doFinal(enc1);
String enc_data = Util.bytesToHexString(en_b);
return enc_data;
} catch (Exception var9) {
var9.printStackTrace();
return null;
}
}
}
public String decryptionDes(String dec_key, String enc_data) {
String dec_key_b = dec_key.replace(" ", "");
String enc_data_b = enc_data.replace(" ", "");
if(IS_DEBUG) {
Log.e("JsLib", dec_key_b);
}
byte[] de_key = Util.hexStringToByteArray(dec_key_b);
if(de_key == null) {
if(IS_DEBUG) {
Log.e("JsLib", "Decryption_data key is null!!!");
}
return null;
} else {
SecureRandom sr = null;
SecretKey secretKey = null;
try {
sr = new SecureRandom();
DESKeySpec e = new DESKeySpec(de_key);
SecretKeyFactory dec = SecretKeyFactory.getInstance("DES");
secretKey = dec.generateSecret(e);
} catch (Exception var13) {
var13.printStackTrace();
return null;
}
try {
Cipher e1 = Cipher.getInstance("DES/ECB/NoPadding");
e1.init(2, secretKey, sr);
byte[] dec1 = Util.hexStringToByteArray(enc_data_b);
byte[] de_b = e1.doFinal(dec1);
String de_data = Util.bytesToHexString(this.removePadding(de_b));
return de_data;
} catch (Exception var12) {
var12.printStackTrace();
return null;
}
}
}
public static String encryptionTriDes(String enc_key, String unenc_data) {
if(IS_DEBUG) {
Log.v("JsLib", "unenc_data=" + unenc_data);
}
byte[] byteKey = Util.hexStringToByteArray(enc_key);
Object en_key = null;
byte[] en_key1;
if(byteKey.length == 16) {
en_key1 = new byte[24];
System.arraycopy(byteKey, 0, en_key1, 0, 16);
System.arraycopy(byteKey, 0, en_key1, 16, 8);
} else {
en_key1 = byteKey;
}
SecretKeySpec key = null;
try {
key = new SecretKeySpec(en_key1, "DESede");
} catch (Exception var10) {
var10.printStackTrace();
return null;
}
try {
Cipher e = Cipher.getInstance("DESede/ECB/NoPadding");
e.init(1, key);
byte[] dec = Util.hexStringToByteArray(unenc_data);
byte[] en_b = e.doFinal(dec);
String en_data = Util.bytesToHexString(en_b);
return en_data;
} catch (Exception var9) {
var9.printStackTrace();
return null;
}
}
public String decryptionTriDes(String dec_key, String enc_data) {
String dec_key_b = dec_key.replace(" ", "");
String enc_data_b = enc_data.replace(" ", "");
byte[] byteKey = Util.hexStringToByteArray(dec_key_b);
Object dn_key = null;
byte[] dn_key1;
if(byteKey.length == 16) {
dn_key1 = new byte[24];
System.arraycopy(byteKey, 0, dn_key1, 0, 16);
System.arraycopy(byteKey, 0, dn_key1, 16, 8);
} else {
dn_key1 = byteKey;
}
SecretKeySpec key = null;
try {
key = new SecretKeySpec(dn_key1, "DESede");
} catch (Exception var13) {
var13.printStackTrace();
return null;
}
try {
Cipher e = Cipher.getInstance("DESede/ECB/NoPadding");
e.init(2, key);
byte[] dec = Util.hexStringToByteArray(enc_data_b);
byte[] de_b = e.doFinal(dec);
String de_data = Util.bytesToHexString(this.removePadding(de_b));
return de_data;
} catch (Exception var12) {
var12.printStackTrace();
return null;
}
}
public String decryptionAES(String dec_key, String enc_data) {
String dec_key_b = dec_key.replace(" ", "");
String enc_data_b = enc_data.replace(" ", "");
byte[] de_key = Util.hexStringToByteArray(dec_key_b);
if(de_key == null) {
return null;
} else {
SecretKeySpec skeySpec = new SecretKeySpec(de_key, "AES");
Cipher cipher = null;
try {
cipher = Cipher.getInstance("AES/ECB/NoPadding ");
} catch (NoSuchAlgorithmException var14) {
var14.printStackTrace();
} catch (NoSuchPaddingException var15) {
var15.printStackTrace();
}
try {
cipher.init(2, skeySpec);
} catch (InvalidKeyException var13) {
var13.printStackTrace();
}
byte[] dec = Util.hexStringToByteArray(enc_data_b);
try {
byte[] e = cipher.doFinal(dec);
String de_data = Util.bytesToHexString(this.removePadding(e));
return de_data;
} catch (Exception var12) {
System.out.println(var12.toString());
return null;
}
}
}
private byte[] removePadding(byte[] txt) {
boolean i = false;
int var4;
for(var4 = 0; var4 < txt.length && txt[var4] != -1; ++var4) {
;
}
if(var4 != txt.length) {
byte[] newtxt = new byte[var4];
System.arraycopy(txt, 0, newtxt, 0, var4);
return newtxt;
} else {
return txt;
}
}
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2.util;
import android.util.Log;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Util {
private static boolean IS_DEBUG = false;
public static final String MANCHESTER_0 = "01";
public static final String MANCHESTER_1 = "10";
public static final byte MANCHESTER_HIGH = 127;
public static final byte MANCHESTER_LOW = -128;
public static final String MANCHESTER_SYNC = "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
public static final String MANCHESTER_BIT_START = "10";
public static final String MANCHESTER_BIT_END = "01";
private static final short HI = -32767;
private static final short LO = 32767;
public Util() {
}
public static String toBinary(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 8);
for(int i = 0; i < 8 * bytes.length; ++i) {
sb.append((char)((bytes[i / 8] << i % 8 & 128) == 0?'0':'1'));
}
return sb.toString();
}
public static byte[] getRoger(String binary) throws NumberFormatException, NullPointerException {
byte[] result = new byte[2];
byte[] holder = (new BigInteger(binary, 2)).toByteArray();
if(holder.length == 1) {
result[0] = holder[0];
} else if(holder.length > 1) {
result[1] = holder[holder.length - 2];
result[0] = holder[holder.length - 1];
}
return result;
}
public static String manchesterEncodeToString(byte[] command) {
StringBuffer manchesterCode = new StringBuffer();
String binaryCommand = toBinary(command);
for(int i = 0; i < binaryCommand.length(); ++i) {
if(binaryCommand.charAt(i) == 48) {
manchesterCode.append("01");
} else {
manchesterCode.append("10");
}
}
return manchesterCode.toString();
}
public static String addManchesterSyncCode(String manchesterCode) {
StringBuilder sb = new StringBuilder();
sb.append("01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101");
int residue;
for(residue = 0; residue < manchesterCode.length() / 16; ++residue) {
sb.append("10");
sb.append(manchesterCode.substring(residue * 16, residue * 16 + 16));
sb.append("01");
}
residue = manchesterCode.length() % 16;
if(residue != 0) {
sb.append("10");
sb.append(manchesterCode.substring(manchesterCode.length() - residue - 1, manchesterCode.length()));
sb.append("01");
}
sb.append("0101010101010101");
return sb.toString();
}
public static short[] wrapToShortSquareWave(String binary, int bufferSize) {
byte N = 10;
short[] squareWave = new short[bufferSize];
for(int i = 0; i < binary.length(); ++i) {
if(binary.charAt(i) == 48) {
squareWave[i * N + 0] = 32767;
squareWave[i * N + 1] = 32767;
squareWave[i * N + 2] = 32767;
squareWave[i * N + 3] = 32767;
squareWave[i * N + 4] = 32767;
squareWave[i * N + 5] = 32767;
squareWave[i * N + 6] = 32767;
squareWave[i * N + 7] = 32767;
squareWave[i * N + 8] = 32767;
squareWave[i * N + 9] = 32767;
} else {
squareWave[i * N + 0] = -32767;
squareWave[i * N + 1] = -32767;
squareWave[i * N + 2] = -32767;
squareWave[i * N + 3] = -32767;
squareWave[i * N + 4] = -32767;
squareWave[i * N + 5] = -32767;
squareWave[i * N + 6] = -32767;
squareWave[i * N + 7] = -32767;
squareWave[i * N + 8] = -32767;
squareWave[i * N + 9] = -32767;
}
}
return squareWave;
}
public static int[] array2ByteToInt(byte[] b) {
Object ret = null;
IntBuffer sBuf = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
int[] ret1 = new int[sBuf.remaining()];
sBuf.get(ret1);
if(IS_DEBUG) {
Log.d("JsLib", "Byew array into " + ret1.length + " length int array");
}
return ret1;
}
public static String manchesterToBin(String ori, String bitMode) throws StringIndexOutOfBoundsException {
if("".equals(ori.trim())) {
return "";
} else {
StringBuilder sb = new StringBuilder();
int i;
String tmp;
if("01".equals(bitMode)) {
for(i = 0; i < ori.length(); i += 2) {
tmp = ori.substring(i, i + 2);
if("01".equals(tmp)) {
sb.append("0");
}
if("10".equals(tmp)) {
sb.append("1");
}
}
}
if("10".equals(bitMode)) {
for(i = 0; i < ori.length(); i += 2) {
tmp = ori.substring(i, i + 2);
if("10".equals(tmp)) {
sb.append("0");
}
if("01".equals(tmp)) {
sb.append("1");
}
}
}
return sb.toString();
}
}
public static String binToManchester(String ori) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < ori.length(); ++i) {
char c = ori.charAt(i);
if(48 == c) {
sb.append("01");
}
if(49 == c) {
sb.append("10");
}
}
return sb.toString();
}
public static String hexToBinary(String hex) {
String bin = Long.toBinaryString(Long.parseLong(hex, 16));
return bin;
}
public static String binaryToHex(String bin) {
String s = Long.toHexString(Long.parseLong(bin, 2));
if(s.length() == 1) {
s = "0" + s;
}
return s;
}
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for(int i = 0; i < len; i += 2) {
data[i / 2] = (byte)((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
}
return data;
}
public static int hexToInt(String hex) {
boolean ret = true;
int ret1;
try {
ret1 = Integer.parseInt(hex, 16);
} catch (NumberFormatException var3) {
ret1 = -1;
}
return ret1;
}
public static String getCommandCRC(String hex) {
long ret = 0L;
for(int crc = 0; crc < hex.length(); crc += 2) {
long l = Long.parseLong(hex.substring(crc, crc + 2), 16);
ret ^= l;
}
String crc1 = Long.toHexString(ret).toUpperCase();
if(crc1.length() == 1) {
crc1 = "0" + crc1;
}
if(IS_DEBUG) {
Log.d("JsLib", "Command: " + hex + ", CRC: " + crc1);
}
return hex + crc1;
}
public static boolean isCRCCorrect(String hexOri) {
String crcOri = hexOri.substring(hexOri.length() - 2, hexOri.length());
String hex = hexOri.substring(0, hexOri.length() - 2);
long ret = 0L;
for(int crc = 0; crc < hex.length(); crc += 2) {
long l = Long.parseLong(hex.substring(crc, crc + 2), 16);
ret ^= l;
}
String crc1 = Long.toHexString(ret).toUpperCase();
if(crc1.length() == 1) {
crc1 = "0" + crc1;
}
if(IS_DEBUG) {
Log.d("JsLib", "Data & CRC: " + hexOri + ", CRC: " + crc1);
}
return crcOri.equals(crc1);
}
public static String hexToASCII(String hex) {
if(hex.length() % 2 != 0) {
if(IS_DEBUG) {
Log.w("JsLib", "hexToASCII comes with ODD characters......!");
}
return "";
} else {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < hex.length() - 1; i += 2) {
String output = hex.substring(i, i + 2);
int decimal = Integer.parseInt(output, 16);
sb.append((char)decimal);
}
return sb.toString();
}
}
public static String asciiToHex(String str) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < str.length(); ++i) {
sb.append(Integer.toHexString(str.charAt(i)));
}
return sb.toString();
}
public static String intToHex(int i) {
String ret = "";
try {
ret = Integer.toHexString(i).toUpperCase();
} catch (Exception var3) {
;
}
if(ret.length() % 2 != 0) {
ret = "0" + ret;
}
return ret;
}
public static String longToHex(long l, int len) {
String ret = "";
try {
ret = Long.toHexString(l).toUpperCase();
} catch (Exception var7) {
;
}
if(len == -1) {
return ret;
} else {
int n = len - ret.length();
String tmp = "";
if(n > 0) {
for(int i = 0; i < n; ++i) {
tmp = tmp + "0";
}
}
return tmp + ret;
}
}
public static String intToHexNoFormat(int i) {
String ret = "";
try {
ret = Integer.toHexString(i).toUpperCase();
} catch (Exception var3) {
;
}
return ret;
}
public static LinkedList<String> splitStringInLength(String str, int length) {
LinkedList list = new LinkedList();
if(str.length() == length) {
list.add(str);
} else {
Matcher m = Pattern.compile(".{1," + String.valueOf(length) + "}").matcher(str);
while(m.find()) {
list.add(str.substring(m.start(), m.end()));
}
}
return list;
}
public static String[] splitCommandInLength(String cmd, String str, int length) {
Matcher m = Pattern.compile(".{1," + String.valueOf(length) + "}").matcher(str);
LinkedList list = new LinkedList();
int count;
for(count = 0; m.find(); ++count) {
list.add(cmd.replaceAll("<DATA>", str.substring(m.start(), m.end())));
}
String[] ret = new String[list.size()];
ret = (String[])list.toArray(ret);
String D = intToHexNoFormat(count);
if(ret.length == 1) {
ret[0] = ret[0].replaceAll("ND", "00");
}
for(int i = 0; i < ret.length; ++i) {
ret[i] = ret[i].replaceAll("ND", intToHexNoFormat(i + 1) + D);
ret[i] = ret[i].replaceAll("NN", intToHex((ret[i].length() - 6) / 2));
}
return ret;
}
public static boolean haveNextPackageToSend(String data) {
try {
String e = data.substring(6, 8).toUpperCase().trim();
return "0A".equals(e);
} catch (Exception var2) {
return false;
}
}
public static boolean isPackageFinished(String data) {
try {
String e = data.substring(2, 3).toUpperCase().trim();
String to = data.substring(3, 4).toUpperCase().trim();
return e.equals(to);
} catch (Exception var3) {
return true;
}
}
public static String bytesToHexString(byte[] data) {
StringBuffer sb = new StringBuffer();
for(int i = 0; i < data.length; ++i) {
String hex = Integer.toHexString(data[i] & 255);
if(hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
public static String getStringRightPart(String str, int n) {
return str != null && !"".equals(str) && str.length() > n?str.substring(str.length() - n, str.length()):str;
}
public static boolean isStringEmpty(String str) {
return str == null || "".equals(str.trim()) || "null".equals(str.trim());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment