@ -15,7 +15,7 @@ MainWindow::MainWindow(QWidget *parent)
pm3state = false ;
util = new Util ( this ) ;
mifare = new Mifare ( u til, this ) ;
mifare = new Mifare ( u i, u til, this ) ;
uiInit ( ) ;
@ -91,6 +91,20 @@ void MainWindow::on_PM3_disconnectButton_clicked()
setStatusBar ( connectStatusBar , " Not Connected " ) ;
}
void MainWindow : : refreshOutput ( const QString & output )
{
qDebug ( ) < < " MainWindow::refresh: " < < output ;
ui - > Raw_outputEdit - > insertPlainText ( output ) ;
ui - > Raw_outputEdit - > moveCursor ( QTextCursor : : End ) ;
}
void MainWindow : : refreshCMD ( const QString & cmd )
{
ui - > Raw_CMDEdit - > setText ( cmd ) ;
if ( cmd ! = " " & & ( ui - > Raw_CMDHistoryWidget - > count ( ) = = 0 | | ui - > Raw_CMDHistoryWidget - > item ( ui - > Raw_CMDHistoryWidget - > count ( ) - 1 ) - > text ( ) ! = cmd ) )
ui - > Raw_CMDHistoryWidget - > addItem ( cmd ) ;
}
// *********************************************************
// ******************** raw command ********************
@ -138,253 +152,52 @@ void MainWindow::on_Raw_CMDHistoryWidget_itemDoubleClicked(QListWidgetItem *item
void MainWindow : : on_MF_Attack_infoButton_clicked ( )
{
util - > execCMD ( " hf 14a info " ) ;
ui - > funcTab - > setCurrentIndex ( 1 ) ;
mifare - > info ( ) ;
}
void MainWindow : : on_MF_Attack_chkButton_clicked ( )
{
QString result = util - > execCMDWithOutput ( " hf mf chk *1 ? " ) ;
result = result . mid ( result . indexOf ( " |---|----------------|----------------| " ) ) ;
QStringList keys = result . split ( " \r \n " ) ;
for ( int i = 0 ; i < 16 ; i + + )
{
ui - > MF_keyWidget - > setItem ( i , 1 , new QTableWidgetItem ( keys [ i + 3 ] . mid ( 7 , 12 ) . trimmed ( ) . toUpper ( ) ) ) ;
ui - > MF_keyWidget - > setItem ( i , 2 , new QTableWidgetItem ( keys [ i + 3 ] . mid ( 24 , 12 ) . trimmed ( ) . toUpper ( ) ) ) ;
}
qDebug ( ) < < " *********** \n " < < keys < < " *********** \n " ;
mifare - > chk ( ) ;
}
void MainWindow : : on_MF_Attack_nestedButton_clicked ( )
{
QString result = util - > execCMDWithOutput ( " hf mf nested 1 * " ) ;
result = result . mid ( result . indexOf ( " |---|----------------|---|----------------|---| " ) ) ;
QStringList keys = result . split ( " \r \n " ) ;
for ( int i = 0 ; i < 16 ; i + + )
{
if ( keys [ i + 3 ] . at ( 23 ) = = ' 1 ' )
ui - > MF_keyWidget - > setItem ( i , 1 , new QTableWidgetItem ( keys [ i + 3 ] . mid ( 7 , 12 ) . trimmed ( ) . toUpper ( ) ) ) ;
if ( keys [ i + 3 ] . at ( 44 ) = = ' 1 ' )
ui - > MF_keyWidget - > setItem ( i , 2 , new QTableWidgetItem ( keys [ i + 3 ] . mid ( 28 , 12 ) . trimmed ( ) . toUpper ( ) ) ) ;
}
qDebug ( ) < < " *********** \n " < < keys < < " *********** \n " ;
mifare - > nested ( ) ;
}
void MainWindow : : on_MF_Attack_hardnestedButton_clicked ( )
{
MF_Attack_hardnestedDialog dialog ;
connect ( & dialog , & MF_Attack_hardnestedDialog : : sendCMD , util , & Util : : execCMD ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted )
ui - > funcTab - > setCurrentIndex ( 1 ) ;
mifare - > hardnested ( ) ;
}
void MainWindow : : on_MF_Attack_sniffButton_clicked ( )
{
util - > execCMD ( " hf mf sniff " ) ;
ui - > funcTab - > setCurrentIndex ( 1 ) ;
mifare - > sniff ( ) ;
}
void MainWindow : : on_MF_Attack_listButton_clicked ( )
{
util - > execCMD ( " hf list mf " ) ;
ui - > funcTab - > setCurrentIndex ( 1 ) ;
mifare - > list ( ) ;
}
void MainWindow : : on_MF_RW_readAllButton_clicked ( )
{
QString result ;
bool isKeyAValid ;
bool isKeyBValid ;
const int waitTime = 300 ;
for ( int i = 0 ; i < 16 ; i + + )
{
QApplication : : processEvents ( ) ;
result = " " ;
isKeyAValid = false ;
isKeyBValid = false ;
// check keys and read the first block of each sector
if ( ui - > MF_keyWidget - > item ( i , 1 ) ! = nullptr & & mifare - > isKeyValid ( ui - > MF_keyWidget - > item ( i , 1 ) - > text ( ) ) )
{
result = util - > execCMDWithOutput ( " hf mf rdbl "
+ QString : : number ( 4 * i )
+ " A "
+ ui - > MF_keyWidget - > item ( i , 1 ) - > text ( ) , waitTime ) ;
if ( result . indexOf ( " isOk:01 " ) ! = - 1 )
{
isKeyAValid = true ;
ui - > MF_dataWidget - > setItem ( 4 * i , 2 , new QTableWidgetItem ( result . mid ( result . indexOf ( " isOk:01 " ) + 13 , 47 ) . toUpper ( ) ) ) ;
}
}
QApplication : : processEvents ( ) ;
if ( ui - > MF_keyWidget - > item ( i , 2 ) ! = nullptr & & mifare - > isKeyValid ( ui - > MF_keyWidget - > item ( i , 2 ) - > text ( ) ) )
{
result = util - > execCMDWithOutput ( " hf mf rdbl "
+ QString : : number ( 4 * i )
+ " B "
+ ui - > MF_keyWidget - > item ( i , 2 ) - > text ( ) , waitTime ) ;
if ( result . indexOf ( " isOk:01 " ) ! = - 1 )
{
isKeyBValid = true ;
ui - > MF_dataWidget - > setItem ( 4 * i , 2 , new QTableWidgetItem ( result . mid ( result . indexOf ( " isOk:01 " ) + 13 , 47 ) . toUpper ( ) ) ) ;
}
}
// read the rest blocks of a sector
if ( isKeyAValid | | isKeyBValid )
{
for ( int j = 1 ; j < 4 ; j + + )
{
QApplication : : processEvents ( ) ;
result = util - > execCMDWithOutput ( " hf mf rdbl "
+ QString : : number ( 4 * i + j )
+ " "
+ ( isKeyAValid ? " A " : " B " )
+ " "
+ ui - > MF_keyWidget - > item ( i , ( isKeyAValid ? 1 : 2 ) ) - > text ( ) , waitTime ) ;
result = result . mid ( result . indexOf ( " isOk:01 " ) + 13 , 47 ) . toUpper ( ) ;
ui - > MF_dataWidget - > setItem ( 4 * i + j , 2 , new QTableWidgetItem ( result ) ) ;
}
QApplication : : processEvents ( ) ;
// fill the MF_dataWidget with the known valid key
//
// check whether the MF_dataWidget contains the valid key,
// and fill MF_keyWidget(when you only have KeyA but the ReadBlock output contains the KeyB)
//
// the structure is not symmetric, since you cannot get KeyA from output
// this program will only process the provided KeyA(in MF_keyWidget)
result = ui - > MF_dataWidget - > item ( 4 * i + 3 , 2 ) - > text ( ) ;
if ( isKeyAValid )
{
for ( int j = 0 ; j < 6 ; j + + )
{
result = result . replace ( j * 3 , 2 , ui - > MF_keyWidget - > item ( i , 1 ) - > text ( ) . mid ( j * 2 , 2 ) ) ;
}
}
else
{
result = result . replace ( 0 , 18 , " ?? ?? ?? ?? ?? ?? " ) ;
}
ui - > MF_dataWidget - > setItem ( 4 * i + 3 , 2 , new QTableWidgetItem ( result ) ) ;
if ( isKeyBValid )
{
for ( int j = 0 ; j < 6 ; j + + )
{
result = result . replace ( 30 + j * 3 , 2 , ui - > MF_keyWidget - > item ( i , 2 ) - > text ( ) . mid ( j * 2 , 2 ) ) ;
ui - > MF_dataWidget - > setItem ( 4 * i + 3 , 2 , new QTableWidgetItem ( result ) ) ;
}
}
else
{
QString tmpKey = result . right ( 18 ) . replace ( " " , " " ) ;
result = util - > execCMDWithOutput ( " hf mf rdbl "
+ QString : : number ( 4 * i + 3 )
+ " B "
+ tmpKey , waitTime ) ;
if ( result . indexOf ( " isOk:01 " ) ! = - 1 )
{
ui - > MF_keyWidget - > setItem ( i , 2 , new QTableWidgetItem ( tmpKey ) ) ;
}
else
{
result = ui - > MF_dataWidget - > item ( 4 * i + 3 , 2 ) - > text ( ) ;
result = result . replace ( 30 , 17 , " ?? ?? ?? ?? ?? ?? " ) ;
ui - > MF_dataWidget - > setItem ( 4 * i + 3 , 2 , new QTableWidgetItem ( result ) ) ;
}
}
}
}
mifare - > readAll ( ) ;
}
void MainWindow : : on_MF_RW_readBlockButton_clicked ( )
{
QString result = util - > execCMDWithOutput ( " hf mf rdbl "
+ ui - > MF_RW_blockBox - > currentText ( )
+ " "
+ ui - > MF_RW_keyTypeBox - > currentText ( )
+ " "
+ ui - > MF_RW_keyEdit - > text ( ) ) ;
if ( result . indexOf ( " isOk:01 " ) ! = - 1 )
{
result = result . mid ( result . indexOf ( " isOk:01 " ) + 13 , 47 ) . toUpper ( ) ;
if ( ( ui - > MF_RW_blockBox - > currentText ( ) . toInt ( ) + 1 ) % 4 = = 0 )
{
if ( ui - > MF_RW_keyTypeBox - > currentText ( ) = = " A " )
{
for ( int i = 0 ; i < 6 ; i + + )
{
result = result . replace ( i * 3 , 2 , ui - > MF_RW_keyEdit - > text ( ) . mid ( i * 2 , 2 ) ) ;
}
ui - > MF_RW_dataEdit - > setText ( result ) ;
QString tmpKey = result . right ( 18 ) . replace ( " " , " " ) ;
result = util - > execCMDWithOutput ( " hf mf rdbl "
+ ui - > MF_RW_keyTypeBox - > currentText ( )
+ " B "
+ tmpKey ) ;
if ( result . indexOf ( " isOk:01 " ) = = - 1 )
{
result = ui - > MF_RW_dataEdit - > text ( ) ;
result = result . replace ( 30 , 17 , " ?? ?? ?? ?? ?? ?? " ) ;
ui - > MF_RW_dataEdit - > setText ( result ) ;
}
}
else
{
for ( int i = 0 ; i < 6 ; i + + )
{
result = result . replace ( 30 + i * 3 , 2 , ui - > MF_RW_keyEdit - > text ( ) . mid ( i * 2 , 2 ) ) ;
}
result = result . replace ( 0 , 18 , " ?? ?? ?? ?? ?? ?? " ) ;
ui - > MF_RW_dataEdit - > setText ( result ) ;
}
}
}
mifare - > read ( ) ;
}
void MainWindow : : on_MF_RW_writeBlockButton_clicked ( )
{
QString result = util - > execCMDWithOutput ( " hf mf wrbl "
+ ui - > MF_RW_blockBox - > currentText ( )
+ " "
+ ui - > MF_RW_keyTypeBox - > currentText ( )
+ " "
+ ui - > MF_RW_keyEdit - > text ( )
+ " "
+ ui - > MF_RW_dataEdit - > text ( ) . replace ( " " , " " ) ) ;
if ( result . indexOf ( " isOk:01 " ) ! = - 1 )
{
}
mifare - > write ( ) ;
}
void MainWindow : : on_MF_RW_writeAllButton_clicked ( )
{
QString result ;
for ( int i = 0 ; i < 16 ; i + + )
{
for ( int j = 0 ; j < 4 ; j + + )
{
result = util - > execCMDWithOutput ( " hf mf wrbl "
+ QString : : number ( i * 4 + j )
+ " A "
+ ui - > MF_keyWidget - > item ( i , 1 ) - > text ( )
+ " "
+ ui - > MF_dataWidget - > item ( 2 , i * 4 + j ) - > text ( ) . replace ( " " , " " ) ) ;
if ( result . indexOf ( " isOk:01 " ) = = - 1 )
{
result = util - > execCMDWithOutput ( " hf mf wrbl "
+ QString : : number ( i * 4 + j )
+ " B "
+ ui - > MF_keyWidget - > item ( i , 2 ) - > text ( )
+ " "
+ ui - > MF_dataWidget - > item ( 2 , i * 4 + j ) - > text ( ) . replace ( " " , " " ) ) ;
}
}
}
mifare - > writeAll ( ) ;
}
// ************************************************
@ -392,21 +205,7 @@ void MainWindow::on_MF_RW_writeAllButton_clicked()
// ******************** other ********************
void MainWindow : : refreshOutput ( const QString & output )
{
qDebug ( ) < < " MainWindow::refresh: " < < output ;
ui - > Raw_outputEdit - > insertPlainText ( output ) ;
ui - > Raw_outputEdit - > moveCursor ( QTextCursor : : End ) ;
}
void MainWindow : : refreshCMD ( const QString & cmd )
{
ui - > Raw_CMDEdit - > setText ( cmd ) ;
if ( cmd ! = " " & & ( ui - > Raw_CMDHistoryWidget - > count ( ) = = 0 | | ui - > Raw_CMDHistoryWidget - > item ( ui - > Raw_CMDHistoryWidget - > count ( ) - 1 ) - > text ( ) ! = cmd ) )
ui - > Raw_CMDHistoryWidget - > addItem ( cmd ) ;
}
void MainWindow : : sendMSG ( )
void MainWindow : : sendMSG ( ) // send command when pressing Enter
{
if ( ui - > Raw_CMDEdit - > hasFocus ( ) )
on_Raw_sendCMDButton_clicked ( ) ;