pull/4/head
wh201906 4 years ago
parent fe8f8b2d51
commit 46b3912e82

@ -1,5 +1,72 @@
#include "mifare.h" #include "mifare.h"
const Mifare::CardType Mifare::card_mini =
{
0,
5,
20,
{4, 4, 4, 4, 4},
{0, 4, 8, 12, 16}
};
const Mifare::CardType Mifare::card_1k =
{
1,
16,
64,
{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 Mifare::CardType Mifare::card_2k =
{
2,
32,
128,
{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 Mifare::CardType Mifare::card_4k =
{
4,
40,
256,
{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}
};
const Mifare::AccessType Mifare::dataCondition[8][4] =
{
{ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_KEY_B, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_KEY_AB},
{ACC_KEY_B, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
const Mifare::AccessType Mifare::trailerReadCondition[8][3] =
{
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
};
const Mifare::AccessType Mifare::trailerWriteCondition[8][3] =
{
{ACC_KEY_A, ACC_NEVER, ACC_KEY_A},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_KEY_B},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_A, ACC_KEY_A, ACC_KEY_A},
{ACC_KEY_B, ACC_KEY_B, ACC_KEY_B},
{ACC_NEVER, ACC_KEY_B, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
Mifare::Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent) Mifare::Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent)
{ {
this->parent = parent; this->parent = parent;

@ -53,39 +53,23 @@ public:
int blks[40]; int blks[40];
}; };
const CardType card_mini = enum AccessType
{ {
0, ACC_NEVER = 0,
5, ACC_KEY_A = 1,
20, ACC_KEY_B = 2,
{4, 4, 4, 4, 4}, ACC_KEY_AB = 3,
{0, 4, 8, 12, 16}
};
const CardType card_1k =
{
1,
16,
64,
{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,
128,
{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,
256,
{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}
}; };
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];
void data_clearData(); void data_clearData();
void data_clearKey(); void data_clearKey();
bool data_isKeyValid(const QString& key); bool data_isKeyValid(const QString& key);

@ -1,40 +1,6 @@
#include "mf_trailerdecoderdialog.h" #include "mf_trailerdecoderdialog.h"
#include "ui_mf_trailerdecoderdialog.h" #include "ui_mf_trailerdecoderdialog.h"
MF_trailerDecoderDialog::AccessType MF_trailerDecoderDialog::dataCondition[8][4] =
{
{ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_KEY_B, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_KEY_AB},
{ACC_KEY_B, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
MF_trailerDecoderDialog::AccessType MF_trailerDecoderDialog::trailerReadCondition[8][3] =
{
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
};
MF_trailerDecoderDialog::AccessType MF_trailerDecoderDialog::trailerWriteCondition[8][3] =
{
{ACC_KEY_A, ACC_NEVER, ACC_KEY_A},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_KEY_B},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_A, ACC_KEY_A, ACC_KEY_A},
{ACC_KEY_B, ACC_KEY_B, ACC_KEY_B},
{ACC_NEVER, ACC_KEY_B, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
MF_trailerDecoderDialog::MF_trailerDecoderDialog(QWidget *parent) : MF_trailerDecoderDialog::MF_trailerDecoderDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::MF_trailerDecoderDialog) ui(new Ui::MF_trailerDecoderDialog)
@ -94,21 +60,21 @@ void MF_trailerDecoderDialog::on_accessBitsEdit_textEdited(const QString &arg1)
bool isKeyBReadable = ACBits[3] == 0 || ACBits[3] == 1 || ACBits[3] == 4; bool isKeyBReadable = ACBits[3] == 0 || ACBits[3] == 1 || ACBits[3] == 4;
for(int j = 0; j < 3; j++) for(int j = 0; j < 3; j++)
{ {
setTableItem(ui->trailerBlockWidget, 0, j, trailerReadCondition[ACBits[3]][j]); setTableItem(ui->trailerBlockWidget, 0, j, Mifare::trailerReadCondition[ACBits[3]][j]);
setTableItem(ui->trailerBlockWidget, 1, j, trailerWriteCondition[ACBits[3]][j]); setTableItem(ui->trailerBlockWidget, 1, j, Mifare::trailerWriteCondition[ACBits[3]][j]);
} }
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
{ {
for(int j = 0; j < 4; j++) for(int j = 0; j < 4; j++)
{ {
AccessType type = dataCondition[ACBits[i]][j]; Mifare::AccessType type = Mifare::dataCondition[ACBits[i]][j];
if(type == ACC_KEY_B && isKeyBReadable) if(type == Mifare::ACC_KEY_B && isKeyBReadable)
{ {
type = ACC_NEVER; type = Mifare::ACC_NEVER;
} }
else if(type == ACC_KEY_AB && isKeyBReadable) else if(type == Mifare::ACC_KEY_AB && isKeyBReadable)
{ {
type = ACC_KEY_A; type = Mifare::ACC_KEY_A;
} }
setTableItem(ui->dataBlockWidget, i, j, type); setTableItem(ui->dataBlockWidget, i, j, type);
} }
@ -136,24 +102,24 @@ void MF_trailerDecoderDialog::on_blockSizeChanged(int id, bool st)
} }
} }
void MF_trailerDecoderDialog::setTableItem(QTableWidget* widget, int row, int column, AccessType accessType) void MF_trailerDecoderDialog::setTableItem(QTableWidget* widget, int row, int column, Mifare::AccessType accessType)
{ {
if(widget->item(row, column) == nullptr) if(widget->item(row, column) == nullptr)
widget->setItem(row, column, new QTableWidgetItem()); widget->setItem(row, column, new QTableWidgetItem());
QString text; QString text;
if(accessType == ACC_NEVER) if(accessType == Mifare::ACC_NEVER)
{ {
text = "X"; text = "X";
} }
else if(accessType == ACC_KEY_A) else if(accessType == Mifare::ACC_KEY_A)
{ {
text = "KeyA"; text = "KeyA";
} }
else if(accessType == ACC_KEY_B) else if(accessType == Mifare::ACC_KEY_B)
{ {
text = "KeyB"; text = "KeyB";
} }
else if(accessType == ACC_KEY_AB) else if(accessType == Mifare::ACC_KEY_AB)
{ {
text = "KeyA+B"; text = "KeyA+B";
} }

@ -6,6 +6,7 @@
#include <QDebug> #include <QDebug>
#include <QButtonGroup> #include <QButtonGroup>
#include <QTableWidget> #include <QTableWidget>
#include "../module/mifare.h"
namespace Ui namespace Ui
{ {
@ -19,13 +20,6 @@ class MF_trailerDecoderDialog : public QDialog
public: public:
explicit MF_trailerDecoderDialog(QWidget *parent = nullptr); explicit MF_trailerDecoderDialog(QWidget *parent = nullptr);
~MF_trailerDecoderDialog(); ~MF_trailerDecoderDialog();
enum AccessType
{
ACC_NEVER = 0,
ACC_KEY_A = 1,
ACC_KEY_B = 2,
ACC_KEY_AB = 3,
};
private slots: private slots:
@ -36,12 +30,7 @@ private:
Ui::MF_trailerDecoderDialog *ui; Ui::MF_trailerDecoderDialog *ui;
QRegularExpressionValidator* validator; QRegularExpressionValidator* validator;
QButtonGroup* sizeGroup; QButtonGroup* sizeGroup;
void setTableItem(QTableWidget *widget, int row, int column, AccessType accessType); void setTableItem(QTableWidget *widget, int row, int column, Mifare::AccessType accessType);
// If I don't make them static, the app will crash(these arrays might take too much space)
static AccessType dataCondition[8][4];
static AccessType trailerReadCondition[8][3];
static AccessType trailerWriteCondition[8][3];
}; };

Loading…
Cancel
Save