mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-20 23:36:31 +08:00
added 'data asn1' - decodes asn1 byte arrays
This commit is contained in:
parent
dfb4c9094b
commit
997cd7577f
|
@ -28,6 +28,7 @@
|
|||
#include "mifare/ndef.h"
|
||||
#include "cliparser.h"
|
||||
#include "cmdlft55xx.h" // print...
|
||||
#include "crypto/asn1utils.h" // ASN1 decode / print
|
||||
|
||||
uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
|
||||
size_t DemodBufferLen = 0;
|
||||
|
@ -2882,6 +2883,33 @@ static int CmdDataModulationSearch(const char *Cmd) {
|
|||
return try_detect_modulation();
|
||||
}
|
||||
|
||||
static int CmdAsn1Decoder(const char* Cmd) {
|
||||
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "data asn1",
|
||||
"Decode ASN1 bytearray\n"
|
||||
"",
|
||||
"data asn1 -d 303381050186922305a5020500a6088101010403030008a7188516eeee4facacf4fbde5e5c49d95e55bfbca74267b02407a9020500\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("d", NULL, "<hex>", "ASN1 encoded byte array"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
int dlen = 256;
|
||||
uint8_t data[256];
|
||||
CLIGetHexWithReturn(ctx, 1, data, &dlen);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// print ASN1 decoded array in TLV view
|
||||
PrintAndLogEx(INFO, "---------------- " _CYAN_("ASN1 TLV") " -----------------");
|
||||
asn1_print(data, dlen, " ");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
|
||||
|
@ -2916,6 +2944,7 @@ static command_t CommandTable[] = {
|
|||
{"getbitstream", CmdGetBitStream, AlwaysAvailable, "Convert GraphBuffer's >=1 values to 1 and <1 to 0"},
|
||||
|
||||
{"-----------", CmdHelp, AlwaysAvailable, "------------------------- " _CYAN_("General") "-------------------------"},
|
||||
{"asn1", CmdAsn1Decoder, AlwaysAvailable, "asn1 decoder"},
|
||||
{"bin2hex", Cmdbin2hex, AlwaysAvailable, "Converts binary to hexadecimal"},
|
||||
{"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"},
|
||||
{"clear", CmdBuffClear, AlwaysAvailable, "Clears bigbuf on deviceside and graph window"},
|
||||
|
|
|
@ -61,7 +61,7 @@ exit:
|
|||
return res;
|
||||
}
|
||||
|
||||
static void print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf) {
|
||||
static void asn1_print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf) {
|
||||
bool candump = true;
|
||||
asn1_tag_dump(tlv, level, &candump);
|
||||
if (is_leaf && candump) {
|
||||
|
@ -73,7 +73,7 @@ int asn1_print(uint8_t *asn1buf, size_t asn1buflen, const char *indent) {
|
|||
|
||||
struct tlvdb *t = tlvdb_parse_multi(asn1buf, asn1buflen);
|
||||
if (t) {
|
||||
tlvdb_visit(t, print_cb, NULL, 0);
|
||||
tlvdb_visit(t, asn1_print_cb, NULL, 0);
|
||||
tlvdb_free(t);
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Can't parse data as TLV tree");
|
||||
|
|
|
@ -157,7 +157,7 @@ enum CardPSVendor GetCardPSVendor(uint8_t *AID, size_t AIDlen) {
|
|||
return CV_NA;
|
||||
}
|
||||
|
||||
static void print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf) {
|
||||
static void emv_print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf) {
|
||||
emv_tag_dump(tlv, level);
|
||||
if (is_leaf) {
|
||||
print_buffer(tlv->value, tlv->len, level);
|
||||
|
@ -169,7 +169,7 @@ bool TLVPrintFromBuffer(uint8_t *data, int datalen) {
|
|||
if (t) {
|
||||
PrintAndLogEx(INFO, "-------------------- " _CYAN_("TLV decoded") " --------------------");
|
||||
|
||||
tlvdb_visit(t, print_cb, NULL, 0);
|
||||
tlvdb_visit(t, emv_print_cb, NULL, 0);
|
||||
tlvdb_free(t);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -182,7 +182,7 @@ void TLVPrintFromTLVLev(struct tlvdb *tlv, int level) {
|
|||
if (!tlv)
|
||||
return;
|
||||
|
||||
tlvdb_visit(tlv, print_cb, NULL, level);
|
||||
tlvdb_visit(tlv, emv_print_cb, NULL, level);
|
||||
}
|
||||
|
||||
void TLVPrintFromTLV(struct tlvdb *tlv) {
|
||||
|
|
Loading…
Reference in a new issue