Skip to content

Commit

Permalink
feat: Allow saving found keys from card and after reading card (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxushka authored Oct 18, 2023
1 parent bb1a145 commit 5a8409e
Show file tree
Hide file tree
Showing 12 changed files with 415 additions and 214 deletions.
13 changes: 9 additions & 4 deletions chameleonultragui/lib/bridge/chameleon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,15 @@ class ChameleonCommunicator {
Future<bool> mf1Auth(int block, int keyType, Uint8List key) async {
// Check if key is valid for block
// keyType 0x60 if A key, 0x61 B key
return (await sendCmd(ChameleonCommand.mf1CheckKey,
data: Uint8List.fromList([keyType, block, ...key])))!
.status ==
0;
int status = (await sendCmd(ChameleonCommand.mf1CheckKey,
data: Uint8List.fromList([keyType, block, ...key])))!
.status;

if (status == 1) {
throw ("Lost card");
}

return status == 0;
}

Future<Uint8List> mf1ReadBlock(int block, int keyType, Uint8List key) async {
Expand Down
3 changes: 2 additions & 1 deletion chameleonultragui/lib/gui/menu/card_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class CardEditMenuState extends State<CardEditMenu> {
},
decoration: InputDecoration(
labelText: localizations.name,
hintText: localizations.enter_name,
hintText: localizations
.enter_name(localizations.card.toLowerCase()),
prefix: Transform(
transform: Matrix4.translationValues(0, 7, 0),
child: IconButton(
Expand Down
32 changes: 29 additions & 3 deletions chameleonultragui/lib/gui/menu/card_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:chameleonultragui/bridge/chameleon.dart';
import 'package:chameleonultragui/gui/menu/card_edit.dart';
import 'package:chameleonultragui/gui/menu/dictionary_export.dart';
import 'package:chameleonultragui/helpers/mifare_classic/general.dart';
import 'package:flutter/material.dart';
import 'package:chameleonultragui/helpers/general.dart';
Expand Down Expand Up @@ -29,7 +30,8 @@ class CardViewMenuState extends State<CardViewMenu> {
return AlertDialog(
title: Text(widget.tagSave.name,
maxLines: 3, overflow: TextOverflow.ellipsis),
content: Column(
content: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
Expand Down Expand Up @@ -91,11 +93,35 @@ class CardViewMenuState extends State<CardViewMenu> {
icon: const Icon(Icons.copy),
),
],
)
),
if (isMifareClassic(widget.tagSave.tag))
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 8),
ElevatedButton(
onPressed: (mfClassicGetKeysFromDump(
widget.tagSave.data)
.isNotEmpty)
? () async {
List<Uint8List> keys =
mfClassicGetKeysFromDump(
widget.tagSave.data);
await showDialog(
context: context,
builder: (BuildContext context) {
return DictionaryExportMenu(keys: keys);
},
);
}
: null,
child: Text(localizations.export_to_dictionary)),
],
)
]
: [],
],
),
)),
actions: [
IconButton(
onPressed: () {
Expand Down
36 changes: 28 additions & 8 deletions chameleonultragui/lib/gui/menu/chameleon_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
}
}

// ignore_for_file: use_build_context_synchronously
@override
Widget build(BuildContext context) {
var appState = context.watch<ChameleonGUIState>();
Expand Down Expand Up @@ -70,7 +69,9 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
onPressed: () async {
await appState.communicator!.enterDFUMode();
appState.connector!.performDisconnect();
Navigator.pop(buildContext);
if (buildContext.mounted) {
Navigator.pop(buildContext);
}
appState.changesMade();
},
child: Row(
Expand Down Expand Up @@ -333,14 +334,21 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
await appState.connector!
.performDisconnect();
}
Navigator.pop(context);

if (context.mounted) {
Navigator.pop(context);
}

appState.changesMade();
},
child: Text(localizations.yes),
),
TextButton(
onPressed: () =>
Navigator.pop(context),
onPressed: () {
if (context.mounted) {
Navigator.pop(context);
}
},
child: Text(localizations.no),
),
],
Expand Down Expand Up @@ -395,7 +403,11 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
bleKeyController.text);
await appState.communicator!
.saveSettings();
Navigator.pop(context);

if (context.mounted) {
Navigator.pop(context);
}

appState.changesMade();
}
},
Expand All @@ -414,7 +426,11 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
child: ElevatedButton(
onPressed: () async {
await appState.communicator!.resetSettings();
Navigator.pop(context);

if (context.mounted) {
Navigator.pop(context);
}

appState.changesMade();
},
child: Row(
Expand Down Expand Up @@ -444,7 +460,11 @@ class ChameleonSettingsState extends State<ChameleonSettings> {
.factoryReset();
await appState.connector!
.performDisconnect();
Navigator.pop(context);

if (context.mounted) {
Navigator.pop(context);
}

appState.changesMade();
},
child: Text(localizations.yes),
Expand Down
Loading

0 comments on commit 5a8409e

Please sign in to comment.