Replace ukbhit by kbd_enter_pressed, not requiring tcgetattr:

Note that it behaves differently now
* it looks for Enter key only, not any key
* it "eats" the input, no need for (void)getchar() after it
* it works the same no matter the value of ICANON
* the mingw version has been adapted to act the similarly

This should fix its usage on Android where tcgetattr always returns -1
This commit is contained in:
Philippe Teuwen 2019-07-11 13:01:34 +02:00
commit 844d732297
27 changed files with 90 additions and 126 deletions

View file

@ -176,7 +176,7 @@ static int usage_hf_iclass_managekeys(void) {
return 0;
}
static int usage_hf_iclass_reader(void) {
PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until a key or the pm3 button is pressed\n");
PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until Enter or the pm3 button is pressed\n");
PrintAndLogEx(NORMAL, "Usage: hf iclass reader [h] [1]\n");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help text");
@ -376,16 +376,14 @@ static int CmdHFiClassSim(const char *Cmd) {
case 2: {
PrintAndLogEx(INFO, "Starting iCLASS sim 2 attack (elite mode)");
PrintAndLogEx(INFO, "press keyboard to cancel");
PrintAndLogEx(INFO, "press Enter to cancel");
PacketResponseNG resp;
clearCommandBuffer();
SendCommandOLD(CMD_SIMULATE_TAG_ICLASS, simType, NUM_CSNS, 0, csns, 8 * NUM_CSNS);
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
tries++;
if (ukbhit()) {
int gc = getchar();
(void)gc;
if (kbd_enter_pressed()) {
PrintAndLogEx(WARNING, "\naborted via keyboard.");
return 0;
}
@ -427,16 +425,14 @@ static int CmdHFiClassSim(const char *Cmd) {
case 4: {
// reader in key roll mode, when it has two keys it alternates when trying to verify.
PrintAndLogEx(INFO, "Starting iCLASS sim 4 attack (elite mode, reader in key roll mode)");
PrintAndLogEx(INFO, "press keyboard to cancel");
PrintAndLogEx(INFO, "press Enter to cancel");
PacketResponseNG resp;
clearCommandBuffer();
SendCommandOLD(CMD_SIMULATE_TAG_ICLASS, simType, NUM_CSNS, 0, csns, 8 * NUM_CSNS);
while (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
tries++;
if (ukbhit()) {
int gc = getchar();
(void)gc;
if (kbd_enter_pressed()) {
PrintAndLogEx(WARNING, "\naborted via keyboard.");
return 0;
}
@ -969,9 +965,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
while (true) {
printf(".");
fflush(stdout);
if (ukbhit()) {
int gc = getchar();
(void)gc;
if (kbd_enter_pressed()) {
PrintAndLogEx(WARNING, "\n[!] aborted via keyboard!\n");
DropField();
return 0;
@ -1945,9 +1939,7 @@ static int CmdHFiClassCheckKeys(const char *Cmd) {
uint64_t t2 = msclock();
uint8_t timeout = 0;
if (ukbhit()) {
int gc = getchar();
(void)gc;
if (kbd_enter_pressed()) {
PrintAndLogEx(WARNING, "\n[!] Aborted via keyboard!\n");
goto out;
}
@ -2446,7 +2438,7 @@ int readIclass(bool loop, bool verbose) {
// loop in client not device - else on windows have a communication error
PacketResponseNG resp;
while (!ukbhit()) {
while (!kbd_enter_pressed()) {
clearCommandBuffer();
SendCommandMIX(CMD_READER_ICLASS, flags, 0, 0, NULL, 0);