FIX; coverity scan 133850, & operation should keep only topbit of lower nibble.

CHG: tabs fixed
This commit is contained in:
iceman1001 2016-08-03 10:01:37 +02:00
commit e8fecd72bc

View file

@ -47,24 +47,29 @@ int usage_legic_read(void){
return 0;
}
int usage_legic_sim(void){
return 0;
}
int usage_legic_rawwrite(void){
return 0;
}
int usage_legic_fill(void){
return 0;
}
/*
* Output BigBuf and deobfuscate LEGIC RF tag data.
* This is based on information given in the talk held
* by Henryk Ploetz and Karsten Nohl at 26c3
*/
int CmdLegicDecode(const char *Cmd) {
// Index for the bytearray.
int i = 0;
int k = 0, segmentNum;
int segment_len = 0;
int segment_flag = 0;
int i = 0, k = 0, segmentNum = 0, segment_len = 0, segment_flag = 0;
int crc = 0, wrp = 0, wrc = 0;
uint8_t stamp_len = 0;
int crc = 0;
int wrp = 0;
int wrc = 0;
uint8_t data_buf[1052]; // receiver buffer, should be 1024..
char token_type[5];
int dcf;
uint8_t data_buf[1052]; // receiver buffer
char token_type[5] = {0,0,0,0,0};
int dcf = 0;
int bIsSegmented = 0;
// download EML memory, where the "legic read" command puts the data.
@ -113,15 +118,15 @@ int CmdLegicDecode(const char *Cmd) {
} else {
switch (data_buf[5] & 0x7f) {
case 0x00 ... 0x2f:
strncpy(token_type, "IAM",sizeof(token_type));
strncpy(token_type, "IAM", sizeof(token_type));
fl = (0x2f - (data_buf[5] & 0x7f)) + 1;
break;
case 0x30 ... 0x6f:
strncpy(token_type, "SAM",sizeof(token_type));
strncpy(token_type, "SAM", sizeof(token_type));
fl = (0x6f - (data_buf[5] & 0x7f)) + 1;
break;
case 0x70 ... 0x7f:
strncpy(token_type, "GAM",sizeof(token_type));
strncpy(token_type, "GAM", sizeof(token_type));
fl = (0x7f - (data_buf[5] & 0x7f)) + 1;
break;
}
@ -134,7 +139,7 @@ int CmdLegicDecode(const char *Cmd) {
data_buf[5],
data_buf[6],
token_type,
(data_buf[5]&0x80)>>7,
(data_buf[5] & 0x80 )>> 7,
stamp_len,
fl
);
@ -153,7 +158,7 @@ int CmdLegicDecode(const char *Cmd) {
data_buf[5],
data_buf[6],
token_type,
(data_buf[5]&0x80)>>7
(data_buf[5]&0x80) >> 7
);
}
@ -162,9 +167,9 @@ int CmdLegicDecode(const char *Cmd) {
if(bIsSegmented) {
PrintAndLog("WRP=%02u, WRC=%01u, RD=%01u, SSC=%02x",
data_buf[7]&0x0f,
(data_buf[7]&0x70)>>4,
(data_buf[7]&0x80)>>7,
data_buf[7] & 0x0f,
(data_buf[7] & 0x70) >> 4,
(data_buf[7] & 0x80) >> 7,
data_buf[8]
);
}
@ -181,12 +186,10 @@ int CmdLegicDecode(const char *Cmd) {
}
}
uint8_t segCrcBytes[8] = {0x00};
uint8_t segCrcBytes[8] = {0,0,0,0,0,0,0,0};
uint32_t segCalcCRC = 0;
uint32_t segCRC = 0;
// Data card?
if(dcf <= 60000) {
@ -297,7 +300,7 @@ int CmdLegicDecode(const char *Cmd) {
i = 8;
wrp = data_buf[7] & 0x0F;
wrc = (data_buf[7] & 0x07) >> 4; // ICEMAN 20160802, this will always be ZERO
wrc = (data_buf[7] & 0x707) >> 4;
bool hasWRC = (wrc > 0);
bool hasWRP = (wrp > wrc);
@ -322,7 +325,7 @@ int CmdLegicDecode(const char *Cmd) {
PrintAndLog("Remaining write protected area: (I %d | WRC %d | WRP %d | WRP_LEN %d)", i, wrc, wrp, wrp_len);
PrintAndLog("\nrow | data");
PrintAndLog("-----+------------------------------------------------");
print_hex_break( data_buf+i, wrp_len, 16);
print_hex_break( data_buf + i, wrp_len, 16);
i += wrp_len;
// does this one work? (Answer: Only if KGH/BGH is used with BCD encoded card number! So maybe this will show just garbage...)
@ -333,7 +336,7 @@ int CmdLegicDecode(const char *Cmd) {
PrintAndLog("Remaining segment payload: (I %d | Remain LEN %d)", i, remain_seg_payload_len);
PrintAndLog("\nrow | data");
PrintAndLog("-----+------------------------------------------------");
print_hex_break( data_buf+i, remain_seg_payload_len, 16);
print_hex_break( data_buf + i, remain_seg_payload_len, 16);
i += remain_seg_payload_len;
PrintAndLog("-----+------------------------------------------------\n");
@ -351,7 +354,7 @@ int CmdLegicRFRead(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_read();
int byte_count=0, offset=0;
int byte_count = 0, offset = 0;
sscanf(Cmd, "%i %i", &offset, &byte_count);
if(byte_count == 0) byte_count = -1;
if(byte_count + offset > 1024) byte_count = 1024 - offset;
@ -362,8 +365,10 @@ int CmdLegicRFRead(const char *Cmd) {
return 0;
}
int CmdLegicLoad(const char *Cmd) {
// iceman: potential bug, where all filepaths or filename which starts with H or h will print the helptext :)
char cmdp = param_getchar(Cmd, 0);
if ( cmdp == 'H' || cmdp == 'h' || cmdp == 0x00) return usage_legic_load();
@ -444,9 +449,11 @@ int CmdLegicSave(const char *Cmd) {
int requested = 1024;
int offset = 0;
int delivered = 0;
char filename[FILE_PATH_SIZE];
char filename[FILE_PATH_SIZE] = {0x00};
uint8_t got[1024] = {0x00};
memset(filename, 0, FILE_PATH_SIZE);
sscanf(Cmd, " %s %i %i", filename, &requested, &offset);
/* If no length given save entire legic read buffer */
@ -501,7 +508,7 @@ int CmdLegicRfSim(const char *Cmd) {
//TODO: write a help text (iceman)
int CmdLegicRfWrite(const char *Cmd) {
UsbCommand c = {CMD_WRITER_LEGIC_RF};
UsbCommand c = {CMD_WRITER_LEGIC_RF, {0,0,0}};
int res = sscanf(Cmd, " 0x%"llx" 0x%"llx, &c.arg[0], &c.arg[1]);
if(res != 2) {
PrintAndLog("Please specify the offset and length as two hex strings");