Proxmark3GUI/module/mifare.h

142 lines
4.1 KiB
C
Raw Normal View History

2020-04-07 23:57:56 +08:00
#ifndef MIFARE_H
#define MIFARE_H
2020-04-22 16:42:58 +08:00
#include "common/util.h"
2020-04-22 23:13:00 +08:00
#include "ui_mainwindow.h"
#include "ui/mf_attack_hardnesteddialog.h"
2020-04-29 14:47:40 +08:00
#include "ui/mf_uid_parameterdialog.h"
2020-05-01 23:37:23 +08:00
#include "ui/mf_sim_simdialog.h"
2020-04-07 23:57:56 +08:00
#include <QObject>
2020-04-22 21:14:33 +08:00
#include <QString>
2020-04-23 17:50:20 +08:00
#include <QStringList>
2020-08-06 00:38:44 +08:00
#include <QRegularExpression>
#include <QMessageBox>
2021-09-17 15:25:03 +08:00
#include <QJsonObject>
2020-04-07 23:57:56 +08:00
class Mifare : public QObject
{
Q_OBJECT
public:
explicit Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent = nullptr);
2020-04-07 23:57:56 +08:00
2020-07-29 22:02:49 +08:00
enum KeyType
{
2020-08-01 21:30:55 +08:00
KEY_A = 'A',
KEY_B = 'B',
2020-07-29 22:02:49 +08:00
};
2020-04-23 17:50:20 +08:00
enum DataType
{
DATA_INVALID,
DATA_WITHSPACE,
DATA_NOSPACE,
};
2020-04-24 16:25:52 +08:00
struct CardType
{
2020-08-08 11:23:17 +08:00
quint8 type;
quint8 sector_size;
quint16 block_size;
quint8 blk[40];
quint8 blks[40];
QString typeText;
2020-04-24 16:25:52 +08:00
};
2020-08-06 11:19:56 +08:00
enum AccessType
2020-04-24 16:25:52 +08:00
{
2020-08-06 11:19:56 +08:00
ACC_NEVER = 0,
ACC_KEY_A = 1,
ACC_KEY_B = 2,
ACC_KEY_AB = 3,
2020-04-24 16:25:52 +08:00
};
enum TargetType
{
TARGET_MIFARE,
TARGET_UID,
TARGET_EMULATOR,
};
2020-08-06 11:19:56 +08:00
static const CardType card_mini;
static const CardType card_1k;
static const CardType card_2k;
static const CardType card_4k;
static const AccessType dataCondition[8][4];
static const AccessType trailerReadCondition[8][3];
static const AccessType trailerWriteCondition[8][3];
QMap<QString, QString> info(bool isRequiringOutput = false);
void chk();
void nested(bool isStaticNested = false);
void darkside();
void hardnested();
void sniff();
void sniff14a();
void list();
void readOne(TargetType targetType = TARGET_MIFARE);
2020-08-08 21:04:09 +08:00
void readSelected(TargetType targetType = TARGET_MIFARE);
void writeOne(TargetType targetType = TARGET_MIFARE);
void writeSelected(TargetType targetType = TARGET_MIFARE);
void dump();
void restore();
2020-08-08 11:23:17 +08:00
void data_clearData(bool clearAll = true);
void data_clearKey(bool clearAll = true);
static bool data_isKeyValid(const QString& key);
static Mifare::DataType data_isDataValid(const QString& data);
2020-04-23 17:50:20 +08:00
void data_syncWithDataWidget(bool syncAll = true, int block = 0);
2020-07-29 22:02:49 +08:00
void data_syncWithKeyWidget(bool syncAll = true, int sector = 0, KeyType keyType = KEY_A);
CardType cardType;
Mifare::CardType getCardType();
void setCardType(int type);
void wipeC();
void setParameterC();
2020-04-26 21:15:08 +08:00
2020-08-01 21:30:55 +08:00
bool data_loadDataFile(const QString& filename);
bool data_loadKeyFile(const QString& filename);
2020-04-27 23:57:21 +08:00
bool data_saveDataFile(const QString& filename, bool isBin);
2020-08-01 21:30:55 +08:00
bool data_saveKeyFile(const QString& filename, bool isBin);
2020-04-26 21:50:55 +08:00
void data_key2Data();
void data_data2Key();
2020-04-27 23:57:21 +08:00
2020-08-01 21:30:55 +08:00
void data_setData(int block, const QString& data);
void data_setKey(int sector, KeyType keyType, const QString& key);
2020-04-29 14:47:40 +08:00
void lockC();
2020-04-30 20:32:43 +08:00
void wipeE();
2020-05-01 23:37:23 +08:00
void simulate();
2020-05-03 23:40:09 +08:00
void loadSniff(const QString& file);
void saveSniff(const QString& file);
2020-08-01 22:04:30 +08:00
void data_fillKeys();
2020-08-04 13:44:20 +08:00
2020-08-13 09:30:47 +08:00
static QList<quint8> data_getACBits(const QString& text);
static int data_b2s(int block);
2020-08-13 09:30:47 +08:00
static bool data_isACBitsValid(const QString& text, QList<quint8> *returnHalfBytes = nullptr);
QString data_getUID();
quint16 getTrailerBlockId(quint8 sectorId, qint8 cardTypeId = -1); // -1: use current cardtype
2021-09-17 15:25:03 +08:00
void setConfigMap(const QVariantMap& configMap);
2020-04-07 23:57:56 +08:00
public slots:
signals:
private:
QWidget* parent;
2020-04-22 23:13:00 +08:00
Ui::MainWindow *ui;
2020-04-22 16:42:58 +08:00
Util* util;
2020-04-23 17:50:20 +08:00
2021-09-17 15:25:03 +08:00
QVariantMap configMap;
2020-04-26 21:50:55 +08:00
QStringList* keyAList;
QStringList* keyBList;
QStringList* dataList;
2020-08-06 00:38:44 +08:00
QRegularExpression* dataPattern;
QRegularExpression* keyPattern_res;
QRegularExpression* keyPattern;
2020-08-01 21:30:55 +08:00
QString bin2text(const QByteArray& buff, int start, int length);
2020-08-13 09:30:47 +08:00
QString _readblk(int blockId, KeyType keyType, const QString& key, TargetType targetType = TARGET_MIFARE, int waitTime = 300);
QStringList _readsec(int sectorId, KeyType keyType, const QString& key, TargetType targetType = TARGET_MIFARE, int waitTime = 300);
bool _writeblk(int blockId, KeyType keyType, const QString& key, const QString& data, TargetType targetType = TARGET_MIFARE, int waitTime = 300);
2020-04-07 23:57:56 +08:00
};
#endif // MIFARE_H