fix felica template read

master
wlt233 2 years ago
parent 01926e3081
commit 51dd062bfa

@ -9,7 +9,6 @@ import android.widget.Toast
class EmuCard : HostNfcFService() { class EmuCard : HostNfcFService() {
private lateinit var card: FelicaCard private lateinit var card: FelicaCard
// byte utils // byte utils
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() } fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
fun ByteArray.toHexString(hasSpace: Boolean = true) = this.joinToString("") { fun ByteArray.toHexString(hasSpace: Boolean = true) = this.joinToString("") {
@ -80,7 +79,7 @@ class EmuCard : HostNfcFService() {
Log.d("HCEFService", "onCreate NFCF") Log.d("HCEFService", "onCreate NFCF")
super.onCreate() super.onCreate()
val globalVar = this.applicationContext as GlobalVar val globalVar = this.applicationContext as GlobalVar
card = FelicaCard(globalVar.IDm) card = FelicaCard(this, globalVar.IDm)
// Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show() // Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show()
} }

@ -1,58 +1,45 @@
package moe.tqlwsl.aicemu package moe.tqlwsl.aicemu
import android.app.Application
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonSyntaxException import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import java.io.BufferedReader import java.io.BufferedReader
import java.io.File
import java.io.IOException import java.io.IOException
import java.io.InputStreamReader import java.io.InputStreamReader
class FelicaCard(IDm: String) { class FelicaCard(context: Context, IDm: String) {
private var cardData = mutableMapOf<String, String>() private var cardData = mutableMapOf<String, String>()
private val gson = Gson() private val gson = Gson()
private val TAG = "AICEmu"
private val fileName = "felica_template.json"
init { init {
// instance = this Log.d(TAG, "Load Felica Data from assets/$fileName")
// val fileName = "felica_template.json" val fileContent = readAssetFile(context, fileName)
// Log.d("HCEFService", "Load Felica Data from assets/$fileName") val mutableBlock = object : TypeToken<MutableMap<String, String>>() {}.type
// val fileContent = readAssetFile(applicationContext, fileName) try {
// val mutableBlock = object : TypeToken<MutableMap<String, String>>() {}.type val jsonData = gson.fromJson<MutableMap<String, String>>(fileContent, mutableBlock)
// try { if (jsonData != null) {
// val jsonData = gson.fromJson<MutableMap<String, String>>(fileContent, mutableBlock) cardData = jsonData
// if (jsonData != null) {
// cardData = jsonData
// val block82 = ByteArray(16)
// val IDmBytes = IDm.decodeHex()
// System.arraycopy(IDmBytes, 0, block82, 0, 16)
// cardData["82"] = block82.toHexString()
// }
val block82 = ByteArray(16) val block82 = ByteArray(16)
Log.d("HCEFService","Felica Card $IDm")
val IDmBytes = IDm.decodeHex() val IDmBytes = IDm.decodeHex()
System.arraycopy(IDmBytes, 0, block82, 0, 8) System.arraycopy(IDmBytes, 0, block82, 0, 8)
cardData["82"] = block82.toHexString() cardData["82"] = block82.toHexString()
val block = ByteArray(16) }
cardData["80"] = block.toHexString() Log.d(TAG,"[Felica Card Data]")
cardData["86"] = block.toHexString() Log.d(TAG, "=".repeat(53))
cardData["90"] = block.toHexString()
cardData["91"] = block.toHexString()
cardData["00"] = block.toHexString()
Log.d("HCEFService","Felica Card Data")
Log.d("HCEFService","=".repeat(53))
for (en in cardData.entries) { for (en in cardData.entries) {
Log.d("HCEFService","[${en.key}]: ${en.value}") Log.d(TAG,"[${en.key}]: ${en.value}")
}
Log.d(TAG, "=".repeat(53))
} catch (e: IOException) {
Log.e(TAG, "assets/$fileName Read Error")
} catch (e: JsonSyntaxException) {
Log.e(TAG, "assets/$fileName Syntax Error")
} }
Log.d("HCEFService","=".repeat(53))
// } catch (e: IOException) {
// Log.e("Error", "File Read Error")
// } catch (e: JsonSyntaxException) {
// Log.e("Error", "File Syntax Error")
// }
} }
// utils // utils
@ -76,33 +63,23 @@ class FelicaCard(IDm: String) {
System.arraycopy(blockData, 0, resp, 0, blockData.size) System.arraycopy(blockData, 0, resp, 0, blockData.size)
return resp return resp
} }
Log.e(TAG, "Invalid Block $idStr")
Log.e("Error", "Invalid Block")
return null return null
} }
fun writeBlock(id: Byte, data: ByteArray) { } fun writeBlock(id: Byte, data: ByteArray) { }
fun readAssetFile(context: Context, fileName: String): String { private fun readAssetFile(context: Context, fileName: String): String {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
// 获取AssetManager
val assetManager = context.assets val assetManager = context.assets
// 通过AssetManager打开文件
val inputStream = assetManager.open(fileName) val inputStream = assetManager.open(fileName)
val bufferedReader = BufferedReader(InputStreamReader(inputStream)) val bufferedReader = BufferedReader(InputStreamReader(inputStream))
// 逐行读取文件内容并将其添加到StringBuilder中
bufferedReader.forEachLine { line -> bufferedReader.forEachLine { line ->
stringBuilder.append(line) stringBuilder.append(line)
stringBuilder.append("\n") stringBuilder.append("\n")
} }
// 关闭流资源
bufferedReader.close() bufferedReader.close()
inputStream.close() inputStream.close()
return stringBuilder.toString() return stringBuilder.toString()
} }
} }

@ -3,5 +3,5 @@ package moe.tqlwsl.aicemu
import android.app.Application import android.app.Application
class GlobalVar : Application() { class GlobalVar : Application() {
var IDm: String = "" var IDm: String = "02fe000000000000"
} }
Loading…
Cancel
Save