|
@@ -21,7 +21,7 @@ fun String.stripF(): String {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-class ApduChannel(private val telephonyManager: TelephonyManager, private val adm: String) {
|
|
|
|
|
|
|
+class ApduChannel(private val telephonyManager: TelephonyManager) {
|
|
|
|
|
|
|
|
class ApduResponse(rawStr: String) {
|
|
class ApduResponse(rawStr: String) {
|
|
|
|
|
|
|
@@ -40,7 +40,7 @@ class ApduChannel(private val telephonyManager: TelephonyManager, private val ad
|
|
|
|
|
|
|
|
private val TAG = "ApduShell"
|
|
private val TAG = "ApduShell"
|
|
|
|
|
|
|
|
- private var authorized: Boolean = false
|
|
|
|
|
|
|
+ public var authorized: Boolean = false
|
|
|
|
|
|
|
|
fun execute(cmd: String): ApduResponse {
|
|
fun execute(cmd: String): ApduResponse {
|
|
|
val cla = cmd.substring(0, 2).toInt(16)
|
|
val cla = cmd.substring(0, 2).toInt(16)
|
|
@@ -67,7 +67,7 @@ class ApduChannel(private val telephonyManager: TelephonyManager, private val ad
|
|
|
return ascii.toByteArray().joinToString("") { "%02x".format(it) }
|
|
return ascii.toByteArray().joinToString("") { "%02x".format(it) }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun authorize() {
|
|
|
|
|
|
|
+ fun authorize(adm: String) {
|
|
|
if (adm.length != 8) {
|
|
if (adm.length != 8) {
|
|
|
Log.e(TAG, "ADM must be 8 characters long")
|
|
Log.e(TAG, "ADM must be 8 characters long")
|
|
|
throw IllegalArgumentException("ADM must be 8 characters long")
|
|
throw IllegalArgumentException("ADM must be 8 characters long")
|
|
@@ -77,17 +77,19 @@ class ApduChannel(private val telephonyManager: TelephonyManager, private val ad
|
|
|
if (res.sw != "9000") {
|
|
if (res.sw != "9000") {
|
|
|
Log.e(TAG, "Authorization failed")
|
|
Log.e(TAG, "Authorization failed")
|
|
|
throw SecurityException("Authorization failed")
|
|
throw SecurityException("Authorization failed")
|
|
|
|
|
+ } else {
|
|
|
|
|
+ authorized = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- execute("00fbffff083239303833303131")
|
|
|
|
|
- execute("00fb0000095b37b1da0cea13c501")
|
|
|
|
|
- execute("00fb0001095b37b1da0cea13c500")
|
|
|
|
|
- execute("00fb0002095b37b1da0cea13c501")
|
|
|
|
|
- execute("00fb0003095b37b1da0cea13c500")
|
|
|
|
|
|
|
+// execute("00fbffff083239303833303131")
|
|
|
|
|
+// execute("00fb0000095b37b1da0cea13c501")
|
|
|
|
|
+// execute("00fb0001095b37b1da0cea13c500")
|
|
|
|
|
+// execute("00fb0002095b37b1da0cea13c501")
|
|
|
|
|
+// execute("00fb0003095b37b1da0cea13c500")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
init {
|
|
init {
|
|
|
- authorize()
|
|
|
|
|
|
|
+ //authorize()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun readIccid(): String {
|
|
fun readIccid(): String {
|
|
@@ -107,9 +109,13 @@ class ApduChannel(private val telephonyManager: TelephonyManager, private val ad
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun readImsi(): String {
|
|
fun readImsi(): String {
|
|
|
- var res = execute("00a4040410a0000000871002ff86ff0389ffffffff")
|
|
|
|
|
|
|
+ var res = execute("00a40004023f00")
|
|
|
|
|
+ if (res.sw != "9000") {
|
|
|
|
|
+ throw Exception("Failed to select MF")
|
|
|
|
|
+ }
|
|
|
|
|
+ res = execute("00a40004027f2000")
|
|
|
if (res.sw != "9000") {
|
|
if (res.sw != "9000") {
|
|
|
- throw Exception("Failed to select AF.USIM")
|
|
|
|
|
|
|
+ throw Exception("Failed to select DF.GSM")
|
|
|
}
|
|
}
|
|
|
res = execute("00a40004026f07")
|
|
res = execute("00a40004026f07")
|
|
|
if (res.sw != "9000") {
|
|
if (res.sw != "9000") {
|
|
@@ -177,23 +183,18 @@ class ApduChannel(private val telephonyManager: TelephonyManager, private val ad
|
|
|
|
|
|
|
|
fun writeImsi(imsi: String) {
|
|
fun writeImsi(imsi: String) {
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
var res = execute("00a40004023f00")
|
|
var res = execute("00a40004023f00")
|
|
|
if (res.sw != "9000") {
|
|
if (res.sw != "9000") {
|
|
|
throw Exception("Failed to select MF")
|
|
throw Exception("Failed to select MF")
|
|
|
}
|
|
}
|
|
|
- Thread.sleep(100)
|
|
|
|
|
- res = execute("00a4040410a0000000871002ff86ff0389ffffffff")
|
|
|
|
|
|
|
+ res = execute("00a40004027f2000")
|
|
|
if (res.sw != "9000") {
|
|
if (res.sw != "9000") {
|
|
|
- throw Exception("Failed to select ADF.USIM")
|
|
|
|
|
|
|
+ throw Exception("Failed to select DF.GSM")
|
|
|
}
|
|
}
|
|
|
- Thread.sleep(100)
|
|
|
|
|
res = execute("00a40004026f07")
|
|
res = execute("00a40004026f07")
|
|
|
if (res.sw != "9000") {
|
|
if (res.sw != "9000") {
|
|
|
throw Exception("Failed to select EF.IMSI")
|
|
throw Exception("Failed to select EF.IMSI")
|
|
|
}
|
|
}
|
|
|
- Thread.sleep(100)
|
|
|
|
|
res = execute("00d6000009${encImsi(imsi)}")
|
|
res = execute("00d6000009${encImsi(imsi)}")
|
|
|
|
|
|
|
|
if (res.sw != "9000") {
|
|
if (res.sw != "9000") {
|