chg: updated the reveng 1.4.4 -> 1.5.2

'reveng -g 11223344' still breaks.
This commit is contained in:
iceman1001 2017-08-29 18:05:56 +02:00
commit 0c6f601f72
9 changed files with 655 additions and 497 deletions

View file

@ -71,14 +71,7 @@ int CmdCrc(const char *Cmd)
// as well as a width array for the width of each model // as well as a width array for the width of each model
int GetModels(char *Models[], int *count, uint8_t *width){ int GetModels(char *Models[], int *count, uint8_t *width){
/* default values */ /* default values */
static model_t model = { static model_t model = MZERO;
PZERO, /* no CRC polynomial, user must specify */
PZERO, /* Init = 0 */
P_BE, /* RefIn = false, RefOut = false, plus P_RTJUST setting in reveng.h */
PZERO, /* XorOut = 0 */
PZERO, /* check value unused */
NULL /* no model name */
};
int ibperhx = 8;//, obperhx = 8; int ibperhx = 8;//, obperhx = 8;
int rflags = 0, uflags = 0; /* search and UI flags */ int rflags = 0, uflags = 0; /* search and UI flags */
@ -136,7 +129,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){
* searched. * searched.
*/ */
/* scan against preset models */ /* scan against preset models */
if (~uflags & C_FORCE) { if (~uflags & C_NOPCK) {
pass = 0; pass = 0;
Cnt = 0; Cnt = 0;
do { do {
@ -252,14 +245,8 @@ int GetModels(char *Models[], int *count, uint8_t *width){
//result = calculated crc hex string //result = calculated crc hex string
int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *result){ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *result){
/* default values */ /* default values */
static model_t model = { static model_t model = MZERO;
PZERO, // no CRC polynomial, user must specify
PZERO, // Init = 0
P_BE, // RefIn = false, RefOut = false, plus P_RTJUST setting in reveng.h
PZERO, // XorOut = 0
PZERO, // check value unused
NULL // no model name
};
int ibperhx = 8, obperhx = 8; int ibperhx = 8, obperhx = 8;
int rflags = 0; // search flags int rflags = 0; // search flags
int c; int c;
@ -389,10 +376,9 @@ int CmdrevengSearch(const char *Cmd){
int dataLen = param_getstr(Cmd, 0, inHexStr); int dataLen = param_getstr(Cmd, 0, inHexStr);
if (dataLen < 4) return 0; if (dataLen < 4) return 0;
char *Models[80]; char *Models[102];
int count = 0; int count = 0;
uint8_t width[80]; uint8_t width[80] = {0};
width[0] = 0;
uint8_t crcChars = 0; uint8_t crcChars = 0;
char result[30]; char result[30];
char revResult[30]; char revResult[30];
@ -418,10 +404,10 @@ int CmdrevengSearch(const char *Cmd){
char *outHex = calloc(dataLen-crcChars+1, sizeof(char)); char *outHex = calloc(dataLen-crcChars+1, sizeof(char));
memcpy(outHex, inHexStr, dataLen-crcChars); memcpy(outHex, inHexStr, dataLen-crcChars);
//PrintAndLog("DEBUG: dataLen: %d, crcChars: %d, Model: %s, CRC: %s, width: %d, outHex: %s",dataLen, crcChars, Models[i], inCRC, width[i], outHex); // PrintAndLog("DEBUG: dataLen: %d, crcChars: %d, Model: %s, CRC: %s, width: %d, outHex: %s",dataLen, crcChars, Models[i], inCRC, width[i], outHex);
ans = RunModel(Models[i], outHex, false, 0, result); ans = RunModel(Models[i], outHex, false, 0, result);
if (ans) { if (ans) {
//test for match // test for match
if (memcmp(result, inCRC, crcChars)==0){ if (memcmp(result, inCRC, crcChars)==0){
PrintAndLog("\nFound a possible match!\nModel: %s\nValue: %s\n",Models[i], result); PrintAndLog("\nFound a possible match!\nModel: %s\nValue: %s\n",Models[i], result);
//optional - stop searching if found... //optional - stop searching if found...
@ -431,7 +417,7 @@ int CmdrevengSearch(const char *Cmd){
char *swapEndian = SwapEndianStr(result, crcChars, crcChars); char *swapEndian = SwapEndianStr(result, crcChars, crcChars);
if (memcmp(swapEndian, inCRC, crcChars)==0){ if (memcmp(swapEndian, inCRC, crcChars)==0){
PrintAndLog("\nFound a possible match!\nModel: %s\nValue EndianSwapped: %s\n",Models[i], swapEndian); PrintAndLog("\nFound a possible match!\nModel: %s\nValue EndianSwapped: %s\n",Models[i], swapEndian);
//optional - stop searching if found... // optional - stop searching if found...
found = true; found = true;
} }
free(swapEndian); free(swapEndian);
@ -439,31 +425,32 @@ int CmdrevengSearch(const char *Cmd){
} }
} }
//if (!found){ // if (!found){
ans = RunModel(Models[i], outHex, true, 0, revResult); ans = RunModel(Models[i], outHex, true, 0, revResult);
if (ans) { if (ans) {
//test for match // test for match
if (memcmp(revResult, inCRC, crcChars)==0){ if (memcmp(revResult, inCRC, crcChars)==0){
PrintAndLog("\nFound a possible match!\nModel Reversed: %s\nValue: %s\n",Models[i], revResult); PrintAndLog("\nFound a possible match!\nModel Reversed: %s\nValue: %s\n",Models[i], revResult);
//optional - stop searching if found... // optional - stop searching if found...
found = true; found = true;
} else { } else {
if (crcChars > 2){ if (crcChars > 2){
char *swapEndian = SwapEndianStr(revResult, crcChars, crcChars); char *swapEndian = SwapEndianStr(revResult, crcChars, crcChars);
if (memcmp(swapEndian, inCRC, crcChars)==0){ if (memcmp(swapEndian, inCRC, crcChars)==0){
PrintAndLog("\nFound a possible match!\nModel Reversed: %s\nValue EndianSwapped: %s\n",Models[i], swapEndian); PrintAndLog("\nFound a possible match!\nModel Reversed: %s\nValue EndianSwapped: %s\n",Models[i], swapEndian);
//optional - stop searching if found... // optional - stop searching if found...
found = true; found = true;
} }
free(swapEndian); free(swapEndian);
} }
} }
} }
//} // }
free(inCRC); free(inCRC);
free(outHex); free(outHex);
free(Models[i]); free(Models[i]);
} }
if (!found) PrintAndLog("\nNo matches found\n"); if (!found) PrintAndLog("\nNo matches found\n");
return 1; return 1;
} }

View file

@ -1,9 +1,10 @@
/* bmpbit.c /* bmpbit.c
* Greg Cook, 27/Jun/2016 * Greg Cook, 7/Feb/2017
*/ */
/* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder /* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder
* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Gregory Cook
* *
* This file is part of CRC RevEng. * This file is part of CRC RevEng.
* *

View file

@ -1,9 +1,10 @@
/* cli.c /* cli.c
* Greg Cook, 27/Jun/2016 * Greg Cook, 19/Feb/2017
*/ */
/* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder /* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder
* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Gregory Cook
* *
* This file is part of CRC RevEng. * This file is part of CRC RevEng.
* *
@ -21,7 +22,9 @@
* along with CRC RevEng. If not, see <https://www.gnu.org/licenses/>. * along with CRC RevEng. If not, see <https://www.gnu.org/licenses/>.
*/ */
/* 2016-06-27: -P sets width like -k /* 2017-02-18: -G ignored if R_HAVEP
* 2017-02-05: added -G
* 2016-06-27: -P sets width like -k
* 2015-04-03: added -z * 2015-04-03: added -z
* 2013-09-16: do not search with -M * 2013-09-16: do not search with -M
* 2013-06-11: uprog() suppresses first progress report * 2013-06-11: uprog() suppresses first progress report
@ -73,14 +76,7 @@ int reveng_main(int argc, char *argv[]) {
*/ */
/* default values */ /* default values */
model_t model = { model_t model = MZERO;
PZERO, /* no CRC polynomial, user must specify */
PZERO, /* Init = 0 */
P_BE, /* RefIn = false, RefOut = false, plus P_RTJUST setting in reveng.h */
PZERO, /* XorOut = 0 */
PZERO, /* check value unused */
NULL /* no model name */
};
int ibperhx = 8, obperhx = 8; int ibperhx = 8, obperhx = 8;
int rflags = 0, uflags = 0; /* search and UI flags */ int rflags = 0, uflags = 0; /* search and UI flags */
@ -102,7 +98,7 @@ int reveng_main(int argc, char *argv[]) {
pos=0; pos=0;
optind=1; optind=1;
do { do {
c=getopt(argc, argv, "?A:BDFLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz"); c=getopt(argc, argv, "?A:BDFGLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz");
switch(c) { switch(c) {
case 'A': /* A: bits per output character */ case 'A': /* A: bits per output character */
case 'a': /* a: bits per character */ case 'a': /* a: bits per character */
@ -138,14 +134,17 @@ int reveng_main(int argc, char *argv[]) {
} }
mode = c; mode = c;
break; break;
case 'F': /* F force search */ case 'F': /* F skip preset model check pass */
#ifndef NOFORCE #ifndef NOFORCE
uflags |= C_FORCE; uflags |= C_NOPCK;
#endif #endif
break; break;
case 'f': /* f arguments are filenames */ case 'f': /* f arguments are filenames */
uflags |= C_INFILE; uflags |= C_INFILE;
break; break;
case 'G': /* G skip brute force search pass */
uflags |= C_NOBFS;
break;
case 'h': /* h get help / usage */ case 'h': /* h get help / usage */
case 'u': /* u get help / usage */ case 'u': /* u get help / usage */
case '?': /* ? get help / usage */ case '?': /* ? get help / usage */
@ -158,8 +157,8 @@ int reveng_main(int argc, char *argv[]) {
pptr = &model.init; pptr = &model.init;
rflags |= R_HAVEI; rflags |= R_HAVEI;
goto ipqx; goto ipqx;
case 'P': /* P: reversed polynomial */
case 'k': /* k: polynomial in Koopman notation */ case 'k': /* k: polynomial in Koopman notation */
case 'P': /* P: reversed polynomial */
pfree(&model.spoly); pfree(&model.spoly);
model.spoly = strtop(optarg, 0, 4); model.spoly = strtop(optarg, 0, 4);
pkchop(&model.spoly); pkchop(&model.spoly);
@ -322,11 +321,10 @@ ipqx:
uerror("no preset models available"); uerror("no preset models available");
return 0; return 0;
} }
for(mode = 0; mode < args; ++mode) { do {
mbynum(&model, mode); mbynum(&model, --args);
mcanon(&model);
ufound(&model); ufound(&model);
} } while(args);
break; break;
case 'd': /* d dump CRC model */ case 'd': /* d dump CRC model */
/* maybe we don't want to do this: /* maybe we don't want to do this:
@ -398,7 +396,7 @@ ipqx:
*/ */
/* scan against preset models */ /* scan against preset models */
if(~uflags & C_FORCE) { if(~uflags & C_NOPCK) {
pass = 0; pass = 0;
do { do {
psets = mcount(); psets = mcount();
@ -428,7 +426,6 @@ ipqx:
pfree(&apoly); pfree(&apoly);
if(qptr == pptr) { if(qptr == pptr) {
/* the selected model solved all arguments */ /* the selected model solved all arguments */
mcanon(&pset);
ufound(&pset); ufound(&pset);
uflags |= C_RESULT; uflags |= C_RESULT;
} }
@ -449,6 +446,11 @@ ipqx:
return 1; return 1;
//exit(EXIT_SUCCESS); //exit(EXIT_SUCCESS);
} }
if(uflags & C_NOBFS && ~rflags & R_HAVEP) {
uerror("no models found");
return 0;
//break;
}
if(!(model.flags & P_REFIN) != !(model.flags & P_REFOUT)){ if(!(model.flags & P_REFIN) != !(model.flags & P_REFOUT)){
uerror("cannot search for crossed-endian models"); uerror("cannot search for crossed-endian models");
return 0; return 0;
@ -481,6 +483,7 @@ ipqx:
break; break;
default: /* no mode specified */ default: /* no mode specified */
fprintf(stderr, "%s: no mode switch specified. Use %s -h for help.\n", myname, myname); fprintf(stderr, "%s: no mode switch specified. Use %s -h for help.\n", myname, myname);
return 0;
//exit(EXIT_FAILURE); //exit(EXIT_FAILURE);
} }
@ -577,7 +580,7 @@ usage(void) {
"Usage:\t"); "Usage:\t");
fputs(myname, stderr); fputs(myname, stderr);
fprintf(stderr, fprintf(stderr,
"\t-cdDesvhu? [-bBfFlLMrStVXyz]\n" "\t-cdDesvhu? [-bBfFGlLMrStVXyz]\n"
"\t\t[-a BITS] [-A OBITS] [-i INIT] [-k KPOLY] [-m MODEL]\n" "\t\t[-a BITS] [-A OBITS] [-i INIT] [-k KPOLY] [-m MODEL]\n"
"\t\t[-p POLY] [-P RPOLY] [-q QPOLY] [-w WIDTH] [-x XOROUT]\n" "\t\t[-p POLY] [-P RPOLY] [-q QPOLY] [-w WIDTH] [-x XOROUT]\n"
"\t\t[STRING...]\n" "\t\t[STRING...]\n"
@ -596,12 +599,13 @@ usage(void) {
"\t-x XOROUT\tfinal register XOR value\n" "\t-x XOROUT\tfinal register XOR value\n"
"Modifier switches:\n" "Modifier switches:\n"
"\t-b big-endian CRC\t\t-B big-endian CRC output\n" "\t-b big-endian CRC\t\t-B big-endian CRC output\n"
"\t-f read files named in STRINGs\t-F find presets less quickly\n" "\t-f read files named in STRINGs\t-F skip preset model check pass\n"
"\t-l little-endian CRC\t\t-L little-endian CRC output\n" "\t-G skip brute force search pass\t-l little-endian CRC\n"
"\t-M non-augmenting algorithm\t-r right-justified output\n" "\t-L little-endian CRC output\t-M non-augmenting algorithm\n"
"\t-S print spaces between chars\t-t left-justified output\n" "\t-r right-justified output\t-S print spaces between characters\n"
"\t-V reverse algorithm only\t-X print uppercase hex\n" "\t-t left-justified output\t-V reverse algorithm only\n"
"\t-y low bytes first in files\t-z raw binary STRINGs\n"); "\t-X print uppercase hexadecimal\t-y low bytes first in files\n"
"\t-z raw binary STRINGs\n");
fprintf(stderr, fprintf(stderr,
"Mode switches:\n" "Mode switches:\n"
"\t-c calculate CRCs\t\t-d dump algorithm parameters\n" "\t-c calculate CRCs\t\t-d dump algorithm parameters\n"
@ -621,7 +625,7 @@ usage(void) {
"\t Outputs a list of all known/common crc models with their\n" "\t Outputs a list of all known/common crc models with their\n"
"\t preset values\n" "\t preset values\n"
"\n" "\n"
"Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook\n" "Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Gregory Cook\n"
"This is free software; see the source for copying conditions. There is NO\n" "This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
"Version " "Version "

View file

@ -1,9 +1,10 @@
/* config.h /* config.h
* Greg Cook, 27/Jun/2016 * Greg Cook, 7/Feb/2017
*/ */
/* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder /* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder
* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Gregory Cook
* *
* This file is part of CRC RevEng. * This file is part of CRC RevEng.
* *

View file

@ -1,9 +1,10 @@
/* model.c /* model.c
* Greg Cook, 26/Jul/2016 * Greg Cook, 19/Feb/2017
*/ */
/* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder /* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder
* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Gregory Cook
* *
* This file is part of CRC RevEng. * This file is part of CRC RevEng.
* *
@ -21,7 +22,9 @@
* along with CRC RevEng. If not, see <https://www.gnu.org/licenses/>. * along with CRC RevEng. If not, see <https://www.gnu.org/licenses/>.
*/ */
/* 2016-02-22: split off preset.c /* 2017-02-19: revised residue calculation for crossed-endian models
* 2017-02-05: added magic field
* 2016-02-22: split off preset.c
* 2012-03-03: single-line Williams model string conversion * 2012-03-03: single-line Williams model string conversion
* 2011-09-03: added mrev(), mnovel() * 2011-09-03: added mrev(), mnovel()
* 2011-01-17: fixed ANSI C warnings (except preset models) * 2011-01-17: fixed ANSI C warnings (except preset models)
@ -54,6 +57,7 @@ mcpy(model_t *dest, const model_t *src) {
pcpy(&dest->init, src->init); pcpy(&dest->init, src->init);
pcpy(&dest->xorout, src->xorout); pcpy(&dest->xorout, src->xorout);
pcpy(&dest->check, src->check); pcpy(&dest->check, src->check);
pcpy(&dest->magic, src->magic);
dest->flags = src->flags; dest->flags = src->flags;
/* link to the name as it is static */ /* link to the name as it is static */
dest->name = src->name; dest->name = src->name;
@ -67,6 +71,7 @@ mfree(model_t *model) {
pfree(&model->init); pfree(&model->init);
pfree(&model->xorout); pfree(&model->xorout);
pfree(&model->check); pfree(&model->check);
pfree(&model->magic);
/* not name as it is static */ /* not name as it is static */
/* not model either, it might point to an array! */ /* not model either, it might point to an array! */
} }
@ -95,25 +100,28 @@ mtostr(const model_t *model) {
* mcanon() should be called on the argument before printing. * mcanon() should be called on the argument before printing.
*/ */
size_t size; size_t size;
char *polystr, *initstr, *xorotstr, *checkstr, strbuf[512], *string = NULL; char *polystr, *initstr, *xorotstr, *checkstr, *magicstr,
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);
checkstr = ptostr(model->check, P_RTJUST, 4); checkstr = ptostr(model->check, P_RTJUST, 4);
magicstr = ptostr(model->magic, P_RTJUST, 4);
sprintf(strbuf, "%lu", plen(model->spoly)); sprintf(strbuf, "%lu", plen(model->spoly));
size = size =
70 82
+ (model->name && *model->name ? 2 + strlen(model->name) : 6)
+ strlen(strbuf) + strlen(strbuf)
+ (polystr && *polystr ? strlen(polystr) : 6) + (polystr && *polystr ? strlen(polystr) : 6)
+ (initstr && *initstr ? strlen(initstr) : 6) + (initstr && *initstr ? strlen(initstr) : 6)
+ (model->flags & P_REFIN ? 4 : 5) + (model->flags & P_REFIN ? 4 : 5)
+ (model->flags & P_REFOUT ? 4 : 5) + (model->flags & P_REFOUT ? 4 : 5)
+ (xorotstr && *xorotstr ? strlen(xorotstr) : 6) + (xorotstr && *xorotstr ? strlen(xorotstr) : 6)
+ (checkstr && *checkstr ? strlen(checkstr) : 6); + (checkstr && *checkstr ? strlen(checkstr) : 6)
+ (magicstr && *magicstr ? strlen(magicstr) : 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,
@ -124,6 +132,7 @@ mtostr(const model_t *model) {
"refout=%s " "refout=%s "
"xorout=0x%s " "xorout=0x%s "
"check=0x%s " "check=0x%s "
"residue=0x%s "
"name=%s", "name=%s",
plen(model->spoly), plen(model->spoly),
polystr && *polystr ? polystr : "(none)", polystr && *polystr ? polystr : "(none)",
@ -132,12 +141,14 @@ mtostr(const model_t *model) {
(model->flags & P_REFOUT) ? "true" : "false", (model->flags & P_REFOUT) ? "true" : "false",
xorotstr && *xorotstr ? xorotstr : "(none)", xorotstr && *xorotstr ? xorotstr : "(none)",
checkstr && *checkstr ? checkstr : "(none)", checkstr && *checkstr ? checkstr : "(none)",
magicstr && *magicstr ? magicstr : "(none)",
(model->name && *model->name) ? strbuf : "(none)"); (model->name && *model->name) ? strbuf : "(none)");
} }
free(polystr); free(polystr);
free(initstr); free(initstr);
free(xorotstr); free(xorotstr);
free(checkstr); free(checkstr);
free(magicstr);
if(!string) if(!string)
uerror("cannot allocate memory for model description"); uerror("cannot allocate memory for model description");
return(string); return(string);
@ -166,23 +177,42 @@ 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)) 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; poly_t checkstr, check, xorout, magic;
/* erase existing check and magic. Models with these
* fields recalculated should have no name.
*/
mnovel(model);
/* generate the check string with the correct bit order */ /* generate the check string with the correct bit order */
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);
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;
pfree(&checkstr);
/* calculate residue by emulating receipt of error-free message
* The residue of a crossed-endian model is calculated assuming
* that the characters of the received CRC are specially
* reflected before submitting the codeword.
*/
xorout=pclone(model->xorout);
if(model->flags & P_REFOUT)
prev(&xorout);
magic = pcrc(xorout, model->spoly, pzero, pzero, model->flags);
pfree(&xorout);
if(model->flags & P_REFIN)
prev(&magic);
model->magic = magic;
} }
void void
@ -221,4 +251,5 @@ 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);
pfree(&model->magic);
} }

View file

@ -1,9 +1,10 @@
/* poly.c /* poly.c
* Greg Cook, 26/Jul/2016 * Greg Cook, 7/Feb/2017
*/ */
/* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder /* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder
* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Gregory Cook
* *
* This file is part of CRC RevEng. * This file is part of CRC RevEng.
* *
@ -640,6 +641,7 @@ pshift(poly_t *dest, const poly_t src, unsigned long head, unsigned long start,
/* copies bits start to end-1 of src to dest, plus the number of leading and trailing zeroes given by head and tail. /* copies bits start to end-1 of src to dest, plus the number of leading and trailing zeroes given by head and tail.
* end may exceed the length of src in which case more zeroes are appended. * end may exceed the length of src in which case more zeroes are appended.
* dest may point to src, in which case the poly is edited in place. * dest may point to src, in which case the poly is edited in place.
* src must be CLEAN.
* On exit, dest is CLEAN. * On exit, dest is CLEAN.
*/ */

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,10 @@
/* reveng.c /* reveng.c
* Greg Cook, 27/Jun/2016 * Greg Cook, 7/Feb/2017
*/ */
/* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder /* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder
* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Gregory Cook
* *
* This file is part of CRC RevEng. * This file is part of CRC RevEng.
* *
@ -151,6 +152,7 @@ requit:
rptr->flags = 0; rptr->flags = 0;
rptr->xorout = pzero; rptr->xorout = pzero;
rptr->check = pzero; rptr->check = pzero;
rptr->magic = pzero;
rptr->name = NULL; rptr->name = NULL;
return(result); return(result);
@ -446,7 +448,7 @@ static void
chkres(int *resc, model_t **result, const poly_t divisor, const poly_t init, int flags, const poly_t xorout, int args, const poly_t *argpolys) { chkres(int *resc, model_t **result, const poly_t divisor, const poly_t init, int flags, const poly_t xorout, int args, const poly_t *argpolys) {
/* Checks a model against the argument list, and adds to the /* Checks a model against the argument list, and adds to the
* external results table if consistent. * external results table if consistent.
* Extends the result array and update the external pointer if * Extends the result array and updates the external pointer if
* necessary. * necessary.
*/ */
model_t *rptr; model_t *rptr;
@ -484,6 +486,8 @@ chkres(int *resc, model_t **result, const poly_t divisor, const poly_t init, int
rptr->init = pclone(init); rptr->init = pclone(init);
rptr->flags = flags; rptr->flags = flags;
rptr->xorout = pclone(xorout); rptr->xorout = pclone(xorout);
rptr->check = pzero;
rptr->magic = pzero;
rptr->name = NULL; rptr->name = NULL;
/* compute check value for this model */ /* compute check value for this model */

View file

@ -1,9 +1,10 @@
/* reveng.h /* reveng.h
* Greg Cook, 25/Jul/2016 * Greg Cook, 19/Jun/2017
*/ */
/* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder /* CRC RevEng: arbitrary-precision CRC calculator and algorithm finder
* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Gregory Cook * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Gregory Cook
* *
* This file is part of CRC RevEng. * This file is part of CRC RevEng.
* *
@ -92,7 +93,7 @@
/* Global definitions */ /* Global definitions */
/* CRC RevEng version string */ /* CRC RevEng version string */
#define VERSION "1.4.4" #define VERSION "1.5.2"
/* bmpbit.c */ /* bmpbit.c */
typedef BMP_T bmp_t; typedef BMP_T bmp_t;
@ -162,12 +163,17 @@ extern int pmpar(const poly_t poly, const poly_t mask);
extern int pident(const poly_t a, const poly_t b); extern int pident(const poly_t a, const poly_t b);
/* model.c */ /* model.c */
/* A model_t constant representing an uninitialised model or zero-bit CRC algorithm. */
#define MZERO {PZERO, PZERO, P_BE, PZERO, PZERO, PZERO, NULL}
typedef struct { typedef struct {
poly_t spoly; /* polynomial with highest-order term removed. length determines CRC width */ poly_t spoly; /* polynomial with highest-order term removed. length determines CRC width */
poly_t init; /* initial register value. length == poly.length */ poly_t init; /* initial register value. length == spoly.length */
int flags; /* P_REFIN and P_REFOUT indicate reflected input/output */ int flags; /* P_REFIN and P_REFOUT indicate reflected input/output */
poly_t xorout; /* final register XOR mask. length == poly.length */ poly_t xorout; /* final register XOR mask. length == spoly.length */
poly_t check; /* optional check value, the CRC of the UTF-8 string "123456789" */ poly_t check; /* optional check value, the CRC of the UTF-8 string "123456789" */
poly_t magic; /* optional magic check value, the residue of a valid codeword */
const char *name; /* optional canonical name of the model */ const char *name; /* optional canonical name of the model */
} model_t; } model_t;
@ -203,8 +209,9 @@ extern model_t *reveng(const model_t *guess, const poly_t qpoly, int rflags, int
/* cli.c */ /* cli.c */
#define C_INFILE 1 #define C_INFILE 1
#define C_FORCE 2 #define C_NOPCK 2
#define C_RESULT 4 #define C_NOBFS 4
#define C_RESULT 8
#define BUFFER 32768 #define BUFFER 32768