mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
chg: detect_classic_prng should only report back true/false
chg: scripting.c got some code cleaning.
This commit is contained in:
parent
8ffe97c75b
commit
80722fe067
2 changed files with 50 additions and 70 deletions
|
@ -852,7 +852,7 @@ bool detect_classic_prng(void){
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
|
||||||
PrintAndLog("PRNG UID: Reply timeout.");
|
PrintAndLog("PRNG UID: Reply timeout.");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if select tag failed.
|
// if select tag failed.
|
||||||
|
@ -862,13 +862,13 @@ bool detect_classic_prng(void){
|
||||||
}
|
}
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &respA, 2500)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &respA, 2500)) {
|
||||||
PrintAndLog("PRNG data: Reply timeout.");
|
PrintAndLog("PRNG data: Reply timeout.");
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check respA
|
// check respA
|
||||||
if (respA.arg[0] != 4) {
|
if (respA.arg[0] != 4) {
|
||||||
PrintAndLog("PRNG data error: Wrong length: %d", respA.arg[0]);
|
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]);
|
uint32_t nonce = bytes_to_num(respA.d.asBytes, respA.arg[0]);
|
||||||
|
|
|
@ -104,35 +104,32 @@ static int l_WaitForResponseTimeout(lua_State *L){
|
||||||
|
|
||||||
//Check number of arguments
|
//Check number of arguments
|
||||||
int n = lua_gettop(L);
|
int n = lua_gettop(L);
|
||||||
if(n == 0)
|
if (n == 0) {
|
||||||
{
|
|
||||||
//signal error by returning Nil, errorstring
|
//signal error by returning Nil, errorstring
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L,"You need to supply at least command to wait for");
|
lua_pushstring(L, "You need to supply at least command to wait for");
|
||||||
return 2; // two return values
|
return 2;
|
||||||
}
|
}
|
||||||
if(n >= 1)
|
|
||||||
{
|
// extract first param. cmd byte to look for
|
||||||
//pop cmd
|
if (n >= 1) {
|
||||||
cmd = luaL_checkunsigned(L,1);
|
cmd = luaL_checkunsigned(L, 1);
|
||||||
}
|
}
|
||||||
if(n >= 2)
|
// extract second param. timeout value
|
||||||
{
|
if(n >= 2){
|
||||||
//Did the user send a timeout ?
|
ms_timeout = luaL_checkunsigned(L, 2);
|
||||||
//Check if the current top of stack is an integer
|
|
||||||
ms_timeout = luaL_checkunsigned(L,2);
|
|
||||||
//printf("Timeout set to %dms\n" , (int) ms_timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UsbCommand response;
|
UsbCommand response;
|
||||||
if(WaitForResponseTimeout(cmd, &response, ms_timeout)) {
|
if (WaitForResponseTimeout(cmd, &response, ms_timeout)) {
|
||||||
//Push it as a string
|
//Push it as a string
|
||||||
lua_pushlstring(L,(const char *)&response, sizeof(UsbCommand));
|
lua_pushlstring(L,(const char *)&response, sizeof(UsbCommand));
|
||||||
return 1;// return 1 to signal one return value
|
return 1;
|
||||||
}else{
|
} else {
|
||||||
//Push a Nil instead
|
//signal error by returning Nil, errorstring
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;// one return value
|
lua_pushstring(L, "No response from the device");
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,12 +157,12 @@ static int l_mfDarkside(lua_State *L){
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 2:{
|
case 2:{
|
||||||
const char *p_keytype = luaL_checklstring(L, 2, &size);
|
const char *p_keytype = luaL_checklstring(L, 2, &size);
|
||||||
if(size != 2) return returnToLuaWithError(L,"Wrong size of keytype, got %d bytes, expected 1", (int) size);
|
if (size != 2) return returnToLuaWithError(L,"Wrong size of keytype, got %d bytes, expected 1", (int) size);
|
||||||
sscanf(p_keytype, "%x", &keytype);
|
sscanf(p_keytype, "%x", &keytype);
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
const char *p_blockno = luaL_checklstring(L, 1, &size);
|
const char *p_blockno = luaL_checklstring(L, 1, &size);
|
||||||
if(size != 2) return returnToLuaWithError(L,"Wrong size of blockno, got %d bytes, expected 2", (int) size);
|
if (size != 2) return returnToLuaWithError(L,"Wrong size of blockno, got %d bytes, expected 2", (int) size);
|
||||||
sscanf(p_blockno, "%02x", &blockno);
|
sscanf(p_blockno, "%02x", &blockno);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -174,19 +171,15 @@ static int l_mfDarkside(lua_State *L){
|
||||||
|
|
||||||
int retval = mfDarkside(blockno & 0xFF, keytype & 0xFF, &key);
|
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];
|
uint8_t dest_key[8];
|
||||||
num_to_bytes(key,sizeof(dest_key),dest_key);
|
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_pushlstring(L,(const char *) dest_key,sizeof(dest_key));
|
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){
|
static int l_clearCommandBuffer(lua_State *L){
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -222,7 +215,7 @@ static int l_foobar(lua_State *L) {
|
||||||
* @return boolean, true if kbhit, false otherwise.
|
* @return boolean, true if kbhit, false otherwise.
|
||||||
*/
|
*/
|
||||||
static int l_ukbhit(lua_State *L) {
|
static int l_ukbhit(lua_State *L) {
|
||||||
lua_pushboolean(L,ukbhit() ? true : false);
|
lua_pushboolean(L, ukbhit() ? true : false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -278,7 +271,7 @@ static int l_aes128decrypt_cbc(lua_State *L) {
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *p_key = luaL_checklstring(L, 1, &size);
|
const char *p_key = luaL_checklstring(L, 1, &size);
|
||||||
if(size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
if (size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
||||||
|
|
||||||
const char *p_encTxt = luaL_checklstring(L, 2, &size);
|
const char *p_encTxt = luaL_checklstring(L, 2, &size);
|
||||||
|
|
||||||
|
@ -303,14 +296,13 @@ static int l_aes128decrypt_cbc(lua_State *L) {
|
||||||
lua_pushlstring(L,(const char *)&outdata, sizeof(outdata));
|
lua_pushlstring(L,(const char *)&outdata, sizeof(outdata));
|
||||||
return 1;// return 1 to signal one return value
|
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
|
//Check number of arguments
|
||||||
int i;
|
int i;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *p_key = luaL_checklstring(L, 1, &size);
|
const char *p_key = luaL_checklstring(L, 1, &size);
|
||||||
if(size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
if (size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
||||||
|
|
||||||
const char *p_encTxt = luaL_checklstring(L, 2, &size);
|
const char *p_encTxt = luaL_checklstring(L, 2, &size);
|
||||||
|
|
||||||
|
@ -335,14 +327,13 @@ static int l_aes128decrypt_ecb(lua_State *L)
|
||||||
return 1;// return 1 to signal one return value
|
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
|
//Check number of arguments
|
||||||
int i;
|
int i;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *p_key = luaL_checklstring(L, 1, &size);
|
const char *p_key = luaL_checklstring(L, 1, &size);
|
||||||
if(size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
if (size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
||||||
|
|
||||||
const char *p_txt = luaL_checklstring(L, 2, &size);
|
const char *p_txt = luaL_checklstring(L, 2, &size);
|
||||||
|
|
||||||
|
@ -367,14 +358,13 @@ static int l_aes128encrypt_cbc(lua_State *L)
|
||||||
return 1;// return 1 to signal one return value
|
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
|
//Check number of arguments
|
||||||
int i;
|
int i;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *p_key = luaL_checklstring(L, 1, &size);
|
const char *p_key = luaL_checklstring(L, 1, &size);
|
||||||
if(size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
if (size != 32) return returnToLuaWithError(L,"Wrong size of key, got %d bytes, expected 32", (int) size);
|
||||||
|
|
||||||
const char *p_txt = luaL_checklstring(L, 2, &size);
|
const char *p_txt = luaL_checklstring(L, 2, &size);
|
||||||
|
|
||||||
|
@ -397,8 +387,7 @@ static int l_aes128encrypt_ecb(lua_State *L)
|
||||||
return 1;// return 1 to signal one return value
|
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;
|
size_t size;
|
||||||
const char *p_str = luaL_checklstring(L, 1, &size);
|
const char *p_str = luaL_checklstring(L, 1, &size);
|
||||||
|
|
||||||
|
@ -407,8 +396,7 @@ static int l_crc8legic(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_crc16(lua_State *L)
|
static int l_crc16(lua_State *L) {
|
||||||
{
|
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *p_str = luaL_checklstring(L, 1, &size);
|
const char *p_str = luaL_checklstring(L, 1, &size);
|
||||||
|
|
||||||
|
@ -417,8 +405,7 @@ static int l_crc16(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_crc64(lua_State *L)
|
static int l_crc64(lua_State *L) {
|
||||||
{
|
|
||||||
size_t size;
|
size_t size;
|
||||||
uint64_t crc = 0;
|
uint64_t crc = 0;
|
||||||
unsigned char outdata[8] = {0x00};
|
unsigned char outdata[8] = {0x00};
|
||||||
|
@ -439,8 +426,7 @@ static int l_crc64(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_crc64_ecma182(lua_State *L)
|
static int l_crc64_ecma182(lua_State *L) {
|
||||||
{
|
|
||||||
//size_t size;
|
//size_t size;
|
||||||
uint64_t crc = 0;
|
uint64_t crc = 0;
|
||||||
unsigned char outdata[8] = {0x00};
|
unsigned char outdata[8] = {0x00};
|
||||||
|
@ -461,17 +447,16 @@ static int l_crc64_ecma182(lua_State *L)
|
||||||
outdata[5] = (uint8_t)(crc >> 16) & 0xff;
|
outdata[5] = (uint8_t)(crc >> 16) & 0xff;
|
||||||
outdata[6] = (uint8_t)(crc >> 8) & 0xff;
|
outdata[6] = (uint8_t)(crc >> 8) & 0xff;
|
||||||
outdata[7] = crc & 0xff;
|
outdata[7] = crc & 0xff;
|
||||||
lua_pushlstring(L,(const char *)&outdata, sizeof(outdata));
|
lua_pushlstring(L, (const char *)&outdata, sizeof(outdata));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_sha1(lua_State *L)
|
static int l_sha1(lua_State *L) {
|
||||||
{
|
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *p_str = luaL_checklstring(L, 1, &size);
|
const char *p_str = luaL_checklstring(L, 1, &size);
|
||||||
unsigned char outdata[20] = {0x00};
|
unsigned char outdata[20] = {0x00};
|
||||||
sha1( (uint8_t*) p_str, size, outdata);
|
sha1( (uint8_t*) p_str, size, outdata);
|
||||||
lua_pushlstring(L,(const char *)&outdata, sizeof(outdata));
|
lua_pushlstring(L, (const char *)&outdata, sizeof(outdata));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +467,7 @@ static int l_reveng_models(lua_State *L){
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int in_width = luaL_checkinteger(L, 1);
|
int in_width = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
if( in_width > 89 ) return returnToLuaWithError(L,"Width cannot exceed 89, got %d", in_width);
|
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.
|
// This array needs to be adjusted if RevEng adds more crc-models.
|
||||||
uint8_t width[100];
|
uint8_t width[100];
|
||||||
|
@ -497,7 +482,6 @@ static int l_reveng_models(lua_State *L){
|
||||||
lua_rawseti(L,-2,i+1);
|
lua_rawseti(L,-2,i+1);
|
||||||
free(models[i]);
|
free(models[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,15 +582,13 @@ static int l_hardnested(lua_State *L){
|
||||||
uint64_t foundkey = 0;
|
uint64_t foundkey = 0;
|
||||||
int retval = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, haveTarget ? trgkey : NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey);
|
int retval = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, haveTarget ? trgkey : NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey);
|
||||||
DropField();
|
DropField();
|
||||||
|
|
||||||
//Push the retval on the stack
|
|
||||||
lua_pushinteger(L,retval);
|
|
||||||
|
|
||||||
//Push the key onto the stack
|
//Push the key onto the stack
|
||||||
uint8_t dest_key[6];
|
uint8_t dest_key[6];
|
||||||
num_to_bytes(foundkey, sizeof(dest_key), dest_key);
|
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));
|
lua_pushlstring(L, (const char *) dest_key, sizeof(dest_key));
|
||||||
return 2; //Two return values
|
return 2; //Two return values
|
||||||
}
|
}
|
||||||
|
@ -617,9 +599,7 @@ static int l_hardnested(lua_State *L){
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static int l_detect_prng(lua_State *L) {
|
static int l_detect_prng(lua_State *L) {
|
||||||
bool valid = detect_classic_prng();
|
lua_pushboolean(L, detect_classic_prng());
|
||||||
//Push the retval on the stack
|
|
||||||
lua_pushinteger(L, valid);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -728,4 +708,4 @@ int set_pm3_libraries(lua_State *L) {
|
||||||
setLuaPath(L, libraries_path);
|
setLuaPath(L, libraries_path);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue