mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 13:00:42 -07:00
added some supprt fct for cliparser, to take a hex byte param and fall back to a default value, or specify how many bytes the param must be
This commit is contained in:
parent
ae45e1d776
commit
ad1f3eae57
2 changed files with 24 additions and 0 deletions
|
@ -285,4 +285,26 @@ uint64_t arg_get_u64_hexstr_def(CLIParserContext *ctx, uint8_t paramnum, uint64_
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int arg_get_u32_hexstr_def(CLIParserContext *ctx, uint8_t paramnum, uint32_t def, uint32_t *out) {
|
||||||
|
return arg_get_u32_hexstr_def_nlen(ctx, paramnum, def, out, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
int arg_get_u32_hexstr_def_nlen(CLIParserContext *ctx, uint8_t paramnum, uint32_t def, uint32_t *out, uint8_t nlen) {
|
||||||
|
int n = 0;
|
||||||
|
uint8_t d[nlen];
|
||||||
|
int res = CLIParamHexToBuf(arg_get_str(ctx, paramnum), d, sizeof(d), &n);
|
||||||
|
if (res == 0 && n == nlen) {
|
||||||
|
uint32_t rv = 0;
|
||||||
|
for (uint8_t i = 0; i < n; i++) {
|
||||||
|
rv <<= 8;
|
||||||
|
rv |= d[i];
|
||||||
|
}
|
||||||
|
*out = rv;
|
||||||
|
return 1;
|
||||||
|
} else if (res == 0 && n) {
|
||||||
|
*out = def;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,4 +68,6 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int
|
||||||
int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);
|
int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);
|
||||||
|
|
||||||
uint64_t arg_get_u64_hexstr_def(CLIParserContext *ctx, uint8_t paramnum, uint64_t def);
|
uint64_t arg_get_u64_hexstr_def(CLIParserContext *ctx, uint8_t paramnum, uint64_t def);
|
||||||
|
int arg_get_u32_hexstr_def(CLIParserContext *ctx, uint8_t paramnum, uint32_t def, uint32_t *out);
|
||||||
|
int arg_get_u32_hexstr_def_nlen(CLIParserContext *ctx, uint8_t paramnum, uint32_t def, uint32_t *out, uint8_t nlen);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue