chg: detect_classic_prng should only report back true/false

chg:  scripting.c  got some code cleaning.
This commit is contained in:
iceman1001 2017-12-18 15:43:45 +01:00
commit 80722fe067
2 changed files with 50 additions and 70 deletions

View file

@ -852,7 +852,7 @@ bool detect_classic_prng(void){
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
PrintAndLog("PRNG UID: Reply timeout.");
return -1;
return false;
}
// if select tag failed.
@ -862,13 +862,13 @@ bool detect_classic_prng(void){
}
if (!WaitForResponseTimeout(CMD_ACK, &respA, 2500)) {
PrintAndLog("PRNG data: Reply timeout.");
return -1;
return false;
}
// check respA
if (respA.arg[0] != 4) {
PrintAndLog("PRNG data error: Wrong length: %d", respA.arg[0]);
return -1;
return false;
}
uint32_t nonce = bytes_to_num(respA.d.asBytes, respA.arg[0]);

View file

@ -104,35 +104,32 @@ static int l_WaitForResponseTimeout(lua_State *L){
//Check number of arguments
int n = lua_gettop(L);
if(n == 0)
{
if (n == 0) {
//signal error by returning Nil, errorstring
lua_pushnil(L);
lua_pushstring(L, "You need to supply at least command to wait for");
return 2; // two return values
return 2;
}
if(n >= 1)
{
//pop cmd
// extract first param. cmd byte to look for
if (n >= 1) {
cmd = luaL_checkunsigned(L, 1);
}
if(n >= 2)
{
//Did the user send a timeout ?
//Check if the current top of stack is an integer
// extract second param. timeout value
if(n >= 2){
ms_timeout = luaL_checkunsigned(L, 2);
//printf("Timeout set to %dms\n" , (int) ms_timeout);
}
UsbCommand response;
if (WaitForResponseTimeout(cmd, &response, ms_timeout)) {
//Push it as a string
lua_pushlstring(L,(const char *)&response, sizeof(UsbCommand));
return 1;// return 1 to signal one return value
return 1;
} else {
//Push a Nil instead
//signal error by returning Nil, errorstring
lua_pushnil(L);
return 1;// one return value
lua_pushstring(L, "No response from the device");
return 2;
}
}
@ -174,19 +171,15 @@ static int l_mfDarkside(lua_State *L){
int retval = mfDarkside(blockno & 0xFF, keytype & 0xFF, &key);
//Push the retval on the stack
lua_pushinteger(L,retval);
//Push the key onto the stack
uint8_t dest_key[8];
num_to_bytes(key, sizeof(dest_key), dest_key);
//printf("Pushing to lua stack: %012" PRIx64 "\n",key);
//Push the retval on the stack
lua_pushinteger(L, retval);
lua_pushlstring(L, (const char *) dest_key, sizeof(dest_key));
return 2; //Two return values
return 2;
}
//static int l_PrintAndLog(lua_State *L){ return CmdHF14AMfDump(luaL_checkstring(L, 1));}
static int l_clearCommandBuffer(lua_State *L){
clearCommandBuffer();
return 0;
@ -303,8 +296,7 @@ static int l_aes128decrypt_cbc(lua_State *L) {
lua_pushlstring(L,(const char *)&outdata, sizeof(outdata));
return 1;// return 1 to signal one return value
}
static int l_aes128decrypt_ecb(lua_State *L)
{
static int l_aes128decrypt_ecb(lua_State *L) {
//Check number of arguments
int i;
uint32_t tmp;
@ -335,8 +327,7 @@ static int l_aes128decrypt_ecb(lua_State *L)
return 1;// return 1 to signal one return value
}
static int l_aes128encrypt_cbc(lua_State *L)
{
static int l_aes128encrypt_cbc(lua_State *L) {
//Check number of arguments
int i;
uint32_t tmp;
@ -367,8 +358,7 @@ static int l_aes128encrypt_cbc(lua_State *L)
return 1;// return 1 to signal one return value
}
static int l_aes128encrypt_ecb(lua_State *L)
{
static int l_aes128encrypt_ecb(lua_State *L) {
//Check number of arguments
int i;
uint32_t tmp;
@ -397,8 +387,7 @@ static int l_aes128encrypt_ecb(lua_State *L)
return 1;// return 1 to signal one return value
}
static int l_crc8legic(lua_State *L)
{
static int l_crc8legic(lua_State *L) {
size_t size;
const char *p_str = luaL_checklstring(L, 1, &size);
@ -407,8 +396,7 @@ static int l_crc8legic(lua_State *L)
return 1;
}
static int l_crc16(lua_State *L)
{
static int l_crc16(lua_State *L) {
size_t size;
const char *p_str = luaL_checklstring(L, 1, &size);
@ -417,8 +405,7 @@ static int l_crc16(lua_State *L)
return 1;
}
static int l_crc64(lua_State *L)
{
static int l_crc64(lua_State *L) {
size_t size;
uint64_t crc = 0;
unsigned char outdata[8] = {0x00};
@ -439,8 +426,7 @@ static int l_crc64(lua_State *L)
return 1;
}
static int l_crc64_ecma182(lua_State *L)
{
static int l_crc64_ecma182(lua_State *L) {
//size_t size;
uint64_t crc = 0;
unsigned char outdata[8] = {0x00};
@ -465,8 +451,7 @@ static int l_crc64_ecma182(lua_State *L)
return 1;
}
static int l_sha1(lua_State *L)
{
static int l_sha1(lua_State *L) {
size_t size;
const char *p_str = luaL_checklstring(L, 1, &size);
unsigned char outdata[20] = {0x00};
@ -497,7 +482,6 @@ static int l_reveng_models(lua_State *L){
lua_rawseti(L,-2,i+1);
free(models[i]);
}
return 1;
}
@ -599,14 +583,12 @@ static int l_hardnested(lua_State *L){
int retval = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, haveTarget ? trgkey : NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey);
DropField();
//Push the retval on the stack
lua_pushinteger(L,retval);
//Push the key onto the stack
uint8_t dest_key[6];
num_to_bytes(foundkey, sizeof(dest_key), dest_key);
//printf("Pushing to lua stack: %012" PRIx64 "\n",key);
//Push the retval on the stack
lua_pushinteger(L,retval);
lua_pushlstring(L, (const char *) dest_key, sizeof(dest_key));
return 2; //Two return values
}
@ -617,9 +599,7 @@ static int l_hardnested(lua_State *L){
* @return
*/
static int l_detect_prng(lua_State *L) {
bool valid = detect_classic_prng();
//Push the retval on the stack
lua_pushinteger(L, valid);
lua_pushboolean(L, detect_classic_prng());
return 1;
}
/*