mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
Use snprintf in client/deps
This commit is contained in:
parent
1711338035
commit
fe4599fb14
7 changed files with 35 additions and 35 deletions
|
@ -173,8 +173,8 @@ crack_states_thread(void *x) {
|
||||||
|
|
||||||
char progress_text[80];
|
char progress_text[80];
|
||||||
char keystr[19];
|
char keystr[19];
|
||||||
sprintf(keystr, "%012" PRIX64 " ", key);
|
snprintf(keystr, sizeof(keystr), "%012" PRIX64 " ", key);
|
||||||
sprintf(progress_text, "Brute force phase completed. Key found: " _GREEN_("%s"), keystr);
|
snprintf(progress_text, sizeof(progress_text), "Brute force phase completed. Key found: " _GREEN_("%s"), keystr);
|
||||||
hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, 0.0, 0);
|
hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, 0.0, 0);
|
||||||
break;
|
break;
|
||||||
} else if (keys_found) {
|
} else if (keys_found) {
|
||||||
|
@ -182,7 +182,7 @@ crack_states_thread(void *x) {
|
||||||
} else {
|
} else {
|
||||||
if (!thread_arg->silent) {
|
if (!thread_arg->silent) {
|
||||||
char progress_text[80];
|
char progress_text[80];
|
||||||
sprintf(progress_text, "Brute force phase: %6.02f%%\t", 100.0 * (float)num_keys_tested / (float)(thread_arg->maximum_states));
|
snprintf(progress_text, sizeof(progress_text), "Brute force phase: %6.02f%%\t", 100.0 * (float)num_keys_tested / (float)(thread_arg->maximum_states));
|
||||||
float remaining_bruteforce = thread_arg->nonces[thread_arg->best_first_bytes[0]].expected_num_brute_force - (float)num_keys_tested / 2;
|
float remaining_bruteforce = thread_arg->nonces[thread_arg->best_first_bytes[0]].expected_num_brute_force - (float)num_keys_tested / 2;
|
||||||
hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, remaining_bruteforce, 5000);
|
hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, remaining_bruteforce, 5000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ static inline uint32_t count_states(uint32_t *bitset) {
|
||||||
|
|
||||||
static void write_bitflips_file(odd_even_t odd_even, uint16_t bitflip, int sum_a0, uint32_t *bitset, uint32_t count) {
|
static void write_bitflips_file(odd_even_t odd_even, uint16_t bitflip, int sum_a0, uint32_t *bitset, uint32_t count) {
|
||||||
char filename[80];
|
char filename[80];
|
||||||
sprintf(filename, "bitflip_%d_%03" PRIx16 "_sum%d_states.bin", odd_even, bitflip, sum_a0);
|
snprintf(filename, sizeof(filename), "bitflip_%d_%03" PRIx16 "_sum%d_states.bin", odd_even, bitflip, sum_a0);
|
||||||
FILE *outfile = fopen(filename, "wb");
|
FILE *outfile = fopen(filename, "wb");
|
||||||
fwrite(&count, 1, sizeof(count), outfile);
|
fwrite(&count, 1, sizeof(count), outfile);
|
||||||
fwrite(bitset, 1, sizeof(uint32_t) * (1 << 19), outfile);
|
fwrite(bitset, 1, sizeof(uint32_t) * (1 << 19), outfile);
|
||||||
|
|
|
@ -215,7 +215,7 @@ const char *luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp) {
|
||||||
}
|
}
|
||||||
case 'p': {
|
case 'p': {
|
||||||
char buff[4 * sizeof(void *) + 8]; /* should be enough space for a `%p' */
|
char buff[4 * sizeof(void *) + 8]; /* should be enough space for a `%p' */
|
||||||
int l = sprintf(buff, "%p", va_arg(argp, void *));
|
int l = snprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
|
||||||
pushstr(L, buff, l);
|
pushstr(L, buff, l);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -879,9 +879,9 @@ static void addquoted(lua_State *L, luaL_Buffer *b, int arg) {
|
||||||
} else if (*s == '\0' || iscntrl(uchar(*s))) {
|
} else if (*s == '\0' || iscntrl(uchar(*s))) {
|
||||||
char buff[10];
|
char buff[10];
|
||||||
if (!isdigit(uchar(*(s + 1))))
|
if (!isdigit(uchar(*(s + 1))))
|
||||||
sprintf(buff, "\\%d", (int)uchar(*s));
|
snprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s));
|
||||||
else
|
else
|
||||||
sprintf(buff, "\\%03d", (int)uchar(*s));
|
snprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s));
|
||||||
luaL_addstring(b, buff);
|
luaL_addstring(b, buff);
|
||||||
} else
|
} else
|
||||||
luaL_addchar(b, *s);
|
luaL_addchar(b, *s);
|
||||||
|
@ -947,7 +947,7 @@ static int str_format(lua_State *L) {
|
||||||
strfrmt = scanformat(L, strfrmt, form);
|
strfrmt = scanformat(L, strfrmt, form);
|
||||||
switch (*strfrmt++) {
|
switch (*strfrmt++) {
|
||||||
case 'c': {
|
case 'c': {
|
||||||
nb = sprintf(buff, form, luaL_checkint(L, arg));
|
nb = snprintf(buff, MAX_ITEM, form, luaL_checkint(L, arg));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'd':
|
case 'd':
|
||||||
|
@ -958,7 +958,7 @@ static int str_format(lua_State *L) {
|
||||||
luaL_argcheck(L, -1 < diff && diff < 1, arg,
|
luaL_argcheck(L, -1 < diff && diff < 1, arg,
|
||||||
"not a number in proper range");
|
"not a number in proper range");
|
||||||
addlenmod(form, LUA_INTFRMLEN);
|
addlenmod(form, LUA_INTFRMLEN);
|
||||||
nb = sprintf(buff, form, ni);
|
nb = snprintf(buff, MAX_ITEM, form, ni);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'o':
|
case 'o':
|
||||||
|
@ -971,7 +971,7 @@ static int str_format(lua_State *L) {
|
||||||
luaL_argcheck(L, -1 < diff && diff < 1, arg,
|
luaL_argcheck(L, -1 < diff && diff < 1, arg,
|
||||||
"not a non-negative number in proper range");
|
"not a non-negative number in proper range");
|
||||||
addlenmod(form, LUA_INTFRMLEN);
|
addlenmod(form, LUA_INTFRMLEN);
|
||||||
nb = sprintf(buff, form, ni);
|
nb = snprintf(buff, MAX_ITEM, form, ni);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'e':
|
case 'e':
|
||||||
|
@ -984,7 +984,7 @@ static int str_format(lua_State *L) {
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G': {
|
case 'G': {
|
||||||
addlenmod(form, LUA_FLTFRMLEN);
|
addlenmod(form, LUA_FLTFRMLEN);
|
||||||
nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
|
nb = snprintf(buff, MAX_ITEM, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'q': {
|
case 'q': {
|
||||||
|
@ -1000,7 +1000,7 @@ static int str_format(lua_State *L) {
|
||||||
luaL_addvalue(&b);
|
luaL_addvalue(&b);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
nb = sprintf(buff, form, s);
|
nb = snprintf(buff, MAX_ITEM, form, s);
|
||||||
lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
|
lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,7 +408,7 @@
|
||||||
*/
|
*/
|
||||||
#define LUA_NUMBER_SCAN "%lf"
|
#define LUA_NUMBER_SCAN "%lf"
|
||||||
#define LUA_NUMBER_FMT "%.14g"
|
#define LUA_NUMBER_FMT "%.14g"
|
||||||
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
|
#define lua_number2str(s,l,n) snprintf((s), (l), LUA_NUMBER_FMT, (n))
|
||||||
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
|
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ int luaV_tostring(lua_State *L, StkId obj) {
|
||||||
else {
|
else {
|
||||||
char s[LUAI_MAXNUMBER2STR];
|
char s[LUAI_MAXNUMBER2STR];
|
||||||
lua_Number n = nvalue(obj);
|
lua_Number n = nvalue(obj);
|
||||||
int l = lua_number2str(s, n);
|
int l = lua_number2str(s, sizeof(s), n);
|
||||||
setsvalue2s(L, obj, luaS_newlstr(L, s, l));
|
setsvalue2s(L, obj, luaS_newlstr(L, s, l));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ char *mtostr(const model_t *model) {
|
||||||
checkstr = ptostr(model->check, P_RTJUST, 4);
|
checkstr = ptostr(model->check, P_RTJUST, 4);
|
||||||
magicstr = ptostr(model->magic, P_RTJUST, 4);
|
magicstr = ptostr(model->magic, P_RTJUST, 4);
|
||||||
|
|
||||||
sprintf(strbuf, "%lu", plen(model->spoly));
|
snprintf(strbuf, sizeof(strbuf), "%lu", plen(model->spoly));
|
||||||
size =
|
size =
|
||||||
82
|
82
|
||||||
+ strlen(strbuf)
|
+ strlen(strbuf)
|
||||||
|
@ -120,26 +120,26 @@ char *mtostr(const model_t *model) {
|
||||||
+ (magicstr && *magicstr ? strlen(magicstr) : 6)
|
+ (magicstr && *magicstr ? strlen(magicstr) : 6)
|
||||||
+ (model->name && *model->name ? 2 + strlen(model->name) : 6);
|
+ (model->name && *model->name ? 2 + strlen(model->name) : 6);
|
||||||
if ((string = calloc(size, sizeof(uint8_t)))) {
|
if ((string = calloc(size, sizeof(uint8_t)))) {
|
||||||
sprintf(strbuf, "\"%s\"", model->name);
|
snprintf(strbuf, sizeof(strbuf), "\"%s\"", model->name);
|
||||||
sprintf(string,
|
snprintf(string, size * sizeof(uint8_t),
|
||||||
"width=%lu "
|
"width=%lu "
|
||||||
"poly=0x%s "
|
"poly=0x%s "
|
||||||
"init=0x%s "
|
"init=0x%s "
|
||||||
"refin=%s "
|
"refin=%s "
|
||||||
"refout=%s "
|
"refout=%s "
|
||||||
"xorout=0x%s "
|
"xorout=0x%s "
|
||||||
"check=0x%s "
|
"check=0x%s "
|
||||||
"residue=0x%s "
|
"residue=0x%s "
|
||||||
"name=%s",
|
"name=%s",
|
||||||
plen(model->spoly),
|
plen(model->spoly),
|
||||||
polystr && *polystr ? polystr : "(none)",
|
polystr && *polystr ? polystr : "(none)",
|
||||||
initstr && *initstr ? initstr : "(none)",
|
initstr && *initstr ? initstr : "(none)",
|
||||||
(model->flags & P_REFIN) ? "true" : "false",
|
(model->flags & P_REFIN) ? "true" : "false",
|
||||||
(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)",
|
magicstr && *magicstr ? magicstr : "(none)",
|
||||||
(model->name && *model->name) ? strbuf : "(none)");
|
(model->name && *model->name) ? strbuf : "(none)");
|
||||||
}
|
}
|
||||||
free(polystr);
|
free(polystr);
|
||||||
free(initstr);
|
free(initstr);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue