mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
minor adjustements, found some comments.
This commit is contained in:
parent
ef085a5948
commit
13629a71d3
1 changed files with 104 additions and 101 deletions
205
client/cmdcrc.c
205
client/cmdcrc.c
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
//#include <stdlib.h>
|
|
||||||
//#include <ctype.h>
|
|
||||||
#include "cmdmain.h"
|
#include "cmdmain.h"
|
||||||
#include "cmdcrc.h"
|
#include "cmdcrc.h"
|
||||||
#include "reveng/reveng.h"
|
#include "reveng/reveng.h"
|
||||||
|
@ -74,10 +72,10 @@ int CmdCrc(const char *Cmd)
|
||||||
if (argc == 3 && memcmp(argv[1],"-g",2)==0) {
|
if (argc == 3 && memcmp(argv[1],"-g",2)==0) {
|
||||||
CmdrevengSearch(argv[2]);
|
CmdrevengSearch(argv[2]);
|
||||||
} else {
|
} else {
|
||||||
reveng_main(argc, argv);
|
reveng_main(argc, argv);
|
||||||
}
|
}
|
||||||
//PrintAndLog("DEBUG argc: %d, %s %s Cmd: %s",argc, argv[0], Cmd2, Cmd);
|
//PrintAndLog("DEBUG argc: %d, %s %s Cmd: %s",argc, argv[0], Cmd2, Cmd);
|
||||||
for(int i = 0; i < argc; ++i){
|
for(int i = 0; i < argc; ++i) {
|
||||||
free(argv[i]);
|
free(argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,121 +129,122 @@ int GetModels(char *Models[], int *count, uint8_t *width){
|
||||||
mfree(&model);
|
mfree(&model);
|
||||||
} else { //reveng -s
|
} else { //reveng -s
|
||||||
|
|
||||||
if(~model.flags & P_MULXN)
|
if(~model.flags & P_MULXN)
|
||||||
return uerr("cannot search for non-Williams compliant models");
|
return uerr("cannot search for non-Williams compliant models");
|
||||||
|
|
||||||
praloc(&model.spoly, (unsigned long)width[0]);
|
praloc(&model.spoly, (unsigned long)width[0]);
|
||||||
praloc(&model.init, (unsigned long)width[0]);
|
praloc(&model.init, (unsigned long)width[0]);
|
||||||
praloc(&model.xorout, (unsigned long)width[0]);
|
praloc(&model.xorout, (unsigned long)width[0]);
|
||||||
if(!plen(model.spoly))
|
|
||||||
|
if(!plen(model.spoly))
|
||||||
palloc(&model.spoly, (unsigned long)width[0]);
|
palloc(&model.spoly, (unsigned long)width[0]);
|
||||||
else
|
else
|
||||||
width[0] = (uint8_t)plen(model.spoly);
|
width[0] = (uint8_t)plen(model.spoly);
|
||||||
|
|
||||||
/* special case if qpoly is zero, search to end of range */
|
/* special case if qpoly is zero, search to end of range */
|
||||||
if(!ptst(qpoly))
|
if(!ptst(qpoly))
|
||||||
rflags &= ~R_HAVEQ;
|
rflags &= ~R_HAVEQ;
|
||||||
|
|
||||||
/* if endianness not specified, try
|
|
||||||
* little-endian then big-endian.
|
|
||||||
* NB: crossed-endian algorithms will not be
|
|
||||||
* searched.
|
|
||||||
*/
|
|
||||||
/* scan against preset models */
|
|
||||||
if(~uflags & C_FORCE) {
|
|
||||||
pass = 0;
|
|
||||||
Cnt = 0;
|
|
||||||
do {
|
|
||||||
psets = mcount();
|
|
||||||
|
|
||||||
while(psets) {
|
|
||||||
mbynum(&pset, --psets);
|
|
||||||
|
|
||||||
/* skip if different width, or refin or refout don't match */
|
|
||||||
if(plen(pset.spoly) != width[0] || (model.flags ^ pset.flags) & (P_REFIN | P_REFOUT))
|
|
||||||
continue;
|
|
||||||
/* skip if the preset doesn't match specified parameters */
|
|
||||||
if(rflags & R_HAVEP && pcmp(&model.spoly, &pset.spoly))
|
|
||||||
continue;
|
|
||||||
if(rflags & R_HAVEI && psncmp(&model.init, &pset.init))
|
|
||||||
continue;
|
|
||||||
if(rflags & R_HAVEX && psncmp(&model.xorout, &pset.xorout))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
//for additional args (not used yet, maybe future?)
|
|
||||||
apoly = pclone(pset.xorout);
|
|
||||||
if(pset.flags & P_REFOUT)
|
|
||||||
prev(&apoly);
|
|
||||||
|
|
||||||
for(qptr = apolys; qptr < pptr; ++qptr) {
|
|
||||||
crc = pcrc(*qptr, pset.spoly, pset.init, apoly, 0);
|
|
||||||
if(ptst(crc)) {
|
|
||||||
pfree(&crc);
|
|
||||||
break;
|
|
||||||
} else
|
|
||||||
pfree(&crc);
|
|
||||||
}
|
|
||||||
pfree(&apoly);
|
|
||||||
if(qptr == pptr) {
|
|
||||||
|
|
||||||
/* the selected model solved all arguments */
|
|
||||||
|
|
||||||
mcanon(&pset);
|
|
||||||
|
|
||||||
size_t size = (pset.name && *pset.name) ? strlen(pset.name) : 6;
|
|
||||||
//PrintAndLog("Size: %d, %s, count: %d",size,pset.name, Cnt);
|
|
||||||
char *tmp = calloc(size+1, sizeof(char));
|
|
||||||
if (tmp == NULL){
|
|
||||||
PrintAndLog("out of memory?");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
width[Cnt] = width[0];
|
|
||||||
memcpy(tmp, pset.name, size);
|
|
||||||
Models[Cnt++] = tmp;
|
|
||||||
*count = Cnt;
|
|
||||||
uflags |= C_RESULT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mfree(&pset);
|
|
||||||
|
|
||||||
/* toggle refIn/refOut and reflect arguments */
|
|
||||||
if(~rflags & R_HAVERI) {
|
|
||||||
model.flags ^= P_REFIN | P_REFOUT;
|
|
||||||
for(qptr = apolys; qptr < pptr; ++qptr)
|
|
||||||
prevch(qptr, ibperhx);
|
|
||||||
}
|
|
||||||
} while(~rflags & R_HAVERI && ++pass < 2);
|
|
||||||
}
|
|
||||||
//got everything now free the memory...
|
|
||||||
|
|
||||||
if(uflags & C_RESULT) {
|
|
||||||
for(qptr = apolys; qptr < pptr; ++qptr)
|
|
||||||
pfree(qptr);
|
|
||||||
}
|
|
||||||
if(!(model.flags & P_REFIN) != !(model.flags & P_REFOUT))
|
|
||||||
return uerr("cannot search for crossed-endian models");
|
|
||||||
|
|
||||||
|
/* if endianness not specified, try
|
||||||
|
* little-endian then big-endian.
|
||||||
|
* NB: crossed-endian algorithms will not be
|
||||||
|
* searched.
|
||||||
|
*/
|
||||||
|
/* scan against preset models */
|
||||||
|
if(~uflags & C_FORCE) {
|
||||||
pass = 0;
|
pass = 0;
|
||||||
|
Cnt = 0;
|
||||||
do {
|
do {
|
||||||
mptr = candmods = reveng(&model, qpoly, rflags, args, apolys);
|
psets = mcount();
|
||||||
if(mptr && plen(mptr->spoly))
|
|
||||||
uflags |= C_RESULT;
|
while(psets) {
|
||||||
while(mptr && plen(mptr->spoly)) {
|
mbynum(&pset, --psets);
|
||||||
mfree(mptr++);
|
|
||||||
|
/* skip if different width, or refin or refout don't match */
|
||||||
|
if(plen(pset.spoly) != width[0] || (model.flags ^ pset.flags) & (P_REFIN | P_REFOUT))
|
||||||
|
continue;
|
||||||
|
/* skip if the preset doesn't match specified parameters */
|
||||||
|
if(rflags & R_HAVEP && pcmp(&model.spoly, &pset.spoly))
|
||||||
|
continue;
|
||||||
|
if(rflags & R_HAVEI && psncmp(&model.init, &pset.init))
|
||||||
|
continue;
|
||||||
|
if(rflags & R_HAVEX && psncmp(&model.xorout, &pset.xorout))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//for additional args (not used yet, maybe future?)
|
||||||
|
apoly = pclone(pset.xorout);
|
||||||
|
if(pset.flags & P_REFOUT)
|
||||||
|
prev(&apoly);
|
||||||
|
|
||||||
|
for(qptr = apolys; qptr < pptr; ++qptr) {
|
||||||
|
crc = pcrc(*qptr, pset.spoly, pset.init, apoly, 0);
|
||||||
|
if(ptst(crc)) {
|
||||||
|
pfree(&crc);
|
||||||
|
break;
|
||||||
|
} else
|
||||||
|
pfree(&crc);
|
||||||
|
}
|
||||||
|
pfree(&apoly);
|
||||||
|
if(qptr == pptr) {
|
||||||
|
|
||||||
|
/* the selected model solved all arguments */
|
||||||
|
|
||||||
|
mcanon(&pset);
|
||||||
|
|
||||||
|
size_t size = (pset.name && *pset.name) ? strlen(pset.name) : 6;
|
||||||
|
//PrintAndLog("Size: %d, %s, count: %d",size,pset.name, Cnt);
|
||||||
|
char *tmp = calloc(size+1, sizeof(char));
|
||||||
|
if (tmp == NULL){
|
||||||
|
PrintAndLog("out of memory?");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
width[Cnt] = width[0];
|
||||||
|
memcpy(tmp, pset.name, size);
|
||||||
|
Models[Cnt++] = tmp;
|
||||||
|
*count = Cnt;
|
||||||
|
uflags |= C_RESULT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(candmods);
|
mfree(&pset);
|
||||||
|
|
||||||
|
/* toggle refIn/refOut and reflect arguments */
|
||||||
if(~rflags & R_HAVERI) {
|
if(~rflags & R_HAVERI) {
|
||||||
model.flags ^= P_REFIN | P_REFOUT;
|
model.flags ^= P_REFIN | P_REFOUT;
|
||||||
for(qptr = apolys; qptr < pptr; ++qptr)
|
for(qptr = apolys; qptr < pptr; ++qptr)
|
||||||
prevch(qptr, ibperhx);
|
prevch(qptr, ibperhx);
|
||||||
}
|
}
|
||||||
} while(~rflags & R_HAVERI && ++pass < 2);
|
} while(~rflags & R_HAVERI && ++pass < 2);
|
||||||
|
}
|
||||||
|
//got everything now free the memory...
|
||||||
|
|
||||||
|
if(uflags & C_RESULT) {
|
||||||
for(qptr = apolys; qptr < pptr; ++qptr)
|
for(qptr = apolys; qptr < pptr; ++qptr)
|
||||||
pfree(qptr);
|
pfree(qptr);
|
||||||
free(apolys);
|
}
|
||||||
if(~uflags & C_RESULT)
|
if(!(model.flags & P_REFIN) != !(model.flags & P_REFOUT))
|
||||||
return uerr("no models found");
|
return uerr("cannot search for crossed-endian models");
|
||||||
mfree(&model);
|
|
||||||
|
pass = 0;
|
||||||
|
do {
|
||||||
|
mptr = candmods = reveng(&model, qpoly, rflags, args, apolys);
|
||||||
|
if(mptr && plen(mptr->spoly))
|
||||||
|
uflags |= C_RESULT;
|
||||||
|
while(mptr && plen(mptr->spoly)) {
|
||||||
|
mfree(mptr++);
|
||||||
|
}
|
||||||
|
free(candmods);
|
||||||
|
if(~rflags & R_HAVERI) {
|
||||||
|
model.flags ^= P_REFIN | P_REFOUT;
|
||||||
|
for(qptr = apolys; qptr < pptr; ++qptr)
|
||||||
|
prevch(qptr, ibperhx);
|
||||||
|
}
|
||||||
|
} while(~rflags & R_HAVERI && ++pass < 2);
|
||||||
|
for(qptr = apolys; qptr < pptr; ++qptr)
|
||||||
|
pfree(qptr);
|
||||||
|
free(apolys);
|
||||||
|
if(~uflags & C_RESULT)
|
||||||
|
return uerr("no models found");
|
||||||
|
mfree(&model);
|
||||||
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -318,9 +317,13 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res
|
||||||
model.flags &= ~P_RTJUST;
|
model.flags &= ~P_RTJUST;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* canonicalise the model, so the one we dump is the one we
|
||||||
|
* calculate with (not with -s, spoly may be blank which will
|
||||||
|
* normalise to zero and clear init and xorout.)
|
||||||
|
*/
|
||||||
mcanon(&model);
|
mcanon(&model);
|
||||||
|
|
||||||
|
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
// v calculate reversed CRC
|
// v calculate reversed CRC
|
||||||
/* Distinct from the -V switch as this causes
|
/* Distinct from the -V switch as this causes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue