mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
syntax sugar
This commit is contained in:
parent
a6c50d7de2
commit
20e9931b63
2 changed files with 27 additions and 36 deletions
|
@ -47,12 +47,11 @@ static const poly_t pzero = PZERO;
|
||||||
|
|
||||||
/* Definitions */
|
/* Definitions */
|
||||||
|
|
||||||
void
|
void mcpy(model_t *dest, const model_t *src) {
|
||||||
mcpy(model_t *dest, const model_t *src) {
|
|
||||||
/* Copies the parameters of src to dest.
|
/* Copies the parameters of src to dest.
|
||||||
* dest must be an initialised model.
|
* dest must be an initialised model.
|
||||||
*/
|
*/
|
||||||
if(!dest || !src) return;
|
if (!dest || !src) return;
|
||||||
pcpy(&dest->spoly, src->spoly);
|
pcpy(&dest->spoly, src->spoly);
|
||||||
pcpy(&dest->init, src->init);
|
pcpy(&dest->init, src->init);
|
||||||
pcpy(&dest->xorout, src->xorout);
|
pcpy(&dest->xorout, src->xorout);
|
||||||
|
@ -63,10 +62,9 @@ mcpy(model_t *dest, const model_t *src) {
|
||||||
dest->name = src->name;
|
dest->name = src->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mfree(model_t *model) {
|
||||||
mfree(model_t *model) {
|
|
||||||
/* Frees the parameters of model. */
|
/* Frees the parameters of model. */
|
||||||
if(!model) return;
|
if (!model) return;
|
||||||
pfree(&model->spoly);
|
pfree(&model->spoly);
|
||||||
pfree(&model->init);
|
pfree(&model->init);
|
||||||
pfree(&model->xorout);
|
pfree(&model->xorout);
|
||||||
|
@ -76,25 +74,23 @@ mfree(model_t *model) {
|
||||||
/* not model either, it might point to an array! */
|
/* not model either, it might point to an array! */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int mcmp(const model_t *a, const model_t *b) {
|
||||||
mcmp(const model_t *a, const model_t *b) {
|
|
||||||
/* Compares a and b for identical effect, i.e. disregarding
|
/* Compares a and b for identical effect, i.e. disregarding
|
||||||
* trailing zeroes in parameter polys.
|
* trailing zeroes in parameter polys.
|
||||||
* Intended for bsearch().
|
* Intended for bsearch().
|
||||||
*/
|
*/
|
||||||
int result;
|
int result;
|
||||||
if(!a || !b) return(!b - !a);
|
if (!a || !b) return (!b - !a);
|
||||||
if((result = psncmp(&a->spoly, &b->spoly))) return(result);
|
if ((result = psncmp(&a->spoly, &b->spoly))) return (result);
|
||||||
if((result = psncmp(&a->init, &b->init))) return(result);
|
if ((result = psncmp(&a->init, &b->init))) return (result);
|
||||||
if((a->flags & P_REFIN) && (~b->flags & P_REFIN)) return(1);
|
if ((a->flags & P_REFIN) && (~b->flags & P_REFIN)) return (1);
|
||||||
if((~a->flags & P_REFIN) && (b->flags & P_REFIN)) return(-1);
|
if ((~a->flags & P_REFIN) && (b->flags & P_REFIN)) return (-1);
|
||||||
if((a->flags & P_REFOUT) && (~b->flags & P_REFOUT)) return(1);
|
if ((a->flags & P_REFOUT) && (~b->flags & P_REFOUT)) return (1);
|
||||||
if((~a->flags & P_REFOUT) && (b->flags & P_REFOUT)) return(-1);
|
if ((~a->flags & P_REFOUT) && (b->flags & P_REFOUT)) return (-1);
|
||||||
return(psncmp(&a->xorout, &b->xorout));
|
return (psncmp(&a->xorout, &b->xorout));
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char * mtostr(const model_t *model) {
|
||||||
mtostr(const model_t *model) {
|
|
||||||
/* Returns a malloc()-ed string containing a Williams model
|
/* Returns a malloc()-ed string containing a Williams model
|
||||||
* record representing the input model.
|
* record representing the input model.
|
||||||
* mcanon() should be called on the argument before printing.
|
* mcanon() should be called on the argument before printing.
|
||||||
|
@ -103,7 +99,7 @@ mtostr(const model_t *model) {
|
||||||
char *polystr, *initstr, *xorotstr, *checkstr, *magicstr,
|
char *polystr, *initstr, *xorotstr, *checkstr, *magicstr,
|
||||||
strbuf[512], *string = NULL;
|
strbuf[512], *string = NULL;
|
||||||
|
|
||||||
if(!model) return(NULL);
|
if (!model) return(NULL);
|
||||||
polystr = ptostr(model->spoly, P_RTJUST, 4);
|
polystr = ptostr(model->spoly, P_RTJUST, 4);
|
||||||
initstr = ptostr(model->init, P_RTJUST, 4);
|
initstr = ptostr(model->init, P_RTJUST, 4);
|
||||||
xorotstr = ptostr(model->xorout, P_RTJUST, 4);
|
xorotstr = ptostr(model->xorout, P_RTJUST, 4);
|
||||||
|
@ -122,7 +118,7 @@ mtostr(const model_t *model) {
|
||||||
+ (checkstr && *checkstr ? strlen(checkstr) : 6)
|
+ (checkstr && *checkstr ? strlen(checkstr) : 6)
|
||||||
+ (magicstr && *magicstr ? strlen(magicstr) : 6)
|
+ (magicstr && *magicstr ? strlen(magicstr) : 6)
|
||||||
+ (model->name && *model->name ? 2 + strlen(model->name) : 6);
|
+ (model->name && *model->name ? 2 + strlen(model->name) : 6);
|
||||||
if((string = malloc(size))) {
|
if ((string = malloc(size))) {
|
||||||
sprintf(strbuf, "\"%s\"", model->name);
|
sprintf(strbuf, "\"%s\"", model->name);
|
||||||
sprintf(string,
|
sprintf(string,
|
||||||
"width=%lu"
|
"width=%lu"
|
||||||
|
@ -154,12 +150,11 @@ mtostr(const model_t *model) {
|
||||||
return(string);
|
return(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mcanon(model_t *model) {
|
||||||
mcanon(model_t *model) {
|
|
||||||
/* canonicalise a model */
|
/* canonicalise a model */
|
||||||
unsigned long dlen;
|
unsigned long dlen;
|
||||||
|
|
||||||
if(!model) return;
|
if (!model) return;
|
||||||
|
|
||||||
/* extending on the right here. This preserves the functionality
|
/* extending on the right here. This preserves the functionality
|
||||||
* of a presumed working model.
|
* of a presumed working model.
|
||||||
|
@ -177,12 +172,11 @@ mcanon(model_t *model) {
|
||||||
* might be noticed. Storing the Check value with each preset
|
* might be noticed. Storing the Check value with each preset
|
||||||
* is highly preferred.
|
* is highly preferred.
|
||||||
*/
|
*/
|
||||||
if(!(plen(model->check) && plen(model->magic)))
|
if (!(plen(model->check) && plen(model->magic)))
|
||||||
mcheck(model);
|
mcheck(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mcheck(model_t *model) {
|
||||||
mcheck(model_t *model) {
|
|
||||||
/* calculate a check for the model */
|
/* calculate a check for the model */
|
||||||
poly_t checkstr, check, xorout, magic;
|
poly_t checkstr, check, xorout, magic;
|
||||||
|
|
||||||
|
@ -195,7 +189,7 @@ mcheck(model_t *model) {
|
||||||
checkstr = strtop("313233343536373839", model->flags, 8);
|
checkstr = strtop("313233343536373839", model->flags, 8);
|
||||||
check = pcrc(checkstr, model->spoly, model->init, pzero, model->flags);
|
check = pcrc(checkstr, model->spoly, model->init, pzero, model->flags);
|
||||||
pfree(&checkstr);
|
pfree(&checkstr);
|
||||||
if(model->flags & P_REFOUT)
|
if (model->flags & P_REFOUT)
|
||||||
prev(&check);
|
prev(&check);
|
||||||
psum(&check, model->xorout, 0UL);
|
psum(&check, model->xorout, 0UL);
|
||||||
model->check = check;
|
model->check = check;
|
||||||
|
@ -206,17 +200,16 @@ mcheck(model_t *model) {
|
||||||
* reflected before submitting the codeword.
|
* reflected before submitting the codeword.
|
||||||
*/
|
*/
|
||||||
xorout=pclone(model->xorout);
|
xorout=pclone(model->xorout);
|
||||||
if(model->flags & P_REFOUT)
|
if (model->flags & P_REFOUT)
|
||||||
prev(&xorout);
|
prev(&xorout);
|
||||||
magic = pcrc(xorout, model->spoly, pzero, pzero, model->flags);
|
magic = pcrc(xorout, model->spoly, pzero, pzero, model->flags);
|
||||||
pfree(&xorout);
|
pfree(&xorout);
|
||||||
if(model->flags & P_REFIN)
|
if (model->flags & P_REFIN)
|
||||||
prev(&magic);
|
prev(&magic);
|
||||||
model->magic = magic;
|
model->magic = magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mrev(model_t *model) {
|
||||||
mrev(model_t *model) {
|
|
||||||
/* reverse the model to calculate reversed CRCs */
|
/* reverse the model to calculate reversed CRCs */
|
||||||
/* Here we invert RefIn and RefOut so that the user need only
|
/* Here we invert RefIn and RefOut so that the user need only
|
||||||
* reverse the order of characters in the arguments, not the
|
* reverse the order of characters in the arguments, not the
|
||||||
|
@ -230,7 +223,7 @@ mrev(model_t *model) {
|
||||||
poly_t temp;
|
poly_t temp;
|
||||||
|
|
||||||
prcp(&model->spoly);
|
prcp(&model->spoly);
|
||||||
if(model->flags & P_REFOUT)
|
if (model->flags & P_REFOUT)
|
||||||
prev(&model->init);
|
prev(&model->init);
|
||||||
else
|
else
|
||||||
prev(&model->xorout);
|
prev(&model->xorout);
|
||||||
|
@ -246,8 +239,7 @@ mrev(model_t *model) {
|
||||||
mnovel(model);
|
mnovel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mnovel(model_t *model) {
|
||||||
mnovel(model_t *model) {
|
|
||||||
/* remove name and check string from modified model */
|
/* remove name and check string from modified model */
|
||||||
model->name = NULL;
|
model->name = NULL;
|
||||||
pfree(&model->check);
|
pfree(&model->check);
|
||||||
|
|
|
@ -1012,8 +1012,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
||||||
s->compressed_len += 7; /* align on byte boundary */
|
s->compressed_len += 7; /* align on byte boundary */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
|
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len >> 3, s->compressed_len - 7 * last));
|
||||||
s->compressed_len-7*last));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue