From 8a49cb84a290a0b9765afb856ff66d8713bbeabb Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 3 Feb 2018 22:17:07 +0100 Subject: [PATCH] fix: script run e - if called with param but no value, use default value for width. fix: if no models found, return lua error. textual changes. --- client/cmdcrc.c | 16 ++++++++-------- client/scripting.c | 23 ++++++++++++++--------- client/scripts/e.lua | 1 + 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/client/cmdcrc.c b/client/cmdcrc.c index fcf5ae309..5f8f209d5 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -90,7 +90,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){ if (width[0] == 0) { //reveng -D *count = mcount(); if (!*count) - return uerr("no preset models available"); + return uerr("[-] no preset models available"); for (int mode = 0; mode < *count; ++mode) { mbynum(&model, mode); @@ -98,7 +98,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){ size_t size = (model.name && *model.name) ? strlen(model.name) : 6; char *tmp = calloc(size+1, sizeof(char)); if (tmp==NULL) - return uerr("out of memory?"); + return uerr("[!] out of memory?"); memcpy(tmp, model.name, size); Models[mode] = tmp; @@ -108,7 +108,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){ } else { //reveng -s 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.init, (unsigned long)width[0]); @@ -175,7 +175,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){ //PrintAndLog("Size: %d, %s, count: %d",size,pset.name, Cnt); char *tmp = calloc(size+1, sizeof(char)); if (tmp == NULL){ - PrintAndLog("out of memory?"); + PrintAndLog("[!] out of memory?"); return 0; } width[Cnt] = width[0]; @@ -204,7 +204,7 @@ int GetModels(char *Models[], int *count, uint8_t *width){ } } if (!(model.flags & P_REFIN) != !(model.flags & P_REFOUT)) - return uerr("cannot search for crossed-endian models"); + return uerr("[!] cannot search for crossed-endian models"); pass = 0; do { @@ -228,10 +228,10 @@ int GetModels(char *Models[], int *count, uint8_t *width){ pfree(qptr); } free(apolys); - if (~uflags & C_RESULT) - return uerr("no models found"); - mfree(&model); + + if (~uflags & C_RESULT) + return uerr("[!] no models found"); } return 1; } diff --git a/client/scripting.c b/client/scripting.c index 38ddc350d..a747ee9fe 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -453,21 +453,26 @@ static int l_sha1(lua_State *L) { static int l_reveng_models(lua_State *L){ - // This array needs to be adjusted if RevEng adds more crc-models. - char *models[100]; int count = 0; - int in_width = luaL_checkinteger(L, 1); - + uint8_t in_width = luaL_checkunsigned(L, 1); if ( in_width > 89 ) return returnToLuaWithError(L,"Width cannot exceed 89, got %d", in_width); // This array needs to be adjusted if RevEng adds more crc-models. - uint8_t width[100]; - width[0] = (uint8_t)in_width; + uint8_t width[102]; + // This array needs to be adjusted if RevEng adds more crc-models. + char *models[102]; + + width[0] = in_width; + int ans = GetModels(models, &count, width); - if (!ans) return 0; - - lua_newtable(L); + if (!ans) { + for (int i =0; i<102; i++) { + free(models[i]); + } + return returnToLuaWithError(L, "Didn't find any models"); + } + lua_newtable(L); for (int i = 0; i < count; i++){ lua_pushstring(L, (const char*)models[i]); lua_rawseti(L,-2,i+1); diff --git a/client/scripts/e.lua b/client/scripts/e.lua index 585e00f88..d6db95f35 100644 --- a/client/scripts/e.lua +++ b/client/scripts/e.lua @@ -50,6 +50,7 @@ function main(args) end data = data or '01020304' + width = width or 0 print( string.rep('-',60) ) print('Bit width of CRC | '..width)