Add Trailer Decoder(Uncompleted)

pull/4/head
wh201906 4 years ago
parent 02b0c312a4
commit a935ff9703

@ -20,6 +20,7 @@ SOURCES += \
common/pm3process.cpp \ common/pm3process.cpp \
common/util.cpp \ common/util.cpp \
module/mifare.cpp \ module/mifare.cpp \
ui/mf_trailerdecoderdialog.cpp \
ui/mf_sim_simdialog.cpp \ ui/mf_sim_simdialog.cpp \
ui/mf_uid_parameterdialog.cpp \ ui/mf_uid_parameterdialog.cpp \
ui/mainwindow.cpp \ ui/mainwindow.cpp \
@ -29,12 +30,14 @@ HEADERS += \
common/pm3process.h \ common/pm3process.h \
common/util.h \ common/util.h \
module/mifare.h \ module/mifare.h \
ui/mf_trailerdecoderdialog.h \
ui/mf_sim_simdialog.h \ ui/mf_sim_simdialog.h \
ui/mf_uid_parameterdialog.h \ ui/mf_uid_parameterdialog.h \
ui/mainwindow.h \ ui/mainwindow.h \
ui/mf_attack_hardnesteddialog.h \ ui/mf_attack_hardnesteddialog.h \
FORMS += \ FORMS += \
ui/mf_trailerdecoderdialog.ui \
ui/mf_sim_simdialog.ui \ ui/mf_sim_simdialog.ui \
ui/mf_uid_parameterdialog.ui \ ui/mf_uid_parameterdialog.ui \
ui/mainwindow.ui \ ui/mainwindow.ui \

@ -904,3 +904,9 @@ void MainWindow::on_testButton_clicked()
{ {
mifare->_readsec(0, Mifare::KEY_A, "FFFFFFFFFFFF"); mifare->_readsec(0, Mifare::KEY_A, "FFFFFFFFFFFF");
} }
void MainWindow::on_MF_trailerDecoderButton_clicked()
{
decDialog = new MF_trailerDecoderDialog(this);
decDialog->show();
}

@ -23,6 +23,7 @@
#include "common/pm3process.h" #include "common/pm3process.h"
#include "module/mifare.h" #include "module/mifare.h"
#include "common/util.h" #include "common/util.h"
#include "ui/mf_trailerdecoderdialog.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui namespace Ui
@ -145,6 +146,8 @@ private slots:
void on_testButton_clicked(); void on_testButton_clicked();
void on_MF_trailerDecoderButton_clicked();
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QButtonGroup* typeBtnGroup; QButtonGroup* typeBtnGroup;
@ -163,6 +166,8 @@ private:
Mifare* mifare; Mifare* mifare;
Util* util; Util* util;
MF_trailerDecoderDialog* decDialog;
void signalInit(); void signalInit();
void MF_widgetReset(); void MF_widgetReset();

@ -213,6 +213,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="MF_trailerDecoderButton">
<property name="text">
<string>Trailer Decoder</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="MF_fontButton"> <widget class="QPushButton" name="MF_fontButton">
<property name="text"> <property name="text">
@ -630,14 +637,14 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QPushButton" name="MF_RW_readAllButton"> <widget class="QPushButton" name="MF_RW_readAllButton">
<property name="text"> <property name="text">
<string>Read Checked</string> <string>Read Selected</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QPushButton" name="MF_RW_writeAllButton"> <widget class="QPushButton" name="MF_RW_writeAllButton">
<property name="text"> <property name="text">
<string>Write Checked</string> <string>Write Selected</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -722,14 +729,14 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QPushButton" name="MF_UID_readAllButton"> <widget class="QPushButton" name="MF_UID_readAllButton">
<property name="text"> <property name="text">
<string>Read Checked</string> <string>Read Selected</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QPushButton" name="MF_UID_writeAllButton"> <widget class="QPushButton" name="MF_UID_writeAllButton">
<property name="text"> <property name="text">
<string>Write Checked</string> <string>Write Selected</string>
</property> </property>
</widget> </widget>
</item> </item>

@ -0,0 +1,107 @@
#include "mf_trailerdecoderdialog.h"
#include "ui_mf_trailerdecoderdialog.h"
MF_trailerDecoderDialog::MF_trailerDecoderDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::MF_trailerDecoderDialog)
{
ui->setupUi(this);
QRegularExpression re("(([0-9a-fA-F]{2} ){0,4})|([0-9a-fA-F]{0,8})");
validator = new QRegularExpressionValidator(this);
validator->setRegularExpression(re);
ui->accessBitsEdit->setValidator(validator);
sizeGroup = new QButtonGroup(this);
sizeGroup->addButton(ui->size4Button, 4);
sizeGroup->addButton(ui->size16Button, 16);
connect(sizeGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, &MF_trailerDecoderDialog::on_blockSizeChanged);
ui->dataBlockWidget->setRowCount(3);
ui->dataBlockWidget->setColumnCount(4);
ui->trailerBlockWidget->setRowCount(2);
ui->trailerBlockWidget->setColumnCount(3);
}
MF_trailerDecoderDialog::~MF_trailerDecoderDialog()
{
delete ui;
}
void MF_trailerDecoderDialog::on_accessBitsEdit_textEdited(const QString &arg1)
{
QString input = arg1;
input.remove(" ");
if(input.length() < 6)
{
ui->isAccessBitsValidLabel->setText("");
return;
}
input = input.left(6);
quint32 result = input.toUInt(nullptr, 16);
quint8 halfBytes[6];
for(int i = 0; i < 6; i++)
{
halfBytes[i] = (result >> ((5 - i) * 4)) & 0xf;
}
qDebug() << result;
if((~halfBytes[0] & 0xf) != halfBytes[5] || (~halfBytes[1] & 0xf) != halfBytes[2] || (~halfBytes[3] & 0xf) != halfBytes[4])
{
ui->isAccessBitsValidLabel->setStyleSheet("color:rgb(200, 0, 0)");
ui->isAccessBitsValidLabel->setText(tr("Invalid! It could make the whole sector blocked irreversibly!"));
}
else
{
ui->isAccessBitsValidLabel->setStyleSheet("color:rgb(0, 200, 0)");
ui->isAccessBitsValidLabel->setText(tr("Valid"));
quint8 ACBits[4];
for(int i = 0; i < 4; i++)
{
ACBits[i] = (((halfBytes[4] >> i) & 1) << 2) & (((halfBytes[5] >> i) & 1) << 1) & (((halfBytes[2] >> i) & 1) << 0);
}
bool isKeyBReadable = ACBits[3] == 0 || ACBits[3] == 1 || ACBits[3] == 4;
setTableItem(ui->trailerBlockWidget, 0, 0, "X");
}
}
void MF_trailerDecoderDialog::on_blockSizeChanged(int id, bool st)
{
if(st)
{
if(id == 4)
{
ui->dataBlockWidget->verticalHeaderItem(0)->setText("Block0");
ui->dataBlockWidget->verticalHeaderItem(1)->setText("Block1");
ui->dataBlockWidget->verticalHeaderItem(2)->setText("Block2");
}
else if(id == 16)
{
ui->dataBlockWidget->verticalHeaderItem(0)->setText("Block0~4");
ui->dataBlockWidget->verticalHeaderItem(1)->setText("Block5~9");
ui->dataBlockWidget->verticalHeaderItem(2)->setText("Block10~14");
}
}
}
void MF_trailerDecoderDialog::setTableItem(QTableWidget* widget, int row, int column, AccessType accessType)
{
if(widget->item(row, column) == nullptr)
widget->setItem(row, column, new QTableWidgetItem());
QString text;
if(accessType == ACC_NEVER)
{
text = "X";
}
else if(accessType == ACC_KEY_A)
{
text = "KeyA";
}
else if(accessType == ACC_KEY_B)
{
text = "KeyB";
}
else if(accessType == ACC_KEY_AB)
{
text = "KeyA+B";
}
widget->item(row, column)->setText(text);
}

@ -0,0 +1,75 @@
#ifndef MF_TRAILERDECODERDIALOG_H
#define MF_TRAILERDECODERDIALOG_H
#include <QDialog>
#include <QValidator>
#include <QDebug>
#include <QButtonGroup>
#include <QTableWidget>
namespace Ui
{
class MF_trailerDecoderDialog;
}
class MF_trailerDecoderDialog : public QDialog
{
Q_OBJECT
public:
explicit MF_trailerDecoderDialog(QWidget *parent = nullptr);
~MF_trailerDecoderDialog();
enum AccessType
{
ACC_NEVER = 0,
ACC_KEY_A = 1,
ACC_KEY_B = 2,
ACC_KEY_AB = 3,
};
private slots:
void on_accessBitsEdit_textEdited(const QString &arg1);
void on_blockSizeChanged(int id, bool st);
private:
Ui::MF_trailerDecoderDialog *ui;
QRegularExpressionValidator* validator;
QButtonGroup* sizeGroup;
void setTableItem(QTableWidget *widget, int row, int column, AccessType accessType);
AccessType 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},
};
AccessType 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},
};
AccessType 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},
};
};
#endif // MF_TRAILERDECODERDIALOG_H

@ -0,0 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MF_trailerDecoderDialog</class>
<widget class="QDialog" name="MF_trailerDecoderDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>531</width>
<height>436</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Trailer Data:(Input the Access Bits, like &quot;FF 07 80 69&quot; or &quot;FF 07 80&quot;)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="accessBitsEdit"/>
</item>
<item>
<widget class="QLabel" name="isAccessBitsValidLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="sizeGroupBox">
<property name="title">
<string>Blocks</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="size4Button">
<property name="text">
<string>4</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="size16Button">
<property name="text">
<string>16</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Data Block Permission:</string>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="dataBlockWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>4</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<row>
<property name="text">
<string>Block0</string>
</property>
</row>
<row>
<property name="text">
<string>Block1</string>
</property>
</row>
<row>
<property name="text">
<string>Block2</string>
</property>
</row>
<column>
<property name="text">
<string>Read</string>
</property>
</column>
<column>
<property name="text">
<string>Write</string>
</property>
</column>
<column>
<property name="text">
<string>Increase</string>
</property>
</column>
<column>
<property name="text">
<string>Decrease/Transfer/Restore</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Trailer Block Permission:</string>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="trailerBlockWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>3</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<row>
<property name="text">
<string>Read</string>
</property>
</row>
<row>
<property name="text">
<string>Write</string>
</property>
</row>
<column>
<property name="text">
<string>KeyA</string>
</property>
</column>
<column>
<property name="text">
<string>Access Bits</string>
</property>
</column>
<column>
<property name="text">
<string>KeyB</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Reference:
MF1S70YYX_V1 Product data sheet
Rev. 3.2 — 23 November 2017</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MF_trailerDecoderDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>MF_trailerDecoderDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading…
Cancel
Save