Browse Source

core: TelephonyManagerApduInterface: convert to UByte first

Otherwise, the integer representation will be negative when the byte
value is greater than 127.
Peter Cai 2 years ago
parent
commit
58bd80556a

+ 5 - 5
app/src/main/java/im/angry/openeuicc/core/TelephonyManagerApduInterface.kt

@@ -42,11 +42,11 @@ class TelephonyManagerApduInterface(
     override fun transmit(tx: ByteArray): ByteArray {
     override fun transmit(tx: ByteArray): ByteArray {
         check(lastChannel != -1) { "Uninitialized" }
         check(lastChannel != -1) { "Uninitialized" }
 
 
-        val cla = tx[0].toInt()
-        val instruction = tx[1].toInt()
-        val p1 = tx[2].toInt()
-        val p2 = tx[3].toInt()
-        val p3 = tx[4].toInt()
+        val cla = tx[0].toUByte().toInt()
+        val instruction = tx[1].toUByte().toInt()
+        val p1 = tx[2].toUByte().toInt()
+        val p2 = tx[3].toUByte().toInt()
+        val p3 = tx[4].toUByte().toInt()
         val p4 = tx.drop(5).toByteArray().encodeHex()
         val p4 = tx.drop(5).toByteArray().encodeHex()
 
 
         return tm.iccTransmitApduLogicalChannelBySlot(info.slotId, lastChannel,
         return tm.iccTransmitApduLogicalChannelBySlot(info.slotId, lastChannel,