|
|
|
@ -269,19 +269,20 @@ void Mifare::list()
|
|
|
|
|
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 result;
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN)
|
|
|
|
|
{
|
|
|
|
|
// use the given key type to read the target block
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf rdbl "
|
|
|
|
@ -313,9 +314,31 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, int w
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
@ -369,7 +392,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Mifare::readOne()
|
|
|
|
|
void Mifare::readOne(TargetType targetType)
|
|
|
|
|
{
|
|
|
|
|
int blockId = ui->MF_RW_blockBox->currentText().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 != "")
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
input.remove(" ");
|
|
|
|
|
|
|
|
|
|
if(!data_isKeyValid(key) || data_isDataValid(input) != DATA_NOSPACE)
|
|
|
|
|
if(data_isDataValid(input) != DATA_NOSPACE)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
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 "
|
|
|
|
|
+ QString::number(blockId)
|
|
|
|
|
+ " "
|
|
|
|
@ -512,13 +540,34 @@ bool Mifare::_writeblk(int blockId, KeyType keyType, const QString& key, const Q
|
|
|
|
|
waitTime);
|
|
|
|
|
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();
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
const int waitTime = 150;
|
|
|
|
|