Skip to content

Commit ad0607e

Browse files
Claudeclaude
andcommitted
feat(classic): add progress callback to ClassicCardReader for key recovery status
Thread an onProgress callback through ClassicCardReader.readCard so the UI can report nested attack key recovery status. The desktop PN53x backend prints progress messages to the console. The parameter defaults to null so existing callers are unaffected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fec855e commit ad0607e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

app/desktop/src/jvmMain/kotlin/com/codebutler/farebot/desktop/PN53xReaderBackend.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ abstract class PN53xReaderBackend(
163163

164164
CardType.MifareClassic -> {
165165
val tech = PN533ClassicTechnology(pn533, target.tg, tagId, info)
166-
ClassicCardReader.readCard(tagId, tech, null)
166+
ClassicCardReader.readCard(tagId, tech, null) { progress ->
167+
println("[$name] $progress")
168+
}
167169
}
168170

169171
CardType.MifareUltralight -> {

card/classic/src/commonMain/kotlin/com/codebutler/farebot/card/classic/ClassicCardReader.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ object ClassicCardReader {
5252
tech: ClassicTechnology,
5353
cardKeys: ClassicCardKeys?,
5454
globalKeys: List<ByteArray>? = null,
55+
onProgress: ((String) -> Unit)? = null,
5556
): RawClassicCard {
5657
val sectors = ArrayList<RawClassicSector>()
5758
val recoveredKeys = mutableMapOf<Int, Pair<ByteArray, Boolean>>()
@@ -173,12 +174,15 @@ object ClassicCardReader {
173174
val rawClassic = PN533RawClassic(tech.rawPn533, tech.rawUid)
174175
val attack = NestedAttack(rawClassic, tech.uidAsUInt)
175176

177+
onProgress?.invoke("Sector $sectorIndex: attempting key recovery...")
178+
176179
val recoveredKey = attack.recoverKey(
177180
knownKeyType = knownKeyType,
178181
knownSectorBlock = knownBlock,
179182
knownKey = knownKey,
180183
targetKeyType = 0x60,
181184
targetBlock = targetBlock,
185+
onProgress = onProgress,
182186
)
183187

184188
if (recoveredKey != null) {
@@ -195,6 +199,9 @@ object ClassicCardReader {
195199
isKeyA = false
196200
}
197201
}
202+
if (authSuccess) {
203+
onProgress?.invoke("Sector $sectorIndex: key recovered!")
204+
}
198205
}
199206
}
200207
}

0 commit comments

Comments
 (0)