x1ongzhu před 1 rokem
rodič
revize
a92dbc48be

+ 3 - 0
app/src/main/AndroidManifest.xml

@@ -6,6 +6,9 @@
     <uses-feature
         android:name="android.hardware.telephony"
         android:required="true" />
+    <uses-feature
+        android:name="android.hardware.telephony.radio.access"
+        android:required="true" />
 
     <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
     <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />

+ 14 - 10
app/src/main/java/com/example/uicceditor/ApduChannel.kt

@@ -78,6 +78,12 @@ class ApduChannel(private val telephonyManager: TelephonyManager, private val ad
             Log.e(TAG, "Authorization failed")
             throw SecurityException("Authorization failed")
         }
+
+        execute("00fbffff083239303833303131")
+        execute("00fb0000095b37b1da0cea13c501")
+        execute("00fb0001095b37b1da0cea13c500")
+        execute("00fb0002095b37b1da0cea13c501")
+        execute("00fb0003095b37b1da0cea13c500")
     }
 
     init {
@@ -170,28 +176,26 @@ class ApduChannel(private val telephonyManager: TelephonyManager, private val ad
     }
 
     fun writeImsi(imsi: String) {
+
+
+
         var res = execute("00a40004023f00")
         if (res.sw != "9000") {
             throw Exception("Failed to select MF")
         }
+        Thread.sleep(100)
         res = execute("00a4040410a0000000871002ff86ff0389ffffffff")
         if (res.sw != "9000") {
             throw Exception("Failed to select ADF.USIM")
         }
+        Thread.sleep(100)
         res = execute("00a40004026f07")
         if (res.sw != "9000") {
             throw Exception("Failed to select EF.IMSI")
         }
-        res = execute("00d6000009083901428002362719")
-        var s = telephonyManager.iccTransmitApduBasicChannel(
-            0x00,
-            0xd6,
-            0x00,
-            0x00,
-            0x09,
-            "083901428002362719"
-        )
-        Log.i(TAG, "writeImsi: $s")
+        Thread.sleep(100)
+        res = execute("00d6000009${encImsi(imsi)}")
+
         if (res.sw != "9000") {
             throw Exception("Failed to write EF.IMSI")
         }

+ 2 - 1
app/src/main/java/com/example/uicceditor/MainActivity.kt

@@ -59,7 +59,7 @@ class MainActivity : AppCompatActivity() {
         binding.btnWriteImsi.setOnClickListener {
             try {
                 val imsi = binding.etImsi.text.toString()
-                if (Regex("^[0-9]{15}$").matches(imsi)) {
+                if (Regex("^[0-9]{15,18}$").matches(imsi)) {
                     apduChannel.writeImsi(imsi)
                     Toast.makeText(this, "IMSI written", Toast.LENGTH_SHORT).show()
                 } else {
@@ -70,6 +70,7 @@ class MainActivity : AppCompatActivity() {
                 Toast.makeText(this, "Error writing IMSI", Toast.LENGTH_SHORT).show()
             }
         }
+
     }
 
     fun getRandomString(length: Int): String {