mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-07 16:48:15 +08: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)
|
||||
{
|
||||
uint8_t tag[TAG_LENGTH] = {0x00,0x00};
|
||||
uint8_t tag[TAG_LENGTH] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint16_t length = 0;
|
||||
//uint8_t value[VALUE_LENGTH];
|
||||
uint8_t lenlen = 0;
|
||||
|
@ -10,40 +10,44 @@ int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag)
|
|||
int z = 0;
|
||||
//decode tag
|
||||
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++;
|
||||
tag[i] = data[i];
|
||||
//assume tag is only two bytes long for now
|
||||
/*
|
||||
while((data[i] & TLV_TAG_MASK) == TLV_TAG_MASK){
|
||||
i++;
|
||||
tag[i] = data[i];
|
||||
}
|
||||
*/
|
||||
|
||||
tag[i] = data[i];
|
||||
|
||||
while((data[i] & TLV_TAG_MASK) == TLV_TAG_MASK){
|
||||
i++;
|
||||
tag[i] = data[i];
|
||||
}
|
||||
|
||||
}
|
||||
i++;
|
||||
//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;
|
||||
i++;
|
||||
length = (uint16_t)data[i];
|
||||
z = 1;
|
||||
while(z < lenlen){
|
||||
while (z < lenlen) {
|
||||
i++;
|
||||
z++;
|
||||
length <<= 8;
|
||||
length += (uint16_t)data[i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
length = (uint16_t)data[i];
|
||||
i++;
|
||||
}
|
||||
//copy results into the structure and return
|
||||
// copy results into the structure and return
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
@ -51,27 +55,40 @@ int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag)
|
|||
//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)
|
||||
{
|
||||
if(!tag || !data || !outputtag || !outputtaglen) //null pointer check
|
||||
if (!tag || !data || !outputtag || !outputtaglen)
|
||||
return 0;
|
||||
|
||||
uint8_t datafieldlen = (datalen / 128) + 1; //field length of the tag
|
||||
uint8_t tlvtotallen = taglen + datafieldlen + datalen; //total length of the tag
|
||||
uint8_t returnedtag[tlvtotallen]; //buffer for the returned tag
|
||||
// field length of the tag
|
||||
uint8_t datafieldlen = (datalen / 128) + 1;
|
||||
|
||||
// total length of the tag
|
||||
uint8_t tlvtotallen = taglen + datafieldlen + datalen;
|
||||
|
||||
// buffer for the returned tag
|
||||
uint8_t returnedtag[tlvtotallen];
|
||||
|
||||
uint8_t counter = 0;
|
||||
memcpy(returnedtag, tag, taglen); //copy tag into buffer
|
||||
|
||||
// copy tag into buffer
|
||||
memcpy(returnedtag, tag, taglen);
|
||||
counter += taglen;
|
||||
if(datalen < 128){ // 1 byte length value
|
||||
|
||||
// 1 byte length value
|
||||
if (datalen < 128){
|
||||
returnedtag[counter++] = datalen;
|
||||
}
|
||||
else{
|
||||
returnedtag[counter++] = datafieldlen | 0x80; //high bit set and number of length bytes
|
||||
for(uint8_t i=datafieldlen; i !=0; i--){
|
||||
returnedtag[counter++] = (datalen >> (i * 8)) & 0xFF; //get current byte
|
||||
} else {
|
||||
|
||||
// high bit set and number of length bytes
|
||||
returnedtag[counter++] = datafieldlen | 0x80;
|
||||
|
||||
for (uint8_t i = datafieldlen; i !=0; i--) {
|
||||
// get current byte
|
||||
returnedtag[counter++] = (datalen >> (i * 8)) & 0xFF;
|
||||
}
|
||||
}
|
||||
memcpy(&returnedtag[counter], data, datalen);
|
||||
*outputtaglen = tlvtotallen;
|
||||
memcpy(outputtag, returnedtag,tlvtotallen);
|
||||
memcpy(outputtag, returnedtag, tlvtotallen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
13
armsrc/tlv.h
13
armsrc/tlv.h
|
@ -6,8 +6,13 @@
|
|||
#include <stddef.h>
|
||||
|
||||
//structure buffer definitions
|
||||
#define TAG_LENGTH 2
|
||||
#define VALUE_LENGTH 1024
|
||||
#ifndef TAG_LENGTH
|
||||
# define TAG_LENGTH 4
|
||||
#endif
|
||||
|
||||
#ifndef VALUE_LENGTH
|
||||
# define VALUE_LENGTH 1024
|
||||
#endif
|
||||
|
||||
//masks
|
||||
//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_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 {
|
||||
uint8_t tag[TAG_LENGTH];
|
||||
uint16_t fieldlength;
|
||||
uint16_t valuelength;
|
||||
uint8_t value[VALUE_LENGTH];
|
||||
}tlvtag;
|
||||
} tlvtag;
|
||||
|
||||
//decode a BER TLV
|
||||
extern int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag);
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
#include "util.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 {
|
||||
ASN1_TAG_GENERIC,
|
||||
|
|
|
@ -371,7 +371,6 @@ bool ParamLoadFromJson(struct tlvdb *tlv) {
|
|||
uint8_t buf[251] = {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)) {
|
||||
json_decref(root);
|
||||
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) {
|
||||
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);
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue