mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
FIX: gcc8.1 warnings
This commit is contained in:
parent
96361abd97
commit
e276bf1ce3
5 changed files with 59 additions and 36 deletions
75
armsrc/tlv.c
75
armsrc/tlv.c
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag)
|
int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag)
|
||||||
{
|
{
|
||||||
uint8_t tag[TAG_LENGTH] = {0x00,0x00};
|
uint8_t tag[TAG_LENGTH] = {0x00, 0x00, 0x00, 0x00};
|
||||||
uint16_t length = 0;
|
uint16_t length = 0;
|
||||||
//uint8_t value[VALUE_LENGTH];
|
//uint8_t value[VALUE_LENGTH];
|
||||||
uint8_t lenlen = 0;
|
uint8_t lenlen = 0;
|
||||||
|
@ -10,40 +10,44 @@ int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag)
|
||||||
int z = 0;
|
int z = 0;
|
||||||
//decode tag
|
//decode tag
|
||||||
tag[0] = data[0];
|
tag[0] = data[0];
|
||||||
if((tag[0] & TLV_TAG_NUMBER_MASK) == TLV_TAG_NUMBER_MASK) { //see subsequent bytes
|
if ((tag[0] & TLV_TAG_NUMBER_MASK) == TLV_TAG_NUMBER_MASK) { //see subsequent bytes
|
||||||
i++;
|
i++;
|
||||||
tag[i] = data[i];
|
|
||||||
//assume tag is only two bytes long for now
|
tag[i] = data[i];
|
||||||
/*
|
|
||||||
while((data[i] & TLV_TAG_MASK) == TLV_TAG_MASK){
|
while((data[i] & TLV_TAG_MASK) == TLV_TAG_MASK){
|
||||||
i++;
|
i++;
|
||||||
tag[i] = data[i];
|
tag[i] = data[i];
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
//decode length
|
//decode length
|
||||||
if((data[i] & TLV_LENGTH_MASK) == TLV_LENGTH_MASK) {
|
if ((data[i] & TLV_LENGTH_MASK) == TLV_LENGTH_MASK) {
|
||||||
lenlen = data[i] ^ TLV_LENGTH_MASK;
|
lenlen = data[i] ^ TLV_LENGTH_MASK;
|
||||||
i++;
|
i++;
|
||||||
length = (uint16_t)data[i];
|
length = (uint16_t)data[i];
|
||||||
z = 1;
|
z = 1;
|
||||||
while(z < lenlen){
|
while (z < lenlen) {
|
||||||
i++;
|
i++;
|
||||||
z++;
|
z++;
|
||||||
length <<= 8;
|
length <<= 8;
|
||||||
length += (uint16_t)data[i];
|
length += (uint16_t)data[i];
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
length = (uint16_t)data[i];
|
length = (uint16_t)data[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
//copy results into the structure and return
|
// copy results into the structure and return
|
||||||
memcpy(returnedtag->tag, tag, TAG_LENGTH);
|
memcpy(returnedtag->tag, tag, TAG_LENGTH);
|
||||||
(*returnedtag).valuelength = length; //return length of tag value
|
|
||||||
(*returnedtag).fieldlength = length + i + 1; //return length of total field
|
// return length of tag value
|
||||||
|
(*returnedtag).valuelength = length;
|
||||||
|
|
||||||
|
// return length of total field
|
||||||
|
(*returnedtag).fieldlength = length + i + 1;
|
||||||
|
|
||||||
memcpy(returnedtag->value, &(data[i]), length);
|
memcpy(returnedtag->value, &(data[i]), length);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -51,27 +55,40 @@ int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag)
|
||||||
//generate a TLV tag off input data
|
//generate a TLV tag off input data
|
||||||
int encode_ber_tlv_item(uint8_t* tag, uint8_t taglen, uint8_t* data, uint32_t datalen, uint8_t* outputtag, uint32_t* outputtaglen)
|
int encode_ber_tlv_item(uint8_t* tag, uint8_t taglen, uint8_t* data, uint32_t datalen, uint8_t* outputtag, uint32_t* outputtaglen)
|
||||||
{
|
{
|
||||||
if(!tag || !data || !outputtag || !outputtaglen) //null pointer check
|
if (!tag || !data || !outputtag || !outputtaglen)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
uint8_t datafieldlen = (datalen / 128) + 1; //field length of the tag
|
// field length of the tag
|
||||||
uint8_t tlvtotallen = taglen + datafieldlen + datalen; //total length of the tag
|
uint8_t datafieldlen = (datalen / 128) + 1;
|
||||||
uint8_t returnedtag[tlvtotallen]; //buffer for the returned tag
|
|
||||||
|
// total length of the tag
|
||||||
|
uint8_t tlvtotallen = taglen + datafieldlen + datalen;
|
||||||
|
|
||||||
|
// buffer for the returned tag
|
||||||
|
uint8_t returnedtag[tlvtotallen];
|
||||||
|
|
||||||
uint8_t counter = 0;
|
uint8_t counter = 0;
|
||||||
memcpy(returnedtag, tag, taglen); //copy tag into buffer
|
|
||||||
|
// copy tag into buffer
|
||||||
|
memcpy(returnedtag, tag, taglen);
|
||||||
counter += taglen;
|
counter += taglen;
|
||||||
if(datalen < 128){ // 1 byte length value
|
|
||||||
|
// 1 byte length value
|
||||||
|
if (datalen < 128){
|
||||||
returnedtag[counter++] = datalen;
|
returnedtag[counter++] = datalen;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
returnedtag[counter++] = datafieldlen | 0x80; //high bit set and number of length bytes
|
// high bit set and number of length bytes
|
||||||
for(uint8_t i=datafieldlen; i !=0; i--){
|
returnedtag[counter++] = datafieldlen | 0x80;
|
||||||
returnedtag[counter++] = (datalen >> (i * 8)) & 0xFF; //get current byte
|
|
||||||
|
for (uint8_t i = datafieldlen; i !=0; i--) {
|
||||||
|
// get current byte
|
||||||
|
returnedtag[counter++] = (datalen >> (i * 8)) & 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(&returnedtag[counter], data, datalen);
|
memcpy(&returnedtag[counter], data, datalen);
|
||||||
*outputtaglen = tlvtotallen;
|
*outputtaglen = tlvtotallen;
|
||||||
memcpy(outputtag, returnedtag,tlvtotallen);
|
memcpy(outputtag, returnedtag, tlvtotallen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
armsrc/tlv.h
13
armsrc/tlv.h
|
@ -6,8 +6,13 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
//structure buffer definitions
|
//structure buffer definitions
|
||||||
#define TAG_LENGTH 2
|
#ifndef TAG_LENGTH
|
||||||
#define VALUE_LENGTH 1024
|
# define TAG_LENGTH 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef VALUE_LENGTH
|
||||||
|
# define VALUE_LENGTH 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
//masks
|
//masks
|
||||||
//if TLV_TAG_NUMBER_MASK bits are set, refer to the next byte for the tag number
|
//if TLV_TAG_NUMBER_MASK bits are set, refer to the next byte for the tag number
|
||||||
|
@ -19,13 +24,13 @@
|
||||||
#define TLV_TAG_MASK 0x80
|
#define TLV_TAG_MASK 0x80
|
||||||
#define TLV_LENGTH_MASK 0x80
|
#define TLV_LENGTH_MASK 0x80
|
||||||
|
|
||||||
//tlv tag structure, tag can be max of 2 bytes, length up to 65535 and value 1024 bytes long
|
//tlv tag structure, tag can be max of 4 bytes, length up to 0xFFFFFFFF and value 1024 bytes long
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t tag[TAG_LENGTH];
|
uint8_t tag[TAG_LENGTH];
|
||||||
uint16_t fieldlength;
|
uint16_t fieldlength;
|
||||||
uint16_t valuelength;
|
uint16_t valuelength;
|
||||||
uint8_t value[VALUE_LENGTH];
|
uint8_t value[VALUE_LENGTH];
|
||||||
}tlvtag;
|
} tlvtag;
|
||||||
|
|
||||||
//decode a BER TLV
|
//decode a BER TLV
|
||||||
extern int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag);
|
extern int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag);
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "proxmark3.h"
|
#include "proxmark3.h"
|
||||||
|
|
||||||
#define PRINT_INDENT(level) {for (int i = 0; i < (level); i++) fprintf(f, " ");}
|
#ifndef PRINT_INDENT
|
||||||
|
# define PRINT_INDENT(level) {for (int i = 0; i < (level); i++) fprintf(f, " ");}
|
||||||
|
#endif
|
||||||
|
|
||||||
enum asn1_tag_t {
|
enum asn1_tag_t {
|
||||||
ASN1_TAG_GENERIC,
|
ASN1_TAG_GENERIC,
|
||||||
|
|
|
@ -371,7 +371,6 @@ bool ParamLoadFromJson(struct tlvdb *tlv) {
|
||||||
uint8_t buf[251] = {0};
|
uint8_t buf[251] = {0};
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
|
||||||
// here max length must be 4, but now tlv_tag_t is 2-byte var. so let it be 2 by now... TODO: needs refactoring tlv_tag_t...
|
|
||||||
if (!HexToBuffer("TLV Error type:", tlvTag, buf, 4, &buflen)) {
|
if (!HexToBuffer("TLV Error type:", tlvTag, buf, 4, &buflen)) {
|
||||||
json_decref(root);
|
json_decref(root);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -212,7 +212,7 @@ void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *sprint_hex(const uint8_t *data, const size_t len) {
|
char *sprint_hex(const uint8_t *data, const size_t len) {
|
||||||
static char buf[UTIL_BUFFER_SIZE_SPRINT] = {0};
|
static char buf[UTIL_BUFFER_SIZE_SPRINT - 3] = {0};
|
||||||
hex_to_buffer((uint8_t *)buf, data, len, sizeof(buf) - 1, 0, 1, true);
|
hex_to_buffer((uint8_t *)buf, data, len, sizeof(buf) - 1, 0, 1, true);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue