Proxmark3GUI/module/mifare.h

142 lines
3.6 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>
#include <QRegExp>
#include <QMessageBox>
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-04-29 14:47:40 +08:00
QString info(bool isRequiringOutput = false);
2020-04-22 23:13:00 +08:00
void chk();
void nested();
void hardnested();
void sniff();
void list();
void read();
void readAll();
void write();
void writeAll();
void dump();
void restore();
2020-04-23 17:50:20 +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
{
int type;
int sectors;
2020-04-25 18:30:45 +08:00
int blocks;
2020-04-24 16:25:52 +08:00
int blk[40];
int blks[40];
};
const CardType card_mini =
{
0,
5,
2020-04-25 18:30:45 +08:00
20,
2020-04-24 16:25:52 +08:00
{4, 4, 4, 4, 4},
{0, 4, 8, 12, 16}
};
const CardType card_1k =
{
1,
16,
2020-04-25 18:30:45 +08:00
64,
2020-04-24 16:25:52 +08:00
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60}
};
const CardType card_2k =
{
2,
32,
2020-04-25 18:30:45 +08:00
128,
2020-04-24 16:25:52 +08:00
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120, 124}
};
const CardType card_4k =
{
4,
40,
2020-04-25 18:30:45 +08:00
256,
2020-04-24 16:25:52 +08:00
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 16, 16, 16, 16, 16, 16, 16, 16},
{0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120, 124, 128, 144, 160, 176, 192, 208, 224, 240}
};
2020-04-23 17:50:20 +08:00
void data_clearData();
void data_clearKey();
2020-08-01 21:30:55 +08:00
bool data_isKeyValid(const QString& key);
2020-04-23 17:50:20 +08:00
Mifare::DataType data_isDataValid(QString data);
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 writeAllC();
void writeC();
void readAllC();
void readC();
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 writeAllE();
void readAllE();
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-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
2020-04-26 21:50:55 +08:00
QStringList* keyAList;
QStringList* keyBList;
QStringList* dataList;
QRegExp* dataPattern;
2020-04-24 16:25:52 +08:00
QRegExp* chkKeyPattern;
QRegExp* nestedKeyPattern;
2020-04-29 14:47:40 +08:00
QRegExp* UIDPattern;
2020-08-01 21:30:55 +08:00
QString bin2text(const QByteArray& buff, int start, int length);
QString _readblk(int blockId, KeyType keyType, QString &key, int waitTime);
2020-04-07 23:57:56 +08:00
};
#endif // MIFARE_H