Minor code clean up.
Added from Pm3-master which will make this fork one step closer to Pm3-master.
case RHT2F_CRYPTO: {
DbpString("Authenticating using key:");
- memcpy(key,htd->crypto.key,6); // 4 or 6 ??
+ memcpy(key,htd->crypto.key,4); //HACK; 4 or 6?? I read both in the code.
Dbhexdump(6,key,false);
blocknr = 0;
bQuiet = false;
void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) {
- uint8_t card_data[24]={0};
+ uint8_t card_data[USB_CMD_DATA_SIZE]={0};
uint16_t block_crc_LUT[255] = {0};
{//Generate a lookup table for block crc
cardsize = memory.k16 ? 255 : 32;
WDT_HIT();
-
+ //Set card_data to all zeroes, we'll fill it with data
+ memset(card_data,0x0,USB_CMD_DATA_SIZE);
+ uint8_t failedRead =0;
+ uint8_t stored_data_length =0;
//then loop around remaining blocks
for(int block=0; block < cardsize; block++){
resp[3], resp[4], resp[5],
resp[6], resp[7]);
+ //Fill up the buffer
+ memcpy(card_data+stored_data_length,resp,8);
+ stored_data_length += 8;
+
+ if(stored_data_length +8 > USB_CMD_DATA_SIZE)
+ {//Time to send this off and start afresh
+ cmd_send(CMD_ACK,
+ stored_data_length,//data length
+ failedRead,//Failed blocks?
+ 0,//Not used ATM
+ card_data, stored_data_length);
+ //reset
+ stored_data_length = 0;
+ failedRead = 0;
+ }
+
}else{
+ failedRead = 1;
+ stored_data_length +=8;//Otherwise, data becomes misaligned
Dbprintf("Failed to dump block %d", block);
-
}
}
+ //Send off any remaining data
+ if(stored_data_length > 0)
+ {
+ cmd_send(CMD_ACK,
+ stored_data_length,//data length
+ failedRead,//Failed blocks?
+ 0,//Not used ATM
+ card_data, stored_data_length);
+ }
//If we got here, let's break
break;
}
+ //Signal end of transmission
+ cmd_send(CMD_ACK,
+ 0,//data length
+ 0,//Failed blocks?
+ 0,//Not used ATM
+ card_data, 0);
+
LED_A_OFF();
}
uint16_t crc = 0;
- uint8_t* resp = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
+ uint8_t* resp = (((uint8_t *)BigBuf) + 3560);
// Reset trace buffer
memset(trace, 0x44, RECV_CMD_OFFSET);
PrintAndLog("Usage: hf 14b write <1|2> <BLOCK> <DATA>");
PrintAndLog(" [1 = SRIX4K]");
PrintAndLog(" [2 = SRI512]");
- PrintAndLog(" [BLOCK number depends on which tag, special block == 255]");
- PrintAndLog(" sample: hf 14b write 1 127 11223344");
- PrintAndLog(" : hf 14b write 1 255 11223344");
+ PrintAndLog(" [BLOCK number depends on tag, special block == FF]");
+ PrintAndLog(" sample: hf 14b write 1 7F 11223344");
+ PrintAndLog(" : hf 14b write 1 FF 11223344");
PrintAndLog(" : hf 14b write 2 15 11223344");
- PrintAndLog(" : hf 14b write 2 255 11223344");
+ PrintAndLog(" : hf 14b write 2 FF 11223344");
return 0;
}
- if ( param_getchar(Cmd, 0) == '2' )
+ if ( cmdp == '2' )
isSrix4k = false;
- blockno = param_get8(Cmd, 1);
+ //blockno = param_get8(Cmd, 1);
+
+ if ( param_gethex(Cmd,1, &blockno, 2) ) {
+ PrintAndLog("Block number must include 2 HEX symbols");
+ return 0;
+ }
if ( isSrix4k ){
if ( blockno > 0x7f && blockno != 0xff ){
}
if ( blockno == 0xff)
- PrintAndLog("Writing to special block %02X [ %s]", blockno, sprint_hex(data,4) );
+ PrintAndLog("[%s] Write special block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512" , blockno, sprint_hex(data,4) );
else
- PrintAndLog("Writing to block %02X [ %s]", blockno, sprint_hex(data,4) );
+ PrintAndLog("[%s] Write block %02X [ %s ]", (isSrix4k)?"SRIX4K":"SRI512", blockno, sprint_hex(data,4) );
sprintf(str, "-c -p 09 %02x %02x%02x%02x%02x", blockno, data[0], data[1], data[2], data[3]);
+
CmdHF14BCmdRaw(str);
return 0;
}
default: numSectors = 16;\r
} \r
\r
- if (cmdp == 'h' || cmdp == 'H') {\r
+ if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') {\r
PrintAndLog("Usage: hf mf restore [card memory]");\r
PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");\r
PrintAndLog("");\r
#include "cmddata.h"
#include "cmdhw.h"
#include "cmdmain.h"
+#include "cmddata.h"
/* low-level hardware control */
/* We should have a valid filename now, e.g. dumpdata-3.bin */
/*Opening file for writing in binary mode*/
- FILE *fh=fopen(fileName,"wb");
- if(!fh) {
+ FILE *fileHandle=fopen(fileName,"wb");
+ if(!fileHandle) {
PrintAndLog("Failed to write to file '%s'", fileName);
- free(fh);
+ free(fileName);
return 1;
}
- fwrite(data, 1, datalen, fh);
- fclose(fh);
+ fwrite(data, 1, datalen, fileHandle);
+ fclose(fileHandle);
PrintAndLog("Saved data to '%s'", fileName);
free(fileName);
#if 0
printf("Sending %d bytes\n", sizeof(UsbCommand));
#endif
-/*
- if (txcmd_pending) {
- ERR("Sending command failed, previous command is still pending");
- }
-*/
- if(offline)
- {
+
+ if (offline) {
PrintAndLog("Sending bytes to proxmark failed - offline");
return;
}
continue;
}
cmd_count = (prx-rx) / sizeof(UsbCommand);
- // printf("received %d bytes, which represents %d commands\n",(prx-rx), cmd_count);
+
for (size_t i=0; i<cmd_count; i++) {
UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
}
if (arg->usb_present == 1) {
rarg.run=1;
- // pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
}
FILE *script_file = NULL;
char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest
- if (arg->script_cmds_file)
- {
+ if (arg->script_cmds_file) {
script_file = fopen(arg->script_cmds_file, "r");
- if (script_file)
- {
+ if (script_file) {
printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
}
}
read_history(".history");
- while(1)
- {
+
+ while(1) {
+
// If there is a script file
if (script_file)
{
- if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file))
- {
+ if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) {
fclose(script_file);
script_file = NULL;
- }
- else
- {
+ } else {
char *nl;
nl = strrchr(script_cmd_buf, '\r');
if (nl) *nl = '\0';
nl = strrchr(script_cmd_buf, '\n');
if (nl) *nl = '\0';
- if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL)
- {
+ if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
memset(cmd, 0, strlen(script_cmd_buf));
strcpy(cmd, script_cmd_buf);
printf("%s\n", cmd);
}
}
- if (!script_file)
- {
+ if (!script_file) {
cmd = readline(PROXPROMPT);
}
if (cmd) {
+
while(cmd[strlen(cmd) - 1] == ' ')
cmd[strlen(cmd) - 1] = 0x00;
exit(0);
break;
}
-
CommandReceived(cmd);
add_history(cmd);
}
pthread_join(reader_thread, NULL);
}
- if (script_file)
- {
+ if (script_file) {
fclose(script_file);
script_file = NULL;
}