mirror of
https://github.com/wh201906/Proxmark3GUI.git
synced 2025-04-21 03:56:19 +08:00
Remove writeC() and readC(), unify them into _readblk() and _writeblk()
This commit is contained in:
parent
3751349004
commit
6af85bffc0
@ -269,19 +269,20 @@ void Mifare::list()
|
|||||||
ui->funcTab->setCurrentIndex(1);
|
ui->funcTab->setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, int waitTime)
|
QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, TargetType targetType, int waitTime)
|
||||||
{
|
{
|
||||||
QString data;
|
QString data;
|
||||||
QString result;
|
QString result;
|
||||||
bool isKeyBlock = (blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 16 == 0);
|
bool isKeyBlock = (blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 16 == 0);
|
||||||
|
|
||||||
|
if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN)
|
||||||
|
{
|
||||||
|
if(targetType == TARGET_MIFARE)
|
||||||
|
{
|
||||||
if(!data_isKeyValid(key))
|
if(!data_isKeyValid(key))
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN)
|
|
||||||
{
|
|
||||||
// use the given key type to read the target block
|
// use the given key type to read the target block
|
||||||
result = util->execCMDWithOutput(
|
result = util->execCMDWithOutput(
|
||||||
"hf mf rdbl "
|
"hf mf rdbl "
|
||||||
@ -313,9 +314,31 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, int w
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
|
else if(targetType == TARGET_UID)
|
||||||
|
{
|
||||||
|
result = util->execCMDWithOutput(
|
||||||
|
"hf mf cgetblk "
|
||||||
|
+ QString::number(blockId),
|
||||||
|
waitTime);
|
||||||
|
if(result.indexOf("No chinese") == -1)
|
||||||
|
{
|
||||||
|
data = dataPattern->match(result).captured().toUpper();
|
||||||
|
data.remove(" ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
data = "";
|
||||||
|
}
|
||||||
|
else if(targetType == TARGET_EMULATOR)
|
||||||
|
{
|
||||||
|
result = util->execCMDWithOutput(
|
||||||
|
"hf mf eget "
|
||||||
|
+ QString::number(blockId),
|
||||||
|
waitTime);
|
||||||
|
data = dataPattern->match(result).captured().toUpper();
|
||||||
|
data.remove(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -369,7 +392,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
|
|||||||
{
|
{
|
||||||
for(int i = 0; i < cardType.blk[sectorId]; i++)
|
for(int i = 0; i < cardType.blk[sectorId]; i++)
|
||||||
{
|
{
|
||||||
data[i] = _readblk(cardType.blks[sectorId] + i, keyType, key, waitTime);
|
data[i] = _readblk(cardType.blks[sectorId] + i, keyType, key, TARGET_MIFARE, waitTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,11 +420,11 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mifare::readOne()
|
void Mifare::readOne(TargetType targetType)
|
||||||
{
|
{
|
||||||
int blockId = ui->MF_RW_blockBox->currentText().toInt();
|
int blockId = ui->MF_RW_blockBox->currentText().toInt();
|
||||||
Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt());
|
Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt());
|
||||||
QString result = _readblk(blockId, keyType, ui->MF_RW_keyEdit->text().toUpper());
|
QString result = _readblk(blockId, keyType, ui->MF_RW_keyEdit->text().toUpper(), targetType);
|
||||||
if(result != "")
|
if(result != "")
|
||||||
{
|
{
|
||||||
ui->MF_RW_dataEdit->setText(result);
|
ui->MF_RW_dataEdit->setText(result);
|
||||||
@ -490,17 +513,22 @@ void Mifare::readSelected(const QList<int>& selectedBlocks)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mifare::_writeblk(int blockId, KeyType keyType, const QString& key, const QString& data, int waitTime)
|
bool Mifare::_writeblk(int blockId, KeyType keyType, const QString& key, const QString& data, TargetType targetType, int waitTime)
|
||||||
{
|
{
|
||||||
|
QString result;
|
||||||
QString input = data.toUpper();
|
QString input = data.toUpper();
|
||||||
input.remove(" ");
|
input.remove(" ");
|
||||||
|
|
||||||
if(!data_isKeyValid(key) || data_isDataValid(input) != DATA_NOSPACE)
|
if(data_isDataValid(input) != DATA_NOSPACE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN)
|
if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN)
|
||||||
{
|
{
|
||||||
QString result = util->execCMDWithOutput(
|
if(targetType == TARGET_MIFARE)
|
||||||
|
{
|
||||||
|
if(!data_isKeyValid(key))
|
||||||
|
return false;
|
||||||
|
result = util->execCMDWithOutput(
|
||||||
"hf mf wrbl "
|
"hf mf wrbl "
|
||||||
+ QString::number(blockId)
|
+ QString::number(blockId)
|
||||||
+ " "
|
+ " "
|
||||||
@ -512,13 +540,34 @@ bool Mifare::_writeblk(int blockId, KeyType keyType, const QString& key, const Q
|
|||||||
waitTime);
|
waitTime);
|
||||||
return (result.indexOf("isOk:01") != -1);
|
return (result.indexOf("isOk:01") != -1);
|
||||||
}
|
}
|
||||||
|
else if(targetType == TARGET_UID)
|
||||||
|
{
|
||||||
|
result = util->execCMDWithOutput(
|
||||||
|
"hf mf csetblk "
|
||||||
|
+ QString::number(blockId)
|
||||||
|
+ " "
|
||||||
|
+ input,
|
||||||
|
waitTime);
|
||||||
|
return (result.indexOf("No chinese") == -1);
|
||||||
|
}
|
||||||
|
else if(targetType == TARGET_EMULATOR)
|
||||||
|
{
|
||||||
|
result = util->execCMDWithOutput(
|
||||||
|
"hf mf eset "
|
||||||
|
+ QString::number(blockId)
|
||||||
|
+ " "
|
||||||
|
+ input,
|
||||||
|
waitTime);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mifare::writeOne()
|
void Mifare::writeOne(TargetType targetType)
|
||||||
{
|
{
|
||||||
int blockId = ui->MF_RW_blockBox->currentText().toInt();
|
int blockId = ui->MF_RW_blockBox->currentText().toInt();
|
||||||
Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt());
|
Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt());
|
||||||
bool isSuccessful = _writeblk(blockId, keyType, ui->MF_RW_keyEdit->text().toUpper(), ui->MF_RW_dataEdit->text());
|
bool isSuccessful = _writeblk(blockId, keyType, ui->MF_RW_keyEdit->text().toUpper(), ui->MF_RW_dataEdit->text(), targetType);
|
||||||
if(isSuccessful)
|
if(isSuccessful)
|
||||||
{
|
{
|
||||||
QMessageBox::information(parent, tr("Info"), tr("Success!"));
|
QMessageBox::information(parent, tr("Info"), tr("Success!"));
|
||||||
@ -546,21 +595,6 @@ void Mifare::writeSelected(const QList<int>& selectedBlocks)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mifare::readC()
|
|
||||||
{
|
|
||||||
int waitTime = 300;
|
|
||||||
int currblk = ui->MF_RW_blockBox->currentText().toInt();
|
|
||||||
QString result = util->execCMDWithOutput(
|
|
||||||
"hf mf cgetblk "
|
|
||||||
+ QString::number(currblk),
|
|
||||||
waitTime);
|
|
||||||
if(result.indexOf("No chinese") == -1)
|
|
||||||
{
|
|
||||||
// result = result.mid(dataPattern->indexIn(result), 47).toUpper();
|
|
||||||
ui->MF_RW_dataEdit->setText(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mifare::readAllC()
|
void Mifare::readAllC()
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
@ -597,25 +631,6 @@ void Mifare::readAllC()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mifare::writeC()
|
|
||||||
{
|
|
||||||
int waitTime = 150;
|
|
||||||
QString result = util->execCMDWithOutput(
|
|
||||||
"hf mf csetblk "
|
|
||||||
+ ui->MF_RW_blockBox->currentText()
|
|
||||||
+ " "
|
|
||||||
+ ui->MF_RW_dataEdit->text().replace(" ", ""),
|
|
||||||
waitTime);
|
|
||||||
if(result.indexOf("No chinese") == -1)
|
|
||||||
{
|
|
||||||
QMessageBox::information(parent, tr("Info"), tr("Success!"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::information(parent, tr("Info"), tr("Failed!"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mifare::writeAllC()
|
void Mifare::writeAllC()
|
||||||
{
|
{
|
||||||
const int waitTime = 150;
|
const int waitTime = 150;
|
||||||
|
@ -17,20 +17,6 @@ class Mifare : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent = nullptr);
|
explicit Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent = nullptr);
|
||||||
|
|
||||||
QString info(bool isRequiringOutput = false);
|
|
||||||
void chk();
|
|
||||||
void nested();
|
|
||||||
void hardnested();
|
|
||||||
void sniff();
|
|
||||||
void snoop();
|
|
||||||
void list();
|
|
||||||
void readOne();
|
|
||||||
void readSelected(const QList<int>& selectedBlocks);
|
|
||||||
void writeOne();
|
|
||||||
void writeSelected(const QList<int>& selectedBlocks);
|
|
||||||
void dump();
|
|
||||||
void restore();
|
|
||||||
|
|
||||||
enum KeyType
|
enum KeyType
|
||||||
{
|
{
|
||||||
KEY_A = 'A',
|
KEY_A = 'A',
|
||||||
@ -61,6 +47,13 @@ public:
|
|||||||
ACC_KEY_AB = 3,
|
ACC_KEY_AB = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TargetType
|
||||||
|
{
|
||||||
|
TARGET_MIFARE,
|
||||||
|
TARGET_UID,
|
||||||
|
TARGET_EMULATOR,
|
||||||
|
};
|
||||||
|
|
||||||
static const CardType card_mini;
|
static const CardType card_mini;
|
||||||
static const CardType card_1k;
|
static const CardType card_1k;
|
||||||
static const CardType card_2k;
|
static const CardType card_2k;
|
||||||
@ -70,6 +63,20 @@ public:
|
|||||||
static const AccessType trailerReadCondition[8][3];
|
static const AccessType trailerReadCondition[8][3];
|
||||||
static const AccessType trailerWriteCondition[8][3];
|
static const AccessType trailerWriteCondition[8][3];
|
||||||
|
|
||||||
|
QString info(bool isRequiringOutput = false);
|
||||||
|
void chk();
|
||||||
|
void nested();
|
||||||
|
void hardnested();
|
||||||
|
void sniff();
|
||||||
|
void snoop();
|
||||||
|
void list();
|
||||||
|
void readOne(TargetType targetType = TARGET_MIFARE);
|
||||||
|
void readSelected(const QList<int>& selectedBlocks);
|
||||||
|
void writeOne(TargetType targetType = TARGET_MIFARE);
|
||||||
|
void writeSelected(const QList<int>& selectedBlocks);
|
||||||
|
void dump();
|
||||||
|
void restore();
|
||||||
|
|
||||||
void data_clearData(bool clearAll = true);
|
void data_clearData(bool clearAll = true);
|
||||||
void data_clearKey(bool clearAll = true);
|
void data_clearKey(bool clearAll = true);
|
||||||
static bool data_isKeyValid(const QString& key);
|
static bool data_isKeyValid(const QString& key);
|
||||||
@ -81,9 +88,7 @@ public:
|
|||||||
Mifare::CardType getCardType();
|
Mifare::CardType getCardType();
|
||||||
void setCardType(int type);
|
void setCardType(int type);
|
||||||
void writeAllC();
|
void writeAllC();
|
||||||
void writeC();
|
|
||||||
void readAllC();
|
void readAllC();
|
||||||
void readC();
|
|
||||||
void wipeC();
|
void wipeC();
|
||||||
void setParameterC();
|
void setParameterC();
|
||||||
|
|
||||||
@ -123,9 +128,9 @@ private:
|
|||||||
QRegularExpression* keyPattern;
|
QRegularExpression* keyPattern;
|
||||||
QString bin2text(const QByteArray& buff, int start, int length);
|
QString bin2text(const QByteArray& buff, int start, int length);
|
||||||
|
|
||||||
QString _readblk(int blockId, KeyType keyType, const QString &key, int waitTime = 300);
|
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, int waitTime = 300);
|
QStringList _readsec(int sectorId, KeyType keyType, const QString &key, int waitTime = 300);
|
||||||
bool _writeblk(int blockId, KeyType keyType, const QString &key, const QString &data, int waitTime = 300);
|
bool _writeblk(int blockId, KeyType keyType, const QString &key, const QString &data, TargetType targetType = TARGET_MIFARE, int waitTime = 300);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MIFARE_H
|
#endif // MIFARE_H
|
||||||
|
@ -504,7 +504,7 @@ void MainWindow::on_MF_RW_readSelectedButton_clicked()
|
|||||||
void MainWindow::on_MF_RW_readBlockButton_clicked()
|
void MainWindow::on_MF_RW_readBlockButton_clicked()
|
||||||
{
|
{
|
||||||
setState(false);
|
setState(false);
|
||||||
mifare->readOne();
|
mifare->readOne(Mifare::TARGET_MIFARE);
|
||||||
setState(true);
|
setState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ void MainWindow::on_MF_UID_readAllButton_clicked()
|
|||||||
void MainWindow::on_MF_UID_readBlockButton_clicked()
|
void MainWindow::on_MF_UID_readBlockButton_clicked()
|
||||||
{
|
{
|
||||||
setState(false);
|
setState(false);
|
||||||
mifare->readC();
|
mifare->readOne(Mifare::TARGET_UID);
|
||||||
setState(true);
|
setState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,7 +562,7 @@ void MainWindow::on_MF_UID_writeAllButton_clicked()
|
|||||||
void MainWindow::on_MF_UID_writeBlockButton_clicked()
|
void MainWindow::on_MF_UID_writeBlockButton_clicked()
|
||||||
{
|
{
|
||||||
setState(false);
|
setState(false);
|
||||||
mifare->writeC();
|
mifare->writeOne(Mifare::TARGET_UID);
|
||||||
setState(true);
|
setState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user