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.
This commit is contained in:
iceman1001 2018-02-03 22:17:07 +01:00
parent 2d2a8b7b1b
commit 8a49cb84a2
3 changed files with 23 additions and 17 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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)