Merge branch 'master' into smartcard-relay

This commit is contained in:
Grayson Martin committed 2023-11-11 13:05:11 -06:00
commit 4e346e8ca2
159 files changed
+10035 -2880

No files matched your search

+2
View File
@@ -279,6 +279,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/mifare/mifare4.c
${PM3_ROOT}/client/src/mifare/mifaredefault.c
${PM3_ROOT}/client/src/mifare/mifarehost.c
${PM3_ROOT}/client/src/mifare/gen4.c
${PM3_ROOT}/client/src/nfc/ndef.c
${PM3_ROOT}/client/src/mifare/lrpcrypto.c
${PM3_ROOT}/client/src/mifare/desfirecrypto.c
@@ -286,6 +287,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/mifare/desfirecore.c
${PM3_ROOT}/client/src/mifare/desfiretest.c
${PM3_ROOT}/client/src/mifare/gallaghercore.c
${PM3_ROOT}/client/src/uart/ringbuffer.c
${PM3_ROOT}/client/src/uart/uart_posix.c
${PM3_ROOT}/client/src/uart/uart_win32.c
${PM3_ROOT}/client/src/ui/overlays.ui
+8 -2
View File
@@ -371,12 +371,16 @@ ifeq ($(PYTHON_FOUND),1)
endif
#######################################################################################################
# macOS doesn't like this params
#MYCFLAGS += --param max-completely-peeled-insns=1000 --param max-completely-peel-times=10000
MYCFLAGS += -O3
CFLAGS ?= $(DEFCFLAGS)
CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES)
# We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env:
PM3CFLAGS = $(CFLAGS)
PM3CFLAGS += -g -I./src -I./include -I../include -I../common -I../common_fpga $(PM3INCLUDES) $(INCLUDES)
PM3CFLAGS += -I./src -I./include -I../include -I../common -I../common_fpga $(PM3INCLUDES) $(INCLUDES)
# WIP Testing
#PM3CFLAGS += -std=c11 -pedantic
@@ -415,7 +419,7 @@ endif
PM3CFLAGS += -DHAVE_SNPRINTF
CXXFLAGS ?= -Wall -Werror -O3
CXXFLAGS ?= -Wall -Werror
CXXFLAGS += $(MYDEFS) $(MYCXXFLAGS) $(MYINCLUDES)
PM3CXXFLAGS = $(CXXFLAGS)
@@ -699,6 +703,7 @@ SRCS = mifare/aiddesfire.c \
mifare/mifare4.c \
mifare/mifaredefault.c \
mifare/mifarehost.c \
mifare/gen4.c \
nfc/ndef.c \
pm3.c \
pm3_binlib.c \
@@ -707,6 +712,7 @@ SRCS = mifare/aiddesfire.c \
pm3line.c \
proxmark3.c \
scandir.c \
uart/ringbuffer.c \
uart/uart_posix.c \
uart/uart_win32.c \
scripting.c \
+1
View File
@@ -59,6 +59,7 @@ const char *getAtrInfo(const char *atr_str);
// atr_t array is expected to be NULL terminated
const static atr_t AtrTable[] = {
{ "3BDF18FFC080B1FE751F033078464646462026204963656D616E1D", "Cardhelper by 0xFFFF and Iceman" },
{ "3B90969181B1FE551FC7D4", "IClass SE Processor (Other) https://www.hidglobal.com/products/embedded-modules/iclass-se/sio-processor"},
"""
C_FOOTER=""" {NULL, "N/A"}
+15
View File
@@ -147,6 +147,7 @@ enum ParserState {
PS_FIRST,
PS_ARGUMENT,
PS_OPTION,
PS_QUOTE,
};
#define isSpace(c)(c == ' ' || c == '\t')
@@ -195,6 +196,10 @@ int CLIParserParseStringEx(CLIParserContext *ctx, const char *str, void *vargtab
case PS_ARGUMENT:
if (state == PS_FIRST)
state = PS_ARGUMENT;
if (str[i] == '"') {
state = PS_QUOTE;
break;
}
if (isSpace(str[i])) {
spaceptr = bufptr;
state = PS_FIRST;
@@ -215,6 +220,16 @@ int CLIParserParseStringEx(CLIParserContext *ctx, const char *str, void *vargtab
*bufptr = str[i];
bufptr++;
break;
case PS_QUOTE:
if (str[i] == '"') {
*bufptr++ = 0x00;
state = PS_FIRST;
} else {
if (isSpace(str[i]) == false) {
*bufptr++ = str[i];
}
}
break;
}
if (bufptr > bufptrend) {
PrintAndLogEx(ERR, "ERROR: Line too long\n");
+65 -2
View File
@@ -141,6 +141,10 @@ F1D83F964314
FFF011223358
FF9F11223358
#
# Elevator system Kherson, Ukraine
AC37E76385F5
576DCFFF2F25
#
# more Keys from mfc_default_keys.lua
000000000001
000000000002
@@ -966,7 +970,7 @@ D58660D1ACDE
C01FC822C6E5
0854BF31111E
#
# More keys
# More keys - Found 8A at Sebel Hotel in Canberra, Australia
8A19D40CF2B5
AE8587108640
#
@@ -1029,6 +1033,10 @@ F8493407799D
6B8BD9860763
D3A297DC2698
#
# Data from reddit
34635A313344
593367486137
#
# Keys from Mifare Classic Tool project
044CE1872BC3
045CECA15535
@@ -1829,11 +1837,17 @@ E19504C39461
FA1FBB3F0F1F
FF16014FEFC7
#
#
# Food GEM
6686FADE5566
#
# Samsung Data Systems (SDS) — Electronic Locks
# Gen 1 S10 KA/KB is FFFFFFFFFFFF, incompatible with Gen 2 locks
#
# SDS Gen 2 S10 KB
C22E04247D9A
#
# Data from Discord, French pool
# SDS Gen 2 S10 KA
9B7C25052FC3
494446555455
#
@@ -2093,6 +2107,45 @@ D144BD193063
# Unknown hotel system Sec 0 / A
353038383134
#
# Brazil transport Sec 8 / A
50d4c54fcdf5
#
# Bandai Namco Passport [fka Banapassport] / Sega Aime Card
# Dumped on the Flipper Devices Discord Server
6090D00632F5
019761AA8082
574343467632
A99164400748
62742819AD7C
CC5075E42BA1
B9DF35A0814C
8AF9C718F23D
58CD5C3673CB
FC80E88EB88C
7A3CDAD7C023
30424C029001
024E4E44001F
ECBBFA57C6AD
4757698143BD
1D30972E6485
F8526D1A8D6D
1300EC8C7E80
F80A65A87FFA
DEB06ED4AF8E
4AD96BF28190
000390014D41
0800F9917CB0
730050555253
4146D4A956C4
131157FBB126
E69DD9015A43
337237F254D5
9A8389F32FBF
7B8FB4A7100B
C8382A233993
7B304F2A12A6
FC9418BF788B
#
# Data from "the more the marriott" mifare project (colonelborkmundus)
# aka The Horde
#
@@ -2225,3 +2278,13 @@ EDC317193709
A1670589B2AF
# SF Hotel (SoMa area)
2E0F00700000
#
# Unknown PACS from Western Australia
CA80E51FA52B
A71E80EA35E1
05597810D63D
#
# Hotel Key from Las Vegas
EA0CA627FD06
80BB8436024C
5044068C5183
+6 -1
View File
@@ -166,11 +166,12 @@ endif (NOT SKIPJANSSONSYSTEM EQUAL 1)
if(EMBED_BZIP2)
cmake_policy(SET CMP0114 NEW)
set(BZIP2_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/bzip2/src/bzip2)
# Specify SOURCE_DIR will cause some errors
ExternalProject_Add(bzip2
GIT_REPOSITORY https://android.googlesource.com/platform/external/bzip2
GIT_TAG platform-tools-30.0.2
PREFIX deps/bzip2
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/bzip2
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/bzip2
CONFIGURE_COMMAND mkdir -p ${BZIP2_BUILD_DIR} && git archive --format tar HEAD | tar -C ${BZIP2_BUILD_DIR} -x
BUILD_IN_SOURCE ON
BUILD_COMMAND make -C ${BZIP2_BUILD_DIR} -j4 CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} LD=${CMAKE_C_COMPILER} AR=${CMAKE_AR} RANLIB=${CMAKE_RANLIB} ${CFLAGS_EXTERNAL_LIB} libbz2.a
@@ -279,6 +280,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/mifare/mifare4.c
${PM3_ROOT}/client/src/mifare/mifaredefault.c
${PM3_ROOT}/client/src/mifare/mifarehost.c
${PM3_ROOT}/client/src/mifare/gen4.c
${PM3_ROOT}/client/src/nfc/ndef.c
${PM3_ROOT}/client/src/mifare/lrpcrypto.c
${PM3_ROOT}/client/src/mifare/desfirecrypto.c
@@ -286,6 +288,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/mifare/desfirecore.c
${PM3_ROOT}/client/src/mifare/desfiretest.c
${PM3_ROOT}/client/src/mifare/gallaghercore.c
${PM3_ROOT}/client/src/uart/ringbuffer.c
${PM3_ROOT}/client/src/uart/uart_posix.c
${PM3_ROOT}/client/src/uart/uart_win32.c
${PM3_ROOT}/client/src/ui/overlays.ui
@@ -656,6 +659,8 @@ if (MINGW)
set(CMAKE_C_FLAGS "-mno-ms-bitfields -fexec-charset=cp850 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-mno-ms-bitfields -fexec-charset=cp850 ${CMAKE_CXX_FLAGS}")
# link Winsock2
set(ADDITIONAL_LNK ws2_32 ${ADDITIONAL_LNK})
endif (MINGW)
# GCC 10 has issues with false positives on stringop-overflow,
@@ -1,3 +1,4 @@
#!/bin/bash
gcc -o test test.c -I../../include -lpm3rrg_rdv4 -L../build -lpthread
gcc -o test_grab test_grab.c -I../../include -lpm3rrg_rdv4 -L../build -lpthread
@@ -1,3 +1,3 @@
#!/bin/bash
LD_LIBRARY_PATH=../build ./test
LD_LIBRARY_PATH=../build ./test /dev/ttyACM0
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
LD_LIBRARY_PATH=../build ./test_grab /dev/ttyACM0
+7 -1
View File
@@ -1,8 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include "pm3.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: %s <port>\n", argv[0]);
exit(-1);
}
pm3 *p;
p = pm3_open("/dev/ttyACM0");
p = pm3_open(argv[1]);
pm3_console(p, "hw status");
pm3_close(p);
}
@@ -0,0 +1,74 @@
#include "pm3.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int pipefd[2];
char buf[8196 + 1];
size_t n;
if (argc < 2) {
printf("Usage: %s <port>\n", argv[0]);
exit(-1);
}
if (pipe(pipefd) == -1) {
exit(-1);
}
int pid = fork();
if (pid == -1) {
perror("fork");
exit(-1);
}
// child
if (pid == 0) {
printf("[INFO] inside child\n");
// Redirect stdout to the write end of the pipe
dup2(pipefd[1], STDOUT_FILENO);
close(pipefd[0]); // Child: close read end of the pipe
close(pipefd[1]); // Close original write end
pm3 *p;
p = pm3_open(argv[1]);
// Execute the command
pm3_console(p, "hw status");
pm3_close(p);
_exit(-1);
} else {
printf("[INFO] inside parent\n");
// Parent: close write end of the pipe
close(pipefd[1]);
// Read from the pipe
while (1) {
n = read(pipefd[0], buf, sizeof(buf));
if (n == -1) {
continue;
}
if (n == 0) {
break;
} else {
// null termination
buf[n] = 0;
if (strstr(buf, "ERROR") != NULL) {
printf("%s", buf);
}
if (strstr(buf, "Unique ID") != NULL) {
printf("%s", buf);
}
}
}
// Close read end
close(pipefd[0]);
}
}
-35
View File
@@ -1,35 +0,0 @@
#!/usr/bin/env bash
# Andrei Costin <zveriu@gmail.com>, 2011
# gen_pm3mfsim_script.sh
# Generates Mifare Classic emulation script file that will load a given EML dump into PM3 and start emulation automagically
# http://www.linuxquestions.org/questions/programming-9/bash-script-parsing-optional-parameters-621728/
# show program usage
show_usage()
{
echo
echo "Usage:"
echo "${0##/} input_eml_without_extension output.cmd"
exit
}
# Minimum number of arguments needed by this program
MINARGS=2
# get the number of command-line arguments given
ARGC=$#
# check to make sure enough arguments were given or exit
if [[ $ARGC -lt $MINARGS ]] ; then
echo "Too few arguments given (Minimum:$MINARGS)"
echo
show_usage
fi
rm $2
echo "hf mf eclr" >> $2
echo "hf mf eload" $1 >> $2
echo "hf mf ekeyprn" >> $2
echo "hf mf sim -u" `cat $1.eml | (read -n 8 uid; echo $uid)` >> $2
+18 -16
View File
@@ -7,7 +7,7 @@ local ansicolors = require('ansicolors')
copyright = ''
author = "Michael Micsen"
version = 'v0.0.1'
version = 'v0.0.2'
desc = [[
Perform simulation of Mifare credentials with HID encoding
This script only supports: H10301
@@ -17,12 +17,12 @@ example = [[
script run hf_mf_sim_hid.lua -f 1 -c 10000
]]
usage = [[
script run hf_mf_sim_hid.lua -f facility -c card_number
script run hf_mf_sim_hid.lua -f <dec> -c <dec>
]]
arguments = [[
-h : this help
-f : facility id
-c : starting card id
-f : facility code
-c : card number
]]
local DEBUG = true
--local bxor = bit32.bxor
@@ -126,7 +126,6 @@ local function cardHex(i, f)
sentinel = lshift(1, 26)
bits = bor(bits, sentinel)
return ('%08x'):format(bits)
end
---
@@ -146,15 +145,14 @@ local function main(args)
if o == 'h' then return help() end
if o == 'f' then
if isempty(a) then
print('You did not supply a facility code, using 0')
print('Defaulting to facility code 0')
facility = 0
else
facility = a
end
end
if o == 'c' then
print(a)
if isempty(a) then return oops('You must supply the flag -c (card number)1') end
if isempty(a) then return oops('You must supply a card number') end
cardnum = a
end
end
@@ -162,23 +160,27 @@ local function main(args)
--Due to my earlier complaints about how this specific getopt library
--works, specifying ':' does not enforce supplying a value, thus we
--need to do these checks all over again.
if isempty(cardnum) then return oops('You must supply the flag -c (card number)2') end
if isempty(cardnum) then return oops('You must supply a card number') end
--If the facility ID is non specified, ensure we code it as zero
if isempty(facility) then
print('Using 0 for the facility code as -f was not supplied')
print('Defaulting to facility code 0')
facility = 0
end
-- Write the MAD to read for a Mifare HID credential
core.console('hf mf esetblk -b 1 -d 1B014D48000000000000000000000000')
core.console('hf mf esetblk -b 3 -d A0A1A2A3A4A5787788C189ECA97F8C2A')
core.console('hf mf esetblk --blk 1 -d 1B014D48000000000000000000000000')
core.console('hf mf esetblk --blk 3 -d A0A1A2A3A4A5787788C189ECA97F8C2A')
--Write the sector trailer for the credential sector
core.console('hf mf esetblk -b 7 -d 484944204953787788AA204752454154')
core.console('hf mf esetblk --blk 7 -d 484944204953787788AA204752454154')
local cardh = cardHex(cardnum, facility)
print('Hex')
print(cardh)
core.console( ('hf mf esetblk -b 5 -d 020000000000000000000000%s'):format(cardh) )
print('Facility Code... ' .. facility)
print('Card number..... ' .. cardnum)
print('Hex............. ' .. cardh)
print('')
core.console( ('hf mf esetblk --blk 5 -d 020000000000000000000000%s'):format(cardh) )
core.console('hf mf sim --1k -i')
end
-6
View File
@@ -87,12 +87,6 @@ local function ExitMsg(msg)
print()
end
local function writedumpfile(infile)
t = infile:read('*all')
len = string.len(t)
local len,hex = bin.unpack(('H%d'):format(len),t)
return hex
end
-- blocks with data
-- there are two dataareas, in block 8 or block 36, ( 1==8 ,
-- checksum type = 0, 1, 2, 3
+5 -5
View File
@@ -82,16 +82,16 @@ local function main(args)
sd = sd or 2000
ed = ed or 2100
if #password ~= 8 then
password = ''
if password ~= '' and #password ~= 8 then
return oops('password must be 4 hex bytes')
end
if #wr_value ~= 8 then
wr_value = 'FFFFFFFF'
return oops('write value must be 4 hex bytes')
end
if #rd_value ~= 8 then
rd_value = 'FFFFFFFF'
return oops('read value must be 4 hex bytes')
end
if sd > ed then
@@ -114,7 +114,7 @@ local function main(args)
local set_tearoff_delay = 'hw tearoff --delay %d'
local enable_tearoff = 'hw tearoff --on'
local wr_template = 'lf em 4x05_write %s %s %s'
local wr_template = 'lf em 4x05 write --addr %s --data %s --pwd %s'
-- init addr to value
core.console(wr_template:format(addr, wr_value, password))
+155 -3
View File
@@ -49,7 +49,7 @@
},
{
"AID": "F21190",
"Vendor": "Metropolitan Transportation Commission",
"Vendor": "Metropolitan Transportation Commission / Cubic",
"Country": "US",
"Name": "Clipper Card",
"Description": "",
@@ -81,7 +81,7 @@
},
{
"AID": "784000",
"Vendor": "NO1",
"Vendor": "NOL",
"Country": "UAE",
"Name": "Nol Card/Dubai",
"Description": "Nol Card/Dubai",
@@ -121,7 +121,7 @@
},
{
"AID": "F21030",
"Vendor": "ORCA Card",
"Vendor": "ORCA (VUX/ERG)",
"Country": "",
"Name": "ORCA Card",
"Description": "(FIDs 02: Trip History; 04: current balance)",
@@ -383,5 +383,157 @@
"Name": "Disney MagicBand",
"Description": "AID found on MagicBand desfire cards",
"Type": "payment system"
},
{
"AID": "F21100",
"Vendor": "MyKI",
"Country": "AUS",
"Name": "Myki",
"Description": "AID found on Myki ticket cards",
"Type": "transport"
},
{
"AID": "F210F0",
"Vendor": "MyKI",
"Country": "AUS",
"Name": "Myki",
"Description": "AID found on Myki ticket cards",
"Type": "transport"
},
{
"AID": "F206B0",
"Vendor": "ACS",
"Country": "AUS",
"Name": "Metrocard / ACS",
"Description": "",
"Type": "transport"
},
{
"AID": "F21050",
"Vendor": "INIT",
"Country": "NZ",
"Name": "Metrocard / Christchurch",
"Description": "",
"Type": "transport"
},
{
"AID": "F21150",
"Vendor": "HAGUESS",
"Country": "CZ",
"Name": "Lítačka / Prague",
"Description": "",
"Type": "transport"
},
{
"AID": "F21360",
"Vendor": "INIT",
"Country": "CZ",
"Name": "HOLO",
"Description": "",
"Type": "transport"
},
{
"AID": "F21381",
"Vendor": "Cubic",
"Country": "US",
"Name": "Ventra",
"Description": "",
"Type": "transport"
},
{
"AID": "F213A0",
"Vendor": "INIT",
"Country": "US",
"Name": "WAVE / Rhode Island",
"Description": "",
"Type": "transport"
},
{
"AID": "F210E0",
"Vendor": "Hop Fastpass",
"Country": "",
"Name": "Hop Fastpass",
"Description": "",
"Type": "transport"
},
{
"AID": "EF2011",
"Vendor": "HSL",
"Country": "FI",
"Name": "HSL / Helsinki",
"Description": "",
"Type": "transport"
},
{
"AID": "A00216",
"Vendor": "ITSO",
"Country": "",
"Name": "ITSO",
"Description": "",
"Type": "transport"
},
{
"AID": "554000",
"Vendor": "AT HOP",
"Country": "",
"Name": "AT HOP",
"Description": "",
"Type": "transport"
},
{
"AID": "534531",
"Vendor": "OPAL",
"Country": "AUS",
"Name": "OPAL",
"Description": "",
"Type": "transport"
},
{
"AID": "2211AF",
"Vendor": "Leap",
"Country": "",
"Name": "Leap",
"Description": "",
"Type": "transport"
},
{
"AID": "015342",
"Vendor": "BEM",
"Country": "TH",
"Name": "BEM / Bangkok",
"Description": "",
"Type": "transport"
},
{
"AID": "012242",
"Vendor": "Istanbulkart",
"Country": "TR",
"Name": "Istanbulkart / Istanbul",
"Description": "",
"Type": "transport"
},
{
"AID": "010000",
"Vendor": "Madrid Public Transit Card",
"Country": "ES",
"Name": "Madrid Public Transit Card",
"Description": "",
"Type": "transport"
},
{
"AID": "000001",
"Vendor": "Invalid / reserved",
"Country": "",
"Name": "Invalid / reserved",
"Description": "used by Compass DESFire and Breeze DESFire",
"Type": "transport"
},
{
"AID": "FFFFFF",
"Vendor": "Reserved for future use",
"Country": "",
"Name": "Reserved for future use",
"Description": "used by AT HOP, Nol, ORCA",
"Type": "transport"
}
]
+52 -2
View File
@@ -2940,7 +2940,7 @@
"system_integrator": "A.I.I."
},
{
"application": "Multi-Modal Transit",
"application": "Multi-Modal Transit (Vix/ERG)",
"company": "ERG Transit Systems",
"mad": "0x2103",
"service_provider": "ERG Transit Systems",
@@ -2953,6 +2953,13 @@
"service_provider": "ERG Transit Systems",
"system_integrator": "ERG Transit Systems"
},
{
"application": "Transit (Metrocard / Christchurch)",
"company": "INIT Transit Systems",
"mad": "0x2105",
"service_provider": "INIT Transit Systems",
"system_integrator": "INIT Transit Systems"
},
{
"application": "Mass Transportation Ticketing",
"company": "Omnifare",
@@ -2995,6 +3002,13 @@
"service_provider": "Emcard",
"system_integrator": "Emtest"
},
{
"application": "Integrated multi-modal transport ticketing system",
"company": "HOP Fastpass",
"mad": "0x210E",
"service_provider": "HOP Fastpass",
"system_integrator": "HOP Fastpass"
},
{
"application": "Integrated multi-modal transport ticketing system",
"company": "Keane Australia PTY Limited",
@@ -3038,7 +3052,7 @@
"system_integrator": "T-Systems GEI"
},
{
"application": "Transportation ticket",
"application": "Transportation ticket (Lítačka)",
"company": "Haguess s.r.o.",
"mad": "0x2115",
"service_provider": "HAGUESS, a.s.",
@@ -3135,6 +3149,35 @@
"service_provider": "RTD",
"system_integrator": "ACS"
},
{
"application": "Bus and rail fare collection (HOLO)",
"company": "INIT",
"mad": "0x2136",
"service_provider": "INIT",
"system_integrator": "INIT"
},
{
"application": "Bus and rail fare collection (Ventra)",
"company": "Cubic",
"mad": "0x2138",
"service_provider": "Cubic",
"system_integrator": "Cubic"
},
{
"application": "Bus and rail fare collection (Clipper)",
"company": "Cubic",
"mad": "0x2139",
"service_provider": "Cubic",
"system_integrator": "Cubic"
},
{
"application": "Bus and rail fare collection (WAVE)",
"company": "INIT Rhode Island",
"mad": "0x213A",
"service_provider": "INIT Rhode Island",
"system_integrator": "INIT Rhode Island"
},
{
"application": "Bus services with extension to rail and taxi",
"company": "Questek Marketing",
@@ -13621,5 +13664,12 @@
"mad": "0xF001",
"service_provider": "Tech ID",
"system_integrator": "Tech ID"
},
{
"application": "Miscellaneous applications",
"company": "Reserved For future Use",
"mad": "0xFFFF",
"service_provider": "RFU",
"system_integrator": "RFU"
}
]
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
8b754191cec19a8172ff77443eee67490f61c53161af2e831ff4e8c7909b788802f5c0b68cecdc5decabe7852479740a0122832803af26b68beab814ced543b8 *client/resources/sim014.bin
+31 -3
View File
@@ -34,6 +34,7 @@ const char *getAtrInfo(const char *atr_str);
// atr_t array is expected to be NULL terminated
const static atr_t AtrTable[] = {
{ "3BDF18FFC080B1FE751F033078464646462026204963656D616E1D", "Cardhelper by 0xFFFF and Iceman" },
{ "3B90969181B1FE551FC7D4", "IClass SE Processor (Other) https://www.hidglobal.com/products/embedded-modules/iclass-se/sio-processor"},
{ "3B..............0031B8640000000073......829000", "MultiApp ID IAS ECC 72K CC (with IAS XL / IAS ECC Applet) IAS ECC Type 3" },
{ "3B..............0031B8640000000073......829000..", "MultiApp ID IAS ECC 72K CC (with IAS XL / IAS ECC Applet) IAS ECC Type 4" },
{ "3B........0031B864........73......829000", "IDClassic IAS (old name: IAS TPC) IAS ECC Type 1\nMultiApp ID IAS ECC 72K CC (with IAS XL / IAS ECC Applet) IAS ECC Type 1" },
@@ -362,6 +363,7 @@ const static atr_t AtrTable[] = {
{ "3B3C110042AF20A32007002283829000", "Orange Mobicarte (SIM card old generation)" },
{ "3B3C110044AF11F7200504FB83819000", "itineris (Old French Mobile Operator SIM card) (Telecommunication)" },
{ "3B3C9400423111A21202095183809000", "Omnitel IT 16K GSM SIM card" },
{ "3B3C9400443111F000002CAE83839000", "Movistar Spain (Telecommunication)" },
{ "3B3C94004B3125A21013144783839000", "GSM SFR" },
{ "3B3C94004C3125A7201B001583839000", "GSM-SIM (900MHz) card of the carrier vodafone for their cellular\nnetwork (phase 2+ with 3V)" },
{ "3B3C9400633112F00000464083839000", "Old russian 'beeline' sim" },
@@ -425,6 +427,7 @@ const static atr_t AtrTable[] = {
{ "3B5F9600805A2C1100101000FFFFFFFF829000", "Calypso (Transport)" },
{ "3B5F9600805A3F0608140101C546DEDC829000", "Navegante(r) Personalizado (Lisbon public transportation card) (Transport)\nhttps://www.navegante.pt/viajar/cartoes" },
{ "3B5F9600805A3F0608140101C546EBDC829000", "Multi-Transport Pass (Navegante) (Metro, Bus, Electric, Boat) Carris Metropolitano, PT (Transport)\nhttps://www.navegante.pt/" },
{ "3B5F9600805A3F0608201223C4325FDE829000", "Montreal metropolitan area and Quebec city area OPUS card (Transport)\nhttps://www.carteopus.info/" },
{ "3B600000", "Meano (Bank)" },
{ "3B61000080", "blank A40CR card (JavaCard)" },
{ "3B630000364180", "Schlumberger Payflex 4k User" },
@@ -1189,6 +1192,7 @@ const static atr_t AtrTable[] = {
{ "3B6F0000805A28130210122B75021B8A829000", "KorriGo, smart transport card in France region Brittany (Transport)\nhttps://www.ter.sncf.com/bretagne/offres/carte-korrigo" },
{ "3B6F0000805A28130210122B7503FB01829000", "origo (France) (Transport)\nhttps://www.breizhgo.bzh/se-deplacer-en-bretagne/KorriGo" },
{ "3B6F0000805A28130210122B750C7E79829000", "Transportation card delivered by STAR (Transportation service from the city of Rennes, France) (Transport)\nhttps://www.star.fr/titres-et-tarifs/carte-korrigo/" },
{ "3B6F0000805A28130210122B750DD382829000", "ZOU! for Region Sud (Transport)\nhttps://zou.maregionsud.fr/ma-carte-zou/" },
{ "3B6F0000805A28130210122B9292E642829000", "Transport card in cote d'or France (mobigo)" },
{ "3B6F0000805A28130210122B9292E829829000", "French transport card of the city of Dijon and Cote d'or department. (Transport)\nhttps://www.viamobigo.fr/fr/acheter-mes-titres-de-transport-mobigo-en-cote-dor/176" },
{ "3B6F0000805A28130210122B92D663FC829000", "Card 'Korrigo' region Bretagne, France, Bibus Brest Metropole public transport (Transport)\nhttps://fr.wikipedia.org/wiki/KorriGo" },
@@ -1227,6 +1231,7 @@ const static atr_t AtrTable[] = {
{ "3B6F0000805A2D06081010027835EDCE829000", "Lisbon Transportation SmartCard (Transport)" },
{ "3B6F0000805A2D06081010027848BBCC829000", "Lisbon Metro Monthly Student Pass (Transport)\nhttps://www.metrolisboa.pt/" },
{ "3B6F0000805A2D0608101005935C42FB829000", "Comboios de Portugal Transit Card (Transport)\nhttps://www.cp.pt/passageiros/pt/consultar-horarios/precos/cartao-cp" },
{ "3B6F0000805A2E130200010104EF8342829000", "Oura Auvergne-Rhone-Alpes (Transport)\nhttps://www.oura.com" },
{ "3B6F0000805A3407061500017917A7E2829000", "Rav-Kav multi-line travel ticket used in the public transportation system in Israel (Transport)\nhttps://www.gov.il/en/departments/guides/multi_line_card" },
{ "3B6F0000805A340706150001792A4B5C829000", "Rav Kav Transit Payment Card (Israel) (Transport)\nhttps://ravkavonline.co.il/" },
{ "3B6F0000805A3B0706150101793E797B829000", "Rav Kav (Transport)\nhttp://alhakav.mot.gov.il/he/rav-kav" },
@@ -1468,7 +1473,7 @@ const static atr_t AtrTable[] = {
{ "3B7F..0000006A4345524553022C3402..039000", "Ceres ST v2" },
{ "3B7F..0000006A4345524553022C3403..039000", "Ceres ST v3" },
{ "3B7F..00008031..65B000000000......8290..", "MultiApp V2.1 (with IAS XL / IAS ECC and IAS Classic Applet V3) [MultiApp V2.1 Type 2]" },
{ "3B7F..000080318065B0........120FFE829000", "IDPrime MD 8840, 3840, 3810, 840 and 830 Cards T=0" },
{ "3B7F..000080318065B0........120FFE829000", "IDPrime MD 8840, 3840, 3810, 840 and 830 Cards T=0\nIDPrime 930 (JavaCard)" },
{ "3B7F0100FE58434F53763235312863295046424D", "XCOS is an Experimental Card Operating System for Atmel based smartcards (Funcard, etc..) (Other)\nhttp://runningserver.com/?page=runningserver.content.download.xcos" },
{ "3B7F04000080318071906754454D44412E309000", "public key (PKI)" },
{ "3B7F1100000031C053CAC4016452D90400829000", "DoD CAC, Oberthur CosmopolIC 32K V4" },
@@ -1604,6 +1609,7 @@ const static atr_t AtrTable[] = {
{ "3B7F96000080318065B085050011120FFF829000", "LuxTrust card (Luxembourg qualified electronic signature / authentication system) (Other)\nhttps://www.luxtrust.com/en/professionals/smartcard" },
{ "3B7F96000080318065B0855956FB120268829000", "qualified certificate (eID)\nhttps://www.elektronicznypodpis.pl/en/offer/qualified-certificates/" },
{ "3B7F96000080318065B0855956FB1202C1829000", "Gemalto USB (eID)" },
{ "3B7F96000080318065B0855956FB120FFE829000", "Thales (Gemalto) IDPrime 941 (PKI)\nhttps://cpl.thalesgroup.com/de/access-management/idprime-md-pki-smart-cards\nThales SafeNet IDPrime 940B (PKI)\nhttps://cpl.thalesgroup.com/resources/access-management/idprime-940-product-brief" },
{ "3B7F96000080318065B0855956FB12FFFE829000", "IDCORE 3140 (JavaCard)" },
{ "3B7F9600008031B865B0850300EF1200F6829000", "Finnish identity card (eID)\nhttp://vrk.fi/en/citizen-certificate" },
{ "3B7F9600008031B865B08504021B1200F6829000", "Finnish ID-card v5.0(?) (eID)\nhttps://dvv.fi/en/fineid-specifications" },
@@ -1705,6 +1711,7 @@ const static atr_t AtrTable[] = {
{ "3B8680014B4F4E41141109", "Mastercard paypass enabled credit card" },
{ "3B8680015741524930310B", "Gusto Karta (Bank)\nhttps://www.gustokarta.cz" },
{ "3B86800157575061737336", "WWPass Passkey (eID)\nhttps://www.wwpass.com/passkey" },
{ "3B868001801434373000A0", "Malta eID Identity Card (eID)\nhttps://www.identitymalta.com/" },
{ "3B8680018031C15211182C", "IDEMIA Cosmo V8.0 with a PIV applet (contactless) (PKI)" },
{ "3B8680018031C152411A7E", "IDEMIA Cosmo V8.1 with a PIV applet (contactless) (PKI)" },
{ "3B86800180540410010FC9", "Nickel.eu prepaid account (Bank)\nhttps://nickel.eu" },
@@ -2006,6 +2013,7 @@ const static atr_t AtrTable[] = {
{ "3B8C8001505CF5A94530AAAA017781D708", "Indonesia ektp (eID)" },
{ "3B8C800150605F2EFA00000000778191D1", "Residence Permit (Switzerland) (eID)" },
{ "3B8C80015064E65B000000000000818085", "Chicago CTA Ventra Transit card\nhttps://www.ventrachicago.com/" },
{ "3B8C80015068DDA5B11C00001177818582", "EZ-Link Card (issued by Land Transport Authority Singapore) (Transport)\nhttps://www.ezlink.com.sg/ez-link-faqs/ez-link-card/" },
{ "3B8C800150710CF3C800000000B37171A8", "MOBIB CARD BELGIUM (Transport)" },
{ "3B8C800150773B2DBD0000001100818594", "Texas Instruments Dynamic NFC Interface Transponder (RF430CL330H)" },
{ "3B8C800150784B2CCB00000000B371713A", "... (Transport)\nhttps://www.portalviva.pt/" },
@@ -2135,6 +2143,7 @@ const static atr_t AtrTable[] = {
{ "3B8F80010031B96409377213738401E0000000AB", "National Identity Card of Slovakia (NFC interface) (eID)\nhttps://en.wikipedia.org/wiki/Slovak_identity_card" },
{ "3B8F80010031C173C800106457494943009000B5", "ICC Solutions Card for Certification (Other)\nhttps://www.iccsolutions.com/" },
{ "3B8F80010031C173C8211064414D31300790008A", "master card (Bank)" },
{ "3B8F80010031C173C8211064414D313307900089", "CheBanca! nexi debit card (Bank)\nhttps://www.chebanca.it/" },
{ "3B8F80010031C173C8211064414D31370790008D", "AirPlus International Mastercard (Bank)\nhttps://www.airplus.com/" },
{ "3B8F80010031C173C8211064414D333007900088", "ING-VISA-Card (Bank)\nhttps://www.ing.de/girokonto/karten-bargeld/" },
{ "3B8F80010031C173C8211064414D333107900089", "NAB VISA Debit (Bank)\nhttps://www.nab.com.au/" },
@@ -2276,7 +2285,7 @@ const static atr_t AtrTable[] = {
{ "3B8F8001804F0CA0000003060E....00000000..", "Contact (7816-10) Extended I2C (as per PCSC std part3)" },
{ "3B8F8001804F0CA0000003060F....00000000..", "Contact (7816-10) 2WBP (as per PCSC std part3)" },
{ "3B8F8001804F0CA00000030610....00000000..", "RFID - FeliCa compatible (as per PCSC std part3)\nContact (7816-10) 3WBP (as per PCSC std part3)" },
{ "3B8F8001804F0CA00000030611003B0000000042", "RFID - FeliCa (generic) (as per PCSC std part3)\nSuica public transit card (Japan IC system)\n(also: Hayakaken, ICOCA, Kitaca, manaca, nimoca, PASMO, PiTaPa, SUGOCA, TOICA)\nhttps://en.wikipedia.org/wiki/Suica\nOctopus, MTR network from Hong Kong, 2014" },
{ "3B8F8001804F0CA00000030611003B0000000042", "RFID - FeliCa (generic) (as per PCSC std part3)\nSuica public transit card (Japan IC system)\n(also: Hayakaken, ICOCA, Kitaca, manaca, nimoca, PASMO, PiTaPa, SUGOCA, TOICA)\nhttps://en.wikipedia.org/wiki/Suica\nOctopus, MTR network from Hong Kong, 2014\ne-Amusement card (Other)\nhttps://en.wikipedia.org/wiki/E-Amusement" },
{ "3B8F8001804F0CA00000030640....00000000..", "RFID - Low Frequency < 135 kHz (as per PCSC std part3)" },
{ "3B8F8001804F0CA0000003064000000000000028", "HID Proximity. Used to access buildings. Reference on the card 'HID0008P'.\nhttp://www.hidglobal.com/product-display/cards-and-credentials/hid-proximity" },
{ "3B8F8001804F0CA0001A0000000078", "iclass 16k cl (eID)" },
@@ -2328,7 +2337,6 @@ const static atr_t AtrTable[] = {
{ "3B959640F001130A0A1D", "xcrypt (Pay TV)" },
{ "3B959640F00F100A096A", "Zain Usim Card (Telecommunication)\nwww.qariya.com" },
{ "3B959680B1FE551FC7477261636513", "IClass SE Processor (Other)\nhttps://www.hidglobal.com/products/embedded-modules/iclass-se/sio-processor" },
{ "3B90969181B1FE551FC7D4", "IClass SE Processor (Other)\nhttps://www.hidglobal.com/products/embedded-modules/iclass-se/sio-processor"},
{ "3B9596C0F01FC20F100A0A16", "viettel (Telecommunication)" },
{ "3B959740F01A160A1941", "SG50 (Samsung Chip) (Telecommunication)" },
{ "3B96004121920000622433339000", "Ukrainian Telecommunications Operator Kyivstar (old simcard) (Telecommunication)\nhttps://kyivstar.ua/uk/mm" },
@@ -2378,6 +2386,7 @@ const static atr_t AtrTable[] = {
{ "3B9A940091010017000126050096", "GSM-SIM T-D1 prepaid (Xtra) (Telecommunication)" },
{ "3B9A940091010017000126060096", "T D1 GSM card" },
{ "3B9A9400920275931100010202..", "SuperSIM (X-sim)" },
{ "3B9A940092029093110001340200", "Orange Spain (Telecommunication)" },
{ "3B9A960092013693170002040300", "GSM-SIM EMT 'Simpel' (prepaid, Estonia)\nhttps://www.emt.ee/web/simpel" },
{ "3B9A960092014893170002120400", "SIM Card C*******r Mobile (Belgium)" },
{ "3B9A960092016693170002120400", "GSM SIM Bite.lv prepaid 'Toxic'; 2008" },
@@ -2396,6 +2405,7 @@ const static atr_t AtrTable[] = {
{ "3B9C131181647265616D6372797074000408", "XPlusTV & INXCT Access Card-9 (FIRECrypt)" },
{ "3B9C131181647265616D6372797074900599", "FireCrypt, access card 9 (Pay TV)" },
{ "3B9C188121455A43332E333420524556204467", "MS-Protect safecard for access system (eID)" },
{ "3B9C188121755A43332E333420524556204457", "ZC3.34 (Other)\nhttps://www.zeitcontrol.de/Smart-card-BasicCard-Enhanced-ZC334-SIM-cut" },
{ "3B9C940068868D0A86980256C2000500", "G3 & GSM & Blank SIM card: to be programmed for OpenBTS with pySim-prog (Telecommunication)" },
{ "3B9C940068868D0C86980245A1000500", "China Mobile (Telecommunication)" },
{ "3B9C940068868D0C86980256408B0500", "mobiledit (Telecommunication)" },
@@ -2490,6 +2500,7 @@ const static atr_t AtrTable[] = {
{ "3B9E95801FC78031E073FE211B66D00217C71100C0", "3 UK SIM card (Telecommunication)" },
{ "3B9E95801FC78031E073FE211B66D00217F61100F1", "Ziggo SmartCard Television Subscription (Pay TV)" },
{ "3B9E95801FC78031E073FE211B66D00219151300", "ABS-CBN (Telecommunication)" },
{ "3B9E95801FC78031E073FE211B66D0022A861300BE", "KPN, Netherlands (Telecommunication)" },
{ "3B9E95C00A1FC68031E073FE211B66D001830D58811E", "Mobile Paypass G199 NFC" },
{ "3B9E96008031C0654D4700000072F7418107", "Russian Magistra (UTF8: Magistra) smart card (eID)\nhttp://www.smart-park.ru/index.php/products/smartcards.html" },
{ "3B9E96008031C0654D5300000072F7418107", "Smart-key for bank-client of MDM Bank (RU) with faktura.ru service (Bank)" },
@@ -2506,6 +2517,7 @@ const static atr_t AtrTable[] = {
{ "3B9E96801FC68031E073FE211B66D0019F8F120002", "Russian 'Megafon' gsm sim card (Telecommunication)\nhttp://www.megafon.ru/" },
{ "3B9E96801FC68031E073FE211B66D0019FBC100033", "sim beeline russia krasnodar (Telecommunication)" },
{ "3B9E96801FC68031E073FE211B66D0019FEF100060", "Infineon SLU14MCO480K2 (JavaCard)" },
{ "3B9E96801FC68031E073FE211B66D0024010150046", "Kyivstar USIM-card (Telecommunication)" },
{ "3B9E96801FC78031E073FE21136200498381900007", "Claro Brazil SIM card (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D000282401000D", "United Mobile SIM" },
{ "3B9E96801FC78031E073FE211B66D0002B2D020004", "KTF SHOW GE-B1400 WCDMA USIM (Telecommunication)" },
@@ -2540,6 +2552,7 @@ const static atr_t AtrTable[] = {
{ "3B9E96801FC78031E073FE211B66D00199FE0E0068", "Finnish Sonera SIM-card (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D001A0041100B4", "Aldi Talk SIM card, Germany (Telecommunication)\nhttps://www.alditalk.de/talk" },
{ "3B9E96801FC78031E073FE211B66D001A01E1100AE", "Zevvle SIM Card (Telecommunication)\nhttps://zevvle.com" },
{ "3B9E96801FC78031E073FE211B66D001A0741000C5", "USIM of Vodafone Germany (MCC 262, MNC 2) (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D001A0DD12006E", "USIM (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D001A0EC11005C", "Boost Mobile Prepaid Micro SIM Card (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D001A1121000A2", "OpenAirInerface (Telecommunication)" },
@@ -2565,6 +2578,7 @@ const static atr_t AtrTable[] = {
{ "3B9E96801FC78031E073FE211B66D00217F41200F3", "SIM card for Swedish operator Vimla! (Telecommunication)\nhttps://www.vimla.se" },
{ "3B9E96801FC78031E073FE211B66D002194B120042", "halebop (swedish mobile provider) SIM card (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D0022436140004", "SIM (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D0022A6D140051", "Mobitel SIM from Sri Lanka (Telecommunication)\nhttps://mobitel.lk/" },
{ "3B9E96801FC78031E073FE211B66D0022A72130049", "SIM Card OI (Brazil) (Telecommunication)" },
{ "3B9E96801FC78031E073FE211B66D0022A861300BD", "Mobile Vikings SIM Card (Telecommunication)\nhttps://mobilevikings.com" },
{ "3B9E96801FC78031E073FE211B66D0022A8F1400B3", "Telefonica USIM (Telecommunication)" },
@@ -2575,6 +2589,7 @@ const static atr_t AtrTable[] = {
{ "3B9E96801FC78031E073FE211B66D00233AD140088", "4G-LTE (Telecommunication)" },
{ "3B9E96803FC3A08031E073FE211B630801140F9000D3", "KT Olleh LTE Warp SA-L 1670 (Telecommunication)" },
{ "3B9E97801FC68031E073FE211B66D0019F7A1200F6", "Spectrun USA Sim Card (Telecommunication)" },
{ "3B9E97801FC68031E073FE211B66D0024011150046", "SIM Card for French mobile provider Unyc (Telecommunication)\nhttps://www.unyc.io/" },
{ "3B9E97801FC68031E073FE211B66D002401D15004A", "Telia Sim card for IoT (Telecommunication)" },
{ "3B9E97801FC68031E073FE211B66D0024027150070", "verymobile wind 3 (Telecommunication)\nhttps://verymobile.it/" },
{ "3B9E97801FC68031E073FE211B66D0025E7315003A", "Twilio Super SIM (Telecommunication)\nhttps://www.twilio.com/iot/super-sim-card" },
@@ -2643,6 +2658,7 @@ const static atr_t AtrTable[] = {
{ "3B9F94801FC78031E073FE2113578681098698621880", "Oyeitimes 5G ISIM R16 (Telecommunication)\nhttps://www.oyeitimes.com/detail.php?id=535&ids=565&idt=&ide=&dd=1410" },
{ "3B9F94801FC78031E073FE21135786850686984218AB", "4G LTE blank USIM Green Card (Telecommunication)\nhttp://grcard.en.alibaba.com/product/60076835567-209365843/4G_LTE_blank_usim_card_for_4G_network.html" },
{ "3B9F94801FC78031E073FE21136321150683079000F8", "Maroc Telecom 4G+ (Telecommunication)" },
{ "3B9F94801FC78031E073FE21136700000000000070AA", "OMANTEL (Telecommunication)\nhttps://portal.omantel.om/Personal/mobile/hayyak" },
{ "3B9F94801FC78031E073FE21136761210D10000070F7", "Celcom XPAX (Telecommunication)\nhttps://www.celcom.com.my/personal/prepaid" },
{ "3B9F94801FC78031E073FE2119573C8660CFB902A0EE", "Gotanet SE USIM (Telecommunication)" },
{ "3B9F94801FC78031E073FE2119573C8660CFBA02A0ED", "Gotanet DK USIM (Telecommunication)" },
@@ -2774,6 +2790,7 @@ const static atr_t AtrTable[] = {
{ "3B9F96801F878031E073FE2119674A555473300948DB", "nano sim/usim card (Telecommunication)" },
{ "3B9F96801F878031E073FE2119674A555475300662F8", "SIM Card (Telecommunication)" },
{ "3B9F96801F878031E073FE2119674A557330310746BE", "Hologram Developer Global IoT SIM Card (Telecommunication)\nhttps://hologram.io/store/global-iot-sim-card/17" },
{ "3B9F96801F878031E073FE2119674A55753031136288", "Zimbabwe sim card provider: ECONET (Telecommunication)" },
{ "3B9F96801F878031E073FE211B674A4C5275310451D5", "Test card provided with 4G/5G network from Amarisoft (Telecommunication)" },
{ "3B9F96801F878031E073FE211B674A4C7530300248A9", "Cardcentrics (Telecommunication)" },
{ "3B9F96801F878031E073FE211B674A4C753034054BA9", "sysmoISIM-SJA2 (Telecommunication)\nhttps://osmocom.org/projects/cellular-infrastructure/wiki/SysmoISIM-SJA2" },
@@ -2944,6 +2961,7 @@ const static atr_t AtrTable[] = {
{ "3B9F96803FC7828031E073F62157574A330581053000CE", "COMPRION M2M eUICC (Telecommunication)" },
{ "3B9F96803FC7828031E073F62157574A4D020B60010069", "eSIM GSMA Card (Telecommunication)\nhttps://www.gsma.com/newsroom/wp-content/uploads/SGP.22_v2.2.pdf" },
{ "3B9F96803FC7828031E073F62157574A4D020B60610009", "ting (Telecommunication)" },
{ "3B9F96803FC7828031E073FE211B57AA8660F0010004FB", "The eSIM.me Card (Telecommunication)\nhttps://esim.me/" },
{ "3B9F96803FC7828031E073FE211B57AA8660F0010011EE", "eSIM.me pluggable eSIM (Telecommunication)\nhttps://esim.me/" },
{ "3B9F96803FC7828031E073FE211B633A204E8300900031", "eSIM (Telecommunication)" },
{ "3B9F96803FC7828031E075F62157210355020B60500019", "st33g1m2 (Telecommunication)\nhttps://www.st.com/en/secure-mcus/st33g1m2.html" },
@@ -3047,6 +3065,7 @@ const static atr_t AtrTable[] = {
{ "3BB813008131205D0057696E4361726402", "SmartCard for Windows 1.1" },
{ "3BB813008131FA524348544D4F494341A5", "citizen digital certificate (PKI)\nhttp://moica.nat.gov.tw/" },
{ "3BB897008131FE45FFFF148230502300F1", "UAE Emirates ID (eID)\nhttps://www.icp.gov.ae" },
{ "3BB89700813FE45FFFF148230502300F", "UAE Emirates ID (eID)" },
{ "3BB89700C00831FE45FFFF148230502300B8", "Infineon SECORA ID X (JavaCard)" },
{ "3BB918008131FE9E8073FF614083000000DF", "Serbian Identity Card\nThis is the new Serbian biometric identity card (every adult cityzen\nmust have). The chip contains owners picture, name, date and place\nof birth, current address, unique ID number and fingerprint." },
{ "3BB9940040144747334D4838353330", "T D1 GSM card (Telecommunication)" },
@@ -3239,6 +3258,7 @@ const static atr_t AtrTable[] = {
{ "3BDB960080B1FE451F830031C064B0FC100007900005", "Oberthur Cosmo V7 debug card (SDK)" },
{ "3BDB960080B1FE451F830031C064B0FC10000F90000D", "ID-One PIV (that's the only non-numeric identifying mark) (PKI)" },
{ "3BDB960080B1FE451F830031C064BAFC10000790000F", "Oberthur ID-One Cosmo v7.0 80K (eID)\nhttps://www.ssi.gouv.fr/uploads/IMG/certificat/ANSSI-CC-cible_2011-64en.pdf" },
{ "3BDB960080B1FE451F830031C064BAFC10000F900007", "Oberthur ID-One Cosmo v7.0 (PKI)\nhttps://csrc.nist.rip/groups/STM/cmvp/documents/140-1/140sp/140sp1236.pdf" },
{ "3BDB960080B1FE451F830031C064BE1B0100019000FB", "Bank card" },
{ "3BDB960080B1FE451F830031C064C30801000F90009B", "SIM Aruba (Italian provider)" },
{ "3BDB960080B1FE451F830031C064C7FC100001900074", "Oberthur Cosmo (eID)\nhttp://www.stampit.org" },
@@ -3247,6 +3267,7 @@ const static atr_t AtrTable[] = {
{ "3BDB960080B1FE451F830031E85427E6040007900084", "Polish encard (eID)" },
{ "3BDB960080B1FE451F830031E85427E604000F90008C", "Token card from iBRE CompanyNet (mbank) (Bank)" },
{ "3BDB960080B1FE451F834553544F4E49412D65494455", "Estonian Identity Card (ID-One Cosmo v8.1) (eID)" },
{ "3BDB960080B1FE451F870031C1640958223607900019", "Idemia Solvo Fly 40 (JavaCard)" },
{ "3BDB960081B1FE451F0380F9A0000003080000100018", "Oberthur CS PIV End Point v1.08 FIPS201 Certified" },
{ "3BDB960081B1FE451F0380F9A0000003480000000149", "Fly Clear card" },
{ "3BDB960081B1FE451F8380F9A0000003080000100098", "Oberthur Cosmo v7 128K with PIV applet\nhttp://www.smartcardfocus.com/shop/ilp/id~410/p/index.shtml" },
@@ -3344,6 +3365,7 @@ const static atr_t AtrTable[] = {
{ "3BDF96FF910131FE4680319052410264050200AC73D622C017", "Acos-ID (AUSTRIACARD's Operating System) (Other)\nhttps://www.austriacard.com/digital-security/solutions/card-solutions/acos-id/" },
{ "3BDF97008131FE588031B05202056405A100AC73D622C021", "Austrian healthcare insurance identification card (HealthCare)\nhttps://www.chipkarte.at" },
{ "3BDF970081B1FE451F838073CC91CBF9A0000003080000100078", "NASA PIV Card (Other)" },
{ "3BE000008131104505", "Emoney indonesia (Bank)" },
{ "3BE000008131204030", "SmarTEC" },
{ "3BE000FF8131FE4514", "'JUKICARD', digitally sign tax documents in Japan" },
{ "3BE20000402049..", "Schlumberger Cryptoflex 4k" },
@@ -3432,6 +3454,7 @@ const static atr_t AtrTable[] = {
{ "3BEE00008131804280318066B0840C016E01830090008E", "MultiApp Cards (Easy 72K Type B and Combi 72K Type B)\nE.SUN Commercial bank debit master card (Bank)\nTaiwan EasyCard (Transport)\nhttps://www.easycard.com.tw/english/index.asp" },
{ "3BEE00008131804380318066B1A1110100F683009000", "Optelio/Desineo Cards (D72 FXR1)" },
{ "3BEE00008131804380318066B1A11101A0F683009000", "Optelio D72 FXR1 (MD) T=1" },
{ "3BEE00008131804380318066B1A30401110B83009000D4", "Japan Post Bank cash card (Bank)\nhttps://www.jp-bank.japanpost.jp/kojin/chokin/sogou/kj_cho_sg_iccard.html" },
{ "3BEE00008131FE45003180718665016702A00A8390001B", "IBM JCOP 'Java Card 2.1.1' et 'Open Platform 2.0.1'" },
{ "3BEE00008131FE4580318066409093060F1783019000FD", "Health insurance (HealthCare)" },
{ "3BEE00008131FE4580318066409093060F17830F9000F3", "IC card for the National Health Insurance, Taiwan" },
@@ -3579,6 +3602,7 @@ const static atr_t AtrTable[] = {
{ "3BF711000140967070370E6CB6D6", "Carte pour decodeur cable numerique (fourni par www.voo.be et\nwww.ledecodeur.be)" },
{ "3BF711000140967070670E6CB6D6", "UK TopUp TV" },
{ "3BF711000140967071090E6CB6D6", "Carte pour decodeur tele de Neuf Telecom TV" },
{ "3BF71300008131FE4500C08AC80C658185", "NXP JCop (JavaCard)" },
{ "3BF71300008131FE45464F4D534F4D53A9", "Health card Russian Federation" },
{ "3BF71300008131FE454A434F503234....", "NXP JCOP v2.4.x (see hist bytes for more info)" },
{ "3BF71300008131FE4580654A5030310415", "Nichizeiren Denshi-shomei (eID)\nhttps://www.nichizeiren.or.jp/taxaccount/auth/fifth/" },
@@ -3818,6 +3842,7 @@ const static atr_t AtrTable[] = {
{ "3BFF1300008131FE45434433690940000020202020202000F3", "VISA credit card (LBBW/Payback VISA) (Bank)" },
{ "3BFF1300008131FE454F574F4B31302D4A................", "OWOK (One Web, One Key) login card\nhttp://www.reiner-sct.com/owok/\nReiner SCT loginCard\nhttps://cardlogin.reiner-sct.com/" },
{ "3BFF1300008131FE4D8025A00000005657444B3333300600D2", "Datakey DCOS model 330 (DKCCOS 6.0 token)" },
{ "3BFF1300918131FE4141434F532046696F6E6131204C6336F4", "TURKEY A101 HADI APP CARD (Bank)\nhttps://a101hadi.a101.com.tr/" },
{ "3BFF1300FF10000031C1738211064414D33470779000", "Visa Debit (Bank)\nhttps://www.chase.com/" },
{ "3BFF1300FF10000031C173C821106441443533079000", "BRADESCO-CONTA SALARIO (Bank)" },
{ "3BFF1300FF10000031C173C8211064414D3130079000", "Tangerine MasterCard (Bank)\nhttps://www.tangerine.ca/en/products/spending/creditcard/money-back/" },
@@ -3883,6 +3908,7 @@ const static atr_t AtrTable[] = {
{ "3BFF1800FF813150456563............................", "GeldKarte v3 (Germany)" },
{ "3BFF1800FF8131FE4165630608710156000FB85073204712D8", "Commerzbank maestro (Bank)\nhttps://www.commerzbank.de/konten-zahlungsverkehr/produkte/girokonten/kostenloses-girokonto/" },
{ "3BFF1800FF8131FE4165630608710156000FB8602AA0471231", "Debit card (Germany): Postbank - GeldKarte (EUR), girocard, V-PAY (Bank)\nhttps://www.postbank.de/" },
{ "3BFF1800FF8131FE41656306087102500023B8907360471271", "Debit card (Germany): Deutsche Kreditbank (DKB), ec-cash, (Bank)\nhttps://www.dkb.de/privatkunden/karten/girocard" },
{ "3BFF1800FF8131FE4165631116710156000F0902904E5711AC", "German Bank Card IDEMIA 9 Maestro/Girocard (Sparkasse S-Payment TPY 1974693D) (Bank)" },
{ "3BFF1800FF8131FE450031C573C00180547615020105900074", "SIGILANCE NFC OpenPGP Smart Card (JavaCard)\nhttps://www.sigilance.com/" },
{ "3BFF1800FF8131FE455448434331305445434F4744484E3224", "National Health Insurance Card, Taiwan" },
@@ -3993,6 +4019,7 @@ const static atr_t AtrTable[] = {
{ "3BFF9600008131FE4380318065B0845651101201788290006A", "SafeNet eToken 5300 (PKI)" },
{ "3BFF9600008131FE4380318065B08456511012021082900001", "Nedap NexS N:Secure (eID)\nhttps://www.nsecure.nl/nl/" },
{ "3BFF9600008131FE4380318065B0846160FB120FFD8290000C", "IDPrime 930 FIPS Level 2 (T=1 CT=96) (BAI3.1) (PKI)" },
{ "3BFF9600008131FE4380318065B0846566FB12017882900085", "eToken 5110+ FIPS 140-2 Level 2 (JavaCard)" },
{ "3BFF9600008131FE4380318065B0846566FB120FFC8290000F", "SmartID 3930 FIDO Contact and Contactless card (PKI)\nhttps://www.smartcardfocus.com/shop/ilp/id~962/safenet-idprime-3930-fido-dual-interface-fips-l2/p/index.shtml" },
{ "3BFF9600008131FE4380318065B0846669FB12FFFE829000F1", "IDCore3230 build 6.8, test APDU applet (JavaCard)" },
{ "3BFF9600008131FE4380318065B085040011120FFF829000E0", "Pakistan National identity card (eID)" },
@@ -4024,6 +4051,7 @@ const static atr_t AtrTable[] = {
{ "3F2F008059AF0201013000000A0E83069F12", "Gemplus GemXplore" },
{ "3F2F008059AF02010230000C0A0E831E9F16", "GSM-SIM (900MHz) card of the carrier 'Mannesmann Mobilfunk' for\ntheir network 'D2-Privat' - now known as Vodafone Mobilfunk\nhttp://www.vodafone.de/" },
{ "3F2F008069AE0202013600000A0E833E9F16", "GSM-SIM e-plus (1800MHz)" },
{ "3F2F008069AF0204013600000A0E833E9F16", "Telia Mobitel GSM (Telecommunication)" },
{ "3F2F008069AF0204013600020A0E833E9F16", "GSM-SIM D2 CallYa (900MHz)" },
{ "3F2F008069AF0307015900000A0E833E9F16", "Nokia SIM Ph2 16K Ver2.0" },
{ "3F2F008069AF0307015900130A0E833E9F16", "Old Spanish Telefonica Movistar GSM SIM card manufactured by Gemplus" },
+2 -4
View File
@@ -104,9 +104,7 @@ static int CIPURSEExchangeEx(bool activate_field, bool leave_field_on, sAPDU_t a
memcpy(result, securedata, rlen);
}
if (result_len != NULL) {
*result_len = rlen;
}
*result_len = rlen;
if (sw != NULL) {
*sw = isw;
@@ -628,7 +626,7 @@ void CIPURSEPrintFileAttrEx(uint8_t *attr, size_t len, bool isDGI) {
}
void CIPURSEPrintFileAttr(uint8_t *attr, size_t len) {
return CIPURSEPrintFileAttrEx(attr, len, false);
CIPURSEPrintFileAttrEx(attr, len, false);
}
void CIPURSEPrintFileUpdateAttr(uint8_t *attr, size_t len) {
+71 -4
View File
@@ -3279,9 +3279,9 @@ static int CmdNumCon(const char *Cmd) {
} radix_t;
radix_t radix[] = {
{"dec..... ", 10},
{"hex..... 0x", 16},
{"bin..... 0b", 2}
{"dec... ", 10},
{"hex... ", 16},
{"bin... ", 2}
};
char s[600] = {0};
@@ -3290,7 +3290,7 @@ static int CmdNumCon(const char *Cmd) {
for (uint8_t i = 0; i < ARRAYLEN(radix); i++) {
MBEDTLS_MPI_CHK(mbedtls_mpi_write_string(&N, radix[i].radix, s, sizeof(s), &slen));
if (slen > 0) {
PrintAndLogEx(INFO, "%s%s", radix[i].desc, s);
PrintAndLogEx(SUCCESS, "%s%s", radix[i].desc, s);
}
}
@@ -3451,6 +3451,72 @@ static int CmdAtrLookup(const char *Cmd) {
return PM3_SUCCESS;
}
static int CmdBinaryMap(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "data bmap",
"Breaks down a hex value to binary according a template\n"
" data bmap -d 16 -m 4,4\n"
"This will give two rows each with four bits",
"data bmap -d 3B\n"
"data bmap -d 3B -m 2,5,1\n"
);
void *argtable[] = {
arg_param_begin,
arg_str0("d", NULL, "<hex>", "hex string"),
arg_str0("m", NULL, "<str>", "binary template"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
int hlen = 5;
uint8_t hex[5 + 1];
CLIGetStrWithReturn(ctx, 1, hex, &hlen);
int tlen = 40;
uint8_t template[40 + 1];
CLIGetStrWithReturn(ctx, 2, template, &tlen);
CLIParserFree(ctx);
char bits[(8 * 4) + 1] = {0};
hextobinstring_n(bits, (char *)hex, hlen);
if (tlen == 0) {
template[0] = '8';
template[1] = 0;
}
char *token = strtok((char *)template, ",");
// header
PrintAndLogEx(INFO, "---+---------------------------");
PrintAndLogEx(INFO, " | b0 b1 b2 b3 b4 b5 b6 b7");
PrintAndLogEx(INFO, "---+---------------------------");
uint8_t i = 0;
uint8_t cnt = 1;
int x = 0;
while (token != NULL) {
sscanf(token, "%d", &x);
PrintAndLogEx(INFO, " %d | %*.s" NOLF, cnt, i * 3, " ");
// incease with previous offset
x += i;
for (; i < (uint8_t)x; i++) {
PrintAndLogEx(NORMAL, "%c " NOLF, bits[7 - i]);
}
PrintAndLogEx(NORMAL, "");
token = strtok(NULL, ",");
cnt++;
}
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
@@ -3493,6 +3559,7 @@ static command_t CommandTable[] = {
{"atr", CmdAtrLookup, AlwaysAvailable, "ATR lookup"},
{"bin2hex", Cmdbin2hex, AlwaysAvailable, "Converts binary to hexadecimal"},
{"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"},
{"bmap", CmdBinaryMap, AlwaysAvailable, "Convert hex value according a binary template"},
{"clear", CmdBuffClear, AlwaysAvailable, "Clears bigbuf on deviceside and graph window"},
{"diff", CmdDiff, AlwaysAvailable, "Diff of input files"},
{"hexsamples", CmdHexsamples, IfPm3Present, "Dump big buffer as hex bytes"},
+1 -2
View File
@@ -379,8 +379,7 @@ static int CmdFlashMemDump(const char *Cmd) {
}
if (filename[0] != '\0') {
saveFile(filename, ".bin", dump, len);
saveFileEML(filename, dump, len, 16);
pm3_save_dump(filename, dump, len, jsfRaw);
}
free(dump);
+1 -12
View File
@@ -370,14 +370,13 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
"Dumps device SPIFFS file to a local file\n"
"Size is handled by first sending a STAT command against file to verify existence",
"mem spiffs dump -s tag.bin --> download binary file from device\n"
"mem spiffs dump -s tag.bin -d aaa -e --> download tag.bin, save as aaa.eml format"
"mem spiffs dump -s tag.bin -d a001 -e --> download tag.bin, save as `a001.bin`"
);
void *argtable[] = {
arg_param_begin,
arg_str1("s", "src", "<fn>", "SPIFFS file to save"),
arg_str0("d", "dest", "<fn>", "file name to save to <w/o .bin>"),
arg_lit0("e", "eml", "also save in EML format"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -390,7 +389,6 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
char dest[FILE_PATH_SIZE] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)dest, FILE_PATH_SIZE, &dlen);
bool eml = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
// get size from spiffs itself !
@@ -433,15 +431,6 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
else
saveFile(fn, ".bin", dump, len); // default
if (eml) {
uint8_t eml_len = 16;
if (strstr(fn, "class") != NULL)
eml_len = 8;
else if (strstr(fn, "mfu") != NULL)
eml_len = 4;
saveFileEML(fn, dump, len, eml_len);
}
free(dump);
return PM3_SUCCESS;
}
+29 -6
View File
@@ -994,7 +994,7 @@ int SelectCard14443A_4_WithParameters(bool disconnect, bool verbose, iso14a_card
// check result
if (resp.oldarg[0] == 0) {
if (verbose) {
PrintAndLogEx(FAILED, "No card in field");
PrintAndLogEx(WARNING, "No ISO1443-A Card in field");
}
return PM3_ECARDEXCHANGE;
}
@@ -1595,6 +1595,7 @@ typedef enum {
MTEMV = 128,
MTFUDAN = 256,
MTISO18092 = 512,
MT424 = 1024,
} nxp_mifare_type_t;
// Based on NXP AN10833 Rev 3.6 and NXP AN10834 Rev 4.1
@@ -1723,7 +1724,7 @@ static int detect_nxp_card(uint8_t sak, uint16_t atqa, uint64_t select_status) {
}
printTag("NTAG 4xx");
type |= MTDESFIRE;
type |= (MTDESFIRE | MT424);
}
} else if ((sak & 0x04) == 0x04) {
printTag("Any MIFARE CL1");
@@ -1920,6 +1921,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
bool isEMV = false;
bool isFUDAN = false;
bool isISO18092 = false;
bool isNTAG424 = false;
int nxptype = MTNONE;
if (card.uidlen <= 4) {
@@ -1929,6 +1931,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
isMifareDESFire = ((nxptype & MTDESFIRE) == MTDESFIRE);
isMifarePlus = ((nxptype & MTPLUS) == MTPLUS);
isMifareUltralight = ((nxptype & MTULTRALIGHT) == MTULTRALIGHT);
isNTAG424 = ((nxptype & MT424) == MT424);
if ((nxptype & MTOTHER) == MTOTHER)
isMifareClassic = true;
@@ -1958,6 +1961,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
isMifareDESFire = ((nxptype & MTDESFIRE) == MTDESFIRE);
isMifarePlus = ((nxptype & MTPLUS) == MTPLUS);
isMifareUltralight = ((nxptype & MTULTRALIGHT) == MTULTRALIGHT);
isNTAG424 = ((nxptype & MT424) == MT424);
if ((nxptype & MTOTHER) == MTOTHER)
isMifareClassic = true;
@@ -2010,8 +2014,8 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
// ******** is card of the MFU type (UL/ULC/NTAG/ etc etc)
DropField();
uint32_t tagT = GetHF14AMfU_Type();
if (tagT != UL_ERROR) {
uint64_t tagT = GetHF14AMfU_Type();
if (tagT != MFU_TT_UL_ERROR) {
ul_print_type(tagT, 0);
isMifareUltralight = true;
printTag("MIFARE Ultralight/C/NTAG Compatible");
@@ -2461,6 +2465,11 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
*/
}
if (isNTAG424) {
PrintAndLogEx(HINT, "Hint: try `" _YELLOW_("hf ntag424 info") "`");
}
PrintAndLogEx(NORMAL, "");
DropField();
return select_status;
@@ -2748,6 +2757,7 @@ int CmdHF14ANdefRead(const char *Cmd) {
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
bool verbose = arg_get_lit(ctx, 2);
bool verbose2 = arg_get_lit(ctx, 2) > 1;
CLIParserFree(ctx);
bool activate_field = true;
@@ -2934,11 +2944,24 @@ int CmdHF14ANdefRead(const char *Cmd) {
memcpy(ndef_file + (i - offset), response, segment_size);
}
if (fnlen != 0) {
saveFile(filename, ".bin", ndef_file, ndef_size);
if (verbose2) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("NDEF raw") " ----------------");
print_buffer(ndef_file, ndef_size, 1);
}
NDEFRecordsDecodeAndPrint(ndef_file, ndef_size, verbose);
pm3_save_dump(filename, ndef_file, ndef_size, jsfNDEF);
if (verbose == false) {
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf 14a ndefread -v`") " for more details");
} else {
if (verbose2 == false) {
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf 14a ndefread -vv`") " for more details");
}
}
free(ndef_file);
return PM3_SUCCESS;
}
+23 -15
View File
@@ -1537,17 +1537,21 @@ static int CmdHF14BDump(const char *Cmd) {
print_sr_blocks(data, cardsize, card.uid);
if (nosave == false) {
// save to file
if (fnlen < 1) {
PrintAndLogEx(INFO, "using UID as filename");
char *fptr = filename + snprintf(filename, sizeof(filename), "hf-14b-");
FillFileNameByUID(fptr, SwapEndian64(card.uid, card.uidlen, 8), "-dump", card.uidlen);
}
size_t datalen = (lastblock + 2) * ST25TB_SR_BLOCK_SIZE;
pm3_save_dump(filename, data, datalen, jsf14b, ST25TB_SR_BLOCK_SIZE);
if (nosave) {
PrintAndLogEx(INFO, "Called with no save option");
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
// save to file
if (fnlen < 1) {
PrintAndLogEx(INFO, "using UID as filename");
char *fptr = filename + snprintf(filename, sizeof(filename), "hf-14b-");
FillFileNameByUID(fptr, SwapEndian64(card.uid, card.uidlen, 8), "-dump", card.uidlen);
}
size_t datalen = (lastblock + 2) * ST25TB_SR_BLOCK_SIZE;
pm3_save_dump(filename, data, datalen, jsf14b_v2);
}
return switch_off_field_14b();
@@ -1697,7 +1701,7 @@ int select_card_14443b_4(bool disconnect, iso14b_card_select_t *card) {
// check result
int status = resp.oldarg[0];
if (status < 0) {
PrintAndLogEx(ERR, "No card in field.");
PrintAndLogEx(WARNING, "No ISO14443-B Card in field");
switch_off_field_14b();
return PM3_ESOFT;
}
@@ -2121,9 +2125,13 @@ int CmdHF14BNdefRead(const char *Cmd) {
goto out;
}
if (fnlen != 0) {
saveFile(filename, ".bin", response + 2, resplen - 4);
}
// get total NDEF length before save. If fails, we save it all
size_t n = 0;
if (NDEFGetTotalLength(response + 2, resplen - 4, &n) != PM3_SUCCESS)
n = resplen - 4;
pm3_save_dump(filename, response + 2, n, jsfNDEF);
res = NDEFRecordsDecodeAndPrint(response + 2, resplen - 4, verbose);
out:
@@ -2164,7 +2172,7 @@ static int CmdHF14BView(const char *Cmd) {
);
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
};
+58 -35
View File
@@ -62,7 +62,7 @@
typedef struct {
uint8_t lock;
uint8_t block[4];
uint8_t block[8];
} t15memory_t;
// structure and database for uid -> tagtype lookups
@@ -849,7 +849,7 @@ static int CmdHF15Info(const char *Cmd) {
"hf 15 info -u E011223344556677"
);
void *argtable[6 + 1] = {};
void *argtable[6 + 1] = {0};
uint8_t arglen = arg_add_default(argtable);
argtable[arglen++] = arg_param_end;
@@ -1143,14 +1143,14 @@ static int CmdHF15ELoad(const char *Cmd) {
static int CmdHF15ESave(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 15 esave",
"Save emulator memory into three files (BIN/EML/JSON) ",
"Save emulator memory into two files (bin/json) ",
"hf 15 esave -f hf-15-01020304"
"hf 15 esave -b 8 -c 42 -f hf-15-01020304"
);
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump"),
arg_int0("b", "blocksize", "<dec>", "block size, defaults to 4"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_int0(NULL, "bsize", "<dec>", "block size, defaults to 4"),
arg_int0("c", "count", "<dec>", "number of blocks to export, defaults to all"),
arg_param_end
};
@@ -1176,13 +1176,18 @@ static int CmdHF15ESave(const char *Cmd) {
}
PrintAndLogEx(INFO, "Downloading %u bytes from emulator memory", bytes);
if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) {
if (GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false) == false) {
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
free(dump);
return PM3_ETIMEOUT;
}
pm3_save_dump(filename, dump, bytes, jsf15, blocksize);
if (blocksize == 8) {
pm3_save_dump(filename, dump, bytes, jsf15_v3);
} else {
pm3_save_dump(filename, dump, bytes, jsf15_v2);
}
free(dump);
return PM3_SUCCESS;
}
@@ -1244,7 +1249,7 @@ static int CmdHF15EView(const char *Cmd) {
}
PrintAndLogEx(INFO, "Downloading %u bytes from emulator memory", bytes);
if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) {
if (GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false) == false) {
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
free(dump);
return PM3_ETIMEOUT;
@@ -1360,12 +1365,13 @@ static int CmdHF15WriteAfi(const char *Cmd) {
"hf 15 writeafi -u E011223344556677 --afi 12 -p 0F0F0F0F"
);
void *argtable[5] = {};
argtable[0] = arg_param_begin;
argtable[1] = arg_str0("u", "uid", "<hex>", "full UID, 8 bytes");
argtable[2] = arg_int1(NULL, "afi", "<dec>", "AFI number (0-255)");
argtable[3] = arg_str0("p", "pwd", "<hex>", "optional AFI/EAS password");
argtable[4] = arg_param_end;
void *argtable[] = {
arg_param_begin,
arg_str0("u", "uid", "<hex>", "full UID, 8 bytes"),
arg_int1(NULL, "afi", "<dec>", "AFI number (0-255)"),
arg_str0("p", "pwd", "<hex>", "optional AFI/EAS password"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -1443,7 +1449,7 @@ static int CmdHF15WriteDsfid(const char *Cmd) {
"hf 15 writedsfid -u E011223344556677 --dsfid 12"
);
void *argtable[6 + 2] = {};
void *argtable[6 + 2] = {0};
uint8_t arglen = arg_add_default(argtable);
argtable[arglen++] = arg_int1(NULL, "dsfid", "<dec>", "DSFID number (0-255)");
argtable[arglen++] = arg_param_end;
@@ -1537,15 +1543,15 @@ static int CmdHF15WriteDsfid(const char *Cmd) {
static int CmdHF15Dump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 15 dump",
"This command dumps the contents of a ISO-15693 tag and save it to file",
"This command dumps the contents of a ISO-15693 tag and save to file (bin/json)",
"hf 15 dump\n"
"hf 15 dump -*\n"
"hf 15 dump -u E011223344556677 -f hf-15-my-dump.bin"
);
void *argtable[6 + 2] = {};
void *argtable[6 + 2] = {0};
uint8_t arglen = arg_add_default(argtable);
argtable[arglen++] = arg_str0("f", "file", "<fn>", "filename of dump"),
argtable[arglen++] = arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
argtable[arglen++] = arg_param_end;
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -1604,9 +1610,12 @@ static int CmdHF15Dump(const char *Cmd) {
// memory.
t15memory_t mem[256];
uint8_t data[256 * 4] = {0};
uint8_t data[256 * 8] = {0};
memset(data, 0, sizeof(data));
// keep track of which block length tag returned?
uint8_t blklen = 4;
for (int retry = 0; (retry < 5 && blocknum < 0x100); retry++) {
req[10] = blocknum;
@@ -1646,9 +1655,15 @@ static int CmdHF15Dump(const char *Cmd) {
break;
}
// lock byte value
mem[blocknum].lock = resp.data.asBytes[0];
memcpy(mem[blocknum].block, resp.data.asBytes + 1, 4);
memcpy(data + (blocknum * 4), resp.data.asBytes + 1, 4);
// is tag responding with 4 or 8 bytes?
if (resp.length == 11) {
blklen = 8;
}
memcpy(mem[blocknum].block, resp.data.asBytes + 1, blklen);
memcpy(data + (blocknum * 4), resp.data.asBytes + 1, blklen);
retry = 0;
blocknum++;
@@ -1659,6 +1674,10 @@ static int CmdHF15Dump(const char *Cmd) {
DropField();
if (blklen == 8) {
PrintAndLogEx(INFO, "8 byte block length detected");
}
PrintAndLogEx(NORMAL, "\n");
PrintAndLogEx(INFO, "block# | data |lck| ascii");
PrintAndLogEx(INFO, "---------+--------------+---+----------");
@@ -1672,9 +1691,9 @@ static int CmdHF15Dump(const char *Cmd) {
PrintAndLogEx(INFO, "%3d/0x%02X | %s | %s | %s"
, i
, i
, sprint_hex(mem[i].block, 4)
, sprint_hex(mem[i].block, blklen)
, lck
, sprint_ascii(mem[i].block, 4)
, sprint_ascii(mem[i].block, blklen)
);
}
PrintAndLogEx(NORMAL, "");
@@ -1687,8 +1706,11 @@ static int CmdHF15Dump(const char *Cmd) {
FillFileNameByUID(fptr, SwapEndian64(uid, sizeof(uid), 8), "-dump", sizeof(uid));
}
size_t datalen = blocknum * 4;
pm3_save_dump(filename, data, datalen, jsf15, 4);
if (blklen == 8) {
pm3_save_dump(filename, data, (size_t)(blocknum * blklen), jsf15_v3);
} else {
pm3_save_dump(filename, data, (size_t)(blocknum * blklen), jsf15_v2);
}
return PM3_SUCCESS;
}
@@ -1771,7 +1793,7 @@ static int CmdHF15Readmulti(const char *Cmd) {
"hf 15 rdmulti -u E011223344556677 -b 12 --cnt 3 -> read three blocks"
);
void *argtable[6 + 3] = {};
void *argtable[6 + 3] = {0};
uint8_t arglen = arg_add_default(argtable);
argtable[arglen++] = arg_int1("b", NULL, "<dec>", "first page number (0-255)");
argtable[arglen++] = arg_int1(NULL, "cnt", "<dec>", "number of pages (1-6)");
@@ -1907,7 +1929,7 @@ static int CmdHF15Readblock(const char *Cmd) {
"hf 15 rdbl -u E011223344556677 -b 12"
);
void *argtable[6 + 2] = {};
void *argtable[6 + 2] = {0};
uint8_t arglen = arg_add_default(argtable);
argtable[arglen++] = arg_int1("b", "blk", "<dec>", "page number (0-255)");
argtable[arglen++] = arg_param_end;
@@ -2000,15 +2022,16 @@ static int CmdHF15Readblock(const char *Cmd) {
return PM3_EWRONGANSWER;
}
// print response
char lck[16] = {0};
if (data[1]) {
snprintf(lck, sizeof(lck), _RED_("%d"), data[1]);
snprintf(lck, sizeof(lck), _RED_("%02X"), data[1]);
} else {
snprintf(lck, sizeof(lck), "%d", data[1]);
snprintf(lck, sizeof(lck), "%02X", data[1]);
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, " #%3d |lck| ascii", block);
PrintAndLogEx(INFO, "#%3d |lck| ascii", block);
PrintAndLogEx(INFO, "------------+---+------");
PrintAndLogEx(INFO, "%s| %s | %s", sprint_hex(data + 2, resp.length - 4), lck, sprint_ascii(data + 2, resp.length - 4));
PrintAndLogEx(NORMAL, "");
@@ -2068,7 +2091,7 @@ static int CmdHF15Write(const char *Cmd) {
"hf 15 wrbl -u E011223344556677 -b 12 -d AABBCCDD"
);
void *argtable[6 + 4] = {};
void *argtable[6 + 4] = {0};
uint8_t arglen = arg_add_default(argtable);
argtable[arglen++] = arg_int1("b", "blk", "<dec>", "page number (0-255)");
argtable[arglen++] = arg_str1("d", "data", "<hex>", "data, 4 bytes");
@@ -2153,15 +2176,15 @@ static int CmdHF15Write(const char *Cmd) {
static int CmdHF15Restore(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 15 restore",
"This command restore the contents of a dump file onto a ISO-15693 tag",
"This command restore the contents of a dump file (bin/eml/json) onto a ISO-15693 tag",
"hf 15 restore\n"
"hf 15 restore -*\n"
"hf 15 restore -u E011223344556677 -f hf-15-my-dump.bin"
);
void *argtable[6 + 5] = {};
void *argtable[6 + 5] = {0};
uint8_t arglen = arg_add_default(argtable);
argtable[arglen++] = arg_str0("f", "file", "<fn>", "filename of dump"),
argtable[arglen++] = arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
argtable[arglen++] = arg_int0("r", "retry", "<dec>", "number of retries (def 3)"),
argtable[arglen++] = arg_int0(NULL, "bs", "<dec>", "block size (def 4)"),
argtable[arglen++] = arg_lit0("v", "verbose", "verbose output");
@@ -2834,7 +2857,7 @@ static int CmdHF15View(const char *Cmd) {
);
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump (bin/eml/json)"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
// arg_lit0("z", "dense", "dense dump output style"),
arg_param_end
};
+7 -12
View File
@@ -414,9 +414,8 @@ static int CmdHFCryptoRFDump(const char *Cmd) {
FillFileNameByUID(fptr, card.uid, "-dump", card.uidlen);
}
saveFileEML(filename, data, datalen, 4);
saveFile(filename, ".bin", data, datalen);
// json?
pm3_save_dump(filename, data, datalen, jsfCryptorf);
return switch_off_field_cryptorf();
}
@@ -424,13 +423,13 @@ static int CmdHFCryptoRFELoad(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf cryptorf eload",
"Loads CryptoRF tag dump into emulator memory on device",
"Loads CryptoRF tag dump (bin/eml/json) into emulator memory on device",
"hf cryptorf eload -f hf-cryptorf-0102030405-dump.bin\n"
);
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -486,14 +485,14 @@ static int CmdHFCryptoRFESave(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf cryptorf esave",
"Save emulator memory to bin/eml/json file\n"
"Save emulator memory to file (bin/json)\n"
"if filename is not supplied, UID will be used.",
"hf cryptorf esave\n"
"hf cryptorf esave -f filename"
);
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "filename of dumpfile"),
arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -527,11 +526,7 @@ static int CmdHFCryptoRFESave(const char *Cmd) {
FillFileNameByUID(fptr, data, "-dump", 4);
}
saveFile(filename, ".bin", data, numofbytes);
//needs to change
saveFileEML(filename, data, numofbytes, 8);
//needs to change
saveFileJSON(filename, jsfRaw, data, numofbytes, NULL);
pm3_save_dump(filename, data, numofbytes, jsfCryptorf);
free(data);
return PM3_SUCCESS;
}
+12 -16
View File
@@ -42,13 +42,9 @@
#define EMRTD_MAX_FILE_SIZE 35000
// ISO7816 commands
#define EMRTD_SELECT 0xA4
#define EMRTD_EXTERNAL_AUTHENTICATE 0x82
#define EMRTD_GET_CHALLENGE 0x84
#define EMRTD_READ_BINARY 0xB0
#define EMRTD_P1_SELECT_BY_EF 0x02
#define EMRTD_P1_SELECT_BY_NAME 0x04
#define EMRTD_P2_PROPRIETARY 0x0C
#define EMRTD_P1_SELECT_BY_EF 0x02
#define EMRTD_P1_SELECT_BY_NAME 0x04
#define EMRTD_P2_PROPRIETARY 0x0C
// App IDs
#define EMRTD_AID_MRTD {0xA0, 0x00, 0x00, 0x02, 0x47, 0x10, 0x01}
@@ -124,7 +120,7 @@ static emrtd_hashalg_t hashalg_table[] = {
{"SHA-1", sha1hash, 20, 7, {0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A}},
{"SHA-256", sha256hash, 32, 11, {0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01}},
{"SHA-512", sha512hash, 64, 11, {0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03}},
{NULL, NULL, 0, 0, {}}
{NULL, NULL, 0, 0, {0}}
};
static emrtd_pacealg_t pacealg_table[] = {
@@ -145,7 +141,7 @@ static emrtd_pacealg_t pacealg_table[] = {
{"ECDH, Integrated Mapping, AES-CMAC-128", NULL, {0x04, 0x00, 0x7F, 0x00, 0x07, 0x02, 0x02, 0x04, 0x04, 0x02}},
{"ECDH, Integrated Mapping, AES-CMAC-192", NULL, {0x04, 0x00, 0x7F, 0x00, 0x07, 0x02, 0x02, 0x04, 0x04, 0x03}},
{"ECDH, Integrated Mapping, AES-CMAC-256", NULL, {0x04, 0x00, 0x7F, 0x00, 0x07, 0x02, 0x02, 0x04, 0x04, 0x04}},
{NULL, NULL, {}}
{NULL, NULL, {0}}
};
static emrtd_pacesdp_t pacesdp_table[] = {
@@ -383,25 +379,25 @@ static void _emrtd_convert_fileid(uint16_t file, uint8_t *dataout) {
}
static int emrtd_select_file_by_name(uint8_t namelen, uint8_t *name) {
return emrtd_exchange_commands_noout((sAPDU_t) {0, EMRTD_SELECT, EMRTD_P1_SELECT_BY_NAME, 0x0C, namelen, name}, false, true);
return emrtd_exchange_commands_noout((sAPDU_t) {0, ISO7816_SELECT_FILE, EMRTD_P1_SELECT_BY_NAME, 0x0C, namelen, name}, false, true);
}
static int emrtd_select_file_by_ef(uint16_t file_id) {
uint8_t data[2];
_emrtd_convert_fileid(file_id, data);
return emrtd_exchange_commands_noout((sAPDU_t) {0, EMRTD_SELECT, EMRTD_P1_SELECT_BY_EF, 0x0C, sizeof(data), data}, false, true);
return emrtd_exchange_commands_noout((sAPDU_t) {0, ISO7816_SELECT_FILE, EMRTD_P1_SELECT_BY_EF, 0x0C, sizeof(data), data}, false, true);
}
static int emrtd_get_challenge(int length, uint8_t *dataout, size_t maxdataoutlen, size_t *dataoutlen) {
return emrtd_exchange_commands((sAPDU_t) {0, EMRTD_GET_CHALLENGE, 0, 0, 0, NULL}, true, length, dataout, maxdataoutlen, dataoutlen, false, true);
return emrtd_exchange_commands((sAPDU_t) {0, ISO7816_GET_CHALLENGE, 0, 0, 0, NULL}, true, length, dataout, maxdataoutlen, dataoutlen, false, true);
}
static int emrtd_external_authenticate(uint8_t *data, int length, uint8_t *dataout, size_t maxdataoutlen, size_t *dataoutlen) {
return emrtd_exchange_commands((sAPDU_t) {0, EMRTD_EXTERNAL_AUTHENTICATE, 0, 0, length, data}, true, length, dataout, maxdataoutlen, dataoutlen, false, true);
return emrtd_exchange_commands((sAPDU_t) {0, ISO7816_EXTERNAL_AUTHENTICATION, 0, 0, length, data}, true, length, dataout, maxdataoutlen, dataoutlen, false, true);
}
static int _emrtd_read_binary(int offset, int bytes_to_read, uint8_t *dataout, size_t maxdataoutlen, size_t *dataoutlen) {
return emrtd_exchange_commands((sAPDU_t) {0, EMRTD_READ_BINARY, offset >> 8, offset & 0xFF, 0, NULL}, true, bytes_to_read, dataout, maxdataoutlen, dataoutlen, false, true);
return emrtd_exchange_commands((sAPDU_t) {0, ISO7816_READ_BINARY, offset >> 8, offset & 0xFF, 0, NULL}, true, bytes_to_read, dataout, maxdataoutlen, dataoutlen, false, true);
}
static void emrtd_bump_ssc(uint8_t *ssc) {
@@ -503,7 +499,7 @@ static bool emrtd_secure_select_file_by_ef(uint8_t *kenc, uint8_t *kmac, uint8_t
memcpy(data + (datalen + 3), do8e, 10);
PrintAndLogEx(DEBUG, "data: %s", sprint_hex_inrow(data, lc));
if (emrtd_exchange_commands((sAPDU_t) {0x0C, EMRTD_SELECT, EMRTD_P1_SELECT_BY_EF, 0x0C, lc, data}, true, 0, response, sizeof(response), &resplen, false, true) == false) {
if (emrtd_exchange_commands((sAPDU_t) {0x0C, ISO7816_SELECT_FILE, EMRTD_P1_SELECT_BY_EF, 0x0C, lc, data}, true, 0, response, sizeof(response), &resplen, false, true) == false) {
return false;
}
@@ -552,7 +548,7 @@ static bool _emrtd_secure_read_binary(uint8_t *kmac, uint8_t *ssc, int offset, i
memcpy(data + 3, do8e, 10);
PrintAndLogEx(DEBUG, "data: %s", sprint_hex_inrow(data, lc));
if (emrtd_exchange_commands((sAPDU_t) {0x0C, EMRTD_READ_BINARY, offset >> 8, offset & 0xFF, lc, data}, true, 0, dataout, maxdataoutlen, dataoutlen, false, true) == false) {
if (emrtd_exchange_commands((sAPDU_t) {0x0C, ISO7816_READ_BINARY, offset >> 8, offset & 0xFF, lc, data}, true, 0, dataout, maxdataoutlen, dataoutlen, false, true) == false) {
return false;
}
+1 -1
View File
@@ -566,7 +566,7 @@ static void reverse_3des_key(const uint8_t *master_key, int length, uint8_t *rev
for (int i = 0; i < length; i++) {
reverse_master_key[i] = master_key[(length - 1) - i];
}
};
}
/**
* Command parser for auth1
+4 -11
View File
@@ -235,14 +235,14 @@ static int CmdHFFudanReader(const char *Cmd) {
static int CmdHFFudanDump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf fudan dump",
"Dump FUDAN tag to binary file\n"
"Dump FUDAN tag to file (bin/json)\n"
"If no <name> given, UID will be used as filename",
"hf fudan dump -f mydump --> dump using filename\n"
);
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "filename of dump"),
arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -339,14 +339,7 @@ static int CmdHFFudanDump(const char *Cmd) {
free(fptr);
}
saveFile(dataFilename, ".bin", (uint8_t *)carddata, sizeof(carddata));
saveFileEML(dataFilename, (uint8_t *)carddata, sizeof(carddata), MAX_FUDAN_BLOCK_SIZE);
iso14a_mf_extdump_t xdump;
xdump.card_info = card;
xdump.dump = (uint8_t *)carddata;
xdump.dumplen = sizeof(carddata);
saveFileJSON(dataFilename, jsfFudan, (uint8_t *)&xdump, sizeof(xdump), NULL);
pm3_save_dump(dataFilename, (uint8_t *)carddata, sizeof(carddata), jsfFudan);
return PM3_SUCCESS;
}
@@ -460,7 +453,7 @@ static int CmdHFFudanView(const char *Cmd) {
);
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
+467 -230
View File
File diff suppressed because it is too large. Load diff
+19 -21
View File
@@ -112,27 +112,25 @@ static int decode_and_print_memory(uint16_t card_size, const uint8_t *input_buff
int fl = 0;
if (data[6] == 0xec) {
if (data[6] == 0xEC) {
strncpy(token_type, "XAM", sizeof(token_type) - 1);
fl = 1;
stamp_len = 0x0c - (data[5] >> 4);
} else {
switch (data[5] & 0x7f) {
case 0x00 ... 0x2f:
strncpy(token_type, "IAM", sizeof(token_type) - 1);
fl = (0x2f - (data[5] & 0x7f)) + 1;
break;
case 0x30 ... 0x6f:
strncpy(token_type, "SAM", sizeof(token_type) - 1);
fl = (0x6f - (data[5] & 0x7f)) + 1;
break;
case 0x70 ... 0x7f:
strncpy(token_type, "GAM", sizeof(token_type) - 1);
fl = (0x7f - (data[5] & 0x7f)) + 1;
break;
uint8_t tmp = data[5] & 0x7F;
if (tmp <= 0x2F) {
strncpy(token_type, "IAM", sizeof(token_type) - 1);
fl = (0x2F - tmp) + 1;
} else if (tmp >= 0x30 && tmp <= 0x6F) {
strncpy(token_type, "SAM", sizeof(token_type) - 1);
fl = (0x6F - tmp) + 1;
} else if (tmp >= 0x70 && tmp <= 0x7F) {
strncpy(token_type, "GAM", sizeof(token_type) - 1);
fl = (0x7F - tmp) + 1;
}
stamp_len = 0xfc - data[6];
stamp_len = 0xFC - data[6];
}
PrintAndLogEx(SUCCESS, "DCF: %d (%02x %02x) Token Type=" _YELLOW_("%s") " (OLE=%01u) OL=%02u FL=%02u",
@@ -858,7 +856,7 @@ static int CmdLegicReader(const char *Cmd) {
static int CmdLegicDump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf legic dump",
"Read all memory from LEGIC Prime tags and saves to (bin/eml/json) dump file\n"
"Read all memory from LEGIC Prime tags and saves to (bin/json) dump file\n"
"It autodetects card type (MIM22, MIM256, MIM1024)",
"hf legic dump --> use UID as filename\n"
"hf legic dump -f myfile \n"
@@ -951,7 +949,7 @@ static int CmdLegicDump(const char *Cmd) {
FillFileNameByUID(filename, data, "-dump", 4);
}
pm3_save_dump(filename, data, readlen, jsfLegic, LEGIC_BLOCK_SIZE);
pm3_save_dump(filename, data, readlen, jsfLegic_v2);
free(data);
return PM3_SUCCESS;
}
@@ -966,7 +964,7 @@ static int CmdLegicRestore(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "Filename to restore"),
arg_str1("f", "file", "<fn>", "Specify a filename to restore"),
arg_lit0(NULL, "ob", "obfuscate dump data (xor with MCC)"),
arg_param_end
};
@@ -1119,7 +1117,7 @@ static int CmdLegicELoad(const char *Cmd) {
static int CmdLegicESave(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf legic esave",
"Saves a (bin/eml/json) dump file of emulator memory",
"Saves a (bin/json) dump file of emulator memory",
"hf legic esave --> uses UID as filename\n"
"hf legic esave -f myfile --22\n"
"hf legic esave -f myfile --22 --de\n"
@@ -1188,7 +1186,7 @@ static int CmdLegicESave(const char *Cmd) {
legic_xor(data, numofbytes);
}
pm3_save_dump(filename, data, numofbytes, jsfLegic, LEGIC_BLOCK_SIZE);
pm3_save_dump(filename, data, numofbytes, jsfLegic_v2);
return PM3_SUCCESS;
}
@@ -1406,7 +1404,7 @@ static int CmdLegicView(const char *Cmd) {
);
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "Filename of dump"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
};
+3 -4
View File
@@ -655,12 +655,12 @@ static int CmdHfLTOWriteBlock(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf lto wrbl",
"Write data to block on LTO tag",
"hf lto wrbl --block 128 -d 0001020304050607080910111213141516171819202122232425262728293031");
"hf lto wrbl --blk 128 -d 0001020304050607080910111213141516171819202122232425262728293031");
void *argtable[] = {
arg_param_begin,
arg_str1("d", "data", "<hex>", "32 bytes of data to write (64 hex symbols, no spaces)"),
arg_int1(NULL, "block", "<dec>", "The block number to write to as an integer"),
arg_int1(NULL, "blk", "<dec>", "The block number to write to as an integer"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -771,8 +771,7 @@ static int CmdHfLTODump(const char *Cmd) {
char *fptr = filename + snprintf(filename, sizeof(filename), "hf-lto-");
FillFileNameByUID(fptr, dump, "-dump", 5);
}
saveFile(filename, ".bin", dump, dump_len);
saveFileEML(filename, dump, dump_len, 32);
pm3_save_dump(filename, dump, dump_len, jsfLto);
free(dump);
return PM3_SUCCESS;
}
+539 -299
View File
File diff suppressed because it is too large. Load diff
+9 -10
View File
@@ -372,8 +372,7 @@ static int mfdes_get_info(mfdes_info_res_t *info) {
}
// --- GET SIGNATURE
static int desfire_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, size_t signature_len, nxp_cardtype_t card_type) {
(void)card_type;
int desfire_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, size_t signature_len) {
if (uid == NULL) {
PrintAndLogEx(DEBUG, "UID=NULL");
@@ -445,7 +444,7 @@ static void swap24(uint8_t *data) {
uint8_t tmp = data[0];
data[0] = data[2];
data[2] = tmp;
};
}
// default parameters
static uint8_t defaultKeyNum = 0;
@@ -742,7 +741,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
res = DesfireReadSignature(&dctx, 0x00, signature, &signature_len);
if (res == PM3_SUCCESS) {
if (signature_len == 56)
desfire_print_signature(info.uid, info.uidlen, signature, signature_len, cardtype);
desfire_print_signature(info.uid, info.uidlen, signature, signature_len);
else
PrintAndLogEx(WARNING, "--- GetSignature returned wrong signature length: %zu", signature_len);
} else {
@@ -808,9 +807,9 @@ static int CmdHF14ADesInfo(const char *Cmd) {
iso14a_card_select_t card;
res = SelectCard14443A_4(true, false, &card);
if (res == PM3_SUCCESS) {
static const char STANDALONE_DESFIRE[] = { 0x75, 0x77, 0x81, 0x02 };
static const char JCOP_DESFIRE[] = { 0x75, 0xf7, 0xb1, 0x02 };
static const char JCOP3_DESFIRE[] = { 0x78, 0x77, 0x71, 0x02 };
static const uint8_t STANDALONE_DESFIRE[] = { 0x75, 0x77, 0x81, 0x02 };
static const uint8_t JCOP_DESFIRE[] = { 0x75, 0xf7, 0xb1, 0x02 };
static const uint8_t JCOP3_DESFIRE[] = { 0x78, 0x77, 0x71, 0x02 };
if (card.sak == 0x20) {
@@ -1126,9 +1125,9 @@ static int CmdHF14aDesChk(const char *Cmd) {
CLIParserInit(&ctx, "hf mfdes chk",
"Checks keys with MIFARE DESFire card.",
"hf mfdes chk --aid 123456 -k 000102030405060708090a0b0c0d0e0f -> check key on aid 0x123456\n"
"hf mfdes chk -d mfdes_default_keys -> check keys from dictionary against all existing aid on card\n"
"hf mfdes chk -d mfdes_default_keys --aid 123456 -> check keys from dictionary against aid 0x123456\n"
"hf mfdes chk --aid 123456 --pattern1b -j keys -> check all 1-byte keys pattern on aid 0x123456 and save found keys to json\n"
"hf mfdes chk -d mfdes_default_keys -> check keys against all existing aid on card\n"
"hf mfdes chk -d mfdes_default_keys --aid 123456 -> check keys against aid 0x123456\n"
"hf mfdes chk --aid 123456 --pattern1b -j keys -> check all 1-byte keys pattern on aid 0x123456 and save found keys to `keys.json`\n"
"hf mfdes chk --aid 123456 --pattern2b --startp2b FA00 -> check all 2-byte keys pattern on aid 0x123456. Start from key FA00FA00...FA00");
void *argtable[] = {
+2
View File
@@ -28,6 +28,8 @@ char *getVersionStr(uint8_t major, uint8_t minor);
int getKeySettings(uint8_t *aid);
*/
int desfire_print_signature(uint8_t *uid, uint8_t uidlen, uint8_t *signature, size_t signature_len);
// Ev1 card limits
#define MAX_NUM_KEYS 0x0F
#define MAX_APPLICATION_COUNT 28
+11 -15
View File
@@ -1384,15 +1384,15 @@ static int CmdHFMFPChk(const char *Cmd) {
static int CmdHFMFPDump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfp dump",
"Dump MIFARE Plus tag to binary file\n"
"Dump MIFARE Plus tag to file (bin/json)\n"
"If no <name> given, UID will be used as filename",
"hf mfp dump\n"
"hf mfp dump --keys hf-mf-066C8B78-key.bin --> MIFARE Plus with keys from specified file\n");
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "filename of dump"),
arg_str0("k", "keys", "<fn>", "filename of keys"),
arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
arg_str0("k", "keys", "<fn>", "Specify a filename for keys file"),
arg_lit0(NULL, "ns", "no save to file"),
arg_lit0("v", "verbose", "Verbose mode"),
arg_param_end
@@ -1448,14 +1448,7 @@ static int CmdHFMFPDump(const char *Cmd) {
free(fptr);
}
saveFile(data_fn, ".bin", mem, MIFARE_4K_MAX_BYTES);
saveFileEML(data_fn, mem, MIFARE_4K_MAX_BYTES, MFBLOCK_SIZE);
iso14a_mf_extdump_t xdump;
xdump.card_info = card;
xdump.dump = mem;
xdump.dumplen = MIFARE_4K_MAX_BYTES;
saveFileJSON(data_fn, jsfCardMemory, (uint8_t *)&xdump, sizeof(xdump), NULL);
pm3_save_mf_dump(filename, dump, MIFARE_4K_MAX_BYTES, jsfCardMemory);
*/
free(mem);
return PM3_SUCCESS;
@@ -1746,16 +1739,19 @@ int CmdHFMFPNDEFRead(const char *Cmd) {
print_buffer(data, datalen, 1);
}
if (fnlen != 0) {
saveFile(filename, ".bin", data, datalen);
}
res = NDEFDecodeAndPrint(data, datalen, verbose);
if (res != PM3_SUCCESS) {
PrintAndLogEx(INFO, "Trying to parse NDEF records w/o NDEF header");
res = NDEFRecordsDecodeAndPrint(data, datalen, verbose);
}
// get total NDEF length before save. If fails, we save it all
size_t n = 0;
if (NDEFGetTotalLength(data, datalen, &n) != PM3_SUCCESS)
n = datalen;
pm3_save_dump(filename, data, n, jsfNDEF);
if (verbose == false) {
PrintAndLogEx(HINT, "Try " _YELLOW_("`hf mfp ndefread -v`") " for more details");
} else {
+251 -188
View File
@@ -51,6 +51,7 @@
#define MAX_MY_D_MOVE 0x25
#define MAX_MY_D_MOVE_LEAN 0x0F
#define MAX_UL_NANO_40 0x0A
#define MAX_UL_AES 0x37
static int CmdHelp(const char *Cmd);
@@ -69,16 +70,25 @@ static uint8_t default_pwd_pack[][4] = {
{0x4E, 0x45, 0x78, 0x54}, // NExT
};
static uint32_t UL_TYPES_ARRAY[] = {
UNKNOWN, UL, UL_C, UL_EV1_48, UL_EV1_128,
NTAG, NTAG_203, NTAG_210, NTAG_212,
NTAG_213, NTAG_215, NTAG_216,
MY_D, MY_D_NFC, MY_D_MOVE, MY_D_MOVE_NFC, MY_D_MOVE_LEAN,
NTAG_I2C_1K, NTAG_I2C_2K, NTAG_I2C_1K_PLUS, NTAG_I2C_2K_PLUS,
FUDAN_UL, NTAG_213_F, NTAG_216_F, UL_EV1, UL_NANO_40,
NTAG_213_TT, NTAG_213_C,
MAGIC_1A, MAGIC_1B, MAGIC_NTAG,
NTAG_210u, UL_MAGIC, UL_C_MAGIC
static uint64_t UL_TYPES_ARRAY[] = {
MFU_TT_UNKNOWN, MFU_TT_UL,
MFU_TT_UL_C, MFU_TT_UL_EV1_48,
MFU_TT_UL_EV1_128, MFU_TT_NTAG,
MFU_TT_NTAG_203, MFU_TT_NTAG_210,
MFU_TT_NTAG_212, MFU_TT_NTAG_213,
MFU_TT_NTAG_215, MFU_TT_NTAG_216,
MFU_TT_MY_D, MFU_TT_MY_D_NFC,
MFU_TT_MY_D_MOVE, MFU_TT_MY_D_MOVE_NFC,
MFU_TT_MY_D_MOVE_LEAN, MFU_TT_NTAG_I2C_1K,
MFU_TT_NTAG_I2C_2K, MFU_TT_NTAG_I2C_1K_PLUS,
MFU_TT_NTAG_I2C_2K_PLUS, MFU_TT_FUDAN_UL,
MFU_TT_NTAG_213_F, MFU_TT_NTAG_216_F,
MFU_TT_UL_EV1, MFU_TT_UL_NANO_40,
MFU_TT_NTAG_213_TT, MFU_TT_NTAG_213_C,
MFU_TT_MAGIC_1A, MFU_TT_MAGIC_1B,
MFU_TT_MAGIC_NTAG, MFU_TT_NTAG_210u,
MFU_TT_UL_MAGIC, MFU_TT_UL_C_MAGIC,
MFU_TT_UL_AES
};
static uint8_t UL_MEMORY_ARRAY[ARRAYLEN(UL_TYPES_ARRAY)] = {
@@ -99,7 +109,7 @@ static uint8_t UL_MEMORY_ARRAY[ARRAYLEN(UL_TYPES_ARRAY)] = {
// MAGIC_1A, MAGIC_1B, MAGIC_NTAG,
MAX_UL_BLOCKS, MAX_UL_BLOCKS, MAX_NTAG_216,
// NTAG_210u, UL_MAGIC, UL_C_MAGIC
MAX_NTAG_210, MAX_UL_BLOCKS, MAX_ULC_BLOCKS
MAX_NTAG_210, MAX_UL_BLOCKS, MAX_ULC_BLOCKS, MAX_UL_AES
};
//------------------------------------
@@ -372,8 +382,8 @@ static int ulev1_requestAuthentication(uint8_t *pwd, uint8_t *pack, uint16_t pac
return len;
}
static int ul_auth_select(iso14a_card_select_t *card, TagTypeUL_t tagtype, bool hasAuthKey, uint8_t *authkey, uint8_t *pack, uint8_t packSize) {
if (hasAuthKey && (tagtype & UL_C)) {
static int ul_auth_select(iso14a_card_select_t *card, uint64_t tagtype, bool hasAuthKey, uint8_t *authkey, uint8_t *pack, uint8_t packSize) {
if (hasAuthKey && (tagtype & MFU_TT_UL_C)) {
//will select card automatically and close connection on error
if (!ulc_authentication(authkey, false)) {
PrintAndLogEx(WARNING, "Authentication Failed UL-C");
@@ -420,7 +430,6 @@ static int ulev1_readTearing(uint8_t counter, uint8_t *response, uint16_t respon
}
static int ulev1_readSignature(uint8_t *response, uint16_t responseLength) {
uint8_t cmd[] = {MIFARE_ULEV1_READSIG, 0x00};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
return len;
@@ -442,16 +451,16 @@ static int ulev1_readSignature(uint8_t *response, uint16_t responseLength) {
static int ul_fudan_check(void) {
iso14a_card_select_t card;
if (!ul_select(&card))
return UL_ERROR;
return MFU_TT_UL_ERROR;
uint8_t cmd[4] = {ISO14443A_CMD_READBLOCK, 0x00, 0x02, 0xa7}; //wrong crc on purpose should be 0xa8
clearCommandBuffer();
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 4, 0, cmd, sizeof(cmd));
PacketResponseNG resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return UL_ERROR;
if (resp.oldarg[0] != 1) return UL_ERROR;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return MFU_TT_UL_ERROR;
if (resp.oldarg[0] != 1) return MFU_TT_UL_ERROR;
return (!resp.data.asBytes[0]) ? FUDAN_UL : UL; //if response == 0x00 then Fudan, else Genuine NXP
return (!resp.data.asBytes[0]) ? MFU_TT_FUDAN_UL : MFU_TT_UL; //if response == 0x00 then Fudan, else Genuine NXP
}
static int ul_print_default(uint8_t *data, uint8_t *real_uid) {
@@ -623,7 +632,7 @@ static int ndef_print_CC(uint8_t *data) {
return PM3_SUCCESS;
}
int ul_print_type(uint32_t tagtype, uint8_t spaces) {
int ul_print_type(uint64_t tagtype, uint8_t spaces) {
if (spaces > 10)
spaces = 10;
@@ -631,73 +640,73 @@ int ul_print_type(uint32_t tagtype, uint8_t spaces) {
char typestr[100];
memset(typestr, 0x00, sizeof(typestr));
if (tagtype & UL)
if (tagtype & MFU_TT_UL)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("MIFARE Ultralight (MF0ICU1)"), spaces, "");
else if (tagtype & UL_C)
else if (tagtype & MFU_TT_UL_C)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("MIFARE Ultralight C (MF0ULC)"), spaces, "");
else if (tagtype & UL_NANO_40)
else if (tagtype & MFU_TT_UL_NANO_40)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("MIFARE Ultralight Nano 40bytes (MF0UNH00)"), spaces, "");
else if (tagtype & UL_EV1_48)
else if (tagtype & MFU_TT_UL_EV1_48)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("MIFARE Ultralight EV1 48bytes (MF0UL1101)"), spaces, "");
else if (tagtype & UL_EV1_128)
else if (tagtype & MFU_TT_UL_EV1_128)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("MIFARE Ultralight EV1 128bytes (MF0UL2101)"), spaces, "");
else if (tagtype & UL_EV1)
else if (tagtype & MFU_TT_UL_EV1)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("MIFARE Ultralight EV1 UNKNOWN"), spaces, "");
else if (tagtype & NTAG)
else if (tagtype & MFU_TT_NTAG)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG UNKNOWN"), spaces, "");
else if (tagtype & NTAG_203)
else if (tagtype & MFU_TT_NTAG_203)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 203 144bytes (NT2H0301F0DT)"), spaces, "");
else if (tagtype & NTAG_210u)
else if (tagtype & MFU_TT_NTAG_210u)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 210u (micro) 48bytes (NT2L1001G0DU)"), spaces, "");
else if (tagtype & NTAG_210)
else if (tagtype & MFU_TT_NTAG_210)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 210 48bytes (NT2L1011G0DU)"), spaces, "");
else if (tagtype & NTAG_212)
else if (tagtype & MFU_TT_NTAG_212)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 212 128bytes (NT2L1211G0DU)"), spaces, "");
else if (tagtype & NTAG_213)
else if (tagtype & MFU_TT_NTAG_213)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 213 144bytes (NT2H1311G0DU)"), spaces, "");
else if (tagtype & NTAG_213_F)
else if (tagtype & MFU_TT_NTAG_213_F)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 213F 144bytes (NT2H1311F0DTL)"), spaces, "");
else if (tagtype & NTAG_213_C)
else if (tagtype & MFU_TT_NTAG_213_C)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 213C 144bytes (NT2H1311C1DTL)"), spaces, "");
else if (tagtype & NTAG_213_TT)
else if (tagtype & MFU_TT_NTAG_213_TT)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 213TT 144bytes (NT2H1311TTDU)"), spaces, "");
else if (tagtype & NTAG_215)
else if (tagtype & MFU_TT_NTAG_215)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 215 504bytes (NT2H1511G0DU)"), spaces, "");
else if (tagtype & NTAG_216)
else if (tagtype & MFU_TT_NTAG_216)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 216 888bytes (NT2H1611G0DU)"), spaces, "");
else if (tagtype & NTAG_216_F)
else if (tagtype & MFU_TT_NTAG_216_F)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG 216F 888bytes (NT2H1611F0DTL)"), spaces, "");
else if (tagtype & NTAG_I2C_1K)
else if (tagtype & MFU_TT_NTAG_I2C_1K)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG I2C 888bytes (NT3H1101FHK)"), spaces, "");
else if (tagtype & NTAG_I2C_2K)
else if (tagtype & MFU_TT_NTAG_I2C_2K)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG I2C 1904bytes (NT3H1201FHK)"), spaces, "");
else if (tagtype & NTAG_I2C_1K_PLUS)
else if (tagtype & MFU_TT_NTAG_I2C_1K_PLUS)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG I2C plus 888bytes (NT3H2111FHK)"), spaces, "");
else if (tagtype & NTAG_I2C_2K_PLUS)
else if (tagtype & MFU_TT_NTAG_I2C_2K_PLUS)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("NTAG I2C plus 1912bytes (NT3H2211FHK)"), spaces, "");
else if (tagtype & MY_D)
else if (tagtype & MFU_TT_MY_D)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("INFINEON my-d\x99 (SLE 66RxxS)"), spaces, "");
else if (tagtype & MY_D_NFC)
else if (tagtype & MFU_TT_MY_D_NFC)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("INFINEON my-d\x99 NFC (SLE 66RxxP)"), spaces, "");
else if (tagtype & MY_D_MOVE)
else if (tagtype & MFU_TT_MY_D_MOVE)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("INFINEON my-d\x99 move (SLE 66R01P)"), spaces, "");
else if (tagtype & MY_D_MOVE_NFC)
else if (tagtype & MFU_TT_MY_D_MOVE_NFC)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("INFINEON my-d\x99 move NFC (SLE 66R01P)"), spaces, "");
else if (tagtype & MY_D_MOVE_LEAN)
else if (tagtype & MFU_TT_MY_D_MOVE_LEAN)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("INFINEON my-d\x99 move lean (SLE 66R01L)"), spaces, "");
else if (tagtype & FUDAN_UL)
else if (tagtype & MFU_TT_FUDAN_UL)
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("FUDAN Ultralight Compatible (or other compatible)"), spaces, "");
else
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("Unknown %06x"), spaces, "", tagtype);
snprintf(typestr, sizeof(typestr), "%*sTYPE: " _YELLOW_("Unknown %06" PRIx64), spaces, "", tagtype);
bool ismagic = ((tagtype & MAGIC) == MAGIC);
bool ismagic = ((tagtype & MFU_TT_MAGIC) == MFU_TT_MAGIC);
if (ismagic)
snprintf(typestr + strlen(typestr), 4, " (");
snprintf(typestr + strlen(typestr), sizeof(typestr) - strlen(typestr), " %s ", (tagtype & MAGIC) ? _GREEN_("magic") : "");
tagtype &= ~(MAGIC);
snprintf(typestr + strlen(typestr), sizeof(typestr) - strlen(typestr), "%s", (tagtype & MAGIC_1A) ? _GREEN_("Gen 1a") : "");
snprintf(typestr + strlen(typestr), sizeof(typestr) - strlen(typestr), "%s", (tagtype & MAGIC_1B) ? _GREEN_("Gen 1b") : "");
snprintf(typestr + strlen(typestr), sizeof(typestr) - strlen(typestr), " %s ", (tagtype & MFU_TT_MAGIC) ? _GREEN_("magic") : "");
tagtype &= ~(MFU_TT_MAGIC);
snprintf(typestr + strlen(typestr), sizeof(typestr) - strlen(typestr), "%s", (tagtype & MFU_TT_MAGIC_1A) ? _GREEN_("Gen 1a") : "");
snprintf(typestr + strlen(typestr), sizeof(typestr) - strlen(typestr), "%s", (tagtype & MFU_TT_MAGIC_1B) ? _GREEN_("Gen 1b") : "");
if (ismagic)
snprintf(typestr + strlen(typestr), 4, " )");
@@ -738,7 +747,7 @@ static int ulc_print_configuration(uint8_t *data) {
return PM3_SUCCESS;
}
static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t startPage) {
static int ulev1_print_configuration(uint64_t tagtype, uint8_t *data, uint8_t startPage) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Configuration"));
@@ -756,7 +765,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
PrintAndLogEx(INFO, " cfg0 [%u/0x%02X]: %s", startPage, startPage, sprint_hex(data, 4));
//NTAG213TT has different ASCII mirroring options and config bytes interpretation from other ulev1 class tags
if (tagtype & NTAG_213_TT) {
if (tagtype & MFU_TT_NTAG_213_TT) {
uint8_t mirror_conf = ((data[0] & 0xE0) >> 5);
uint8_t mirror_byte = ((data[0] & 0x18) >> 3);
uint8_t mirror_page = data[2];
@@ -822,7 +831,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
PrintAndLogEx(INFO, " mirror start page %02X | byte pos %02X - %s", mirror_page, mirror_byte, (mirror_page >= 0x4 && ((mirror_user_mem_start_byte + bytes_required_for_mirror_data) <= 144)) ? _GREEN_("OK") : _YELLOW_("Invalid value"));
}
} else if (tagtype & (NTAG_213_F | NTAG_216_F)) {
} else if (tagtype & (MFU_TT_NTAG_213_F | MFU_TT_NTAG_216_F)) {
uint8_t mirror_conf = ((data[0] & 0xC0) >> 6);
uint8_t mirror_byte = (data[0] & 0x30);
bool sleep_en = (data[0] & 0x08);
@@ -865,7 +874,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
break;
}
// valid mirror start page and byte position within start page.
if (tagtype & NTAG_213_F) {
if (tagtype & MFU_TT_NTAG_213_F) {
switch (mirror_conf) {
case 1:
{ PrintAndLogEx(INFO, " mirror start block %02X | byte pos %02X - %s", data[2], mirror_byte, (data[2] >= 0x4 && data[2] <= 0x24) ? "OK" : "Invalid value"); break;}
@@ -876,7 +885,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
default:
break;
}
} else if (tagtype & NTAG_216_F) {
} else if (tagtype & MFU_TT_NTAG_216_F) {
switch (mirror_conf) {
case 1:
{ PrintAndLogEx(INFO, " mirror start block %02X | byte pos %02X - %s", data[2], mirror_byte, (data[2] >= 0x4 && data[2] <= 0xDE) ? "OK" : "Invalid value"); break;}
@@ -901,7 +910,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
uint8_t tt_msg_resp_len = 0;
uint8_t tt_status_resp[5] = {0x00};
if (tagtype & NTAG_213_TT) {
if (tagtype & MFU_TT_NTAG_213_TT) {
tt_enabled = (data[1] & 0x02);
tt_msg_resp_len = ul_read(45, tt_message, 4);
@@ -941,7 +950,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
PrintAndLogEx(INFO, " PACK [%u/0x%02X]: %s - (cannot be read)", startPage + 3, startPage + 3, sprint_hex(data + 12, 2));
PrintAndLogEx(INFO, " RFU [%u/0x%02X]: %s- (cannot be read)", startPage + 3, startPage + 3, sprint_hex(data + 14, 2));
if (tagtype & NTAG_213_TT) {
if (tagtype & MFU_TT_NTAG_213_TT) {
if (data[1] & 0x06) {
PrintAndLogEx(INFO, "TT_MSG [45/0x2D]: %s- (cannot be read)", sprint_hex(tt_message, tt_msg_resp_len));
PrintAndLogEx(INFO, " - tamper message is masked in memory");
@@ -952,7 +961,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
}
//The NTAG213TT only returns meaningful information for the fields below if the tamper feature is enabled
if ((tagtype & NTAG_213_TT) && tt_enabled) {
if ((tagtype & MFU_TT_NTAG_213_TT) && tt_enabled) {
uint8_t tt_status_len = ntagtt_getTamperStatus(tt_status_resp, 5);
@@ -1012,9 +1021,10 @@ static int ulev1_print_counters(void) {
return len;
}
static int ulev1_print_signature(TagTypeUL_t tagtype, uint8_t *uid, uint8_t *signature, size_t signature_len) {
static int ulev1_print_signature(uint64_t tagtype, uint8_t *uid, uint8_t *signature, size_t signature_len) {
#define PUBLIC_ECDA_KEYLEN 33
#define PUBLIC_ECDA_192_KEYLEN 49
// known public keys for the originality check (source: https://github.com/alexbatalov/node-nxp-originality-verifier)
// ref: AN11350 NTAG 21x Originality Signature Validation
// ref: AN11341 MIFARE Ultralight EV1 Originality Signature Validation
@@ -1028,6 +1038,11 @@ static int ulev1_print_signature(TagTypeUL_t tagtype, uint8_t *uid, uint8_t *sig
{"MIKRON Public key", "04f971eda742a4a80d32dcf6a814a707cc3dc396d35902f72929fdcd698b3468f2"},
};
// https://www.nxp.com/docs/en/application-note/AN13452.pdf
const ecdsa_publickey_t nxp_mfu_192_public_keys[] = {
{"NXP Ultralight AES", "0453BF8C49B7BD9FE3207A91513B9C1D238ECAB07186B772104AB535F7D3AE63CF7C7F3DD0D169DA3E99E43C6399621A86"},
};
/*
uint8_t nxp_mfu_public_keys[6][PUBLIC_ECDA_KEYLEN] = {
// UL, NTAG21x and NDEF
@@ -1076,34 +1091,60 @@ static int ulev1_print_signature(TagTypeUL_t tagtype, uint8_t *uid, uint8_t *sig
*/
uint8_t i;
bool is_valid = false;
for (i = 0; i < ARRAYLEN(nxp_mfu_public_keys); i++) {
if (signature_len == 32) {
for (i = 0; i < ARRAYLEN(nxp_mfu_public_keys); i++) {
int dl = 0;
uint8_t key[PUBLIC_ECDA_KEYLEN] = {0};
param_gethex_to_eol(nxp_mfu_public_keys[i].value, 0, key, PUBLIC_ECDA_KEYLEN, &dl);
int dl = 0;
uint8_t key[PUBLIC_ECDA_KEYLEN] = {0};
param_gethex_to_eol(nxp_mfu_public_keys[i].value, 0, key, PUBLIC_ECDA_KEYLEN, &dl);
int res = ecdsa_signature_r_s_verify(MBEDTLS_ECP_DP_SECP128R1, key, uid, 7, signature, signature_len, false);
int res = ecdsa_signature_r_s_verify(MBEDTLS_ECP_DP_SECP128R1, key, uid, 7, signature, signature_len, false);
is_valid = (res == 0);
if (is_valid)
break;
is_valid = (res == 0);
if (is_valid)
break;
}
}
bool is_192_valid = false;
if (signature_len == 48) {
for (i = 0; i < ARRAYLEN(nxp_mfu_192_public_keys); i++) {
int dl = 0;
uint8_t key[PUBLIC_ECDA_192_KEYLEN] = {0};
param_gethex_to_eol(nxp_mfu_192_public_keys[i].value, 0, key, PUBLIC_ECDA_192_KEYLEN, &dl);
int res = ecdsa_signature_r_s_verify(MBEDTLS_ECP_DP_SECP192R1, key, uid, 7, signature, signature_len, false);
is_192_valid = (res == 0);
if (is_192_valid)
break;
}
}
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Signature"));
if (is_valid == false || i == ARRAYLEN(nxp_mfu_public_keys)) {
PrintAndLogEx(INFO, " Elliptic curve parameters: NID_secp128r1");
if (is_192_valid) {
PrintAndLogEx(INFO, " IC signature public key name: " _GREEN_("%s"), nxp_mfu_192_public_keys[i].desc);
PrintAndLogEx(INFO, "IC signature public key value: %s", nxp_mfu_192_public_keys[i].value);
PrintAndLogEx(INFO, " Elliptic curve parameters: NID_secp192r1");
PrintAndLogEx(INFO, " TAG IC Signature: %s", sprint_hex_inrow(signature, signature_len));
PrintAndLogEx(SUCCESS, " Signature verification ( " _RED_("fail") " )");
return PM3_ESOFT;
PrintAndLogEx(SUCCESS, " Signature verification ( " _GREEN_("successful") " )");
return PM3_SUCCESS;
}
PrintAndLogEx(INFO, " IC signature public key name: " _GREEN_("%s"), nxp_mfu_public_keys[i].desc);
PrintAndLogEx(INFO, "IC signature public key value: %s", nxp_mfu_public_keys[i].value);
PrintAndLogEx(INFO, " Elliptic curve parameters: NID_secp128r1");
if (is_valid) {
PrintAndLogEx(INFO, " IC signature public key name: " _GREEN_("%s"), nxp_mfu_public_keys[i].desc);
PrintAndLogEx(INFO, "IC signature public key value: %s", nxp_mfu_public_keys[i].value);
PrintAndLogEx(INFO, " Elliptic curve parameters: NID_secp128r1");
PrintAndLogEx(INFO, " TAG IC Signature: %s", sprint_hex_inrow(signature, signature_len));
PrintAndLogEx(SUCCESS, " Signature verification ( " _GREEN_("successful") " )");
return PM3_SUCCESS;
}
PrintAndLogEx(INFO, " Elliptic curve parameters: %s", (signature_len == 48) ? "NID_secp192r1" : "NID_secp128r1");
PrintAndLogEx(INFO, " TAG IC Signature: %s", sprint_hex_inrow(signature, signature_len));
PrintAndLogEx(SUCCESS, " Signature verification ( " _GREEN_("successful") " )");
return PM3_SUCCESS;
PrintAndLogEx(SUCCESS, " Signature verification ( " _RED_("fail") " )");
return PM3_ESOFT;
}
static int ulev1_print_version(uint8_t *data) {
@@ -1152,14 +1193,14 @@ static int ulc_magic_test(){
uint8_t nonce1[11] = {0x00};
uint8_t nonce2[11] = {0x00};
if ( !ul_select(&card) ){
return UL_ERROR;
return MFU_TT_UL_ERROR;
}
int status = ulc_requestAuthentication(nonce1, sizeof(nonce1));
if ( status > 0 ) {
status = ulc_requestAuthentication(nonce2, sizeof(nonce2));
returnValue = ( !memcmp(nonce1, nonce2, 11) ) ? UL_C_MAGIC : UL_C;
returnValue = ( !memcmp(nonce1, nonce2, 11) ) ? MFU_TT_UL_C_MAGIC : MFU_TT_UL_C;
} else {
returnValue = UL;
returnValue = MFU_TT_UL;
}
DropField();
return returnValue;
@@ -1172,12 +1213,12 @@ static int ul_magic_test(void) {
iso14a_card_select_t card;
if (ul_select(&card) == false)
return UL_ERROR;
return MFU_TT_UL_ERROR;
int status = ul_comp_write(0, NULL, 0);
DropField();
if (status == 0)
return MAGIC;
return MFU_TT_MAGIC;
// check for GEN1A, GEN1B and NTAG21x
uint8_t is_generation = 0;
@@ -1191,11 +1232,11 @@ static int ul_magic_test(void) {
}
switch (is_generation) {
case MAGIC_GEN_1A:
return MAGIC_1A;
return MFU_TT_MAGIC_1A;
case MAGIC_GEN_1B:
return MAGIC_1B;
return MFU_TT_MAGIC_1B;
case MAGIC_NTAG21X:
return MAGIC_NTAG;
return MFU_TT_MAGIC_NTAG;
default:
break;
}
@@ -1461,7 +1502,7 @@ static int mfu_get_version_uid(uint8_t *version, uint8_t *uid) {
return PM3_SUCCESS;
}
static int mfu_fingerprint(TagTypeUL_t tagtype, bool hasAuthKey, uint8_t *authkey, int ak_len) {
static int mfu_fingerprint(uint64_t tagtype, bool hasAuthKey, uint8_t *authkey, int ak_len) {
uint8_t *data = NULL;
int res = PM3_SUCCESS;
@@ -1486,7 +1527,7 @@ static int mfu_fingerprint(TagTypeUL_t tagtype, bool hasAuthKey, uint8_t *authke
uint8_t keytype = 0;
if (hasAuthKey) {
if (tagtype & UL_C)
if (tagtype & MFU_TT_UL_C)
keytype = 1; //UL_C auth
else
keytype = 2; //UL_EV1/NTAG auth
@@ -1567,17 +1608,17 @@ out:
uint32_t GetHF14AMfU_Type(void) {
TagTypeUL_t tagtype = UNKNOWN;
uint64_t tagtype = MFU_TT_UNKNOWN;
iso14a_card_select_t card;
if (ul_select(&card) == false)
return UL_ERROR;
return MFU_TT_UL_ERROR;
// Ultralight - ATQA / SAK
if (card.atqa[1] != 0x00 || card.atqa[0] != 0x44 || card.sak != 0x00) {
//PrintAndLogEx(NORMAL, "Tag is not Ultralight | NTAG | MY-D [ATQA: %02X %02X SAK: %02X]\n", card.atqa[1], card.atqa[0], card.sak);
DropField();
return UL_ERROR;
return MFU_TT_UL_ERROR;
}
if (card.uid[0] != 0x05) {
@@ -1628,79 +1669,80 @@ uint32_t GetHF14AMfU_Type(void) {
Feiju NTAG 0053040201000F03
*/
if (memcmp(version, "\x00\x04\x03\x01\x01\x00\x0B", 7) == 0) { tagtype = UL_EV1_48; break; }
else if (memcmp(version, "\x00\x04\x03\x01\x02\x00\x0B", 7) == 0) { tagtype = UL_NANO_40; break; }
else if (memcmp(version, "\x00\x04\x03\x02\x01\x00\x0B", 7) == 0) { tagtype = UL_EV1_48; break; }
else if (memcmp(version, "\x00\x04\x03\x01\x01\x00\x0E", 7) == 0) { tagtype = UL_EV1_128; break; }
else if (memcmp(version, "\x00\x04\x03\x02\x01\x00\x0E", 7) == 0) { tagtype = UL_EV1_128; break; }
else if (memcmp(version, "\x00\x34\x21\x01\x01\x00\x0E", 7) == 0) { tagtype = UL_EV1_128; break; } // Mikron JSC Russia EV1 41 pages tag
else if (memcmp(version, "\x00\x04\x04\x01\x01\x00\x0B", 7) == 0) { tagtype = NTAG_210; break; }
else if (memcmp(version, "\x00\x04\x04\x01\x02\x00\x0B", 7) == 0) { tagtype = NTAG_210u; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x02\x00\x0B", 7) == 0) { tagtype = NTAG_210u; break; }
else if (memcmp(version, "\x00\x04\x04\x01\x01\x00\x0E", 7) == 0) { tagtype = NTAG_212; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x01\x00\x0F", 7) == 0) { tagtype = NTAG_213; break; }
else if (memcmp(version, "\x00\x53\x04\x02\x01\x00\x0F", 7) == 0) { tagtype = NTAG_213; break; } //Shanghai Feiju Microelectronics Co. Ltd. China (Xiaomi Air Purifier filter)
else if (memcmp(version, "\x00\x04\x04\x02\x01\x01\x0F", 7) == 0) { tagtype = NTAG_213_C; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x01\x00\x11", 7) == 0) { tagtype = NTAG_215; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x01\x00\x13", 7) == 0) { tagtype = NTAG_216; break; }
else if (memcmp(version, "\x00\x04\x04\x04\x01\x00\x0F", 7) == 0) { tagtype = NTAG_213_F; break; }
else if (memcmp(version, "\x00\x04\x04\x04\x01\x00\x13", 7) == 0) { tagtype = NTAG_216_F; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x03\x00\x0F", 7) == 0) { tagtype = NTAG_213_TT; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x01\x13", 7) == 0) { tagtype = NTAG_I2C_1K; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x01\x15", 7) == 0) { tagtype = NTAG_I2C_2K; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x02\x13", 7) == 0) { tagtype = NTAG_I2C_1K_PLUS; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x02\x15", 7) == 0) { tagtype = NTAG_I2C_2K_PLUS; break; }
else if (version[2] == 0x04) { tagtype = NTAG; break; }
else if (version[2] == 0x03) { tagtype = UL_EV1; }
if (memcmp(version, "\x00\x04\x03\x01\x01\x00\x0B", 7) == 0) { tagtype = MFU_TT_UL_EV1_48; break; }
else if (memcmp(version, "\x00\x04\x03\x01\x02\x00\x0B", 7) == 0) { tagtype = MFU_TT_UL_NANO_40; break; }
else if (memcmp(version, "\x00\x04\x03\x02\x01\x00\x0B", 7) == 0) { tagtype = MFU_TT_UL_EV1_48; break; }
else if (memcmp(version, "\x00\x04\x03\x01\x01\x00\x0E", 7) == 0) { tagtype = MFU_TT_UL_EV1_128; break; }
else if (memcmp(version, "\x00\x04\x03\x02\x01\x00\x0E", 7) == 0) { tagtype = MFU_TT_UL_EV1_128; break; }
else if (memcmp(version, "\x00\x04\x03\x01\x04\x00\x0F\x03", 8) == 0) { tagtype = MFU_TT_UL_AES; break; }
else if (memcmp(version, "\x00\x34\x21\x01\x01\x00\x0E", 7) == 0) { tagtype = MFU_TT_UL_EV1_128; break; } // Mikron JSC Russia EV1 41 pages tag
else if (memcmp(version, "\x00\x04\x04\x01\x01\x00\x0B", 7) == 0) { tagtype = MFU_TT_NTAG_210; break; }
else if (memcmp(version, "\x00\x04\x04\x01\x02\x00\x0B", 7) == 0) { tagtype = MFU_TT_NTAG_210u; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x02\x00\x0B", 7) == 0) { tagtype = MFU_TT_NTAG_210u; break; }
else if (memcmp(version, "\x00\x04\x04\x01\x01\x00\x0E", 7) == 0) { tagtype = MFU_TT_NTAG_212; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x01\x00\x0F", 7) == 0) { tagtype = MFU_TT_NTAG_213; break; }
else if (memcmp(version, "\x00\x53\x04\x02\x01\x00\x0F", 7) == 0) { tagtype = MFU_TT_NTAG_213; break; } // Shanghai Feiju Microelectronics Co. Ltd. China (Xiaomi Air Purifier filter)
else if (memcmp(version, "\x00\x04\x04\x02\x01\x01\x0F", 7) == 0) { tagtype = MFU_TT_NTAG_213_C; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x01\x00\x11", 7) == 0) { tagtype = MFU_TT_NTAG_215; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x01\x00\x13", 7) == 0) { tagtype = MFU_TT_NTAG_216; break; }
else if (memcmp(version, "\x00\x04\x04\x04\x01\x00\x0F", 7) == 0) { tagtype = MFU_TT_NTAG_213_F; break; }
else if (memcmp(version, "\x00\x04\x04\x04\x01\x00\x13", 7) == 0) { tagtype = MFU_TT_NTAG_216_F; break; }
else if (memcmp(version, "\x00\x04\x04\x02\x03\x00\x0F", 7) == 0) { tagtype = MFU_TT_NTAG_213_TT; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x01\x13", 7) == 0) { tagtype = MFU_TT_NTAG_I2C_1K; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x01\x15", 7) == 0) { tagtype = MFU_TT_NTAG_I2C_2K; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x02\x13", 7) == 0) { tagtype = MFU_TT_NTAG_I2C_1K_PLUS; break; }
else if (memcmp(version, "\x00\x04\x04\x05\x02\x02\x15", 7) == 0) { tagtype = MFU_TT_NTAG_I2C_2K_PLUS; break; }
else if (version[2] == 0x04) { tagtype = MFU_TT_NTAG; break; }
else if (version[2] == 0x03) { tagtype = MFU_TT_UL_EV1; }
break;
}
case 0x01:
tagtype = UL_C;
tagtype = MFU_TT_UL_C;
break;
case 0x00:
tagtype = UL;
tagtype = MFU_TT_UL;
break;
case -1 :
tagtype = (UL | UL_C | NTAG_203);
tagtype = (MFU_TT_UL | MFU_TT_UL_C | MFU_TT_NTAG_203);
break; // could be UL | UL_C magic tags
default :
tagtype = UNKNOWN;
tagtype = MFU_TT_UNKNOWN;
break;
}
// UL vs UL-C vs ntag203 test
if (tagtype & (UL | UL_C | NTAG_203)) {
if (!ul_select(&card)) return UL_ERROR;
if (tagtype & (MFU_TT_UL | MFU_TT_UL_C | MFU_TT_NTAG_203)) {
if (!ul_select(&card)) return MFU_TT_UL_ERROR;
// do UL_C check first...
uint8_t nonce[11] = {0x00};
int status = ulc_requestAuthentication(nonce, sizeof(nonce));
DropField();
if (status > 1) {
tagtype = UL_C;
tagtype = MFU_TT_UL_C;
} else {
// need to re-select after authentication error
if (ul_select(&card) == false)
return UL_ERROR;
return MFU_TT_UL_ERROR;
uint8_t data[16] = {0x00};
// read page 0x26-0x29 (last valid ntag203 page)
status = ul_read(0x26, data, sizeof(data));
if (status <= 1) {
tagtype = UL;
tagtype = MFU_TT_UL;
} else {
// read page 0x30 (should error if it is a ntag203)
status = ul_read(0x30, data, sizeof(data));
if (status <= 1) {
tagtype = NTAG_203;
tagtype = MFU_TT_NTAG_203;
} else {
tagtype = UNKNOWN;
tagtype = MFU_TT_UNKNOWN;
}
}
DropField();
}
}
if (tagtype & UL) {
if (tagtype & MFU_TT_UL) {
tagtype = ul_fudan_check();
DropField();
}
@@ -1711,23 +1753,23 @@ uint32_t GetHF14AMfU_Type(void) {
switch (nib) {
// case 0: tagtype = SLE66R35E7; break; //or SLE 66R35E7 - mifare compat... should have different sak/atqa for mf 1k
case 1:
tagtype = MY_D;
tagtype = MFU_TT_MY_D;
break; // or SLE 66RxxS ... up to 512 pages of 8 user bytes...
case 2:
tagtype = (MY_D_NFC);
tagtype = MFU_TT_MY_D_NFC;
break; // or SLE 66RxxP ... up to 512 pages of 8 user bytes... (or in nfc mode FF pages of 4 bytes)
case 3:
tagtype = (MY_D_MOVE | MY_D_MOVE_NFC);
tagtype = (MFU_TT_MY_D_MOVE | MFU_TT_MY_D_MOVE_NFC);
break; // or SLE 66R01P // 38 pages of 4 bytes //notice: we can not currently distinguish between these two
case 7:
tagtype = MY_D_MOVE_LEAN;
tagtype = MFU_TT_MY_D_MOVE_LEAN;
break; // or SLE 66R01L // 16 pages of 4 bytes
}
}
tagtype |= ul_magic_test();
if (tagtype == (UNKNOWN | MAGIC)) {
tagtype = (UL_MAGIC);
if (tagtype == (MFU_TT_UNKNOWN | MFU_TT_MAGIC)) {
tagtype = (MFU_TT_UL_MAGIC);
}
return tagtype;
}
@@ -1780,8 +1822,8 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
uint8_t pack[4] = {0, 0, 0, 0};
int len;
TagTypeUL_t tagtype = GetHF14AMfU_Type();
if (tagtype == UL_ERROR)
uint64_t tagtype = GetHF14AMfU_Type();
if (tagtype == MFU_TT_UL_ERROR)
return PM3_ESOFT;
PrintAndLogEx(NORMAL, "");
@@ -1812,7 +1854,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
}
// UL_C Specific
if ((tagtype & UL_C)) {
if ((tagtype & MFU_TT_UL_C)) {
// read pages 0x28, 0x29, 0x2A, 0x2B
uint8_t ulc_conf[16] = {0x00};
@@ -1829,7 +1871,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
mfu_fingerprint(tagtype, has_auth_key, authkeyptr, ak_len);
if ((tagtype & MAGIC)) {
if ((tagtype & MFU_TT_MAGIC)) {
//just read key
uint8_t ulc_deskey[16] = {0x00};
status = ul_read(0x2C, ulc_deskey, sizeof(ulc_deskey));
@@ -1863,7 +1905,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
// do counters and signature first (don't neet auth)
// ul counters are different than ntag counters
if ((tagtype & (UL_EV1_48 | UL_EV1_128 | UL_EV1))) {
if ((tagtype & (MFU_TT_UL_EV1_48 | MFU_TT_UL_EV1_128 | MFU_TT_UL_EV1))) {
if (ulev1_print_counters() != 3) {
// failed - re-select
if (ul_auth_select(&card, tagtype, has_auth_key, authkeyptr, pack, sizeof(pack)) == PM3_ESOFT) {
@@ -1873,7 +1915,7 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
}
// NTAG counters?
if ((tagtype & (NTAG_213 | NTAG_213_F | NTAG_213_C | NTAG_213_TT | NTAG_215 | NTAG_216))) {
if ((tagtype & (MFU_TT_NTAG_213 | MFU_TT_NTAG_213_F | MFU_TT_NTAG_213_C | MFU_TT_NTAG_213_TT | MFU_TT_NTAG_215 | MFU_TT_NTAG_216))) {
if (ntag_print_counter()) {
// failed - re-select
if (ul_auth_select(&card, tagtype, has_auth_key, authkeyptr, pack, sizeof(pack)) == PM3_ESOFT) {
@@ -1883,8 +1925,12 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
}
// Read signature
if ((tagtype & (UL_EV1_48 | UL_EV1_128 | UL_EV1 | UL_NANO_40 | NTAG_210u | NTAG_213 | NTAG_213_F | NTAG_213_C | NTAG_213_TT | NTAG_215 | NTAG_216 | NTAG_216_F | NTAG_I2C_1K | NTAG_I2C_2K | NTAG_I2C_1K_PLUS | NTAG_I2C_2K_PLUS))) {
uint8_t ulev1_signature[32] = {0x00};
if ((tagtype & (MFU_TT_UL_EV1_48 | MFU_TT_UL_EV1_128 | MFU_TT_UL_EV1 | MFU_TT_UL_NANO_40 |
MFU_TT_NTAG_210u | MFU_TT_NTAG_213 | MFU_TT_NTAG_213_F | MFU_TT_NTAG_213_C |
MFU_TT_NTAG_213_TT | MFU_TT_NTAG_215 | MFU_TT_NTAG_216 | MFU_TT_NTAG_216_F |
MFU_TT_NTAG_I2C_1K | MFU_TT_NTAG_I2C_2K | MFU_TT_NTAG_I2C_1K_PLUS | MFU_TT_NTAG_I2C_2K_PLUS |
MFU_TT_UL_AES))) {
uint8_t ulev1_signature[49] = {0x00};
status = ulev1_readSignature(ulev1_signature, sizeof(ulev1_signature));
if (status == -1) {
PrintAndLogEx(ERR, "Error: tag didn't answer to READ SIGNATURE");
@@ -1892,7 +1938,9 @@ static int CmdHF14AMfUInfo(const char *Cmd) {
return PM3_ESOFT;
}
if (status == 32) {
ulev1_print_signature(tagtype, card.uid, ulev1_signature, sizeof(ulev1_signature));
ulev1_print_signature(tagtype, card.uid, ulev1_signature, 32);
} else if (status == 48) {
ulev1_print_signature(tagtype, card.uid, ulev1_signature, 48);
} else {
// re-select
if (ul_auth_select(&card, tagtype, has_auth_key, authkeyptr, pack, sizeof(pack)) == PM3_ESOFT) {
@@ -2096,8 +2144,8 @@ static int CmdHF14AMfUWrBl(const char *Cmd) {
uint8_t *authKeyPtr = authenticationkey;
// starting with getting tagtype
TagTypeUL_t tagtype = GetHF14AMfU_Type();
if (tagtype == UL_ERROR)
uint64_t tagtype = GetHF14AMfU_Type();
if (tagtype == MFU_TT_UL_ERROR)
return PM3_ESOFT;
uint8_t maxblockno = 0;
@@ -2217,8 +2265,8 @@ static int CmdHF14AMfURdBl(const char *Cmd) {
uint8_t *authKeyPtr = authenticationkey;
// start with getting tagtype
TagTypeUL_t tagtype = GetHF14AMfU_Type();
if (tagtype == UL_ERROR)
uint64_t tagtype = GetHF14AMfU_Type();
if (tagtype == MFU_TT_UL_ERROR)
return PM3_ESOFT;
uint8_t maxblockno = 0;
@@ -2328,7 +2376,12 @@ void printMFUdumpEx(mfu_dump_t *card, uint16_t pages, uint8_t startpage) {
for (uint16_t i = 0; i < pages; ++i) {
if (i < 3) {
PrintAndLogEx(INFO, "%3d/0x%02X | %s| | %s", i + startpage, i + startpage, sprint_hex(data + i * 4, 4), sprint_ascii(data + i * 4, 4));
PrintAndLogEx(INFO, "%3d/0x%02X | " _RED_("%s")"| | %s",
i + startpage,
i + startpage,
sprint_hex(data + i * 4, 4),
sprint_ascii(data + i * 4, 4)
);
continue;
}
switch (i) {
@@ -2434,7 +2487,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfu dump",
"Dump MIFARE Ultralight/NTAG tag to binary/eml/json files.\n"
"Dump MIFARE Ultralight/NTAG tag to files (bin/json)\n"
"It autodetects card type."
"Supports:\n"
"Ultralight, Ultralight-C, Ultralight EV1\n"
@@ -2501,8 +2554,8 @@ static int CmdHF14AMfUDump(const char *Cmd) {
authKeyPtr = SwapEndian64(authenticationkey, ak_len, 4);
}
TagTypeUL_t tagtype = GetHF14AMfU_Type();
if (tagtype == UL_ERROR)
uint64_t tagtype = GetHF14AMfU_Type();
if (tagtype == MFU_TT_UL_ERROR)
return PM3_ESOFT;
//get number of pages to read
@@ -2519,7 +2572,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Reading tag memory...");
uint8_t keytype = 0;
if (has_auth_key || has_pwd) {
if (tagtype & UL_C)
if (tagtype & MFU_TT_UL_C)
keytype = 1; //UL_C auth
else
keytype = 2; //UL_EV1/NTAG auth
@@ -2569,7 +2622,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
// not ul_c and not std ul then attempt to collect info like
// VERSION, SIGNATURE, COUNTERS, TEARING, PACK,
if (!(tagtype & UL_C || tagtype & UL || tagtype & MY_D_MOVE || tagtype & MY_D_MOVE_LEAN)) {
if (!(tagtype & MFU_TT_UL_C || tagtype & MFU_TT_UL || tagtype & MFU_TT_MY_D_MOVE || tagtype & MFU_TT_MY_D_MOVE_LEAN)) {
//attempt to read pack
uint8_t get_pack[] = {0, 0};
if (ul_auth_select(&card, tagtype, true, authKeyPtr, get_pack, sizeof(get_pack)) != PM3_SUCCESS) {
@@ -2599,7 +2652,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
uint8_t n = 0;
// NTAG has 1 counter, at 0x02
if ((tagtype & (NTAG_213 | NTAG_213_F | NTAG_213_C | NTAG_213_TT | NTAG_215 | NTAG_216))) {
if ((tagtype & (MFU_TT_NTAG_213 | MFU_TT_NTAG_213_F | MFU_TT_NTAG_213_C | MFU_TT_NTAG_213_TT | MFU_TT_NTAG_215 | MFU_TT_NTAG_216))) {
n = 2;
}
@@ -2647,7 +2700,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
authKeyPtr = authenticationkey;
}
if (tagtype & UL_C) { //add 4 pages
if (tagtype & MFU_TT_UL_C) { //add 4 pages
memcpy(data + pages * 4, authKeyPtr, ak_len);
pages += ak_len / 4;
} else { // 2nd page from end
@@ -2665,23 +2718,27 @@ static int CmdHF14AMfUDump(const char *Cmd) {
printMFUdumpEx(&dump_file_data, pages, start_page);
if (nosave == false) {
// user supplied filename?
if (fnlen < 1) {
PrintAndLogEx(INFO, "Using UID as filename");
uint8_t uid[7] = {0};
memcpy(uid, (uint8_t *)&dump_file_data.data, 3);
memcpy(uid + 3, (uint8_t *)&dump_file_data.data + 4, 4);
strcat(filename, "hf-mfu-");
FillFileNameByUID(filename, uid, "-dump", sizeof(uid));
}
if (nosave) {
PrintAndLogEx(INFO, "Called with no save option");
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
uint16_t datalen = pages * MFU_BLOCK_SIZE + MFU_DUMP_PREFIX_LENGTH;
pm3_save_dump(filename, (uint8_t *)&dump_file_data, datalen, jsfMfuMemory, MFU_BLOCK_SIZE);
// user supplied filename?
if (fnlen < 1) {
PrintAndLogEx(INFO, "Using UID as filename");
uint8_t uid[7] = {0};
memcpy(uid, (uint8_t *)&dump_file_data.data, 3);
memcpy(uid + 3, (uint8_t *)&dump_file_data.data + 4, 4);
strcat(filename, "hf-mfu-");
FillFileNameByUID(filename, uid, "-dump", sizeof(uid));
}
if (is_partial) {
PrintAndLogEx(WARNING, "Partial dump created. (%d of %d blocks)", pages, card_mem_size);
}
uint16_t datalen = pages * MFU_BLOCK_SIZE + MFU_DUMP_PREFIX_LENGTH;
pm3_save_dump(filename, (uint8_t *)&dump_file_data, datalen, jsfMfuMemory);
if (is_partial) {
PrintAndLogEx(WARNING, "Partial dump created. (%d of %d blocks)", pages, card_mem_size);
}
return PM3_SUCCESS;
@@ -2742,13 +2799,13 @@ int CmdHF14MfUTamper(const char *Cmd) {
bool disable = arg_get_lit(ctx, 2);
CLIParserFree(ctx);
TagTypeUL_t tagtype = GetHF14AMfU_Type();
if (tagtype == UL_ERROR) {
uint64_t tagtype = GetHF14AMfU_Type();
if (tagtype == MFU_TT_UL_ERROR) {
PrintAndLogEx(WARNING, "Tag type not detected");
DropField();
return PM3_ESOFT;
}
if (tagtype != NTAG_213_TT) {
if (tagtype != MFU_TT_NTAG_213_TT) {
PrintAndLogEx(WARNING, "Tag type not NTAG 213TT");
DropField();
return PM3_ESOFT;
@@ -2766,7 +2823,7 @@ int CmdHF14MfUTamper(const char *Cmd) {
if (use_msg) {
if (ul_select(&card) == false) {
DropField();
return UL_ERROR;
return MFU_TT_UL_ERROR;
}
PrintAndLogEx(INFO, "Trying to write tamper message\n");
SendCommandMIX(CMD_HF_MIFAREU_WRITEBL, tt_msg_page, 0, 0, msg_data, 4);
@@ -2789,7 +2846,7 @@ int CmdHF14MfUTamper(const char *Cmd) {
if (ul_select(&card) == false) {
PrintAndLogEx(ERR, "Unable to select tag");
DropField();
return UL_ERROR;
return MFU_TT_UL_ERROR;
}
uint8_t cfg_page[4] = {0x00};
@@ -2840,7 +2897,7 @@ int CmdHF14MfUTamper(const char *Cmd) {
static int CmdHF14AMfURestore(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfu restore",
"Restore MIFARE Ultralight/NTAG dump file to tag.\n",
"Restore MIFARE Ultralight/NTAG dump file (bin/eml/json) to tag.\n",
"hf mfu restore -f myfile -s -> special write\n"
"hf mfu restore -f myfile -k AABBCCDD -s -> special write, use key\n"
"hf mfu restore -f myfile -k AABBCCDD -ser -> special write, use key, write dump pwd, ..."
@@ -2848,7 +2905,7 @@ static int CmdHF14AMfURestore(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "specify dump filename (bin/eml/json)"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_str0("k", "key", "<hex>", "key for authentication (UL-C 16 bytes, EV1/NTAG 4 bytes)"),
arg_lit0("l", NULL, "swap entered key's endianness"),
arg_lit0("s", NULL, "enable special write UID -MAGIC TAG ONLY-"),
@@ -3065,7 +3122,7 @@ static int CmdHF14AMfUeLoad(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "Filename of dump"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_int0("q", "qty", "<dec>", "Number of blocks to load from eml file"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
@@ -4375,8 +4432,8 @@ int CmdHF14MfuNDEFRead(const char *Cmd) {
}
// Get tag type
TagTypeUL_t tagtype = GetHF14AMfU_Type();
if (tagtype == UL_ERROR) {
uint64_t tagtype = GetHF14AMfU_Type();
if (tagtype == MFU_TT_UL_ERROR) {
PrintAndLogEx(WARNING, "No Ultralight / NTAG based tag found");
return PM3_ESOFT;
}
@@ -4443,14 +4500,20 @@ int CmdHF14MfuNDEFRead(const char *Cmd) {
}
DropField();
if (fnlen != 0) {
saveFile(filename, ".bin", records, (size_t)maxsize);
}
status = NDEFRecordsDecodeAndPrint(records, (size_t)maxsize, verbose);
if (status != PM3_SUCCESS) {
status = NDEFDecodeAndPrint(records, (size_t)maxsize, verbose);
}
// get total NDEF length before save. If fails, we save it all
size_t n = 0;
if (NDEFGetTotalLength(records, maxsize, &n) != PM3_SUCCESS)
n = maxsize;
pm3_save_dump(filename, records, n, jsfNDEF);
char *jooki = strstr((char *)records, "s.jooki.rocks/s/?s=");
if (jooki) {
jooki += 17;
@@ -4557,18 +4620,18 @@ static int CmdHF14AMfuEView(const char *Cmd) {
static int CmdHF14AMfuESave(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfu esave",
"Saves emulator memory to a MIFARE Ultralight/NTAG dump file (bin/eml/json)\n"
"Saves emulator memory to a MIFARE Ultralight/NTAG dump file (bin/json)\n"
"By default number of pages saved depends on defined tag type.\n"
"You can override this with option --end.",
"hf mfu esave\n"
"hf mfu esave --end 255 -> saves whole memory\n"
"hf mfu esave -f hf-mfu-04010203040506-dump.json"
"hf mfu esave -f hf-mfu-04010203040506-dump"
);
void *argtable[] = {
arg_param_begin,
arg_int0("e", "end", "<dec>", "index of last block"),
arg_str0("f", "file", "<fn>", "filename of dump"),
arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
arg_param_end
};
@@ -4613,7 +4676,7 @@ static int CmdHF14AMfuESave(const char *Cmd) {
// save dump. Last block contains PACK + RFU
uint16_t datalen = (end + 1) * MFU_BLOCK_SIZE + MFU_DUMP_PREFIX_LENGTH;
res = pm3_save_dump(filename, (uint8_t *)dump, datalen, jsfMfuMemory, MFU_BLOCK_SIZE);
res = pm3_save_dump(filename, (uint8_t *)dump, datalen, jsfMfuMemory);
free(dump);
return res;
@@ -4628,7 +4691,7 @@ static int CmdHF14AMfuView(const char *Cmd) {
);
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "Filename of dump"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_lit0("v", "verbose", "Verbose output"),
arg_param_end
};
+40 -40
View File
@@ -43,7 +43,7 @@ typedef struct {
} PACKED old_mfu_dump_t;
uint32_t GetHF14AMfU_Type(void);
int ul_print_type(uint32_t tagtype, uint8_t spaces);
int ul_print_type(uint64_t tagtype, uint8_t spaces);
void printMFUdumpEx(mfu_dump_t *card, uint16_t pages, uint8_t startpage);
int ul_read_uid(uint8_t *uid);
int trace_mfuc_try_default_3des_keys(uint8_t **correct_key, int state, uint8_t (*authdata)[16]);
@@ -55,44 +55,44 @@ int CmdHF14MfUTamper(const char *Cmd);
uint16_t ul_ev1_packgen_VCNEW(uint8_t *uid, uint32_t pwd);
uint32_t ul_ev1_otpgenA(uint8_t *uid);
typedef enum TAGTYPE_UL {
UNKNOWN = 0x000000,
UL = 0x1,
UL_C = 0x2,
UL_EV1_48 = 0x4,
UL_EV1_128 = 0x8,
NTAG = 0x10,
NTAG_203 = 0x20,
NTAG_210 = 0x40,
NTAG_212 = 0x80,
NTAG_213 = 0x100,
NTAG_215 = 0x200,
NTAG_216 = 0x400,
MY_D = 0x800,
MY_D_NFC = 0x1000,
MY_D_MOVE = 0x2000,
MY_D_MOVE_NFC = 0x4000,
MY_D_MOVE_LEAN = 0x8000,
NTAG_I2C_1K = 0x10000,
NTAG_I2C_2K = 0x20000,
NTAG_I2C_1K_PLUS = 0x40000,
NTAG_I2C_2K_PLUS = 0x80000,
FUDAN_UL = 0x100000,
MAGIC = 0x200000,
NTAG_213_F = 0x400000,
NTAG_216_F = 0x800000,
UL_EV1 = 0x1000000,
UL_NANO_40 = 0x2000000,
NTAG_213_TT = 0x4000000,
NTAG_213_C = 0x8000000,
MAGIC_1A = 0x10000000 | MAGIC,
MAGIC_1B = 0x20000000 | MAGIC,
MAGIC_NTAG = 0x40000000 | MAGIC,
NTAG_210u = 0x80000000,
UL_MAGIC = UL | MAGIC,
UL_C_MAGIC = UL_C | MAGIC,
// Don't forget to fill UL_TYPES_ARRAY and UL_MEMORY_ARRAY if new types are added
UL_ERROR = 0xFFFFFF,
} TagTypeUL_t;
#define MFU_TT_UNKNOWN 0x0ULL
#define MFU_TT_UL 0x1ULL
#define MFU_TT_UL_C 0x2ULL
#define MFU_TT_UL_EV1_48 0x4ULL
#define MFU_TT_UL_EV1_128 0x8ULL
#define MFU_TT_NTAG 0x10ULL
#define MFU_TT_NTAG_203 0x20ULL
#define MFU_TT_NTAG_210 0x40ULL
#define MFU_TT_NTAG_212 0x80ULL
#define MFU_TT_NTAG_213 0x100ULL
#define MFU_TT_NTAG_215 0x200ULL
#define MFU_TT_NTAG_216 0x400ULL
#define MFU_TT_MY_D 0x800ULL
#define MFU_TT_MY_D_NFC 0x1000ULL
#define MFU_TT_MY_D_MOVE 0x2000ULL
#define MFU_TT_MY_D_MOVE_NFC 0x4000ULL
#define MFU_TT_MY_D_MOVE_LEAN 0x8000ULL
#define MFU_TT_NTAG_I2C_1K 0x10000ULL
#define MFU_TT_NTAG_I2C_2K 0x20000ULL
#define MFU_TT_NTAG_I2C_1K_PLUS 0x40000ULL
#define MFU_TT_NTAG_I2C_2K_PLUS 0x80000ULL
#define MFU_TT_FUDAN_UL 0x100000ULL
#define MFU_TT_MAGIC 0x200000ULL
#define MFU_TT_NTAG_213_F 0x400000ULL
#define MFU_TT_NTAG_216_F 0x800000ULL
#define MFU_TT_UL_EV1 0x1000000ULL
#define MFU_TT_UL_NANO_40 0x2000000ULL
#define MFU_TT_NTAG_213_TT 0x4000000ULL
#define MFU_TT_NTAG_213_C 0x8000000ULL
#define MFU_TT_MAGIC_1A (0x10000000ULL | MFU_TT_MAGIC)
#define MFU_TT_MAGIC_1B (0x20000000ULL | MFU_TT_MAGIC)
#define MFU_TT_MAGIC_NTAG (0x40000000ULL | MFU_TT_MAGIC)
#define MFU_TT_NTAG_210u 0x80000000ULL
#define MFU_TT_UL_AES 0x100000000ULL
#define MFU_TT_UL_MAGIC (MFU_TT_UL | MFU_TT_MAGIC)
#define MFU_TT_UL_C_MAGIC (MFU_TT_UL_C | MFU_TT_MAGIC)
// Don't forget to fill UL_TYPES_ARRAY and UL_MEMORY_ARRAY if new types are added
#define MFU_TT_UL_ERROR 0x7FFFFFFFULL
#endif
+1393 -118
View File
File diff suppressed because it is too large. Load diff
+8 -3
View File
@@ -404,10 +404,15 @@ int CmdHFST25TANdefRead(const char *Cmd) {
return PM3_ESOFT;
}
if (fnlen != 0) {
saveFile(filename, ".bin", response + 2, resplen - 4);
}
NDEFRecordsDecodeAndPrint(response + 2, resplen - 4, verbose);
// get total NDEF length before save. If fails, we save it all
size_t n = 0;
if (NDEFGetTotalLength(response, resplen, &n) != PM3_SUCCESS)
n = resplen;
pm3_save_dump(filename, response + 2, n, jsfNDEF);
return PM3_SUCCESS;
}
+4 -4
View File
@@ -429,7 +429,7 @@ static void TexcomReverseCode(const uint8_t *code, int length, uint8_t *reverse_
for (int i = 0; i < length; i++) {
reverse_code[i] = code[(length - 1) - i];
}
};
}
static int texkom_get_type(texkom_card_select_t *card, bool verbose) {
@@ -493,7 +493,7 @@ static int texkom_get_type(texkom_card_select_t *card, bool verbose) {
noiselvl = TEXKOM_NOISE_THRESHOLD;
}
uint32_t implengths[256] = {};
uint32_t implengths[256] = { 0 };
uint32_t implengthslen = 0;
uint32_t impulseindx = 0;
uint32_t impulsecnt = 0;
@@ -707,7 +707,7 @@ static int CmdHFTexkomReader(const char *Cmd) {
//PrintAndLogEx(WARNING, "--- indx: %d, len: %d, max: %d, noise: %d", sindx, slen, maxlvl, noiselvl);
uint32_t implengths[256] = {};
uint32_t implengths[256] = { 0 };
uint32_t implengthslen = 0;
uint32_t impulseindx = 0;
uint32_t impulsecnt = 0;
@@ -872,7 +872,7 @@ static int CmdHFTexkomSim(const char *Cmd) {
uint8_t data[8];
uint8_t modulation;
uint32_t timeout;
} PACKED payload = {};
} PACKED payload = {0};
bool verbose = arg_get_lit(ctx, 1);
payload.modulation = 0; // tk-13
+5 -5
View File
@@ -838,13 +838,13 @@ static int CmdHFTopazDump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf topaz dump",
"Dump TOPAZ tag to binary file\n"
"Dump TOPAZ tag to file (bin/json)\n"
"If no <name> given, UID will be used as filename",
"hf topaz dump\n");
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "filename of dump"),
arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
arg_lit0(NULL, "ns", "no save to file"),
arg_param_end
};
@@ -897,9 +897,9 @@ static int CmdHFTopazDump(const char *Cmd) {
}
if (topaz_tag.size)
pm3_save_dump(filename, (uint8_t *)&topaz_tag, sizeof(topaz_tag_t) + topaz_tag.size, jsfTopaz, TOPAZ_BLOCK_SIZE);
pm3_save_dump(filename, (uint8_t *)&topaz_tag, sizeof(topaz_tag_t) + topaz_tag.size, jsfTopaz);
else
pm3_save_dump(filename, (uint8_t *)&topaz_tag, sizeof(topaz_tag_t), jsfTopaz, TOPAZ_BLOCK_SIZE);
pm3_save_dump(filename, (uint8_t *)&topaz_tag, sizeof(topaz_tag_t), jsfTopaz);
if (set_dynamic) {
free(topaz_tag.dynamic_memory);
@@ -916,7 +916,7 @@ static int CmdHFTopazView(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "filename of dump (bin/eml/json)"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
+3 -3
View File
@@ -356,7 +356,7 @@ static int VASReader(uint8_t *pidHash, const char *url, size_t urlLen, uint8_t *
};
if (SelectCard14443A_4_WithParameters(false, false, NULL, &polling_parameters) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "No card in field");
PrintAndLogEx(WARNING, "No ISO14443-A Card in field");
return PM3_ECARDEXCHANGE;
}
@@ -586,10 +586,10 @@ static command_t CommandTable[] = {
int CmdHFVAS(const char *Cmd) {
clearCommandBuffer();
return CmdsParse(CommandTable, Cmd);
};
}
static int CmdHelp(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
CmdsHelp(CommandTable);
return PM3_SUCCESS;
};
}
+1 -14
View File
@@ -611,9 +611,7 @@ static int CmdHFXeroxDump(const char *Cmd) {
int fnlen = 0;
char filename[FILE_PATH_SIZE] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
bool decrypt = arg_get_lit(ctx, 2);
CLIParserFree(ctx);
iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + 11);
@@ -682,7 +680,6 @@ static int CmdHFXeroxDump(const char *Cmd) {
PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout);
// PrintAndLogEx(INPLACE, "blk %3d", blocknum);
}
}
@@ -773,23 +770,13 @@ static int CmdHFXeroxDump(const char *Cmd) {
PrintAndLogEx(NORMAL, "");
if (0 == filename[0]) { // generate filename from uid
/*
PrintAndLogEx(INFO, "Using UID as filename");
sprintf(filename, "hf-xerox-%02X%02X%02X%02X%02X%02X%02X%02X-dump%s",
card.uid[7],card.uid[6],card.uid[5],card.uid[4],card.uid[3],card.uid[2],card.uid[1],card.uid[0],
decrypt ? "-dec" : "");
*/
char *fptr = filename;
PrintAndLogEx(INFO, "Using UID as filename");
fptr += snprintf(fptr, sizeof(filename), "hf-xerox-");
FillFileNameByUID(fptr, SwapEndian64(card.uid, card.uidlen, 8), decrypt ? "-dump-dec" : "-dump", card.uidlen);
}
size_t datalen = blocknum * 4;
saveFile(filename, ".bin", data, datalen);
saveFileEML(filename, data, datalen, 4);
// saveFileJSON(filename, jsf15, data, datalen, NULL);
pm3_save_dump(filename, data, blocknum * 4, jsf14b_v2);
return PM3_SUCCESS;
}
+36 -16
View File
@@ -35,6 +35,7 @@
#include "pmflash.h" // rdv40validation_t
#include "cmdflashmem.h" // get_signature..
#include "uart/uart.h" // configure timeout
#include "util_posix.h"
static int CmdHelp(const char *Cmd);
@@ -44,6 +45,7 @@ static void lookup_chipid_short(uint32_t iChipID, uint32_t mem_used) {
case 0x270B0A40:
asBuff = "AT91SAM7S512 Rev A";
break;
case 0x270B0A4E:
case 0x270B0A4F:
asBuff = "AT91SAM7S512 Rev B";
break;
@@ -152,6 +154,7 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
case 0x270B0A40:
asBuff = "AT91SAM7S512 Rev A";
break;
case 0x270B0A4E:
case 0x270B0A4F:
asBuff = "AT91SAM7S512 Rev B";
break;
@@ -809,19 +812,29 @@ static int CmdStatus(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw status",
"Show runtime status information about the connected Proxmark3",
"hw status"
"hw status\n"
"hw status --ms 1000 -> Test connection speed with 1000ms timeout\n"
);
void *argtable[] = {
arg_param_begin,
arg_int0("m", "ms", "<ms>", "speed test timeout in micro seconds"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
int32_t speedTestTimeout = arg_get_int_def(ctx, 1, -1);
CLIParserFree(ctx);
clearCommandBuffer();
PacketResponseNG resp;
SendCommandNG(CMD_STATUS, NULL, 0);
if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000) == false) {
if (speedTestTimeout < 0) {
speedTestTimeout = 0;
SendCommandNG(CMD_STATUS, NULL, 0);
} else {
SendCommandNG(CMD_STATUS, (uint8_t *)&speedTestTimeout, sizeof(speedTestTimeout));
}
if (WaitForResponseTimeout(CMD_STATUS, &resp, 2000 + speedTestTimeout) == false) {
PrintAndLogEx(WARNING, "Status command timeout. Communication speed test timed out");
return PM3_ETIMEOUT;
}
@@ -931,14 +944,14 @@ static int CmdTimeout(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hw timeout",
"Set the communication timeout on the client side",
"hw timeout --> Show current timeout\n"
"hw timeout -t 20 --> Set the timeout to 20ms\n"
"hw timeout -t 500 --> Set the timeout to 500ms\n"
"hw timeout --> Show current timeout\n"
"hw timeout -m 20 --> Set the timeout to 20ms\n"
"hw timeout --ms 500 --> Set the timeout to 500ms\n"
);
void *argtable[] = {
arg_param_begin,
arg_int0("t", "timeout", "<dec>", "timeout in ms"),
arg_int0("m", "ms", "<ms>", "timeout in micro seconds"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -949,20 +962,20 @@ static int CmdTimeout(const char *Cmd) {
// timeout is not given/invalid, just show the current timeout then return
if (arg < 0) {
PrintAndLogEx(INFO, "Current communication timeout: %ums", oldTimeout);
PrintAndLogEx(INFO, "Current communication timeout... " _GREEN_("%u") " ms", oldTimeout);
return PM3_SUCCESS;
}
uint32_t newTimeout = arg;
// UART_USB_CLIENT_RX_TIMEOUT_MS is considered as the minimum required timeout.
if (newTimeout < UART_USB_CLIENT_RX_TIMEOUT_MS) {
PrintAndLogEx(WARNING, "Timeout less than %ums might cause errors.", UART_USB_CLIENT_RX_TIMEOUT_MS);
PrintAndLogEx(WARNING, "Timeout less than %u ms might cause errors.", UART_USB_CLIENT_RX_TIMEOUT_MS);
} else if (newTimeout > 5000) {
PrintAndLogEx(WARNING, "Timeout greater than 5000ms makes the client unresponsive.");
PrintAndLogEx(WARNING, "Timeout greater than 5000 ms makes the client unresponsive.");
}
uart_reconfigure_timeouts(newTimeout);
PrintAndLogEx(INFO, "Old communication timeout: %ums", oldTimeout);
PrintAndLogEx(INFO, "New communication timeout: %ums", newTimeout);
PrintAndLogEx(INFO, "Old communication timeout... %u ms", oldTimeout);
PrintAndLogEx(INFO, "New communication timeout... " _GREEN_("%u") " ms", newTimeout);
return PM3_SUCCESS;
}
@@ -979,6 +992,7 @@ static int CmdPing(const char *Cmd) {
arg_u64_0("l", "len", "<dec>", "length of payload to send"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint32_t len = arg_get_u32_def(ctx, 1, 32);
CLIParserFree(ctx);
@@ -987,7 +1001,7 @@ static int CmdPing(const char *Cmd) {
len = PM3_CMD_DATA_SIZE;
if (len) {
PrintAndLogEx(INFO, "Ping sent with payload len " _YELLOW_("%d"), len);
PrintAndLogEx(INFO, "Ping sent with payload len... " _YELLOW_("%d"), len);
} else {
PrintAndLogEx(INFO, "Ping sent");
}
@@ -996,16 +1010,22 @@ static int CmdPing(const char *Cmd) {
PacketResponseNG resp;
uint8_t data[PM3_CMD_DATA_SIZE] = {0};
for (uint16_t i = 0; i < len; i++)
for (uint16_t i = 0; i < len; i++) {
data[i] = i & 0xFF;
}
uint64_t tms = msclock();
SendCommandNG(CMD_PING, data, len);
if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) {
tms = msclock() - tms;
if (len) {
bool error = (memcmp(data, resp.data.asBytes, len) != 0);
PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received") " and content () %s )", error ? _RED_("fail") : _GREEN_("ok"));
PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received")
" in " _YELLOW_("%" PRIu64) " ms and content ( %s )",
tms, error ? _RED_("fail") : _GREEN_("ok"));
} else {
PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received"));
PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received")
" in " _YELLOW_("%" PRIu64) " ms", tms);
}
} else
PrintAndLogEx(WARNING, "Ping response " _RED_("timeout"));
+2 -2
View File
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
// //-----------------------------------------------------------------------------
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
@@ -469,7 +469,7 @@ int CmdFlexdemod(const char *Cmd) {
sum += data[i++];
}
bits[bit] = (sum > 0) ? 1 : 0;
PrintAndLogEx(NORMAL, "bit %d sum %d", bit, sum);
// PrintAndLogEx(NORMAL, "bit %d sum %d", bit, sum);
}
for (bit = 0; bit < 64; bit++) {
+3 -2
View File
@@ -528,8 +528,9 @@ static int CmdEM410xBrute(const char *Cmd) {
//The line start with # is comment, skip
if (buf[0] == '#') continue;
if (param_gethex(buf, 0, uid, 10)) {
PrintAndLogEx(FAILED, "EM Tag IDs must include 5 hex bytes (10 hex symbols)");
int uidlen = 0;
if (param_gethex_ex(buf, 0, uid, &uidlen) && (uidlen != 10)) {
PrintAndLogEx(FAILED, "EM Tag IDs must include 5 hex bytes (10 hex symbols), got ( " _RED_("%d") " )", uidlen);
free(uidblock);
fclose(f);
return PM3_ESOFT;
+20 -11
View File
@@ -514,6 +514,7 @@ int CmdEM4x05Dump(const char *Cmd) {
arg_param_begin,
arg_str0("p", "pwd", "<hex>", "password (00000000)"),
arg_str0("f", "file", "<fn>", "override filename prefix (optional). Default is based on UID"),
arg_lit0(NULL, "ns", "no save to file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
@@ -522,6 +523,7 @@ int CmdEM4x05Dump(const char *Cmd) {
int fnlen = 0;
char filename[FILE_PATH_SIZE] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
bool nosave = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
uint8_t addr = 0;
@@ -693,6 +695,13 @@ int CmdEM4x05Dump(const char *Cmd) {
} else {
}
if (nosave) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "Called with no save option");
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
// all ok save dump to file
if (success == PM3_SUCCESS) {
@@ -709,9 +718,9 @@ int CmdEM4x05Dump(const char *Cmd) {
}
PrintAndLogEx(NORMAL, "");
if (card_type == EM_4369 || card_type == EM_4469)
pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x69, 4);
pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x69);
else
pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x05, 4);
pm3_save_dump(filename, (uint8_t *)data, sizeof(data), jsfEM4x05);
}
PrintAndLogEx(NORMAL, "");
return success;
@@ -741,16 +750,16 @@ int CmdEM4x05Read(const char *Cmd) {
bool use_pwd = false;
if (addr > 15) {
PrintAndLogEx(ERR, "Address must be between 0 and 15");
PrintAndLogEx(ERR, "Address must be between 0 and 15, got " _RED_("%d"), addr);
return PM3_EINVARG;
}
if (inputpwd == 0xFFFFFFFFFFFFFFFF) {
PrintAndLogEx(INFO, "Reading address %02u", addr);
PrintAndLogEx(INFO, "Reading address " _YELLOW_("%02u"), addr);
} else {
pwd = (inputpwd & 0xFFFFFFFF);
use_pwd = true;
PrintAndLogEx(INFO, "Reading address %02u using password %08X", addr, pwd);
PrintAndLogEx(INFO, "Reading address " _YELLOW_("%02u") " using password " _YELLOW_("%08X"), addr, pwd);
}
uint32_t word = 0;
@@ -818,14 +827,14 @@ int CmdEM4x05Write(const char *Cmd) {
if (use_pwd) {
if (protect_operation)
PrintAndLogEx(INFO, "Writing protection words data %08X using password %08X", data, pwd);
PrintAndLogEx(INFO, "Writing protection words data " _YELLOW_("%08X") " using password " _YELLOW_("%08X"), data, pwd);
else
PrintAndLogEx(INFO, "Writing address %d data %08X using password %08X", addr, data, pwd);
PrintAndLogEx(INFO, "Writing address " _YELLOW_("%d") " data " _YELLOW_("%08X") " using password " _YELLOW_("%08X"), addr, data, pwd);
} else {
if (protect_operation)
PrintAndLogEx(INFO, "Writing protection words data %08X", data);
PrintAndLogEx(INFO, "Writing protection words data " _YELLOW_("%08X"), data);
else
PrintAndLogEx(INFO, "Writing address %d data %08X", addr, data);
PrintAndLogEx(INFO, "Writing address " _YELLOW_("%d") " data " _YELLOW_("%08X"), addr, data);
}
res = PM3_SUCCESS;
@@ -850,7 +859,7 @@ int CmdEM4x05Write(const char *Cmd) {
if (status == PM3_SUCCESS)
PrintAndLogEx(SUCCESS, "Data written and verified");
else if (status == PM3_EFAILED)
PrintAndLogEx(ERR, "Tag denied %s operation", protect_operation ? "Protect" : "Write");
PrintAndLogEx(ERR, "Tag denied " _RED_("%s") " operation", protect_operation ? "Protect" : "Write");
else
PrintAndLogEx(DEBUG, "No answer from tag");
@@ -2020,7 +2029,7 @@ int CmdEM4x05Sniff(const char *Cmd) {
PrintAndLogEx(SUCCESS, "-------+-------------+----------+-----+------------------------------------------------------------");
smartbuf bits = { 0 };
bits.ptr = malloc(EM4X05_BITS_BUFSIZE);
bits.ptr = calloc(EM4X05_BITS_BUFSIZE, sizeof(uint8_t));
bits.size = EM4X05_BITS_BUFSIZE;
bits.idx = 0;
size_t idx = 0;
+7 -7
View File
@@ -194,7 +194,7 @@ int CmdEM4x50ELoad(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "dump filename (bin/eml/json)"),
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
arg_param_end
};
@@ -223,7 +223,7 @@ int CmdEM4x50ELoad(const char *Cmd) {
int CmdEM4x50ESave(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf em 4x50 esave",
"Saves bin/eml/json dump file of emulator memory.",
"Saves bin/json dump file of emulator memory.",
"lf em 4x50 esave -> use UID as filename\n"
"lf em 4x50 esave -f mydump\n"
);
@@ -264,7 +264,7 @@ int CmdEM4x50ESave(const char *Cmd) {
FillFileNameByUID(fptr, (uint8_t *)&data[4 * EM4X50_DEVICE_ID], "-dump", 4);
}
pm3_save_dump(filename, data, DUMP_FILESIZE, jsfEM4x50, 4);
pm3_save_dump(filename, data, DUMP_FILESIZE, jsfEM4x50);
return PM3_SUCCESS;
}
@@ -796,7 +796,7 @@ int CmdEM4x50Reader(const char *Cmd) {
int CmdEM4x50Dump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf em 4x50 dump",
"Reads all blocks/words from EM4x50 tag and saves dump in bin/eml/json format",
"Reads all blocks/words from EM4x50 tag and saves dump in (bin/json) format",
"lf em 4x50 dump\n"
"lf em 4x50 dump -f mydump\n"
"lf em 4x50 dump -p 12345678\n"
@@ -805,7 +805,7 @@ int CmdEM4x50Dump(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "specify dump filename (bin/eml/json)"),
arg_str0("f", "file", "<fn>", "specify dump filename"),
arg_str0("p", "pwd", "<hex>", "password, 4 hex bytes, lsb"),
arg_param_end
};
@@ -867,7 +867,7 @@ int CmdEM4x50Dump(const char *Cmd) {
memcpy(data + (i * 4), words[i].byte, 4);
}
pm3_save_dump(filename, data, sizeof(data), jsfEM4x50, 4);
pm3_save_dump(filename, data, sizeof(data), jsfEM4x50);
return PM3_SUCCESS;
}
@@ -1113,7 +1113,7 @@ int CmdEM4x50Restore(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str0("u", "uid", "<hex>", "uid, 4 hex bytes, msb"),
arg_str0("f", "file", "<fn>", "specify dump filename (bin/eml/json)"),
arg_str0("f", "file", "<fn>", "specify a filename for dump file"),
arg_str0("p", "pwd", "<hex>", "password, 4 hex bytes, lsb"),
arg_param_end
};
+26 -7
View File
@@ -44,6 +44,7 @@
#include "wiegand_formats.h"
#include "wiegand_formatutils.h"
#include "cmdlfem4x05.h" // EM defines
#include "loclass/cipherutils.h" // bitstreamout
#ifndef BITS
# define BITS 96
@@ -399,14 +400,32 @@ static int CmdHIDClone(const char *Cmd) {
packed.Mid = mid;
packed.Bot = bot;
} else if (bin_len) {
int res = binstring_to_u96(&top, &mid, &bot, (const char *)bin);
if (res != bin_len) {
PrintAndLogEx(ERR, "Binary string contains none <0|1> chars");
return PM3_EINVARG;
uint8_t hex[12];
memset(hex, 0, sizeof(hex));
BitstreamOut_t bout = {hex, 0, 0 };
for (int i = 0; i < 96 - bin_len - 1; i++) {
pushBit(&bout, 0);
}
packed.Top = top;
packed.Mid = mid;
packed.Bot = bot;
// add binary sentinel bit.
pushBit(&bout, 1);
// convert binary string to hex bytes
for (int i = 0; i < bin_len; i++) {
char c = bin[i];
if (c == '1')
pushBit(&bout, 1);
else if (c == '0')
pushBit(&bout, 0);
}
packed.Length = bin_len;
packed.Top = bytes_to_num(hex, 4);
packed.Mid = bytes_to_num(hex + 4, 4);
packed.Bot = bytes_to_num(hex + 8, 4);
add_HID_header(&packed);
} else {
if (HIDPack(format_idx, &card, &packed, true) == false) {
PrintAndLogEx(WARNING, "The card data could not be encoded in the selected format.");
+1 -1
View File
@@ -1127,7 +1127,7 @@ static int CmdLFHitag2Dump(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Dumping tag memory...");
pm3_save_dump(filename, data, 48, jsfHitag, 4);
pm3_save_dump(filename, data, 48, jsfHitag);
return PM3_SUCCESS;
}
+134 -58
View File
@@ -2217,7 +2217,7 @@ static int CmdT55xxDump(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "lf t55xx dump",
"This command dumps a T55xx card Page 0 block 0-7.\n"
"It will create three files (bin/eml/json)",
"It will create two files (bin/json)",
"lf t55xx dump\n"
"lf t55xx dump -p aabbccdd --override\n"
"lf t55xx dump -f my_lf_dump"
@@ -2298,8 +2298,14 @@ static int CmdT55xxDump(const char *Cmd) {
}
}
if (nosave) {
PrintAndLogEx(INFO, "Called with no save option");
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
// all ok, save dump to file
if (success && nosave == false) {
if (success) {
// set default filename, if not set by user
if (strlen(filename) == 0) {
@@ -2315,17 +2321,13 @@ static int CmdT55xxDump(const char *Cmd) {
}
// Swap endian so the files match the txt display
uint32_t data[T55x7_BLOCK_COUNT];
uint32_t data[T55x7_BLOCK_COUNT] = {0};
for (int i = 0; i < T55x7_BLOCK_COUNT; i++) {
data[i] = BSWAP_32(cardmem[i].blockdata);
}
// saveFileEML will add .eml extension to filename
// saveFile (binary) passes in the .bin extension.
saveFileJSON(filename, jsfT55x7, (uint8_t *)data, T55x7_BLOCK_COUNT * sizeof(uint32_t), NULL);
saveFileEML(filename, (uint8_t *)data, T55x7_BLOCK_COUNT * sizeof(uint32_t), sizeof(uint32_t));
saveFile(filename, ".bin", data, sizeof(data));
pm3_save_dump(filename, (uint8_t *)data, (T55x7_BLOCK_COUNT * sizeof(uint32_t)), jsfT55x7);
}
return PM3_SUCCESS;
@@ -2340,7 +2342,7 @@ static int CmdT55xxRestore(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str0("f", "file", "<fn>", "filename of dump file"),
arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
arg_str0("p", "pwd", "<hex>", "password if target card has password set (4 hex bytes)"),
arg_param_end
};
@@ -3498,11 +3500,12 @@ out:
// some return all page 1 (64 bits) and others return just that block (32 bits)
// unfortunately the 64 bits makes this more likely to get a false positive...
bool tryDetectP1(bool getData) {
uint8_t preamble[] = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1};
size_t startIdx = 0;
uint8_t fc1 = 0, fc2 = 0, ans = 0;
int clk = 0, firstClockEdge = 0;
bool st = true;
uint8_t preamble_atmel[] = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1};
uint8_t preamble_silicon[] = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1};
size_t startIdx = 0;
uint8_t fc1 = 0, fc2 = 0, ans = 0;
int clk = 0, firstClockEdge = 0;
bool st = true;
if (getData) {
if (!AcquireData(T55x7_PAGE1, T55x7_TRACE_BLOCK1, false, 0, 0))
@@ -3512,15 +3515,29 @@ bool tryDetectP1(bool getData) {
// try fsk clock detect. if successful it cannot be any other type of modulation... (in theory...)
ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, &firstClockEdge);
if (ans && ((fc1 == 10 && fc2 == 8) || (fc1 == 8 && fc2 == 5))) {
if ((FSKrawDemod(0, 0, 0, 0, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (FSKrawDemod(0, 0, 0, 0, false) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
if ((FSKrawDemod(0, 1, 0, 0, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (FSKrawDemod(0, 1, 0, 0, false) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
return false;
}
@@ -3528,44 +3545,82 @@ bool tryDetectP1(bool getData) {
// try ask clock detect. it could be another type even if successful.
clk = GetAskClock("", false);
if (clk > 0) {
if ((ASKDemod_ext(0, 0, 1, 0, false, false, false, 1, &st) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (ASKDemod_ext(0, 0, 1, 0, false, false, false, 1, &st) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
st = true;
if ((ASKDemod_ext(0, 1, 1, 0, false, false, false, 1, &st) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (ASKDemod_ext(0, 1, 1, 0, false, false, false, 1, &st) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
if ((ASKbiphaseDemod(0, 0, 0, 2, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (ASKbiphaseDemod(0, 0, 0, 2, false) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
if ((ASKbiphaseDemod(0, 0, 1, 2, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (ASKbiphaseDemod(0, 0, 1, 2, false) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
}
// try NRZ clock detect. it could be another type even if successful.
clk = GetNrzClock("", false); //has the most false positives :(
if (clk > 0) {
if ((NRZrawDemod(0, 0, 1, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (NRZrawDemod(0, 0, 1, false) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
if ((NRZrawDemod(0, 1, 1, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
if (NRZrawDemod(0, 1, 1, false) == PM3_SUCCESS) {
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
}
@@ -3577,33 +3632,54 @@ bool tryDetectP1(bool getData) {
// save_restoreGB(GRAPH_SAVE);
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
//CmdLtrim("-i 160");
if ((PSKDemod(0, 0, 6, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
if (PSKDemod(0, 0, 6, false) == PM3_SUCCESS) {
//save_restoreGB(GRAPH_RESTORE);
return true;
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
if ((PSKDemod(0, 1, 6, false) == PM3_SUCCESS) &&
preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
if (PSKDemod(0, 1, 6, false) == PM3_SUCCESS) {
//save_restoreGB(GRAPH_RESTORE);
return true;
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
}
// PSK2 - needs a call to psk1TOpsk2.
if (PSKDemod(0, 0, 6, false) == PM3_SUCCESS) {
psk1TOpsk2(g_DemodBuffer, g_DemodBufferLen);
if (preambleSearchEx(g_DemodBuffer, preamble, sizeof(preamble), &g_DemodBufferLen, &startIdx, false) &&
//save_restoreGB(GRAPH_RESTORE);
if (preambleSearchEx(g_DemodBuffer, preamble_atmel, sizeof(preamble_atmel), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
return true;
}
if (preambleSearchEx(g_DemodBuffer, preamble_silicon, sizeof(preamble_silicon), &g_DemodBufferLen, &startIdx, false) &&
(g_DemodBufferLen == 32 || g_DemodBufferLen == 64)) {
//save_restoreGB(GRAPH_RESTORE);
return true;
}
} // inverse waves does not affect PSK2 demod
//undo trim samples
//save_restoreGB(GRAPH_RESTORE);
// no other modulation clocks = 2 or 4 so quit searching
if (fc1 != 8) return false;
if (fc1 != 8) {
return false;
}
}
return false;
}
// does this need to be a callable command?
+35 -13
View File
@@ -113,26 +113,48 @@ static int CmdNfcDecode(const char *Cmd) {
return res;
}
// convert from MFC dump file to a pure NDEF byte array
if (HasMADKey(dump)) {
PrintAndLogEx(SUCCESS, "MFC dump file detected. Converting...");
uint8_t ndef[4096] = {0};
uint16_t ndeflen = 0;
uint8_t *tmp = dump;
if (convert_mad_to_arr(dump, bytes_read, ndef, &ndeflen) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Failed converting, aborting...");
free(dump);
return PM3_ESOFT;
// if not MIFARE Classic default sizes, assume its Ultralight/NTAG
if (bytes_read != MIFARE_4K_MAX_BYTES
&& bytes_read != MIFARE_2K_MAX_BYTES
&& bytes_read != MIFARE_1K_MAX_BYTES
&& bytes_read != MIFARE_MINI_MAX_BYTES) {
uint8_t **pd = &tmp;
mfu_df_e df = detect_mfu_dump_format(pd, verbose);
if (df == MFU_DF_OLDBIN) {
tmp += OLD_MFU_DUMP_PREFIX_LENGTH + (4 * 4);
bytes_read -= OLD_MFU_DUMP_PREFIX_LENGTH + (4 * 4);
} else if (df == MFU_DF_NEWBIN) {
tmp += MFU_DUMP_PREFIX_LENGTH + (4 * 4);
bytes_read -= MFU_DUMP_PREFIX_LENGTH + (4 * 4);
}
pd = NULL;
memcpy(dump, ndef, ndeflen);
bytes_read = ndeflen;
} else {
// convert from MFC dump file to a pure NDEF byte array
if (HasMADKey(tmp)) {
PrintAndLogEx(SUCCESS, "MFC dump file detected. Converting...");
uint8_t ndef[4096] = {0};
uint16_t ndeflen = 0;
if (convert_mad_to_arr(tmp, bytes_read, ndef, &ndeflen) != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Failed converting, aborting...");
free(dump);
return PM3_ESOFT;
}
memcpy(tmp, ndef, ndeflen);
bytes_read = ndeflen;
}
}
res = NDEFDecodeAndPrint(dump, bytes_read, verbose);
res = NDEFDecodeAndPrint(tmp, bytes_read, verbose);
if (res != PM3_SUCCESS) {
PrintAndLogEx(INFO, "Trying to parse NDEF records w/o NDEF header");
res = NDEFRecordsDecodeAndPrint(dump, bytes_read, verbose);
res = NDEFRecordsDecodeAndPrint(tmp, bytes_read, verbose);
}
free(dump);
+1
View File
@@ -22,6 +22,7 @@
#ifdef HAVE_PYTHON
//#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <ctype.h>
#include <wchar.h>
#endif
+30 -14
View File
@@ -179,7 +179,7 @@ static void PrintATR(uint8_t *atr, size_t atrlen) {
if (T0 & 0x80) {
uint8_t TD1 = atr[2 + T1len];
PrintAndLogEx(INFO, " - TD1 (First offered transmission protocol, presence of TA2..TD2) [ 0x%02x ] Protocol T%d", TD1, TD1 & 0x0f);
PrintAndLogEx(INFO, " - TD1 (First offered transmission protocol, presence of TA2..TD2) [ 0x%02x ] Protocol " _GREEN_("T%d"), TD1, TD1 & 0x0f);
protocol_T0_present = false;
if ((TD1 & 0x0f) == 0) {
protocol_T0_present = true;
@@ -204,7 +204,7 @@ static void PrintATR(uint8_t *atr, size_t atrlen) {
}
if (TD1 & 0x80) {
uint8_t TDi = atr[2 + T1len + TD1len];
PrintAndLogEx(INFO, " - TD2 (A supported protocol or more global parameters, presence of TA3..TD3) [ 0x%02x ] Protocol T%d", TDi, TDi & 0x0f);
PrintAndLogEx(INFO, " - TD2 (A supported protocol or more global parameters, presence of TA3..TD3) [ 0x%02x ] Protocol " _GREEN_("T%d"), TDi, TDi & 0x0f);
if ((TDi & 0x0f) == 0) {
protocol_T0_present = true;
}
@@ -333,7 +333,7 @@ static int smart_responseEx(uint8_t *out, int maxoutlen, bool verbose) {
needGetData = true;
}
if (needGetData == true) {
if (needGetData) {
// Don't discard data we already received except the SW code.
// If we only received 1 byte, this is the echo of INS, we discard it.
totallen -= 2;
@@ -360,6 +360,7 @@ static int smart_responseEx(uint8_t *out, int maxoutlen, bool verbose) {
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(cmd_getresp));
payload->flags = SC_RAW | SC_LOG;
payload->len = sizeof(cmd_getresp);
payload->wait_delay = 0;
memcpy(payload->data, cmd_getresp, sizeof(cmd_getresp));
clearCommandBuffer();
@@ -421,6 +422,7 @@ static int CmdSmartRaw(const char *Cmd) {
arg_lit0("s", NULL, "active smartcard with select (get ATR)"),
arg_lit0("t", "tlv", "executes TLV decoder if it possible"),
arg_lit0("0", NULL, "use protocol T=0"),
arg_int0(NULL, "timeout", "<ms>", "Timeout in MS waiting for SIM to respond. (def 337ms)"),
arg_str1("d", "data", "<hex>", "bytes to send"),
arg_param_end
};
@@ -431,10 +433,11 @@ static int CmdSmartRaw(const char *Cmd) {
bool active_select = arg_get_lit(ctx, 3);
bool decode_tlv = arg_get_lit(ctx, 4);
bool use_t0 = arg_get_lit(ctx, 5);
int timeout = arg_get_int_def(ctx, 6, -1);
int dlen = 0;
uint8_t data[PM3_CMD_DATA_SIZE] = {0x00};
int res = CLIParamHexToBuf(arg_get_str(ctx, 6), data, sizeof(data), &dlen);
int res = CLIParamHexToBuf(arg_get_str(ctx, 7), data, sizeof(data), &dlen);
CLIParserFree(ctx);
if (res) {
@@ -458,6 +461,13 @@ static int CmdSmartRaw(const char *Cmd) {
payload->flags |= SC_SELECT;
}
payload->wait_delay = 0;
if (timeout > -1) {
payload->flags |= SC_WAIT;
payload->wait_delay = timeout;
}
PrintAndLogEx(DEBUG, "SIM Card timeout... %u ms", payload->wait_delay);
if (dlen > 0) {
if (use_t0)
payload->flags |= SC_RAW_T0;
@@ -500,9 +510,9 @@ static int CmdSmartRaw(const char *Cmd) {
data[4] = 0;
}
if (decode_tlv && len > 4)
if (decode_tlv && len > 4) {
TLVPrintFromBuffer(buf, len - 2);
else {
} else {
if (len > 2) {
PrintAndLogEx(INFO, "Response data:");
PrintAndLogEx(INFO, " # | bytes | ascii");
@@ -518,16 +528,16 @@ out:
}
static int CmdSmartUpgrade(const char *Cmd) {
PrintAndLogEx(INFO, "-------------------------------------------------------------------");
PrintAndLogEx(INFO, "--------------------------------------------------------------------");
PrintAndLogEx(WARNING, _RED_("WARNING") " - sim module firmware upgrade");
PrintAndLogEx(WARNING, _RED_("A dangerous command, do wrong and you could brick the sim module"));
PrintAndLogEx(INFO, "-------------------------------------------------------------------");
PrintAndLogEx(INFO, "--------------------------------------------------------------------");
PrintAndLogEx(NORMAL, "");
CLIParserContext *ctx;
CLIParserInit(&ctx, "smart upgrade",
"Upgrade RDV4 sim module firmware",
"smart upgrade -f sim013.bin"
"smart upgrade -f sim014.bin"
);
void *argtable[] = {
@@ -585,9 +595,10 @@ static int CmdSmartUpgrade(const char *Cmd) {
}
hashstring[128] = '\0';
int hash1n = 0;
uint8_t hash_1[64];
if (param_gethex(hashstring, 0, hash_1, 128)) {
PrintAndLogEx(FAILED, "Couldn't read SHA-512 file");
if (param_gethex_ex(hashstring, 0, hash_1, &hash1n) && hash1n != 128) {
PrintAndLogEx(FAILED, "Couldn't read SHA-512 file. expect 128 hex bytes, got ( "_RED_("%d") " )", hash1n);
free(hashstring);
free(firmware);
return PM3_ESOFT;
@@ -903,6 +914,7 @@ static void smart_brute_prim(void) {
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + 5);
payload->flags = SC_RAW_T0;
payload->len = 5;
payload->wait_delay = 0;
memcpy(payload->data, get_card_data + i, 5);
clearCommandBuffer();
@@ -946,6 +958,7 @@ static int smart_brute_sfi(bool decodeTLV) {
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + sizeof(READ_RECORD));
payload->flags = SC_RAW_T0;
payload->len = sizeof(READ_RECORD);
payload->wait_delay = 0;
memcpy(payload->data, READ_RECORD, sizeof(READ_RECORD));
clearCommandBuffer();
@@ -1099,7 +1112,7 @@ static int CmdSmartBruteforceSFI(const char *Cmd) {
smart_card_raw_t *payload = calloc(1, sizeof(smart_card_raw_t) + hexlen);
payload->flags = SC_RAW_T0;
payload->len = hexlen;
payload->wait_delay = 0;
memcpy(payload->data, cmddata, hexlen);
clearCommandBuffer();
SendCommandNG(CMD_SMART_RAW, (uint8_t *)payload, sizeof(smart_card_raw_t) + hexlen);
@@ -1335,6 +1348,7 @@ int ExchangeAPDUSC(bool verbose, uint8_t *datain, int datainlen, bool activateCa
payload->flags |= (SC_SELECT | SC_CONNECT);
}
payload->len = datainlen;
payload->wait_delay = 0;
memcpy(payload->data, datain, datainlen);
clearCommandBuffer();
@@ -1366,8 +1380,9 @@ int ExchangeAPDUSC(bool verbose, uint8_t *datain, int datainlen, bool activateCa
}
bool smart_select(bool verbose, smart_card_atr_t *atr) {
if (atr)
if (atr) {
memset(atr, 0, sizeof(smart_card_atr_t));
}
clearCommandBuffer();
SendCommandNG(CMD_SMART_ATR, NULL, 0);
@@ -1385,8 +1400,9 @@ bool smart_select(bool verbose, smart_card_atr_t *atr) {
smart_card_atr_t card;
memcpy(&card, (smart_card_atr_t *)resp.data.asBytes, sizeof(smart_card_atr_t));
if (atr)
if (atr) {
memcpy(atr, &card, sizeof(smart_card_atr_t));
}
if (verbose)
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
+15 -6
View File
@@ -666,19 +666,28 @@ int TestProxmark(pm3_device_t *dev) {
g_conn.send_via_fpc_usart = g_pm3_capabilities.via_fpc;
g_conn.uart_speed = g_pm3_capabilities.baudrate;
bool is_tcp_conn = (memcmp(g_conn.serial_port_name, "tcp:", 4) == 0);
bool is_tcp_conn = (g_conn.send_via_ip == PM3_TCPv4 || g_conn.send_via_ip == PM3_TCPv6);
bool is_bt_conn = (memcmp(g_conn.serial_port_name, "bt:", 3) == 0);
bool is_udp_conn = (g_conn.send_via_ip == PM3_UDPv4 || g_conn.send_via_ip == PM3_UDPv6);
PrintAndLogEx(INFO, "Communicating with PM3 over %s%s%s",
PrintAndLogEx(INFO, "Communicating with PM3 over %s%s%s%s",
(g_conn.send_via_fpc_usart) ? _YELLOW_("FPC UART") : _YELLOW_("USB-CDC"),
(is_tcp_conn) ? " over " _YELLOW_("TCP") : "",
(is_bt_conn) ? " over " _YELLOW_("BT") : ""
(is_bt_conn) ? " over " _YELLOW_("BT") : "",
(is_udp_conn) ? " over " _YELLOW_("UDP") : ""
);
if (g_conn.send_via_fpc_usart) {
PrintAndLogEx(INFO, "PM3 UART serial baudrate: " _YELLOW_("%u") "\n", g_conn.uart_speed);
} else {
int res = uart_reconfigure_timeouts(is_tcp_conn ? UART_TCP_CLIENT_RX_TIMEOUT_MS : UART_USB_CLIENT_RX_TIMEOUT_MS);
int res;
if (g_conn.send_via_local_ip) {
// (g_conn.send_via_local_ip == true) -> ((is_tcp_conn || is_udp_conn) == true)
res = uart_reconfigure_timeouts(is_tcp_conn ? UART_TCP_LOCAL_CLIENT_RX_TIMEOUT_MS : UART_UDP_LOCAL_CLIENT_RX_TIMEOUT_MS);
} else if (is_tcp_conn || is_udp_conn) {
res = uart_reconfigure_timeouts(UART_NET_CLIENT_RX_TIMEOUT_MS);
} else {
res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS);
}
if (res != PM3_SUCCESS) {
return res;
}
@@ -789,7 +798,7 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms
show_warning = false;
}
// just to avoid CPU busy loop:
msleep(10);
msleep(1);
}
return false;
}
+12
View File
@@ -54,6 +54,14 @@ typedef enum {
FPGA_MEM,
} DeviceMemType_t;
typedef enum {
PM3_TCPv4,
PM3_TCPv6,
PM3_UDPv4,
PM3_UDPv6,
PM3_NONE,
} CommunicationProtocol_t;
typedef struct {
bool run; // If TRUE, continue running the uart_communication thread
bool block_after_ACK; // if true, block after receiving an ACK package
@@ -62,6 +70,10 @@ typedef struct {
bool send_with_crc_on_fpc;
// "Session" flag, to tell via which interface next msgs are sent: USB or FPC USART
bool send_via_fpc_usart;
// to tell if we are using TCP/UDP/TCP(IPv6)/UDP(IPv6)
CommunicationProtocol_t send_via_ip;
// to tell if the target address is local address(127.0.0.1/localhost/::1)
bool send_via_local_ip;
// To memorise baudrate
uint32_t uart_speed;
uint16_t last_command;
+4 -4
View File
@@ -15,7 +15,7 @@
//-----------------------------------------------------------------------------
// asn.1 dumping
//-----------------------------------------------------------------------------
#define _POSIX_C_SOURCE 200809L // need for strnlen()
#include "asn1dump.h"
#include "commonutil.h" // ARRAYLEN
@@ -344,17 +344,17 @@ static void asn1_tag_dump_object_id(const struct tlv *tlv, const struct asn1_tag
} else {
const char *ppstr = NULL;
mbedtls_oid_get_attr_short_name(&asn1_buf, &ppstr);
if (ppstr && strnlen(ppstr, 1)) {
if (ppstr && str_nlen(ppstr, 1)) {
PrintAndLogEx(NORMAL, " (%s)", ppstr);
return;
}
mbedtls_oid_get_sig_alg_desc(&asn1_buf, &ppstr);
if (ppstr && strnlen(ppstr, 1)) {
if (ppstr && str_nlen(ppstr, 1)) {
PrintAndLogEx(NORMAL, " (%s)", ppstr);
return;
}
mbedtls_oid_get_extended_key_usage(&asn1_buf, &ppstr);
if (ppstr && strnlen(ppstr, 1)) {
if (ppstr && str_nlen(ppstr, 1)) {
PrintAndLogEx(NORMAL, " (%s)", ppstr);
return;
}
+3 -1
View File
@@ -629,8 +629,10 @@ int blowfish_decrypt(uint8_t *iv, uint8_t *key, uint8_t *input, uint8_t *output,
mbedtls_blowfish_init(&blow);
if (mbedtls_blowfish_setkey(&blow, key, 64))
return 1;
if (mbedtls_blowfish_crypt_cbc(&blow, MBEDTLS_BLOWFISH_DECRYPT, length, iiv, input, output))
return 2;
mbedtls_blowfish_free(&blow);
return 0;
@@ -647,7 +649,7 @@ int ansi_x963_sha256(uint8_t *sharedSecret, size_t sharedSecretLen, uint8_t *sha
uint32_t counter = 0x00000001;
for (int i = 0; i < (keyDataLen / 32); ++i) {
uint8_t *hashMaterial = malloc(4 + sharedSecretLen + sharedInfoLen);
uint8_t *hashMaterial = calloc(4 + sharedSecretLen + sharedInfoLen, sizeof(uint8_t));
memcpy(hashMaterial, sharedSecret, sharedSecretLen);
hashMaterial[sharedSecretLen] = (counter >> 24);
hashMaterial[sharedSecretLen + 1] = (counter >> 16) & 0xFF;
+171 -79
View File
@@ -44,28 +44,30 @@ static int CmdHelp(const char *Cmd);
#define TLV_ADD(tag, value)( tlvdb_change_or_add_node(tlvRoot, tag, sizeof(value) - 1, (const unsigned char *)value) )
static void ParamLoadDefaults(struct tlvdb *tlvRoot) {
//9F02:(Amount, authorized (Numeric)) len:6
// 9F02:(Amount, authorized (Numeric)) len:6
TLV_ADD(0x9F02, "\x00\x00\x00\x00\x01\x00");
//9F1A:(Terminal Country Code) len:2
// 9F1A:(Terminal Country Code) len:2
TLV_ADD(0x9F1A, "ru");
//5F2A:(Transaction Currency Code) len:2
// 5F2A:(Transaction Currency Code) len:2
// USD 840, EUR 978, RUR 810, RUB 643, RUR 810(old), UAH 980, AZN 031, n/a 999
TLV_ADD(0x5F2A, "\x09\x80");
//9A:(Transaction Date) len:3
TLV_ADD(0x5F2A, "\x090\x78");
// 9A:(Transaction Date) len:3
TLV_ADD(0x9A, "\x00\x00\x00");
//9C:(Transaction Type) len:1 | 00 => Goods and service #01 => Cash
// 9C:(Transaction Type) len:1
// | 00 => Goods and Service
// | 01 => Cash
TLV_ADD(0x9C, "\x00");
// 9F37 Unpredictable Number len:4
// 9F37 Unpredictable Number (UN) len:4
TLV_ADD(0x9F37, "\x01\x02\x03\x04");
// 9F6A Unpredictable Number (MSD for UDOL) len:4
TLV_ADD(0x9F6A, "\x01\x02\x03\x04");
//9F66:(Terminal Transaction Qualifiers (TTQ)) len:4
// 9F66:(Terminal Transaction Qualifiers (TTQ)) len:4
TLV_ADD(0x9F66, "\x26\x00\x00\x00"); // qVSDC
//95:(Terminal Verification Results) len:5
// 95:(Terminal Verification Results) len:5
// all OK TVR
TLV_ADD(0x95, "\x00\x00\x00\x00\x00");
// 9F4E Merchant Name and Location len:x
TLV_ADD(0x9F4E, "proxmrk3rdv\x00");
TLV_ADD(0x9F4E, "proxmark3rdv4\x00");
}
static void PrintChannel(Iso7816CommandChannel channel) {
@@ -298,14 +300,14 @@ static int emv_parse_track1(const uint8_t *d, size_t n, bool verbose) {
case 0: {
size_t a = strlen(token);
if (a == 16) {
PrintAndLogEx(INFO, "PAN...................... %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c",
PrintAndLogEx(INFO, "PAN...................... " _GREEN_("%c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c"),
token[1], token[2], token[3], token[4],
token[5], token[6], token[7], token[8],
token[9], token[10], token[11], token[12],
token[13], token[14], token[15], token[16]
);
} else if (a == 19) {
PrintAndLogEx(INFO, "PAN...................... %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c",
PrintAndLogEx(INFO, "PAN...................... " _GREEN_("%c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c"),
token[1], token[2], token[3], token[4],
token[5], token[6], token[7], token[8],
token[9], token[10], token[11], token[12],
@@ -362,7 +364,7 @@ static int emv_parse_track2(const uint8_t *d, size_t n, bool verbose) {
if (tmp[0] == ';')
tmp++;
PrintAndLogEx(INFO, "PAN...................... %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c",
PrintAndLogEx(INFO, "PAN...................... "_GREEN_("%c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c"),
tmp[0], tmp[1], tmp[2], tmp[3],
tmp[4], tmp[5], tmp[6], tmp[7],
tmp[8], tmp[9], tmp[10], tmp[11],
@@ -479,7 +481,7 @@ static int emv_parse_card_details(uint8_t *response, size_t reslen, bool verbose
if (apan_full != NULL) {
const struct tlv *apan_tlv = tlvdb_get_tlv(apan_full);
if (apan_tlv->len == 8) {
PrintAndLogEx(INFO, "PAN.................. " _YELLOW_("%02x%02x %02x%02x %02x%02x %02x%02x"),
PrintAndLogEx(INFO, "PAN.................. " _GREEN_("%02x%02x %02x%02x %02x%02x %02x%02x"),
apan_tlv->value[0],
apan_tlv->value[1],
apan_tlv->value[2],
@@ -543,6 +545,33 @@ static int emv_parse_card_details(uint8_t *response, size_t reslen, bool verbose
// Track 3 Data
// to be impl.
// Unpredicable Number (UN)
struct tlvdb *un1_full = tlvdb_find_full(root, 0x9f37);
if (un1_full != NULL) {
const struct tlv *un1_tlv = tlvdb_get_tlv(un1_full);
if (un1_tlv->len) {
PrintAndLogEx(INFO, "9F37 Unpredicable Number... " _YELLOW_("%s"), sprint_hex_inrow(un1_tlv->value, un1_tlv->len));
}
}
// Unpredicable Number (UN)
struct tlvdb *un_full = tlvdb_find_full(root, 0x9f6a);
if (un_full != NULL) {
const struct tlv *un_tlv = tlvdb_get_tlv(un_full);
if (un_tlv->len) {
PrintAndLogEx(INFO, "9F6A Unpredicable Number... " _YELLOW_("%s"), sprint_hex_inrow(un_tlv->value, un_tlv->len));
emv_parse_track2(un_tlv->value, un_tlv->len, verbose);
}
}
struct tlvdb *merch_full = tlvdb_find_full(root, 0x9f4e);
if (merch_full != NULL) {
const struct tlv *merch_tlv = tlvdb_get_tlv(merch_full);
if (merch_tlv->len) {
PrintAndLogEx(INFO, "Merchant Name and Location... " _YELLOW_("%s"), sprint_hex_inrow(merch_tlv->value, merch_tlv->len));
}
}
tlvdb_free(root);
return PM3_SUCCESS;
}
@@ -571,7 +600,7 @@ static int CmdEMVSelect(const char *Cmd) {
bool activateField = arg_get_lit(ctx, 1);
bool leaveSignalON = arg_get_lit(ctx, 2);
bool APDULogging = arg_get_lit(ctx, 3);
bool show_apdu = arg_get_lit(ctx, 3);
bool decodeTLV = arg_get_lit(ctx, 4);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 5))
@@ -580,7 +609,7 @@ static int CmdEMVSelect(const char *Cmd) {
CLIGetHexWithReturn(ctx, 6, data, &datalen);
CLIParserFree(ctx);
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
// exec
uint8_t buf[APDU_RES_LEN] = {0};
@@ -597,6 +626,7 @@ static int CmdEMVSelect(const char *Cmd) {
if (decodeTLV)
TLVPrintFromBuffer(buf, len);
SetAPDULogging(false);
return PM3_SUCCESS;
}
@@ -621,7 +651,7 @@ static int CmdEMVSearch(const char *Cmd) {
bool activateField = arg_get_lit(ctx, 1);
bool leaveSignalON = arg_get_lit(ctx, 2);
bool APDULogging = arg_get_lit(ctx, 3);
bool show_apdu = arg_get_lit(ctx, 3);
bool decodeTLV = arg_get_lit(ctx, 4);
Iso7816CommandChannel channel = CC_CONTACTLESS;
@@ -632,13 +662,14 @@ static int CmdEMVSearch(const char *Cmd) {
PrintChannel(channel);
CLIParserFree(ctx);
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
const char *al = "Applets list";
struct tlvdb *t = tlvdb_fixed(1, strlen(al), (const unsigned char *)al);
if (EMVSearch(channel, activateField, leaveSignalON, decodeTLV, t, false)) {
tlvdb_free(t);
SetAPDULogging(false);
return PM3_ERFTRANS;
}
@@ -651,6 +682,7 @@ static int CmdEMVSearch(const char *Cmd) {
tlvdb_free(t);
SetAPDULogging(false);
return PM3_SUCCESS;
}
@@ -678,19 +710,23 @@ static int CmdEMVPPSE(const char *Cmd) {
bool activateField = arg_get_lit(ctx, 1);
bool leaveSignalON = arg_get_lit(ctx, 2);
uint8_t PSENum = 2;
if (arg_get_lit(ctx, 3))
if (arg_get_lit(ctx, 3)) {
PSENum = 1;
if (arg_get_lit(ctx, 4))
}
if (arg_get_lit(ctx, 4)) {
PSENum = 2;
bool APDULogging = arg_get_lit(ctx, 5);
}
bool show_apdu = arg_get_lit(ctx, 5);
bool decodeTLV = arg_get_lit(ctx, 6);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 7))
if (arg_get_lit(ctx, 7)) {
channel = CC_CONTACT;
}
PrintChannel(channel);
CLIParserFree(ctx);
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
// exec
uint8_t buf[APDU_RES_LEN] = {0};
@@ -707,6 +743,7 @@ static int CmdEMVPPSE(const char *Cmd) {
if (decodeTLV)
TLVPrintFromBuffer(buf, len);
SetAPDULogging(false);
return PM3_SUCCESS;
}
@@ -738,16 +775,17 @@ static int CmdEMVGPO(const char *Cmd) {
bool leaveSignalON = arg_get_lit(ctx, 1);
bool paramsLoadFromFile = arg_get_lit(ctx, 2);
bool dataMakeFromPDOL = arg_get_lit(ctx, 3);
bool APDULogging = arg_get_lit(ctx, 4);
bool show_apdu = arg_get_lit(ctx, 4);
bool decodeTLV = arg_get_lit(ctx, 5);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 6))
if (arg_get_lit(ctx, 6)) {
channel = CC_CONTACT;
}
PrintChannel(channel);
CLIGetHexWithReturn(ctx, 7, data, &datalen);
CLIParserFree(ctx);
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
// Init TLV tree
const char *alr = "Root terminal TLV tree";
@@ -775,6 +813,7 @@ static int CmdEMVGPO(const char *Cmd) {
PrintAndLogEx(ERR, "Can't create PDOL TLV.");
tlvdb_free(tmp_ext);
tlvdb_free(tlvRoot);
SetAPDULogging(false);
return PM3_ESOFT;
}
} else {
@@ -790,8 +829,10 @@ static int CmdEMVGPO(const char *Cmd) {
PrintAndLogEx(ERR, "Can't create PDOL data.");
tlvdb_free(tmp_ext);
tlvdb_free(tlvRoot);
if (pdol_data_tlv != &data_tlv)
if (pdol_data_tlv != &data_tlv) {
free(pdol_data_tlv);
}
SetAPDULogging(false);
return PM3_ESOFT;
}
PrintAndLogEx(INFO, "PDOL data[%zu]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
@@ -817,6 +858,7 @@ static int CmdEMVGPO(const char *Cmd) {
if (decodeTLV)
TLVPrintFromBuffer(buf, len);
SetAPDULogging(false);
return PM3_SUCCESS;
}
@@ -843,11 +885,12 @@ static int CmdEMVReadRecord(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool leaveSignalON = arg_get_lit(ctx, 1);
bool APDULogging = arg_get_lit(ctx, 2);
bool show_apdu = arg_get_lit(ctx, 2);
bool decodeTLV = arg_get_lit(ctx, 3);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 4))
if (arg_get_lit(ctx, 4)) {
channel = CC_CONTACT;
}
PrintChannel(channel);
CLIGetHexWithReturn(ctx, 5, data, &datalen);
CLIParserFree(ctx);
@@ -857,13 +900,14 @@ static int CmdEMVReadRecord(const char *Cmd) {
return PM3_EINVARG;
}
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
// exec
uint8_t buf[APDU_RES_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVReadRecord(channel, leaveSignalON, data[0], data[1], buf, sizeof(buf), &len, &sw, NULL);
SetAPDULogging(false);
if (sw)
PrintAndLogEx(INFO, "APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
@@ -910,14 +954,17 @@ static int CmdEMVAC(const char *Cmd) {
bool trTypeCDA = arg_get_lit(ctx, 2);
uint8_t termDecision = 0xff;
if (arg_get_str_len(ctx, 3)) {
if (!strncmp(arg_get_str(ctx, 3)->sval[0], "aac", 4))
if (!strncmp(arg_get_str(ctx, 3)->sval[0], "aac", 4)) {
termDecision = EMVAC_AAC;
if (!strncmp(arg_get_str(ctx, 3)->sval[0], "tc", 4))
}
if (!strncmp(arg_get_str(ctx, 3)->sval[0], "tc", 4)) {
termDecision = EMVAC_TC;
if (!strncmp(arg_get_str(ctx, 3)->sval[0], "arqc", 4))
}
if (!strncmp(arg_get_str(ctx, 3)->sval[0], "arqc", 4)) {
termDecision = EMVAC_ARQC;
}
if (termDecision == 0xff) {
if (termDecision == 0xFF) {
PrintAndLogEx(ERR, "ERROR: can't find terminal decision '%s'", arg_get_str(ctx, 3)->sval[0]);
CLIParserFree(ctx);
return PM3_EINVARG;
@@ -925,22 +972,25 @@ static int CmdEMVAC(const char *Cmd) {
} else {
termDecision = EMVAC_TC;
}
if (trTypeCDA)
if (trTypeCDA) {
termDecision = termDecision | EMVAC_CDAREQ;
}
bool paramsLoadFromFile = arg_get_lit(ctx, 4);
bool dataMakeFromCDOL = arg_get_lit(ctx, 5);
bool APDULogging = arg_get_lit(ctx, 6);
bool show_apdu = arg_get_lit(ctx, 6);
bool decodeTLV = arg_get_lit(ctx, 7);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 8))
if (arg_get_lit(ctx, 8)) {
channel = CC_CONTACT;
}
PrintChannel(channel);
CLIGetHexWithReturn(ctx, 9, data, &datalen);
CLIParserFree(ctx);
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
// Init TLV tree
const char *alr = "Root terminal TLV tree";
@@ -969,6 +1019,7 @@ static int CmdEMVAC(const char *Cmd) {
PrintAndLogEx(ERR, "Can't create CDOL TLV.");
tlvdb_free(tmp_ext);
tlvdb_free(tlvRoot);
SetAPDULogging(false);
return PM3_ESOFT;
}
} else {
@@ -985,6 +1036,7 @@ static int CmdEMVAC(const char *Cmd) {
size_t len = 0;
uint16_t sw = 0;
int res = EMVAC(channel, leaveSignalON, termDecision, (uint8_t *)cdol_data_tlv->value, cdol_data_tlv->len, buf, sizeof(buf), &len, &sw, tlvRoot);
SetAPDULogging(false);
if (cdol_data_tlv != &data_tlv)
free(cdol_data_tlv);
@@ -1023,20 +1075,22 @@ static int CmdEMVGenerateChallenge(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool leaveSignalON = arg_get_lit(ctx, 1);
bool APDULogging = arg_get_lit(ctx, 2);
bool show_apdu = arg_get_lit(ctx, 2);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 3))
if (arg_get_lit(ctx, 3)) {
channel = CC_CONTACT;
}
PrintChannel(channel);
CLIParserFree(ctx);
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
// exec
uint8_t buf[APDU_RES_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVGenerateChallenge(channel, leaveSignalON, buf, sizeof(buf), &len, &sw, NULL);
SetAPDULogging(false);
if (sw)
PrintAndLogEx(INFO, "APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
@@ -1046,8 +1100,9 @@ static int CmdEMVGenerateChallenge(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Challenge: %s", sprint_hex(buf, len));
if (len != 4 && len != 8)
PrintAndLogEx(WARNING, "Length of challenge must be 4 or 8, but it %zu", len);
if (len != 4 && len != 8) {
PrintAndLogEx(WARNING, "Length of challenge must be 4 or 8, got " _YELLOW_("%zu"), len);
}
return PM3_SUCCESS;
}
@@ -1081,16 +1136,17 @@ static int CmdEMVInternalAuthenticate(const char *Cmd) {
bool leaveSignalON = arg_get_lit(ctx, 1);
bool paramsLoadFromFile = arg_get_lit(ctx, 2);
bool dataMakeFromDDOL = arg_get_lit(ctx, 3);
bool APDULogging = arg_get_lit(ctx, 4);
bool show_apdu = arg_get_lit(ctx, 4);
bool decodeTLV = arg_get_lit(ctx, 5);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 6))
if (arg_get_lit(ctx, 6)) {
channel = CC_CONTACT;
}
PrintChannel(channel);
CLIGetHexWithReturn(ctx, 7, data, &datalen);
CLIParserFree(ctx);
SetAPDULogging(APDULogging);
SetAPDULogging(show_apdu);
// Init TLV tree
const char *alr = "Root terminal TLV tree";
@@ -1119,6 +1175,7 @@ static int CmdEMVInternalAuthenticate(const char *Cmd) {
PrintAndLogEx(ERR, "Can't create DDOL TLV.");
tlvdb_free(tmp_ext);
tlvdb_free(tlvRoot);
SetAPDULogging(false);
return PM3_ESOFT;
}
} else {
@@ -1135,6 +1192,7 @@ static int CmdEMVInternalAuthenticate(const char *Cmd) {
size_t len = 0;
uint16_t sw = 0;
int res = EMVInternalAuthenticate(channel, leaveSignalON, data, datalen, buf, sizeof(buf), &len, &sw, NULL);
SetAPDULogging(false);
if (ddol_data_tlv != &data_tlv)
free(ddol_data_tlv);
@@ -1154,7 +1212,14 @@ static int CmdEMVInternalAuthenticate(const char *Cmd) {
return PM3_SUCCESS;
}
#define dreturn(n) {free(pdol_data_tlv); tlvdb_free(tlvSelect); tlvdb_free(tlvRoot); DropFieldEx( channel ); return n;}
#define dreturn(n) { \
free(pdol_data_tlv); \
tlvdb_free(tlvSelect); \
tlvdb_free(tlvRoot); \
DropFieldEx( channel ); \
SetAPDULogging(false); \
return n; \
}
static void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum TransactionType TrType, bool GenACGPO) {
@@ -1297,21 +1362,24 @@ static int CmdEMVExec(const char *Cmd) {
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool activateField = arg_get_lit(ctx, 1);
bool showAPDU = arg_get_lit(ctx, 2);
bool show_apdu = arg_get_lit(ctx, 2);
bool decodeTLV = arg_get_lit(ctx, 3);
bool paramLoadJSON = arg_get_lit(ctx, 4);
bool forceSearch = arg_get_lit(ctx, 5);
enum TransactionType TrType = TT_MSD;
if (arg_get_lit(ctx, 7))
if (arg_get_lit(ctx, 7)) {
TrType = TT_QVSDCMCHIP;
}
if (arg_get_lit(ctx, 8))
if (arg_get_lit(ctx, 8)) {
TrType = TT_CDA;
}
if (arg_get_lit(ctx, 9))
if (arg_get_lit(ctx, 9)) {
TrType = TT_VSDC;
}
bool GenACGPO = arg_get_lit(ctx, 10);
@@ -1324,14 +1392,14 @@ static int CmdEMVExec(const char *Cmd) {
uint8_t psenum = (channel == CC_CONTACT) ? 1 : 2;
CLIParserFree(ctx);
if (!IfPm3Smartcard()) {
if (IfPm3Smartcard() == false) {
if (channel == CC_CONTACT) {
PrintAndLogEx(WARNING, "PM3 does not have SMARTCARD support. Exiting.");
return PM3_EDEVNOTSUPP;
}
}
SetAPDULogging(showAPDU);
SetAPDULogging(show_apdu);
uint8_t buf[APDU_RES_LEN] = {0};
size_t len = 0;
@@ -1357,7 +1425,7 @@ static int CmdEMVExec(const char *Cmd) {
// PPSE
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "* PPSE.");
SetAPDULogging(showAPDU);
SetAPDULogging(show_apdu);
res = EMVSearchPSE(channel, activateField, true, psenum, decodeTLV, tlvSelect);
// check PPSE instead of PSE and vice versa
@@ -1398,7 +1466,7 @@ static int CmdEMVExec(const char *Cmd) {
// Select
PrintAndLogEx(INFO, "\n* Selecting AID:%s", sprint_hex_inrow(AID, AIDlen));
SetAPDULogging(showAPDU);
SetAPDULogging(show_apdu);
res = EMVSelect(channel, false, true, AID, AIDlen, buf, sizeof(buf), &len, &sw, tlvRoot);
if (res) {
@@ -1406,8 +1474,9 @@ static int CmdEMVExec(const char *Cmd) {
dreturn(PM3_ERFTRANS);
}
if (decodeTLV)
if (decodeTLV) {
TLVPrintFromBuffer(buf, len);
}
PrintAndLogEx(INFO, "* Selected.");
PrintAndLogEx(INFO, "\n* Init transaction parameters.");
@@ -1462,8 +1531,9 @@ static int CmdEMVExec(const char *Cmd) {
PrintAndLogEx(INFO, "\n* Read records from AFL.");
const struct tlv *AFL = tlvdb_get(tlvRoot, 0x94, NULL);
if (!AFL || !AFL->len)
if (!AFL || !AFL->len) {
PrintAndLogEx(WARNING, "WARNING: AFL not found.");
}
while (AFL && AFL->len) {
if (AFL->len % 4) {
@@ -1584,19 +1654,24 @@ static int CmdEMVExec(const char *Cmd) {
TLVPrintFromTLVLev(cvr, 1);
PrintAndLogEx(INFO, " IDD option id: 0x%02x", IAD->value[8]);
PrintAndLogEx(INFO, " IDD: %s", sprint_hex(&IAD->value[9], 23));
} else if (IAD->len >= IAD->value[0] + 1) {
PrintAndLogEx(INFO, " Key index: 0x%02x", IAD->value[1]);
PrintAndLogEx(INFO, " Crypto ver: 0x%02x(%03d)", IAD->value[2], IAD->value[2]);
PrintAndLogEx(INFO, " CVR: %s", sprint_hex(&IAD->value[3], IAD->value[0] - 2));
struct tlvdb *cvr = tlvdb_fixed(0x20, IAD->value[0] - 2, &IAD->value[3]);
TLVPrintFromTLVLev(cvr, 1);
if (IAD->len >= 8) {
int iddLen = IAD->value[7];
PrintAndLogEx(NORMAL, " IDD length: %d", iddLen);
if (iddLen >= 1)
if (iddLen >= 1) {
PrintAndLogEx(NORMAL, " IDD option id: 0x%02x", IAD->value[8]);
if (iddLen >= 2)
}
if (iddLen >= 2) {
PrintAndLogEx(NORMAL, " IDD: %s", sprint_hex(&IAD->value[9], iddLen - 1));
}
}
}
} else {
@@ -1611,6 +1686,7 @@ static int CmdEMVExec(const char *Cmd) {
// Mastercard M/CHIP
if (GetCardPSVendor(AID, AIDlen) == CV_MASTERCARD && (TrType == TT_QVSDCMCHIP || TrType == TT_CDA)) {
const struct tlv *CDOL1 = tlvdb_get(tlvRoot, 0x8c, NULL);
if (CDOL1 && GetCardPSVendor(AID, AIDlen) == CV_MASTERCARD) { // and m/chip transaction flag
PrintAndLogEx(INFO, "\n--> Mastercard M/Chip transaction.");
@@ -1621,6 +1697,7 @@ static int CmdEMVExec(const char *Cmd) {
PrintAndLogEx(ERR, "Error GetChallenge. APDU error %4x", sw);
dreturn(PM3_ERFTRANS);
}
if (len < 4) {
PrintAndLogEx(ERR, "Error GetChallenge. Wrong challenge length %zu", len);
dreturn(PM3_ESOFT);
@@ -1651,8 +1728,9 @@ static int CmdEMVExec(const char *Cmd) {
dreturn(PM3_ERFTRANS);
}
if (decodeTLV)
if (decodeTLV) {
TLVPrintFromBuffer(buf, len);
}
// CDA
PrintAndLogEx(INFO, "\n* CDA:");
@@ -1675,7 +1753,8 @@ static int CmdEMVExec(const char *Cmd) {
if (CID) {
emv_tag_dump(CID, 1);
PrintAndLogEx(INFO, "------------------------------");
if (CID->len > 0) {
if (CID->len) {
switch (CID->value[0] & EMVAC_AC_MASK) {
case EMVAC_AAC:
PrintAndLogEx(INFO, "Transaction DECLINED.");
@@ -1725,8 +1804,9 @@ static int CmdEMVExec(const char *Cmd) {
.len = 3,
.value = (uint8_t *)"\x9f\x6a\x04",
};
if (!UDOL)
if (!UDOL) {
PrintAndLogEx(INFO, "Use default UDOL.");
}
struct tlv *udol_data_tlv = dol_process(UDOL ? UDOL : &defUDOL, tlvRoot, 0x01); // 0x01 - dummy tag
if (!udol_data_tlv) {
@@ -1801,6 +1881,7 @@ static int CmdEMVExec(const char *Cmd) {
uint8_t IDDlen = 0; // Issuer discretionary data length
PrintAndLogEx(INFO, "IAD length: %zu", IAD->len);
PrintAndLogEx(INFO, "VDDlen: %d", VDDlen);
if (VDDlen < IAD->len - 1) {
IDDlen = IAD->value[VDDlen + 1];
}
@@ -1822,9 +1903,11 @@ static int CmdEMVExec(const char *Cmd) {
PrintAndLogEx(WARNING, "Wrong CVR length! CVR: %s", sprint_hex(&IAD->value[3], VDDlen - 2));
}
}
if (IDDlen) {
PrintAndLogEx(INFO, "IDD: %s", sprint_hex(&IAD->value[VDDlen + 1], IDDlen));
}
} else {
PrintAndLogEx(WARNING, "Issuer Application Data (IAD) not found.");
}
@@ -1898,6 +1981,7 @@ static int CmdEMVExec(const char *Cmd) {
tlvdb_free(tlvRoot);
PrintAndLogEx(SUCCESS, "\n* Transaction completed.");
SetAPDULogging(false);
return PM3_SUCCESS;
}
@@ -1928,25 +2012,29 @@ static int CmdEMVScan(const char *Cmd) {
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool showAPDU = arg_get_lit(ctx, 1);
bool show_apdu = arg_get_lit(ctx, 1);
bool decodeTLV = arg_get_lit(ctx, 2);
bool extractTLVElements = arg_get_lit(ctx, 3);
bool paramLoadJSON = arg_get_lit(ctx, 4);
enum TransactionType TrType = TT_MSD;
if (arg_get_lit(ctx, 6))
if (arg_get_lit(ctx, 6)) {
TrType = TT_QVSDCMCHIP;
if (arg_get_lit(ctx, 7))
}
if (arg_get_lit(ctx, 7)) {
TrType = TT_CDA;
if (arg_get_lit(ctx, 8))
}
if (arg_get_lit(ctx, 8)) {
TrType = TT_VSDC;
}
bool GenACGPO = arg_get_lit(ctx, 9);
bool MergeJSON = arg_get_lit(ctx, 10);
Iso7816CommandChannel channel = CC_CONTACTLESS;
if (arg_get_lit(ctx, 11))
if (arg_get_lit(ctx, 11)) {
channel = CC_CONTACT;
}
PrintChannel(channel);
@@ -1958,15 +2046,13 @@ static int CmdEMVScan(const char *Cmd) {
CLIParserFree(ctx);
if (!IfPm3Smartcard()) {
if (IfPm3Smartcard() == false) {
if (channel == CC_CONTACT) {
PrintAndLogEx(WARNING, "PM3 does not have SMARTCARD support, exiting");
return PM3_EDEVNOTSUPP;
}
}
SetAPDULogging(showAPDU);
uint8_t AID[APDU_AID_LEN] = {0};
size_t AIDlen = 0;
uint8_t buf[APDU_RES_LEN] = {0};
@@ -1996,6 +2082,8 @@ static int CmdEMVScan(const char *Cmd) {
root = json_object();
}
SetAPDULogging(show_apdu);
// drop field at start
DropFieldEx(channel);
@@ -2073,7 +2161,7 @@ static int CmdEMVScan(const char *Cmd) {
}
// EMV SELECT application
SetAPDULogging(showAPDU);
SetAPDULogging(show_apdu);
EMVSelectApplication(tlvSelect, AID, &AIDlen);
tlvdb_free(tlvSelect);
@@ -2093,7 +2181,7 @@ static int CmdEMVScan(const char *Cmd) {
// EMV SELECT applet
PrintAndLogEx(INFO, "Selecting AID: " _GREEN_("%s"), sprint_hex_inrow(AID, AIDlen));
SetAPDULogging(showAPDU);
SetAPDULogging(show_apdu);
res = EMVSelect(channel, false, true, AID, AIDlen, buf, sizeof(buf), &len, &sw, tlvRoot);
if (res) {
@@ -2184,10 +2272,12 @@ static int CmdEMVScan(const char *Cmd) {
sfijson = json_path_get(root, "$.Application.Records");
}
if (!json_is_array(sfijson)) {
PrintAndLogEx(ERR, "Internal logic error. `$.Application.Records` is not an array.");
break;
}
for (int i = 0; i < AFL->len / 4; i++) {
uint8_t SFI = AFL->value[i * 4 + 0] >> 3;
uint8_t SFIstart = AFL->value[i * 4 + 1];
@@ -2243,11 +2333,11 @@ static int CmdEMVScan(const char *Cmd) {
JsonSaveHex(jsonelm, "Offline", SFIoffline, 1);
struct tlvdb *rsfi = tlvdb_parse_multi(buf, len);
if (extractTLVElements)
if (extractTLVElements) {
JsonSaveTLVTree(root, jsonelm, "$.Data", rsfi);
else
} else {
JsonSaveTLVTreeElm(jsonelm, "$.Data", rsfi, true, true, false);
}
tlvdb_free(rsfi);
}
}
@@ -2273,7 +2363,7 @@ static int CmdEMVScan(const char *Cmd) {
tlvdb_free(tlvRoot);
DropFieldEx(channel);
SetAPDULogging(false);
if (MergeJSON == false) {
// create unique new name
@@ -2356,7 +2446,7 @@ static int CmdEMVRoca(const char *Cmd) {
CLIParserFree(ctx);
PrintChannel(channel);
if (!IfPm3Smartcard()) {
if (IfPm3Smartcard() == false) {
if (channel == CC_CONTACT) {
PrintAndLogEx(WARNING, "PM3 does not have SMARTCARD support, exiting");
return PM3_EDEVNOTSUPP;
@@ -2395,6 +2485,7 @@ static int CmdEMVRoca(const char *Cmd) {
PrintAndLogEx(ERR, "Can't found any of EMV AID, exiting");
tlvdb_free(tlvSelect);
DropFieldEx(channel);
SetAPDULogging(false);
return PM3_ERFTRANS;
}
@@ -2590,6 +2681,7 @@ static int CmdEMVRoca(const char *Cmd) {
}
out:
SetAPDULogging(false);
tlvdb_free(tlvRoot);
DropFieldEx(channel);
return ret;
@@ -2685,7 +2777,6 @@ static int CmdEMVReader(const char *Cmd) {
uint8_t log_file_records = 31;
struct tlvdb *tlogDB = NULL;
// try getting the LOG TEMPLATE.
bool log_found = false;
bool log_template_found = false;
@@ -2777,8 +2868,9 @@ static int CmdEMVReader(const char *Cmd) {
continue;
}
if (sw == 0x6A83)
if (sw == 0x6A83) {
break;
}
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, "Transaction log # " _YELLOW_("%u"), i);
+1 -1
View File
@@ -37,7 +37,7 @@ void PKISetStrictExecution(bool se) {
strictExecution = se;
}
static const unsigned char empty_tlv_value[] = {};
static const unsigned char empty_tlv_value[] = {0};
static const struct tlv empty_tlv = {.tag = 0x0, .len = 0, .value = empty_tlv_value};
static size_t emv_pki_hash_psn[256] = { 0, 0, 11, 2, 17, 2, };
+2
View File
@@ -822,9 +822,11 @@ bool emv_tag_dump(const struct tlv *tlv, int level) {
emv_tag_dump_string(tlv, tag, level);
break;
case EMV_TAG_NUMERIC:
PrintAndLogEx(NORMAL, "");
emv_tag_dump_numeric(tlv, tag, level);
break;
case EMV_TAG_YYMMDD:
PrintAndLogEx(NORMAL, "");
emv_tag_dump_yymmdd(tlv, tag, level);
break;
case EMV_TAG_CVR:
+2 -1
View File
@@ -22,6 +22,7 @@
#define TLV_H
#include "common.h"
#include <stdbool.h>
typedef uint32_t tlv_tag_t;
@@ -41,7 +42,7 @@ struct tlvdb {
struct tlvdb_root {
struct tlvdb db;
size_t len;
unsigned char buf[0];
unsigned char buf[];
};
typedef void (*tlv_cb)(void *data, const struct tlv *tlv, int level, bool is_leaf);
+930 -222
View File
File diff suppressed because it is too large. Load diff
+76 -25
View File
@@ -29,15 +29,34 @@
#include "mifare/mifarehost.h"
#include "cmdhfmfu.h"
#include "protocols.h" // iclass defines
#include "cmdhftopaz.h" // TOPAZ defines
#include "mifare/mifaredefault.h" // MFP / AES defines
typedef union {
void *v;
uint8_t *bytes;
mfu_dump_t *mfu;
topaz_tag_t *topaz;
iso14a_mf_extdump_t *mfc;
iso14a_mf_dump_ev1_t *mfc_ev1;
} udata_t;
typedef enum {
jsfRaw,
jsfCardMemory,
jsfMfc_v2,
jsfMfc_v3,
jsfMfuMemory,
jsfHitag,
jsfIclass,
jsf14b,
jsf14b_v2,
jsf15,
jsf15_v2,
jsf15_v3,
jsfLegic,
jsfLegic_v2,
jsfT55x7,
jsfT5555,
jsfMfPlusKeys,
@@ -49,6 +68,9 @@ typedef enum {
jsfFido,
jsfFudan,
jsfTopaz,
jsfLto,
jsfCryptorf,
jsfNDEF,
} JSONFileType;
typedef enum {
@@ -57,8 +79,27 @@ typedef enum {
JSON,
DICTIONARY,
MCT,
FLIPPER,
} DumpFileType_t;
typedef enum {
MFU_DF_UNKNOWN,
MFU_DF_PLAINBIN,
MFU_DF_OLDBIN,
MFU_DF_NEWBIN
} mfu_df_e;
typedef enum {
NFC_DF_UNKNOWN,
NFC_DF_MFC,
NFC_DF_MFU,
NFC_DF_MFDES,
NFC_DF_14_3A,
NFC_DF_14_3B,
NFC_DF_14_4A,
NFC_DF_PICOPASS,
} nfc_df_e;
int fileExists(const char *filename);
// set a path in the path list g_session.defaultPaths
@@ -80,19 +121,6 @@ char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePath
*/
int saveFile(const char *preferredName, const char *suffix, const void *data, size_t datalen);
/**
* @brief Utility function to save data to a textfile (EML). This method takes a preferred name, but if that
* file already exists, it tries with another name until it finds something suitable.
* E.g. dumpdata-15.txt
*
* @param preferredName
* @param data The binary data to write to the file
* @param datalen the length of the data
* @param blocksize the length of one row
* @return 0 for ok, 1 for failz
*/
int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t blocksize);
/** STUB
* @brief Utility function to save JSON data to a file. This method takes a preferred name, but if that
* file already exists, it tries with another name until it finds something suitable.
@@ -176,6 +204,19 @@ int loadFileEML_safe(const char *preferredName, void **pdata, size_t *datalen);
*/
int loadFileMCT_safe(const char *preferredName, void **pdata, size_t *datalen);
/**
* @brief Utility function to load data from a textfile (NFC). This method takes a preferred name.
* E.g. dumpdata-15.nfc
*
* @param preferredName
* @param data The data array to store the loaded bytes from file
* @param maxdatalen maximum size of data array in bytes
* @param datalen the number of bytes loaded from file
* @param ft
* @return 0 for ok, 1 for failz
*/
int loadFileNFC_safe(const char *preferredName, void *data, size_t maxdatalen, size_t *datalen, nfc_df_e ft);
/**
* @brief Utility function to load data from a JSON textfile. This method takes a preferred name.
* E.g. dumpdata-15.json
@@ -235,12 +276,6 @@ int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t key
int loadFileBinaryKey(const char *preferredName, const char *suffix, void **keya, void **keyb, size_t *alen, size_t *blen);
typedef enum {
MFU_DF_UNKNOWN,
MFU_DF_PLAINBIN,
MFU_DF_OLDBIN,
MFU_DF_NEWBIN
} mfu_df_e;
/**
* @brief Utility function to check and convert plain mfu dump format to new mfu binary format.
* plain dumps doesn't have any extra data, like version, signature etc.
@@ -250,7 +285,8 @@ typedef enum {
* @return PM3_SUCCESS for ok, PM3_ESOFT for fails
*/
int convert_mfu_dump_format(uint8_t **dump, size_t *dumplen, bool verbose);
mfu_df_e detect_mfu_dump_format(uint8_t **dump, size_t *dumplen, bool verbose);
mfu_df_e detect_mfu_dump_format(uint8_t **dump, bool verbose);
nfc_df_e detect_nfc_dump_format(const char *preferredName, bool verbose);
int searchAndList(const char *pm3dir, const char *ext);
int searchFile(char **foundpath, const char *pm3dir, const char *searchname, const char *suffix, bool silent);
@@ -276,18 +312,33 @@ int pm3_load_dump(const char *fn, void **pdump, size_t *dumplen, size_t maxdumpl
/** STUB
* @brief Utility function to save data to three file files (BIN/EML/JSON).
* @brief Utility function to save data to three file files (BIN/JSON).
* It also tries to save according to user preferences set dump folder paths.
* E.g. dumpdata.bin
* E.g. dumpdata.eml
* E.g. dumpdata.json
*
* @param fn
* @param d The binary data to write to the file
* @param n the length of the data
* @param jsft json format type for the different memory cards (MFC, MFUL, LEGIC, 14B, 15, ICLASS etc)
* @param blocksize
* @return PM3_SUCCESS if OK
*/
int pm3_save_dump(const char *fn, uint8_t *d, size_t n, JSONFileType jsft, size_t blocksize);
int pm3_save_dump(const char *fn, uint8_t *d, size_t n, JSONFileType jsft);
/** STUB
* @brief Utility function to save data to three file files (BIN/JSON).
* It also tries to save according to user preferences set dump folder paths.
* E.g. dumpdata.bin
* E.g. dumpdata.json
*
* This function is dedicated for MIFARE CLASSIC dumps. Checking for 4 or 7 byte UID in indata.
* Saves the corrected data in the json file
*
* @param fn
* @param d The binary data to write to the file
* @param n the length of the data
* @param jsft json format type for the different memory cards (MFC, MFUL, LEGIC, 14B, 15, ICLASS etc)
* @return PM3_SUCCESS if OK
*/
int pm3_save_mf_dump(const char *fn, uint8_t *d, size_t n, JSONFileType jsft);
#endif // FILEUTILS_H
+5
View File
@@ -133,6 +133,11 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool l
res = ExchangeAPDU14a(data, datalen, activate_field, leave_field_on, result, (int)max_result_len, (int *)result_len);
if (res != PM3_SUCCESS) {
res = exchange_14b_apdu(data, datalen, activate_field, leave_field_on, result, (int)max_result_len, (int *)result_len, 4000);
if (res == PM3_SUCCESS) {
PrintAndLogEx(INFO, "Testing ISO14443-B... ( " _GREEN_("ok") " )");
} else {
PrintAndLogEx(INFO, "Testing ISO14443-B... ( " _RED_("fail") " )");
}
}
break;
}
+10 -13
View File
@@ -108,20 +108,20 @@ typedef struct {
return r->value; \
}
MAKE_ENUM_TYPE(uint8_t);
MAKE_ENUM_TYPE(uint8_t)
// KSX6924LookupCardType
MAKE_ENUM_CONST(CardType, uint8_t,
{ 0x00, "Pre-paid" },
{ 0x10, "Post-pay" },
{ 0x20, "Mobile post-pay" },
);
)
// KSX6924LookupAlg
MAKE_ENUM_CONST(Alg, uint8_t,
{ 0x00, "SEED" },
{ 0x10, "3DES" },
);
)
// KSX6924LookupTMoneyIDCenter
MAKE_ENUM_CONST(TMoneyIDCenter, uint8_t,
@@ -139,20 +139,17 @@ MAKE_ENUM_CONST(TMoneyIDCenter, uint8_t,
{ 0x0b, "EB Card Corporation" },
{ 0x0c, "Seoul Bus Transport Association" },
{ 0x0d, "Cardnet" },
);
)
// KSX6924LookupTMoneyUserCode
MAKE_ENUM_CONST(TMoneyUserCode, uint8_t,
{ 0x01, "Regular/normal" },
{ 0x02, "Child" },
{ 0x04, "Youth" },
{ 0x06, "elderly" },
{ 0x0f, "Test" },
{ 0xff, "Inactive" },
);
)
// KSX6924LookupTMoneyDisRate
MAKE_ENUM_CONST(TMoneyDisRate, uint8_t,
@@ -163,7 +160,7 @@ MAKE_ENUM_CONST(TMoneyDisRate, uint8_t,
{ 0x20, "Merit, basic" },
{ 0x21, "Merit, companion" },
);
)
// KSX6924LookupTMoneyTCode
MAKE_ENUM_CONST(TMoneyTCode, uint8_t,
@@ -171,7 +168,7 @@ MAKE_ENUM_CONST(TMoneyTCode, uint8_t,
{ 0x01, "SK Telecom" },
{ 0x02, "Korea Telecom" },
{ 0x03, "LG Uplus" },
);
)
// KSX6924LookupTMoneyCCode
MAKE_ENUM_CONST(TMoneyCCode, uint8_t,
@@ -187,7 +184,7 @@ MAKE_ENUM_CONST(TMoneyCCode, uint8_t,
{ 0x09, "Woori Card" },
{ 0x0a, "Hana SK Card" },
{ 0x0b, "Hyundai Card" },
);
)
static const char *KSX6924_UNKNOWN = "Unknown";
@@ -320,7 +317,7 @@ bool KSX6924ParsePurseInfo(const uint8_t *purseInfo, size_t purseLen, struct ksx
// TODO
return true;
};
}
/**
* Prints out a ksx6924_purse_info
@@ -523,7 +520,7 @@ bool KSX6924ParseInitializeCardResponse(const uint8_t *initCardResponse, size_t
// TODO
return true;
};
}
/**
* Prints out a Initialize Card response
+3 -2
View File
@@ -43,6 +43,7 @@
#include "mifare/mad.h"
#include "mifare/aiddesfire.h"
const CLIParserOption DesfireAlgoOpts[] = {
{T_DES, "des"},
{T_3DES, "2tdea"},
@@ -1749,7 +1750,7 @@ int DesfireFillAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS ap
memcpy(
appList[indx].appDFName,
&buf[i * 24 + 1 + 5],
// strnlen((char *)&buf[i * 24 + 1 + 5], 16)
// str_nlen((char *)&buf[i * 24 + 1 + 5], 16)
16
);
}
@@ -2879,7 +2880,7 @@ int DesfireISOSelect(DesfireContext_t *dctx, DesfireISOSelectControl cntr, uint8
}
int DesfireISOSelectDF(DesfireContext_t *dctx, char *dfname, uint8_t *resp, size_t *resplen) {
return DesfireISOSelect(dctx, ISSDFName, (uint8_t *)dfname, strnlen(dfname, 16), resp, resplen);
return DesfireISOSelect(dctx, ISSDFName, (uint8_t *)dfname, str_nlen(dfname, 16), resp, resplen);
}
int DesfireISOGetChallenge(DesfireContext_t *dctx, DesfireCryptoAlgorithm keytype, uint8_t *resp, size_t *resplen) {
+2 -2
View File
@@ -788,11 +788,11 @@ bool desfire_crc32_check(uint8_t *data, const size_t len, uint8_t *crc) {
}
void iso14443a_crc_append(uint8_t *data, size_t len) {
return compute_crc(CRC_14443_A, data, len, data + len, data + len + 1);
compute_crc(CRC_14443_A, data, len, data + len, data + len + 1);
}
void iso14443a_crc(uint8_t *data, size_t len, uint8_t *pbtCrc) {
return compute_crc(CRC_14443_A, data, len, pbtCrc, pbtCrc + 1);
compute_crc(CRC_14443_A, data, len, pbtCrc, pbtCrc + 1);
}
bool iso14443a_crc_check(uint8_t *data, const size_t len, uint8_t *crc) {
+212
View File
@@ -0,0 +1,212 @@
//-----------------------------------------------------------------------------
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// Common functionality for low/high-frequency GALLAGHER tag encoding & decoding.
//-----------------------------------------------------------------------------
#include "gen4.h"
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "commonutil.h"
#include "util.h"
#include "ui.h"
#include "mifaredefault.h"
#include "comms.h"
#include "cmdhf14a.h"
#include "protocols.h"
#include "mfkey.h"
#include "util_posix.h"
#include "cmdparser.h"
static int mfG4ExCommand(uint8_t cmd, uint8_t *pwd, uint8_t *data, size_t datalen, uint8_t *response, size_t *responselen, bool verbose) {
struct p {
uint8_t cmdheader;
uint8_t pwd[4];
uint8_t command;
uint8_t data[32];
} PACKED payload;
memset(&payload, 0, sizeof(payload));
if (datalen > sizeof(payload.data)) {
return PM3_EINVARG;
}
payload.cmdheader = 0xCF;
payload.command = cmd;
if (pwd != NULL) {
memcpy(payload.pwd, pwd, sizeof(payload.pwd));
}
if (data != NULL && datalen > 0) {
memcpy(payload.data, data, datalen);
}
int resplen = 0;
clearCommandBuffer();
SendCommandOLD(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_RAW | ISO14A_NO_RATS | ISO14A_APPEND_CRC, 6 + datalen, 0, (uint8_t *)&payload, 6 + datalen);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
if (resp.oldarg[0] != 2) {
if (verbose) PrintAndLogEx(ERR, "No card in the field.");
return PM3_ETIMEOUT;
}
iso14a_card_select_t card;
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
if (verbose) {
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card.uid, card.uidlen));
PrintAndLogEx(SUCCESS, "ATQA: " _GREEN_("%02X %02X"), card.atqa[1], card.atqa[0]);
PrintAndLogEx(SUCCESS, " SAK: " _GREEN_("%02X [%" PRIu64 "]"), card.sak, resp.oldarg[0]);
}
} else {
if (verbose) PrintAndLogEx(ERR, "No card in the field.");
return PM3_ETIMEOUT;
}
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
resplen = resp.oldarg[0];
if (!resplen) {
if (verbose) PrintAndLogEx(ERR, "No card response.");
return PM3_EFAILED;
}
resplen = resplen - 2; // 14A CRC
if (resplen < 0)
resplen = 0;
if (resplen > 40) {
if (verbose) PrintAndLogEx(ERR, "Buffer too small(%d).", resplen);
return PM3_EOVFLOW;
}
if (response != NULL)
memcpy(response, resp.data.asBytes, resplen);
if (responselen != NULL)
*responselen = resplen;
return PM3_SUCCESS;
} else {
if (verbose) PrintAndLogEx(ERR, "Reply timeout.");
return PM3_ETIMEOUT;
}
}
int mfG4GetConfig(uint8_t *pwd, uint8_t *data, size_t *datalen, bool verbose) {
uint8_t resp[40] = {0};
size_t resplen = 0;
int res = mfG4ExCommand(GEN4_CMD_DUMP_CONFIG, pwd, NULL, 0, resp, &resplen, verbose);
if (res != PM3_SUCCESS) {
return res;
}
if (data != NULL)
memcpy(data, resp, resplen);
if (datalen != NULL)
*datalen = resplen;
return PM3_SUCCESS;
}
int mfG4GetFactoryTest(uint8_t *pwd, uint8_t *data, size_t *datalen, bool verbose) {
uint8_t resp[40] = {0};
size_t resplen = 0;
int res = mfG4ExCommand(GEN4_CMD_FACTORY_TEST, pwd, NULL, 0, resp, &resplen, verbose);
if (res != PM3_SUCCESS) {
return res;
}
if (data != NULL)
memcpy(data, resp, resplen);
if (datalen != NULL)
*datalen = resplen;
return PM3_SUCCESS;
}
int mfG4ChangePassword(uint8_t *pwd, uint8_t *newpwd, bool verbose) {
uint8_t resp[40] = {0};
size_t resplen = 0;
int res = mfG4ExCommand(GEN4_CMD_CHANGE_PASSWORD, pwd, newpwd, 4, resp, &resplen, verbose);
if (res != PM3_SUCCESS) {
return res;
}
if (resplen != 2 || resp[0] != 0x90 || resp[1] != 0x00)
return PM3_EAPDU_FAIL;
return PM3_SUCCESS;
}
int mfG4GetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags) {
struct p {
uint8_t blockno;
uint8_t pwd[4];
uint8_t workFlags;
} PACKED payload;
payload.blockno = blockno;
memcpy(payload.pwd, pwd, sizeof(payload.pwd));
payload.workFlags = workFlags;
clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_G4_RDBL, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_MIFARE_G4_RDBL, &resp, 1500)) {
if (resp.status != PM3_SUCCESS) {
return PM3_EUNDEF;
}
memcpy(data, resp.data.asBytes, MFBLOCK_SIZE);
} else {
PrintAndLogEx(WARNING, "command execute timeout");
return PM3_ETIMEOUT;
}
return PM3_SUCCESS;
}
int mfG4SetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags) {
struct p {
uint8_t blockno;
uint8_t pwd[4];
uint8_t data[MFBLOCK_SIZE];
uint8_t workFlags;
} PACKED payload;
payload.blockno = blockno;
memcpy(payload.pwd, pwd, sizeof(payload.pwd));
memcpy(payload.data, data, sizeof(payload.data));
payload.workFlags = workFlags;
clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_G4_WRBL, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_MIFARE_G4_WRBL, &resp, 1500)) {
if (resp.status != PM3_SUCCESS) {
return PM3_EUNDEF;
}
} else {
PrintAndLogEx(WARNING, "command execute timeout");
return PM3_ETIMEOUT;
}
return PM3_SUCCESS;
}
+47
View File
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------------
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// High frequency ISO14443A commands
//-----------------------------------------------------------------------------
#ifndef __GEN4_H
#define __GEN4_H
#include "common.h"
#define GEN4_CMD_CONFIG_GTU 0x32
#define GEN4_CMD_CONFIG_ATS 0x34
#define GEN4_CMD_CONFIG_ATQA_SAK 0x35
#define GEN4_CMD_CONFIG_UID_LEN 0x68
#define GEN4_CMD_CONFIG_UL_ENABLE 0x69
#define GEN4_CMD_CONFIG_UL_MODE 0x6A
#define GEN4_CMD_CONFIG_UL_SECTOR_COUNT 0x6A
#define GEN4_CMD_DUMP_CONFIG 0xC6
#define GEN4_CMD_FACTORY_TEST 0xCC
#define GEN4_CMD_WRITE_BLOCK 0xCD
#define GEN4_CMD_READ_BLOCK 0xCE
#define GEN4_CMD_BL0_DIRECT_WRITE_EN 0xCF
#define GEN4_CMD_SET_CONFIG 0xF0
#define GEN4_CMD_SET_CONFIG_PERMANENT 0xF1
#define GEN4_CMD_CHANGE_PASSWORD 0xFE
int mfG4GetConfig(uint8_t *pwd, uint8_t *data, size_t *datalen, bool verbose);
int mfG4GetFactoryTest(uint8_t *pwd, uint8_t *data, size_t *datalen, bool verbose);
int mfG4GetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags);
int mfG4SetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags);
int mfG4ChangePassword(uint8_t *pwd, uint8_t *newpwd, bool verbose);
#endif
+4 -1
View File
@@ -21,10 +21,13 @@
#include "common.h"
#define DES_KEY_LEN 8
#define AES_KEY_LEN 16
#define T2DES_KEY_LEN 16
#define T3DES_KEY_LEN 24
#define MAX_AES_KEYS_LIST_LEN 1024
#define MFKEY_SIZE 6
#define MFBLOCK_SIZE 16
#define MIFARE_4K_MAXBLOCK 256
+2 -52
View File
@@ -40,6 +40,8 @@
#include "crypto/libpcrypto.h"
#include "util.h" // xor
#include "mbedtls/sha1.h" // SHA1
#include "cmdhf14a.h"
#include "gen4.h"
int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) {
uint32_t uid = 0;
@@ -1173,58 +1175,6 @@ int mfGen3Freeze(void) {
}
}
int mfG4GetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags) {
struct p {
uint8_t blockno;
uint8_t pwd[4];
uint8_t workFlags;
} PACKED payload;
payload.blockno = blockno;
memcpy(payload.pwd, pwd, sizeof(payload.pwd));
payload.workFlags = workFlags;
clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_G4_RDBL, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_MIFARE_G4_RDBL, &resp, 1500)) {
if (resp.status != PM3_SUCCESS) {
return PM3_EUNDEF;
}
memcpy(data, resp.data.asBytes, MFBLOCK_SIZE);
} else {
PrintAndLogEx(WARNING, "command execute timeout");
return PM3_ETIMEOUT;
}
return PM3_SUCCESS;
}
int mfG4SetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags) {
struct p {
uint8_t blockno;
uint8_t pwd[4];
uint8_t data[MFBLOCK_SIZE];
uint8_t workFlags;
} PACKED payload;
payload.blockno = blockno;
memcpy(payload.pwd, pwd, sizeof(payload.pwd));
memcpy(payload.data, data, sizeof(payload.data));
payload.workFlags = workFlags;
clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_G4_WRBL, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_MIFARE_G4_WRBL, &resp, 1500)) {
if (resp.status != PM3_SUCCESS) {
return PM3_EUNDEF;
}
} else {
PrintAndLogEx(WARNING, "command execute timeout");
return PM3_ETIMEOUT;
}
return PM3_SUCCESS;
}
// variables
uint32_t cuid = 0; // uid part used for crypto1.
-3
View File
@@ -96,9 +96,6 @@ int mfGen3UID(uint8_t *uid, uint8_t uidlen, uint8_t *oldUid);
int mfGen3Block(uint8_t *block, int blockLen, uint8_t *newBlock);
int mfGen3Freeze(void);
int mfG4GetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags);
int mfG4SetBlock(uint8_t *pwd, uint8_t blockno, uint8_t *data, uint8_t workFlags);
int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len);
int detect_classic_prng(void);
+55 -7
View File
@@ -634,6 +634,7 @@ static const char *ndef_wifi_auth_lookup(uint8_t *d) {
return "";
}
static int ndefDecodeMime_wifi_wsc(NDEFHeader_t *ndef) {
if (ndef->PayloadLen == 0) {
PrintAndLogEx(INFO, "no payload");
@@ -649,7 +650,7 @@ static int ndefDecodeMime_wifi_wsc(NDEFHeader_t *ndef) {
if (ndef->Payload[pos] != 0x10) {
n -= 1;
pos -= 1;
pos += 1;
continue;
}
@@ -713,7 +714,7 @@ static int ndefDecodeMime_wifi_wsc(NDEFHeader_t *ndef) {
pos += len;
}
// NETWORK_IDX
// NETWORK_IDX - always set to 1, deprecated
if (memcmp(&ndef->Payload[pos], "\x10\x26", 2) == 0) {
// 10 26 00 01 01
uint8_t len = 3;
@@ -775,19 +776,34 @@ static int ndefDecodeMime_wifi_wsc(NDEFHeader_t *ndef) {
pos += 2;
pos += len;
}
// rf-bands
if (memcmp(&ndef->Payload[pos], "\x10\x3C", 2) == 0) {
uint8_t len = 3;
if (ndef->Payload[pos + 2 + 2] == 0x01) {
PrintAndLogEx(INFO, "RF Bands........ %s ( " _YELLOW_("2.4 GHZ")" )", sprint_hex(&ndef->Payload[pos + 2], len));
} else if (ndef->Payload[pos + 2 + 2] == 0x02) {
PrintAndLogEx(INFO, "RF Bands........ %s ( " _YELLOW_("5.0 GHZ")" )", sprint_hex(&ndef->Payload[pos + 2], len));
}
n -= 2;
n -= len;
pos += 2;
pos += len;
}
}
/*
ap-channel 0, 6
+ credential
device-name
mac-address
manufacturer
model-name
model-number
+ oob-password
primary-device-type
rf-bands
secondary-device-type-list
serial-number
ssid
@@ -1182,6 +1198,7 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("NDEF parsing") " ----------------");
while (indx < ndefLen) {
switch (ndef[indx]) {
case 0x00: {
indx++;
@@ -1246,8 +1263,9 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
PrintAndLogEx(SUCCESS, "Found NDEF message ( " _YELLOW_("%u") " bytes )", len);
int res = NDEFRecordsDecodeAndPrint(&ndef[indx], len, verbose);
if (res != PM3_SUCCESS)
if (res != PM3_SUCCESS) {
return res;
}
}
indx += len;
@@ -1269,12 +1287,42 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
return PM3_SUCCESS;
}
default: {
if (verbose)
if (verbose) {
PrintAndLogEx(ERR, "unknown tag 0x%02x", ndef[indx]);
}
return PM3_ESOFT;
}
}
}
return PM3_SUCCESS;
}
int NDEFGetTotalLength(uint8_t *ndef, size_t ndeflen, size_t *outlen) {
size_t idx = 0;
while (idx < ndeflen) {
if (ndef[idx] == 0x00 ||
ndef[idx] == 0x01 ||
ndef[idx] == 0x02 ||
ndef[idx] == 0x03 ||
ndef[idx] == 0xFD) {
idx++;
idx += ndefTLVGetLength(&ndef[idx], &idx);
continue;
}
if (ndef[idx] == 0xFE) {
idx++;
break;
}
// invalid NDEF
*outlen = 0;
return PM3_ESOFT;
}
*outlen = idx;
return PM3_SUCCESS;
}
+1 -1
View File
@@ -76,5 +76,5 @@ typedef struct {
int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose);
int NDEFRecordsDecodeAndPrint(uint8_t *ndefRecord, size_t ndefRecordLen, bool verbose);
int NDEFGetTotalLength(uint8_t *ndef, size_t ndeflen, size_t *outlen);
#endif // _NDEF_H_
+18 -7
View File
@@ -42,8 +42,9 @@ const static vocabulary_t vocabulary[] = {
{ 1, "prefs help" },
{ 1, "prefs show" },
{ 1, "prefs get barmode" },
{ 1, "prefs get clientdebug" },
{ 1, "prefs get clientdelay" },
{ 1, "prefs get client.debug" },
{ 1, "prefs get client.delay" },
{ 1, "prefs get client.timeout" },
{ 1, "prefs get color" },
{ 1, "prefs get savepaths" },
{ 1, "prefs get emoji" },
@@ -52,8 +53,9 @@ const static vocabulary_t vocabulary[] = {
{ 1, "prefs get plotsliders" },
{ 1, "prefs set help" },
{ 1, "prefs set barmode" },
{ 1, "prefs set clientdebug" },
{ 1, "prefs set clientdelay" },
{ 1, "prefs set client.debug" },
{ 1, "prefs set client.delay" },
{ 1, "prefs set client.timeout" },
{ 1, "prefs set color" },
{ 1, "prefs set emoji" },
{ 1, "prefs set hints" },
@@ -105,6 +107,7 @@ const static vocabulary_t vocabulary[] = {
{ 1, "data atr" },
{ 1, "data bin2hex" },
{ 0, "data bitsamples" },
{ 1, "data bmap" },
{ 1, "data clear" },
{ 1, "data diff" },
{ 0, "data hexsamples" },
@@ -269,7 +272,7 @@ const static vocabulary_t vocabulary[] = {
{ 1, "hf iclass help" },
{ 1, "hf iclass list" },
{ 0, "hf iclass dump" },
{ 1, "hf iclass info" },
{ 0, "hf iclass info" },
{ 0, "hf iclass rdbl" },
{ 0, "hf iclass reader" },
{ 0, "hf iclass restore" },
@@ -285,7 +288,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf iclass esave" },
{ 0, "hf iclass esetblk" },
{ 0, "hf iclass eview" },
{ 1, "hf iclass configcard" },
{ 0, "hf iclass configcard" },
{ 1, "hf iclass calcnewkey" },
{ 1, "hf iclass encode" },
{ 1, "hf iclass encrypt" },
@@ -363,17 +366,20 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf mf gen3uid" },
{ 0, "hf mf gen3blk" },
{ 0, "hf mf gen3freeze" },
{ 0, "hf mf ginfo" },
{ 0, "hf mf ggetblk" },
{ 0, "hf mf gload" },
{ 0, "hf mf gsave" },
{ 0, "hf mf gsetblk" },
{ 0, "hf mf gview" },
{ 0, "hf mf gchpwd" },
{ 0, "hf mf gdmcfg" },
{ 0, "hf mf gdmsetcfg" },
{ 0, "hf mf gdmsetblk" },
{ 0, "hf mf ndefformat" },
{ 0, "hf mf ndefread" },
{ 0, "hf mf ndefwrite" },
{ 0, "hf mf encodehid" },
{ 1, "hf mfp help" },
{ 1, "hf mfp list" },
{ 0, "hf mfp auth" },
@@ -451,8 +457,13 @@ const static vocabulary_t vocabulary[] = {
{ 1, "hf mfdes test" },
{ 1, "hf ntag424 help" },
{ 0, "hf ntag424 info" },
{ 0, "hf ntag424 sdm" },
{ 1, "hf ntag424 view" },
{ 0, "hf ntag424 auth" },
{ 0, "hf ntag424 read" },
{ 0, "hf ntag424 write" },
{ 0, "hf ntag424 getfs" },
{ 0, "hf ntag424 changefs" },
{ 0, "hf ntag424 changekey" },
{ 1, "hf seos help" },
{ 0, "hf seos info" },
{ 1, "hf seos list" },
+115 -47
View File
@@ -26,14 +26,15 @@
//-----------------------------------------------------------------------------
#include "preferences.h"
#include "comms.h"
#include "emv/emvjson.h"
#include <string.h>
#include "cmdparser.h"
#include <ctype.h>
#include <dirent.h>
#include <proxmark3.h>
#include "proxmark3.h"
#include "comms.h"
#include "emv/emvjson.h"
#include "cmdparser.h"
#include "cliparser.h"
#include "uart/uart.h" // uart_reconfigure_timeouts
static int CmdHelp(const char *Cmd);
static int setCmdHelp(const char *Cmd);
@@ -44,7 +45,7 @@ static char *prefGetFilename(void) {
if (searchHomeFilePath(&path, NULL, preferencesFilename, false) == PM3_SUCCESS)
return path;
else
return strdup(preferencesFilename);
return str_dup(preferencesFilename);
}
int preferences_load(void) {
@@ -52,6 +53,8 @@ int preferences_load(void) {
// Set all defaults
g_session.client_debug_level = cdbOFF;
// g_session.device_debug_level = ddbOFF;
g_session.timeout = uart_get_timeouts();
g_session.window_changed = false;
g_session.plot.x = 10;
g_session.plot.y = 30;
@@ -260,7 +263,7 @@ void preferences_save_callback(json_t *root) {
}
*/
JsonSaveInt(root, "client.exe.delay", g_session.client_exe_delay);
JsonSaveInt(root, "client.timeout", g_session.timeout);
}
void preferences_load_callback(json_t *root) {
json_error_t up_error = {0};
@@ -355,6 +358,10 @@ void preferences_load_callback(json_t *root) {
// client command execution delay
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "client.exe.delay", &i1) == 0)
g_session.client_exe_delay = i1;
// client command timeout
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "client.timeout", &i1) == 0)
g_session.timeout = i1;
}
// Help Functions
@@ -379,44 +386,44 @@ static void showEmojiState(prefShowOpt_t opt) {
switch (g_session.emoji_mode) {
case EMO_ALIAS:
PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("alias"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("alias"), prefShowMsg(opt));
break;
case EMO_EMOJI:
PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("emoji"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("emoji"), prefShowMsg(opt));
break;
case EMO_ALTTEXT:
PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("alttext"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("alttext"), prefShowMsg(opt));
break;
case EMO_NONE:
PrintAndLogEx(INFO, " %s emoji.................. "_GREEN_("none"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s emoji................... "_GREEN_("none"), prefShowMsg(opt));
break;
default:
PrintAndLogEx(INFO, " %s emoji.................. "_RED_("unknown"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s emoji................... "_RED_("unknown"), prefShowMsg(opt));
}
}
static void showColorState(prefShowOpt_t opt) {
if (g_session.supports_colors)
PrintAndLogEx(INFO, " %s color.................. "_GREEN_("ansi"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s color................... "_GREEN_("ansi"), prefShowMsg(opt));
else
PrintAndLogEx(INFO, " %s color.................. "_WHITE_("off"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s color................... "_WHITE_("off"), prefShowMsg(opt));
}
static void showClientDebugState(prefShowOpt_t opt) {
switch (g_session.client_debug_level) {
case cdbOFF:
PrintAndLogEx(INFO, " %s client debug........... "_WHITE_("off"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s client debug............ "_WHITE_("off"), prefShowMsg(opt));
break;
case cdbSIMPLE:
PrintAndLogEx(INFO, " %s client debug........... "_GREEN_("simple"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s client debug............ "_GREEN_("simple"), prefShowMsg(opt));
break;
case cdbFULL:
PrintAndLogEx(INFO, " %s client debug........... "_GREEN_("full"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s client debug............ "_GREEN_("full"), prefShowMsg(opt));
break;
default:
PrintAndLogEx(INFO, " %s client debug........... "_RED_("unknown"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s client debug............ "_RED_("unknown"), prefShowMsg(opt));
}
}
/*
@@ -448,17 +455,17 @@ static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) {
char s[50];
switch (path_index) {
case spDefault:
strcpy(s, "default save path......");
strcpy(s, "default save path.......");
break;
case spDump:
strcpy(s, "dump save path.........");
strcpy(s, "dump save path..........");
break;
case spTrace:
strcpy(s, "trace save path........");
strcpy(s, "trace save path.........");
break;
case spItemCount:
default:
strcpy(s, _RED_("unknown")" save path......");
strcpy(s, _RED_("unknown")" save path.......");
}
if (path_index < spItemCount) {
@@ -478,7 +485,7 @@ static void showSavePathState(savePaths_t path_index, prefShowOpt_t opt) {
}
static void showPlotPosState(void) {
PrintAndLogEx(INFO, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
PrintAndLogEx(INFO, " plot window............. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
g_session.plot.x,
g_session.plot.y,
g_session.plot.h,
@@ -487,7 +494,7 @@ static void showPlotPosState(void) {
}
static void showOverlayPosState(void) {
PrintAndLogEx(INFO, " Slider/Overlay window.. X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
PrintAndLogEx(INFO, " slider/overlay window... X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
g_session.overlay.x,
g_session.overlay.y,
g_session.overlay.h,
@@ -497,44 +504,47 @@ static void showOverlayPosState(void) {
static void showHintsState(prefShowOpt_t opt) {
if (g_session.show_hints)
PrintAndLogEx(INFO, " %s hints.................. "_GREEN_("on"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s hints................... "_GREEN_("on"), prefShowMsg(opt));
else
PrintAndLogEx(INFO, " %s hints.................. "_WHITE_("off"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s hints................... "_WHITE_("off"), prefShowMsg(opt));
}
static void showPlotSliderState(prefShowOpt_t opt) {
if (g_session.overlay_sliders)
PrintAndLogEx(INFO, " %s show plot sliders...... "_GREEN_("on"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s show plot sliders....... "_GREEN_("on"), prefShowMsg(opt));
else
PrintAndLogEx(INFO, " %s show plot sliders...... "_WHITE_("off"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s show plot sliders....... "_WHITE_("off"), prefShowMsg(opt));
}
static void showBarModeState(prefShowOpt_t opt) {
switch (g_session.bar_mode) {
case STYLE_BAR:
PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("bar"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s barmode................. "_GREEN_("bar"), prefShowMsg(opt));
break;
case STYLE_MIXED:
PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("mixed"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s barmode................. "_GREEN_("mixed"), prefShowMsg(opt));
break;
case STYLE_VALUE:
PrintAndLogEx(INFO, " %s barmode................ "_GREEN_("value"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s barmode................. "_GREEN_("value"), prefShowMsg(opt));
break;
default:
PrintAndLogEx(INFO, " %s barmode............... "_RED_("unknown"), prefShowMsg(opt));
PrintAndLogEx(INFO, " %s barmode................ "_RED_("unknown"), prefShowMsg(opt));
}
}
static void showOutputState(prefShowOpt_t opt) {
PrintAndLogEx(INFO, " %s output................. %s", prefShowMsg(opt),
PrintAndLogEx(INFO, " %s output.................. %s", prefShowMsg(opt),
g_session.dense_output ? _GREEN_("dense") : _WHITE_("normal"));
}
static void showClientExeDelayState(void) {
PrintAndLogEx(INFO, " Cmd execution delay.... "_GREEN_("%u"), g_session.client_exe_delay);
PrintAndLogEx(INFO, " cmd execution delay..... "_GREEN_("%u"), g_session.client_exe_delay);
}
static void showClientTimeoutState(void) {
PrintAndLogEx(INFO, " communication timeout... " _GREEN_("%u") " ms", g_session.timeout);
}
static int setCmdEmoji(const char *Cmd) {
CLIParserContext *ctx;
@@ -636,9 +646,9 @@ static int setCmdColor(const char *Cmd) {
static int setCmdDebug(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs set clientdebug ",
CLIParserInit(&ctx, "prefs set client.debug ",
"Set persistent preference of using clientside debug level",
"prefs set clientdebug --simple"
"prefs set client.debug --simple"
);
void *argtable[] = {
@@ -798,10 +808,10 @@ static int setCmdOutput(const char *Cmd) {
static int setCmdExeDelay(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs set clientdelay",
CLIParserInit(&ctx, "prefs set client.delay",
"Set persistent preference of delay before executing a command in the client",
"prefs set clientdelay --ms 0 --> unsets any delay\n"
"prefs set clientdelay --ms 1000 --> sets 1000ms delay"
"prefs set client.delay --ms 0 --> unsets any delay\n"
"prefs set client.delay --ms 1000 --> sets 1000ms delay"
);
void *argtable[] = {
@@ -824,9 +834,47 @@ static int setCmdExeDelay(const char *Cmd) {
return PM3_SUCCESS;
}
static int setClientTimeout(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs set client.timeout",
"Set persistent preference of client communication timeout",
"prefs set client.timeout --ms 0 --> unsets any timeout\n"
"prefs set client.timeout -m 20 --> Set the timeout to 20ms\n"
"prefs set client.timeout --ms 500 --> Set the timeout to 500ms\n"
);
void *argtable[] = {
arg_param_begin,
arg_int0("m", "ms", "<ms>", "timeout in micro seconds"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint32_t new_value = (uint32_t)arg_get_int_def(ctx, 1, 0);
CLIParserFree(ctx);
// UART_USB_CLIENT_RX_TIMEOUT_MS is considered as the minimum required timeout.
if (new_value < UART_USB_CLIENT_RX_TIMEOUT_MS) {
PrintAndLogEx(WARNING, "Timeout less than %u ms might cause errors.", UART_USB_CLIENT_RX_TIMEOUT_MS);
} else if (new_value > 5000) {
PrintAndLogEx(WARNING, "Timeout greater than 5000 ms makes the client unresponsive.");
}
if (g_session.timeout != new_value) {
showClientTimeoutState();
g_session.timeout = new_value;
uart_reconfigure_timeouts(new_value);
showClientTimeoutState();
preferences_save();
} else {
showClientTimeoutState();
}
return PM3_SUCCESS;
}
static int setCmdHint(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs set hints ",
CLIParserInit(&ctx, "prefs set hints",
"Set persistent preference of showing hint messages in the client",
"prefs set hints --on"
);
@@ -1087,9 +1135,9 @@ static int getCmdColor(const char *Cmd) {
static int getCmdDebug(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs get clientdebug",
CLIParserInit(&ctx, "prefs get client.debug",
"Get preference of using clientside debug level",
"prefs get clientdebug"
"prefs get client.debug"
);
void *argtable[] = {
arg_param_begin,
@@ -1169,9 +1217,9 @@ static int getCmdSavePaths(const char *Cmd) {
static int getCmdExeDelay(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs get clientdelay",
CLIParserInit(&ctx, "prefs get client.delay",
"Get preference of delay time before execution of a command in the client",
"prefs get clientdelay"
"prefs get client.delay"
);
void *argtable[] = {
arg_param_begin,
@@ -1183,10 +1231,27 @@ static int getCmdExeDelay(const char *Cmd) {
return PM3_SUCCESS;
}
static int getClientTimeout(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs get client.timeout",
"Get preference of delay time before execution of a command in the client",
"prefs get client.timeout"
);
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
showClientTimeoutState();
return PM3_SUCCESS;
}
static command_t CommandTableGet[] = {
{"barmode", getCmdBarMode, AlwaysAvailable, "Get bar mode preference"},
{"clientdebug", getCmdDebug, AlwaysAvailable, "Get client debug level preference"},
{"clientdelay", getCmdExeDelay, AlwaysAvailable, "Get client execution delay preference"},
{"client.debug", getCmdDebug, AlwaysAvailable, "Get client debug level preference"},
{"client.delay", getCmdExeDelay, AlwaysAvailable, "Get client execution delay preference"},
{"client.timeout", getClientTimeout, AlwaysAvailable, "Get client execution delay preference"},
{"color", getCmdColor, AlwaysAvailable, "Get color support preference"},
{"savepaths", getCmdSavePaths, AlwaysAvailable, "Get file folder "},
// {"devicedebug", getCmdDeviceDebug, AlwaysAvailable, "Get device debug level"},
@@ -1200,8 +1265,10 @@ static command_t CommandTableGet[] = {
static command_t CommandTableSet[] = {
{"help", setCmdHelp, AlwaysAvailable, "This help"},
{"barmode", setCmdBarMode, AlwaysAvailable, "Set bar mode"},
{"clientdebug", setCmdDebug, AlwaysAvailable, "Set client debug level"},
{"clientdelay", setCmdExeDelay, AlwaysAvailable, "Set client execution delay"},
{"client.debug", setCmdDebug, AlwaysAvailable, "Set client debug level"},
{"client.delay", setCmdExeDelay, AlwaysAvailable, "Set client execution delay"},
{"client.timeout", setClientTimeout, AlwaysAvailable, "Set client communication timeout"},
{"color", setCmdColor, AlwaysAvailable, "Set color support"},
{"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"},
{"hints", setCmdHint, AlwaysAvailable, "Set hint display"},
@@ -1265,6 +1332,7 @@ static int CmdPrefShow(const char *Cmd) {
showBarModeState(prefShowNone);
showClientExeDelayState();
showOutputState(prefShowNone);
showClientTimeoutState();
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
+29 -8
View File
@@ -127,9 +127,10 @@ static void showBanner(void) {
static const char *prompt_dev = "";
static const char *prompt_ctx = "";
static const char *prompt_net = "";
static void prompt_compose(char *buf, size_t buflen, const char *promptctx, const char *promptdev) {
snprintf(buf, buflen - 1, PROXPROMPT_COMPOSE, promptdev, promptctx);
static void prompt_compose(char *buf, size_t buflen, const char *promptctx, const char *promptdev, const char *promptnet) {
snprintf(buf, buflen - 1, PROXPROMPT_COMPOSE, promptdev, promptnet, promptctx);
}
static int check_comm(void) {
@@ -138,7 +139,7 @@ static int check_comm(void) {
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode. Use "_YELLOW_("\"hw connect\"") " to reconnect\n");
prompt_dev = PROXPROMPT_DEV_OFFLINE;
char prompt[PROXPROMPT_MAX_SIZE] = {0};
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev);
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev, prompt_net);
char prompt_filtered[PROXPROMPT_MAX_SIZE] = {0};
memcpy_filter_ansi(prompt_filtered, prompt, sizeof(prompt_filtered), !g_session.supports_colors);
pm3line_update_prompt(prompt_filtered);
@@ -265,10 +266,30 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
bool printprompt = false;
if (g_session.pm3_present) {
if (g_conn.send_via_fpc_usart == false)
prompt_dev = PROXPROMPT_DEV_USB;
else
switch (g_conn.send_via_ip) {
case PM3_TCPv4:
prompt_net = PROXPROMPT_NET_TCPV4;
break;
case PM3_TCPv6:
prompt_net = PROXPROMPT_NET_TCPV6;
break;
case PM3_UDPv4:
prompt_net = PROXPROMPT_NET_UDPV4;
break;
case PM3_UDPv6:
prompt_net = PROXPROMPT_NET_UDPV6;
break;
case PM3_NONE:
default:
break;
}
if (g_conn.send_via_fpc_usart)
prompt_dev = PROXPROMPT_DEV_FPC;
else
prompt_dev = PROXPROMPT_DEV_USB;
} else {
prompt_dev = PROXPROMPT_DEV_OFFLINE;
}
@@ -341,7 +362,7 @@ check_script:
pm3line_check(check_comm);
prompt_ctx = PROXPROMPT_CTX_INTERACTIVE;
char prompt[PROXPROMPT_MAX_SIZE] = {0};
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev);
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev, prompt_net);
char prompt_filtered[PROXPROMPT_MAX_SIZE] = {0};
memcpy_filter_ansi(prompt_filtered, prompt, sizeof(prompt_filtered), !g_session.supports_colors);
g_pendingPrompt = true;
@@ -391,7 +412,7 @@ check_script:
g_printAndLog &= PRINTANDLOG_LOG;
}
char prompt[PROXPROMPT_MAX_SIZE] = {0};
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev);
prompt_compose(prompt, sizeof(prompt), prompt_ctx, prompt_dev, prompt_net);
// always filter RL magic separators if not using readline
char prompt_filtered[PROXPROMPT_MAX_SIZE] = {0};
memcpy_filter_rlmarkers(prompt_filtered, prompt, sizeof(prompt_filtered));
+7 -1
View File
@@ -24,7 +24,7 @@
#define PROXPROMPT_MAX_SIZE 255
#define PROXPROMPT_COMPOSE "[" "%s%s" "] pm3 --> "
#define PROXPROMPT_COMPOSE "[" "%s%s%s" "] pm3 --> "
#define PROXPROMPT_CTX_SCRIPTFILE "|" _RL_GREEN_("script")
#define PROXPROMPT_CTX_SCRIPTCMD "|" _RL_GREEN_("script")
@@ -35,6 +35,12 @@
#define PROXPROMPT_DEV_FPC _RL_BOLD_GREEN_("fpc")
#define PROXPROMPT_DEV_OFFLINE _RL_BOLD_RED_("offline")
#define PROXPROMPT_NET_TCPV4 "|" _RL_BOLD_GREEN_("tcp")
#define PROXPROMPT_NET_UDPV4 "|" _RL_BOLD_GREEN_("udp")
#define PROXPROMPT_NET_TCPV6 "|" _RL_BOLD_GREEN_("tcp v6")
#define PROXPROMPT_NET_UDPV6 "|" _RL_BOLD_GREEN_("udp v6")
#define PROXHISTORY "history.txt"
#define PROXLOG "log_%Y%m%d%H%M%S.txt"
#define MAX_NESTED_CMDSCRIPT 10
+118
View File
@@ -0,0 +1,118 @@
#include "ringbuffer.h"
#include <stdlib.h>
RingBuffer *RingBuf_create(int capacity) {
RingBuffer *buffer = (RingBuffer *)malloc(sizeof(RingBuffer));
if (!buffer) {
return NULL;
}
buffer->data = (uint8_t *)calloc(capacity, sizeof(uint8_t));
if (!buffer->data) {
free(buffer);
return NULL;
}
buffer->capacity = capacity;
buffer->size = 0;
buffer->front = 0;
buffer->rear = 0;
return buffer;
}
inline bool RingBuf_isFull(RingBuffer *buffer) {
return buffer->size == buffer->capacity;
}
inline bool RingBuf_isEmpty(RingBuffer *buffer) {
return buffer->size == 0;
}
bool RingBuf_enqueue(RingBuffer *buffer, uint8_t value) {
if (RingBuf_isFull(buffer)) {
return false;
}
buffer->data[buffer->rear] = value;
buffer->rear = (buffer->rear + 1) % buffer->capacity;
buffer->size++;
return true;
}
bool RingBuf_dequeue(RingBuffer *buffer, uint8_t *value) {
if (RingBuf_isEmpty(buffer)) {
return false;
}
*value = buffer->data[buffer->front];
buffer->front = (buffer->front + 1) % buffer->capacity;
buffer->size--;
return true;
}
int RingBuf_enqueueBatch(RingBuffer *buffer, const uint8_t *values, int count) {
int processed = 0;
if (RingBuf_getAvailableSize(buffer) < count) {
count = RingBuf_getAvailableSize(buffer);
}
for (int i = 0; i < count; i++) {
buffer->data[buffer->rear] = values[i];
buffer->rear = (buffer->rear + 1) % buffer->capacity;
processed++;
}
buffer->size += processed;
return processed;
}
int RingBuf_dequeueBatch(RingBuffer *buffer, uint8_t *values, int count) {
int processed = 0;
if (buffer->size < count) {
count = buffer->size;
}
for (int i = 0; i < count; i++) {
values[i] = buffer->data[buffer->front];
buffer->front = (buffer->front + 1) % buffer->capacity;
processed++;
}
buffer->size -= processed;
return processed;
}
inline int RingBuf_getUsedSize(RingBuffer *buffer) {
return buffer->size;
}
inline int RingBuf_getAvailableSize(RingBuffer *buffer) {
return (buffer->capacity) - (buffer->size);
}
void RingBuf_destroy(RingBuffer *buffer) {
if (buffer != NULL)
free(buffer->data);
free(buffer);
}
inline int RingBuf_getContinousAvailableSize(RingBuffer *buffer) {
const int availableSize = RingBuf_getAvailableSize(buffer);
const int continousSize = (buffer->capacity) - (buffer->rear);
return (availableSize < continousSize) ? availableSize : continousSize;
}
inline void RingBuf_postEnqueueBatch(RingBuffer *buffer, int count) {
// no check there
buffer->rear = (buffer->rear + count) % buffer->capacity;
buffer->size += count;
}
inline uint8_t *RingBuf_getRearPtr(RingBuffer *buffer) {
return buffer->data + buffer->rear;
}
+31
View File
@@ -0,0 +1,31 @@
#ifndef _RINGBUFFER_H_
#define _RINGBUFFER_H_
#include <stdbool.h>
#include <stdint.h>
typedef struct {
uint8_t *data;
int capacity;
int size;
int front;
int rear;
} RingBuffer;
RingBuffer *RingBuf_create(int capacity);
bool RingBuf_isFull(RingBuffer *buffer);
bool RingBuf_isEmpty(RingBuffer *buffer);
bool RingBuf_enqueue(RingBuffer *buffer, uint8_t value);
bool RingBuf_dequeue(RingBuffer *buffer, uint8_t *value);
int RingBuf_enqueueBatch(RingBuffer *buffer, const uint8_t *values, int count);
int RingBuf_dequeueBatch(RingBuffer *buffer, uint8_t *values, int count);
int RingBuf_getUsedSize(RingBuffer *buffer);
int RingBuf_getAvailableSize(RingBuffer *buffer);
void RingBuf_destroy(RingBuffer *buffer);
// for direct write
int RingBuf_getContinousAvailableSize(RingBuffer *buffer);
void RingBuf_postEnqueueBatch(RingBuffer *buffer, int count);
uint8_t *RingBuf_getRearPtr(RingBuffer *buffer);
#endif
+4
View File
@@ -82,4 +82,8 @@ int uart_reconfigure_timeouts(uint32_t value);
*/
uint32_t uart_get_timeouts(void);
/* Specify the outbound address and port for TCP/UDP connections
*/
bool uart_bind(void *socket, char *bindAddrStr, char *bindPortStr, bool isBindingIPv6);
#endif // _UART_H_
+410 -20
View File
@@ -21,6 +21,7 @@
#define _DEFAULT_SOURCE
#include "uart.h"
#include "ringbuffer.h"
#include <stdio.h>
#include <string.h>
@@ -30,9 +31,11 @@
#include <unistd.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#ifdef HAVE_BLUEZ
#include <bluetooth/bluetooth.h>
@@ -46,12 +49,16 @@
#ifndef SOL_TCP
# define SOL_TCP IPPROTO_TCP
#endif
#ifndef SOL_UDP
# define SOL_UDP IPPROTO_UDP
#endif
typedef struct termios term_info;
typedef struct {
int fd; // Serial port file descriptor
term_info tiOld; // Terminal info before using the port
term_info tiNew; // Terminal info during the transaction
RingBuffer *udpBuffer;
} serial_port_unix_t_t;
// see pm3_cmd.h
@@ -81,10 +88,13 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
return INVALID_SERIAL_PORT;
}
sp->udpBuffer = NULL;
// init timeouts
timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000;
g_conn.send_via_local_ip = false;
g_conn.send_via_ip = PM3_NONE;
char *prefix = strdup(pcPortName);
char *prefix = str_dup(pcPortName);
if (prefix == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
@@ -102,35 +112,140 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
struct addrinfo *addr = NULL, *rp;
char *addrstr = strdup(pcPortName + 4);
if (addrstr == NULL) {
char *addrPortStr = str_dup(pcPortName + 4);
char *addrstr = addrPortStr;
const char *portstr;
if (addrPortStr == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
return INVALID_SERIAL_PORT;
}
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
char *colon = strrchr(addrstr, ':');
const char *portstr;
if (colon) {
portstr = colon + 1;
*colon = '\0';
} else {
// find the "bind" option
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
char *bindAddrStr = NULL;
char *bindPortStr = NULL;
bool isBindingIPv6 = false; // Assume v4
if (bindAddrPortStr != NULL) {
*bindAddrPortStr = '\0'; // as the end of target address (and port)
bindAddrPortStr += 6;
bindAddrStr = bindAddrPortStr;
// find the start of the bind address
char *endBracket = strrchr(bindAddrPortStr, ']');
if (bindAddrPortStr[0] == '[') {
bindAddrStr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// find the bind port
char *lColon = strchr(bindAddrPortStr, ':');
char *rColon = strrchr(bindAddrPortStr, ':');
if (rColon == NULL) {
// no colon
// ",bind=<ipv4 address>", ",bind=[<ipv4 address>]"
bindPortStr = NULL;
} else if (lColon == rColon) {
// only one colon
// ",bind=<ipv4 address>:<port>", ",bind=[<ipv4 address>]:<port>"
bindPortStr = rColon + 1;
} else {
// two or more colon, IPv6 address
// ",bind=[<ipv6 address>]:<port>"
// ",bind=<ipv6 address>", ",bind=[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
bindPortStr = rColon + 1;
} else {
bindPortStr = NULL;
}
isBindingIPv6 = true;
}
// handle the end of the bind address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
// for bind option, it's possible to only specify address or port
if (strlen(bindAddrStr) == 0)
bindAddrStr = NULL;
if (bindPortStr != NULL && strlen(bindPortStr) == 0)
bindPortStr = NULL;
}
// find the start of the address
char *endBracket = strrchr(addrPortStr, ']');
if (addrPortStr[0] == '[') {
addrstr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// assume v4
g_conn.send_via_ip = PM3_TCPv4;
// find the port
char *lColon = strchr(addrPortStr, ':');
char *rColon = strrchr(addrPortStr, ':');
if (rColon == NULL) {
// no colon
// "tcp:<ipv4 address>", "tcp:[<ipv4 address>]"
portstr = "18888";
} else if (lColon == rColon) {
// only one colon
// "tcp:<ipv4 address>:<port>", "tcp:[<ipv4 address>]:<port>"
portstr = rColon + 1;
} else {
// two or more colon, IPv6 address
// "tcp:[<ipv6 address>]:<port>"
// "tcp:<ipv6 address>", "tcp:[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
portstr = rColon + 1;
} else {
portstr = "18888";
}
g_conn.send_via_ip = PM3_TCPv6;
}
// handle the end of the address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
struct addrinfo info;
memset(&info, 0, sizeof(info));
info.ai_family = PF_UNSPEC;
info.ai_socktype = SOCK_STREAM;
if ((strstr(addrstr, "localhost") != NULL) ||
(strstr(addrstr, "127.0.0.1") != NULL) ||
(strstr(addrstr, "::1") != NULL)) {
g_conn.send_via_local_ip = true;
}
int s = getaddrinfo(addrstr, portstr, &info, &addr);
if (s != 0) {
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
freeaddrinfo(addr);
free(addrstr);
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
@@ -142,6 +257,15 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
if (sfd == -1)
continue;
if (!uart_bind(&sfd, bindAddrStr, bindPortStr, isBindingIPv6)) {
PrintAndLogEx(ERR, "error: Could not bind. errno: %d", errno);
close(sfd);
freeaddrinfo(addr);
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
break;
@@ -149,7 +273,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
freeaddrinfo(addr);
free(addrstr);
free(addrPortStr);
if (rp == NULL) { /* No address succeeded */
PrintAndLogEx(ERR, "error: Could not connect");
@@ -165,9 +289,194 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
free(sp);
return INVALID_SERIAL_PORT;
}
return sp;
}
if (memcmp(prefix, "udp:", 4) == 0) {
free(prefix);
if (strlen(pcPortName) <= 4) {
free(sp);
return INVALID_SERIAL_PORT;
}
struct addrinfo *addr = NULL, *rp;
char *addrPortStr = str_dup(pcPortName + 4);
char *addrstr = addrPortStr;
const char *portstr;
if (addrPortStr == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
return INVALID_SERIAL_PORT;
}
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
// find the "bind" option
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
char *bindAddrStr = NULL;
char *bindPortStr = NULL;
bool isBindingIPv6 = false; // Assume v4
if (bindAddrPortStr != NULL) {
*bindAddrPortStr = '\0'; // as the end of target address (and port)
bindAddrPortStr += 6;
bindAddrStr = bindAddrPortStr;
// find the start of the bind address
char *endBracket = strrchr(bindAddrPortStr, ']');
if (bindAddrPortStr[0] == '[') {
bindAddrStr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// find the bind port
char *lColon = strchr(bindAddrPortStr, ':');
char *rColon = strrchr(bindAddrPortStr, ':');
if (rColon == NULL) {
// no colon
// ",bind=<ipv4 address>", ",bind=[<ipv4 address>]"
bindPortStr = NULL;
} else if (lColon == rColon) {
// only one colon
// ",bind=<ipv4 address>:<port>", ",bind=[<ipv4 address>]:<port>"
bindPortStr = rColon + 1;
} else {
// two or more colon, IPv6 address
// ",bind=[<ipv6 address>]:<port>"
// ",bind=<ipv6 address>", ",bind=[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
bindPortStr = rColon + 1;
} else {
bindPortStr = NULL;
}
isBindingIPv6 = true;
}
// handle the end of the bind address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
// for bind option, it's possible to only specify address or port
if (strlen(bindAddrStr) == 0)
bindAddrStr = NULL;
if (bindPortStr != NULL && strlen(bindPortStr) == 0)
bindPortStr = NULL;
}
// find the start of the address
char *endBracket = strrchr(addrPortStr, ']');
if (addrPortStr[0] == '[') {
addrstr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// Assume v4
g_conn.send_via_ip = PM3_UDPv4;
// find the port
char *lColon = strchr(addrPortStr, ':');
char *rColon = strrchr(addrPortStr, ':');
if (rColon == NULL) {
// no colon
// "udp:<ipv4 address>", "udp:[<ipv4 address>]"
portstr = "18888";
} else if (lColon == rColon) {
// only one colon
// "udp:<ipv4 address>:<port>", "udp:[<ipv4 address>]:<port>"
portstr = rColon + 1;
} else {
// two or more colon, IPv6 address
// "udp:[<ipv6 address>]:<port>"
// "udp:<ipv6 address>", "udp:[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
portstr = rColon + 1;
} else {
portstr = "18888";
}
g_conn.send_via_ip = PM3_UDPv6;
}
// handle the end of the address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
struct addrinfo info;
memset(&info, 0, sizeof(info));
info.ai_family = PF_UNSPEC;
info.ai_socktype = SOCK_DGRAM;
if ((strstr(addrstr, "localhost") != NULL) ||
(strstr(addrstr, "127.0.0.1") != NULL) ||
(strstr(addrstr, "::1") != NULL)) {
g_conn.send_via_local_ip = true;
}
int s = getaddrinfo(addrstr, portstr, &info, &addr);
if (s != 0) {
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
freeaddrinfo(addr);
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
int sfd;
for (rp = addr; rp != NULL; rp = rp->ai_next) {
sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sfd == -1)
continue;
if (!uart_bind(&sfd, bindAddrStr, bindPortStr, isBindingIPv6)) {
PrintAndLogEx(ERR, "error: Could not bind. errno: %d", errno);
close(sfd);
freeaddrinfo(addr);
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
break;
close(sfd);
}
freeaddrinfo(addr);
free(addrPortStr);
if (rp == NULL) { /* No address succeeded */
PrintAndLogEx(ERR, "error: Could not connect");
free(sp);
return INVALID_SERIAL_PORT;
}
sp->fd = sfd;
sp->udpBuffer = RingBuf_create(MAX(sizeof(PacketResponseNGRaw), sizeof(PacketResponseOLD)) * 30);
return sp;
}
if (memcmp(prefix, "bt:", 3) == 0) {
free(prefix);
@@ -211,6 +520,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
sp->fd = sfd;
g_conn.send_via_ip = PM3_NONE;
return sp;
#else // HAVE_BLUEZ
PrintAndLogEx(ERR, "Sorry, this client doesn't support native Bluetooth addresses");
@@ -231,7 +542,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
// we must use max timeout!
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
size_t servernameLen = (strlen(pcPortName) - 7) + 1;
char serverNameBuf[servernameLen];
@@ -262,6 +573,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
sp->fd = localsocket;
g_conn.send_via_ip = PM3_NONE;
return sp;
}
@@ -331,6 +644,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
}
g_conn.uart_speed = uart_get_speed(sp);
g_conn.send_via_ip = PM3_NONE;
return sp;
}
@@ -351,6 +665,7 @@ void uart_close(const serial_port sp) {
//silent error message as it can be called from uart_open failing modes, e.g. when waiting for port to appear
//PrintAndLogEx(ERR, "UART error while closing port");
}
RingBuf_destroy(spu->udpBuffer);
close(spu->fd);
free(sp);
}
@@ -359,6 +674,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
uint32_t byteCount; // FIONREAD returns size on 32b
fd_set rfds;
struct timeval tv;
const serial_port_unix_t_t *spu = (serial_port_unix_t_t *)sp;
if (newtimeout_pending) {
timeout.tv_usec = newtimeout_value * 1000;
@@ -367,11 +683,30 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
// Reset the output count
*pszRxLen = 0;
do {
int res;
if (spu->udpBuffer != NULL) {
// for UDP connection, try to use the data from the buffer
byteCount = RingBuf_getAvailableSize(spu->udpBuffer);
// Cap the number of bytes, so we don't overrun the buffer
if (pszMaxRxLen - (*pszRxLen) < byteCount) {
// PrintAndLogEx(ERR, "UART:: RX prevent overrun (have %u, need %u)", pszMaxRxLen - (*pszRxLen), byteCount);
byteCount = pszMaxRxLen - (*pszRxLen);
}
res = RingBuf_dequeueBatch(spu->udpBuffer, pbtRx + (*pszRxLen), byteCount);
*pszRxLen += res;
if (*pszRxLen == pszMaxRxLen) {
// We have all the data we wanted.
return PM3_SUCCESS;
}
}
// Reset file descriptor
FD_ZERO(&rfds);
FD_SET(((serial_port_unix_t_t *)sp)->fd, &rfds);
FD_SET(spu->fd, &rfds);
tv = timeout;
int res = select(((serial_port_unix_t_t *)sp)->fd + 1, &rfds, NULL, NULL, &tv);
res = select(spu->fd + 1, &rfds, NULL, NULL, &tv);
// Read error
if (res < 0) {
@@ -390,10 +725,31 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
}
// Retrieve the count of the incoming bytes
res = ioctl(((serial_port_unix_t_t *)sp)->fd, FIONREAD, &byteCount);
res = ioctl(spu->fd, FIONREAD, &byteCount);
// PrintAndLogEx(ERR, "UART:: RX ioctl res %d byteCount %u", res, byteCount);
if (res < 0) return PM3_ENOTTY;
// For UDP connection, put the incoming data into the buffer and handle them in the next round
if (spu->udpBuffer != NULL) {
if (RingBuf_getContinousAvailableSize(spu->udpBuffer) >= byteCount) {
// write to the buffer directly
res = read(spu->fd, RingBuf_getRearPtr(spu->udpBuffer), RingBuf_getAvailableSize(spu->udpBuffer));
if (res >= 0) {
RingBuf_postEnqueueBatch(spu->udpBuffer, res);
}
} else {
// use transit buffer
uint8_t transitBuf[MAX(sizeof(PacketResponseNGRaw), sizeof(PacketResponseOLD)) * 30];
res = read(spu->fd, transitBuf, RingBuf_getAvailableSize(spu->udpBuffer));
RingBuf_enqueueBatch(spu->udpBuffer, transitBuf, res);
}
// Stop if the OS has some troubles reading the data
if (res < 0) {
return PM3_EIO;
}
continue;
}
// Cap the number of bytes, so we don't overrun the buffer
if (pszMaxRxLen - (*pszRxLen) < byteCount) {
// PrintAndLogEx(ERR, "UART:: RX prevent overrun (have %u, need %u)", pszMaxRxLen - (*pszRxLen), byteCount);
@@ -401,7 +757,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
}
// There is something available, read the data
res = read(((serial_port_unix_t_t *)sp)->fd, pbtRx + (*pszRxLen), byteCount);
res = read(spu->fd, pbtRx + (*pszRxLen), byteCount);
// Stop if the OS has some troubles reading the data
if (res <= 0) {
@@ -423,13 +779,14 @@ int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
uint32_t pos = 0;
fd_set rfds;
struct timeval tv;
const serial_port_unix_t_t *spu = (serial_port_unix_t_t *)sp;
while (pos < len) {
// Reset file descriptor
FD_ZERO(&rfds);
FD_SET(((serial_port_unix_t_t *)sp)->fd, &rfds);
FD_SET(spu->fd, &rfds);
tv = timeout;
int res = select(((serial_port_unix_t_t *)sp)->fd + 1, NULL, &rfds, NULL, &tv);
int res = select(spu->fd + 1, NULL, &rfds, NULL, &tv);
// Write error
if (res < 0) {
@@ -444,7 +801,7 @@ int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
}
// Send away the bytes
res = write(((serial_port_unix_t_t *)sp)->fd, pbtTx + pos, len - pos);
res = write(spu->fd, pbtTx + pos, len - pos);
// Stop if the OS has some troubles sending the data
if (res <= 0)
@@ -638,4 +995,37 @@ uint32_t uart_get_speed(const serial_port sp) {
};
return uiPortSpeed;
}
bool uart_bind(void *socket, char *bindAddrStr, char *bindPortStr, bool isBindingIPv6) {
if (bindAddrStr == NULL && bindPortStr == NULL)
return true; // no need to bind
struct sockaddr_storage bindSockaddr;
memset(&bindSockaddr, 0, sizeof(bindSockaddr));
int bindPort = 0; // 0: port unspecified
if (bindPortStr != NULL)
bindPort = atoi(bindPortStr);
if (!isBindingIPv6) {
struct sockaddr_in *bindSockaddr4 = (struct sockaddr_in *)&bindSockaddr;
bindSockaddr4->sin_family = AF_INET;
bindSockaddr4->sin_port = htons(bindPort);
if (bindAddrStr == NULL)
bindSockaddr4->sin_addr.s_addr = INADDR_ANY;
else
bindSockaddr4->sin_addr.s_addr = inet_addr(bindAddrStr);
} else {
struct sockaddr_in6 *bindSockaddr6 = (struct sockaddr_in6 *)&bindSockaddr;
bindSockaddr6->sin6_family = AF_INET6;
bindSockaddr6->sin6_port = htons(bindPort);
if (bindAddrStr == NULL)
bindSockaddr6->sin6_addr = in6addr_any;
else
inet_pton(AF_INET6, bindAddrStr, &(bindSockaddr6->sin6_addr));
}
int res = bind(*(int *)socket, (struct sockaddr *)&bindSockaddr, sizeof(bindSockaddr));
return (res >= 0);
}
#endif
+425 -30
View File
@@ -17,6 +17,7 @@
//-----------------------------------------------------------------------------
#include "uart.h"
#include "ringbuffer.h"
#include <stdio.h>
#include <string.h>
@@ -33,16 +34,17 @@
#include <ws2tcpip.h>
typedef struct {
HANDLE hPort; // Serial port handle
DCB dcb; // Device control settings
COMMTIMEOUTS ct; // Serial port time-out configuration
SOCKET hSocket; // Socket handle
HANDLE hPort; // Serial port handle
DCB dcb; // Device control settings
COMMTIMEOUTS ct; // Serial port time-out configuration
SOCKET hSocket; // Socket handle
RingBuffer *udpBuffer; // Buffer for UDP
} serial_port_windows_t;
// this is for TCP connection
struct timeval timeout = {
.tv_sec = 0, // 0 second
.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000
.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000
};
uint32_t newtimeout_value = 0;
@@ -63,8 +65,7 @@ static int uart_reconfigure_timeouts_polling(serial_port sp) {
return PM3_SUCCESS;
newtimeout_pending = false;
serial_port_windows_t *spw;
spw = (serial_port_windows_t *)sp;
serial_port_windows_t *spw = (serial_port_windows_t *)sp;
spw->ct.ReadIntervalTimeout = newtimeout_value;
spw->ct.ReadTotalTimeoutMultiplier = 0;
spw->ct.ReadTotalTimeoutConstant = newtimeout_value;
@@ -90,7 +91,11 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
return INVALID_SERIAL_PORT;
}
char *prefix = strdup(pcPortName);
sp->udpBuffer = NULL;
g_conn.send_via_local_ip = false;
g_conn.send_via_ip = PM3_NONE;
char *prefix = str_dup(pcPortName);
if (prefix == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
@@ -109,22 +114,119 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
struct addrinfo *addr = NULL, *rp;
char *addrstr = strdup(pcPortName + 4);
if (addrstr == NULL) {
char *addrPortStr = str_dup(pcPortName + 4);
char *addrstr = addrPortStr;
const char *portstr;
if (addrPortStr == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
return INVALID_SERIAL_PORT;
}
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
char *colon = strrchr(addrstr, ':');
const char *portstr;
if (colon) {
portstr = colon + 1;
*colon = '\0';
} else {
// find the "bind" option
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
char *bindAddrStr = NULL;
char *bindPortStr = NULL;
bool isBindingIPv6 = false; // Assume v4
if (bindAddrPortStr != NULL) {
*bindAddrPortStr = '\0'; // as the end of target address (and port)
bindAddrPortStr += 6;
bindAddrStr = bindAddrPortStr;
// find the start of the bind address
char *endBracket = strrchr(bindAddrPortStr, ']');
if (bindAddrPortStr[0] == '[') {
bindAddrStr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// find the bind port
char *lColon = strchr(bindAddrPortStr, ':');
char *rColon = strrchr(bindAddrPortStr, ':');
if (rColon == NULL) {
// no colon
// ",bind=<ipv4 address>", ",bind=[<ipv4 address>]"
bindPortStr = NULL;
} else if (lColon == rColon) {
// only one colon
// ",bind=<ipv4 address>:<port>", ",bind=[<ipv4 address>]:<port>"
bindPortStr = rColon + 1;
} else {
// two or more colon, IPv6 address
// ",bind=[<ipv6 address>]:<port>"
// ",bind=<ipv6 address>", ",bind=[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
bindPortStr = rColon + 1;
} else {
bindPortStr = NULL;
}
isBindingIPv6 = true;
}
// handle the end of the bind address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
// for bind option, it's possible to only specify address or port
if (strlen(bindAddrStr) == 0)
bindAddrStr = NULL;
if (bindPortStr != NULL && strlen(bindPortStr) == 0)
bindPortStr = NULL;
}
// find the start of the address
char *endBracket = strrchr(addrPortStr, ']');
if (addrPortStr[0] == '[') {
addrstr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// Assume v4
g_conn.send_via_ip = PM3_TCPv4;
// find the port
char *lColon = strchr(addrPortStr, ':');
char *rColon = strrchr(addrPortStr, ':');
if (rColon == NULL) {
// no colon
// "tcp:<ipv4 address>", "tcp:[<ipv4 address>]"
portstr = "18888";
} else if (lColon == rColon) {
// only one colon
// "tcp:<ipv4 address>:<port>", "tcp:[<ipv4 address>]:<port>"
portstr = rColon + 1;
} else {
// two or more colon, IPv6 address
// "tcp:[<ipv6 address>]:<port>"
// "tcp:<ipv6 address>", "tcp:[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
portstr = rColon + 1;
} else {
portstr = "18888";
}
g_conn.send_via_ip = PM3_TCPv6;
}
// handle the end of the address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
WSADATA wsaData;
@@ -134,19 +236,27 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
PrintAndLogEx(ERR, "error: WSAStartup failed with error: %d", iResult);
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
memset(&info, 0, sizeof(info));
info.ai_family = AF_UNSPEC;
info.ai_socktype = SOCK_STREAM;
info.ai_protocol = IPPROTO_TCP;
if ((strstr(addrstr, "localhost") != NULL) ||
(strstr(addrstr, "127.0.0.1") != NULL) ||
(strstr(addrstr, "::1") != NULL)) {
g_conn.send_via_local_ip = true;
}
int s = getaddrinfo(addrstr, portstr, &info, &addr);
if (s != 0) {
PrintAndLogEx(ERR, "error: getaddrinfo: %s", gai_strerror(s));
PrintAndLogEx(ERR, "error: getaddrinfo: %d: %s", s, gai_strerror(s));
freeaddrinfo(addr);
free(addrstr);
free(addrPortStr);
free(sp);
WSACleanup();
return INVALID_SERIAL_PORT;
@@ -159,6 +269,17 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
if (hSocket == INVALID_SOCKET)
continue;
if (!uart_bind(&hSocket, bindAddrStr, bindPortStr, isBindingIPv6)) {
PrintAndLogEx(ERR, "error: Could not bind. error: %u", WSAGetLastError());
closesocket(hSocket);
hSocket = INVALID_SOCKET;
freeaddrinfo(addr);
free(addrPortStr);
free(sp);
WSACleanup();
return INVALID_SERIAL_PORT;
}
if (connect(hSocket, rp->ai_addr, (int)rp->ai_addrlen) != INVALID_SOCKET)
break;
@@ -167,7 +288,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
freeaddrinfo(addr);
free(addrstr);
free(addrPortStr);
if (rp == NULL) { /* No address succeeded */
PrintAndLogEx(ERR, "error: Could not connect");
@@ -189,6 +310,205 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
return sp;
}
if (memcmp(prefix, "udp:", 4) == 0) {
free(prefix);
if (strlen(pcPortName) <= 4) {
PrintAndLogEx(ERR, "error: tcp port name length too short");
free(sp);
return INVALID_SERIAL_PORT;
}
struct addrinfo *addr = NULL, *rp;
char *addrPortStr = str_dup(pcPortName + 4);
char *addrstr = addrPortStr;
const char *portstr;
if (addrPortStr == NULL) {
PrintAndLogEx(ERR, "error: string duplication");
free(sp);
return INVALID_SERIAL_PORT;
}
timeout.tv_usec = UART_NET_CLIENT_RX_TIMEOUT_MS * 1000;
// find the "bind" option
char *bindAddrPortStr = strstr(addrPortStr, ",bind=");
char *bindAddrStr = NULL;
char *bindPortStr = NULL;
bool isBindingIPv6 = false; // Assume v4
if (bindAddrPortStr != NULL) {
*bindAddrPortStr = '\0'; // as the end of target address (and port)
bindAddrPortStr += 6;
bindAddrStr = bindAddrPortStr;
// find the start of the bind address
char *endBracket = strrchr(bindAddrPortStr, ']');
if (bindAddrPortStr[0] == '[') {
bindAddrStr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched in bind option");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// find the bind port
char *lColon = strchr(bindAddrPortStr, ':');
char *rColon = strrchr(bindAddrPortStr, ':');
if (rColon == NULL) {
// no colon
// ",bind=<ipv4 address>", ",bind=[<ipv4 address>]"
bindPortStr = NULL;
} else if (lColon == rColon) {
// only one colon
// ",bind=<ipv4 address>:<port>", ",bind=[<ipv4 address>]:<port>"
bindPortStr = rColon + 1;
} else {
// two or more colon, IPv6 address
// ",bind=[<ipv6 address>]:<port>"
// ",bind=<ipv6 address>", ",bind=[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
bindPortStr = rColon + 1;
} else {
bindPortStr = NULL;
}
isBindingIPv6 = true;
}
// handle the end of the bind address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
// for bind option, it's possible to only specify address or port
if (strlen(bindAddrStr) == 0)
bindAddrStr = NULL;
if (bindPortStr != NULL && strlen(bindPortStr) == 0)
bindPortStr = NULL;
}
// find the start of the address
char *endBracket = strrchr(addrPortStr, ']');
if (addrPortStr[0] == '[') {
addrstr += 1;
if (endBracket == NULL) {
PrintAndLogEx(ERR, "error: wrong address: [] unmatched");
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
}
// Assume v4
g_conn.send_via_ip = PM3_UDPv4;
// find the port
char *lColon = strchr(addrPortStr, ':');
char *rColon = strrchr(addrPortStr, ':');
if (rColon == NULL) {
// no colon
// "udp:<ipv4 address>", "udp:[<ipv4 address>]"
portstr = "18888";
} else if (lColon == rColon) {
// only one colon
// "udp:<ipv4 address>:<port>", "udp:[<ipv4 address>]:<port>"
portstr = rColon + 1;
} else {
// two or more colon, IPv6 address
// "udp:[<ipv6 address>]:<port>"
// "udp:<ipv6 address>", "udp:[<ipv6 address>]"
if (endBracket != NULL && rColon == endBracket + 1) {
portstr = rColon + 1;
} else {
portstr = "18888";
}
g_conn.send_via_ip = PM3_UDPv6;
}
// handle the end of the address
if (endBracket != NULL) {
*endBracket = '\0';
} else if (rColon != NULL && lColon == rColon) {
*rColon = '\0';
}
WSADATA wsaData;
struct addrinfo info;
int iResult;
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
PrintAndLogEx(ERR, "error: WSAStartup failed with error: %d", iResult);
free(addrPortStr);
free(sp);
return INVALID_SERIAL_PORT;
}
memset(&info, 0, sizeof(info));
info.ai_family = AF_UNSPEC;
info.ai_socktype = SOCK_DGRAM;
info.ai_protocol = IPPROTO_UDP;
if ((strstr(addrstr, "localhost") != NULL) ||
(strstr(addrstr, "127.0.0.1") != NULL) ||
(strstr(addrstr, "::1") != NULL)) {
g_conn.send_via_local_ip = true;
}
int s = getaddrinfo(addrstr, portstr, &info, &addr);
if (s != 0) {
PrintAndLogEx(ERR, "error: getaddrinfo: %d: %s", s, gai_strerror(s));
freeaddrinfo(addr);
free(addrPortStr);
free(sp);
WSACleanup();
return INVALID_SERIAL_PORT;
}
SOCKET hSocket = INVALID_SOCKET;
for (rp = addr; rp != NULL; rp = rp->ai_next) {
hSocket = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (hSocket == INVALID_SOCKET)
continue;
if (!uart_bind(&hSocket, bindAddrStr, bindPortStr, isBindingIPv6)) {
PrintAndLogEx(ERR, "error: Could not bind. error: %u", WSAGetLastError());
closesocket(hSocket);
hSocket = INVALID_SOCKET;
freeaddrinfo(addr);
free(addrPortStr);
free(sp);
WSACleanup();
return INVALID_SERIAL_PORT;
}
if (connect(hSocket, rp->ai_addr, (int)rp->ai_addrlen) != INVALID_SOCKET)
break;
closesocket(hSocket);
hSocket = INVALID_SOCKET;
}
freeaddrinfo(addr);
free(addrPortStr);
if (rp == NULL) { /* No address succeeded */
PrintAndLogEx(ERR, "error: Could not connect");
WSACleanup();
free(sp);
return INVALID_SERIAL_PORT;
}
sp->hSocket = hSocket;
sp->udpBuffer = RingBuf_create(MAX(sizeof(PacketResponseNGRaw), sizeof(PacketResponseOLD)) * 30);
return sp;
}
// Copy the input "com?" to "\\.\COM?" format
snprintf(acPortName, sizeof(acPortName), "\\\\.\\%s", pcPortName);
_strupr(acPortName);
@@ -231,6 +551,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}
}
g_conn.uart_speed = uart_get_speed(sp);
g_conn.send_via_ip = PM3_NONE;
return sp;
}
@@ -241,13 +562,14 @@ void uart_close(const serial_port sp) {
closesocket(spw->hSocket);
WSACleanup();
}
RingBuf_destroy(spw->udpBuffer);
if (spw->hPort != INVALID_HANDLE_VALUE)
CloseHandle(spw->hPort);
free(sp);
}
bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
serial_port_windows_t *spw;
serial_port_windows_t *spw = (serial_port_windows_t *)sp;
// Set port speed (Input and Output)
switch (uiPortSpeed) {
@@ -265,7 +587,6 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
return false;
};
spw = (serial_port_windows_t *)sp;
spw->dcb.BaudRate = uiPortSpeed;
bool result = SetCommState(spw->hPort, &spw->dcb);
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
@@ -284,11 +605,12 @@ uint32_t uart_get_speed(const serial_port sp) {
}
int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) {
serial_port_windows_t *spw = (serial_port_windows_t *)sp;
if (spw->hSocket == INVALID_SOCKET) { // serial port
const serial_port_windows_t *spw = (serial_port_windows_t *)sp;
if (spw->hSocket == INVALID_SOCKET) {
// serial port
uart_reconfigure_timeouts_polling(sp);
int res = ReadFile(((serial_port_windows_t *)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL);
int res = ReadFile(spw->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL);
if (res)
return PM3_SUCCESS;
@@ -299,7 +621,8 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
}
return PM3_ENOTTY;
} else { // TCP
} else {
// TCP or UDP
uint32_t byteCount; // FIONREAD returns size on 32b
fd_set rfds;
struct timeval tv;
@@ -311,12 +634,31 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
// Reset the output count
*pszRxLen = 0;
do {
int res;
if (spw->udpBuffer != NULL) {
// for UDP connection, try to use the data from the buffer
byteCount = RingBuf_getAvailableSize(spw->udpBuffer);
// Cap the number of bytes, so we don't overrun the buffer
if (pszMaxRxLen - (*pszRxLen) < byteCount) {
// PrintAndLogEx(ERR, "UART:: RX prevent overrun (have %u, need %u)", pszMaxRxLen - (*pszRxLen), byteCount);
byteCount = pszMaxRxLen - (*pszRxLen);
}
res = RingBuf_dequeueBatch(spw->udpBuffer, pbtRx + (*pszRxLen), byteCount);
*pszRxLen += res;
if (*pszRxLen == pszMaxRxLen) {
// We have all the data we wanted.
return PM3_SUCCESS;
}
}
// Reset file descriptor
FD_ZERO(&rfds);
FD_SET(spw->hSocket, &rfds);
tv = timeout;
// the first argument nfds is ignored in Windows
int res = select(0, &rfds, NULL, NULL, &tv);
res = select(0, &rfds, NULL, NULL, &tv);
// Read error
if (res == SOCKET_ERROR) {
@@ -336,9 +678,30 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
// Retrieve the count of the incoming bytes
res = ioctlsocket(spw->hSocket, FIONREAD, (u_long *)&byteCount);
// PrintAndLogEx(ERR, "UART:: RX ioctl res %d byteCount %u", res, byteCount);
// PrintAndLogEx(ERR, "UART:: RX ioctl res %d byteCount %u", res, byteCount);
if (res == SOCKET_ERROR) return PM3_ENOTTY;
// For UDP connection, put the incoming data into the buffer and handle them in the next round
if (spw->udpBuffer != NULL) {
if (RingBuf_getContinousAvailableSize(spw->udpBuffer) >= byteCount) {
// write to the buffer directly
res = recv(spw->hSocket, (char *)RingBuf_getRearPtr(spw->udpBuffer), RingBuf_getAvailableSize(spw->udpBuffer), 0);
if (res >= 0) {
RingBuf_postEnqueueBatch(spw->udpBuffer, res);
}
} else {
// use transit buffer
uint8_t transitBuf[MAX(sizeof(PacketResponseNGRaw), sizeof(PacketResponseOLD)) * 30];
res = recv(spw->hSocket, (char *)transitBuf, RingBuf_getAvailableSize(spw->udpBuffer), 0);
RingBuf_enqueueBatch(spw->udpBuffer, transitBuf, res);
}
// Stop if the OS has some troubles reading the data
if (res < 0) {
return PM3_EIO;
}
continue;
}
// Cap the number of bytes, so we don't overrun the buffer
if (pszMaxRxLen - (*pszRxLen) < byteCount) {
// PrintAndLogEx(ERR, "UART:: RX prevent overrun (have %u, need %u)", pszMaxRxLen - (*pszRxLen), byteCount);
@@ -366,10 +729,10 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
}
int uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) {
serial_port_windows_t *spw = (serial_port_windows_t *)sp;
const serial_port_windows_t *spw = (serial_port_windows_t *)sp;
if (spw->hSocket == INVALID_SOCKET) { // serial port
DWORD txlen = 0;
int res = WriteFile(((serial_port_windows_t *)sp)->hPort, p_tx, len, &txlen, NULL);
int res = WriteFile(spw->hPort, p_tx, len, &txlen, NULL);
if (res)
return PM3_SUCCESS;
@@ -417,4 +780,36 @@ int uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) {
}
}
bool uart_bind(void *socket, char *bindAddrStr, char *bindPortStr, bool isBindingIPv6) {
if (bindAddrStr == NULL && bindPortStr == NULL)
return true; // no need to bind
struct sockaddr_storage bindSockaddr;
memset(&bindSockaddr, 0, sizeof(bindSockaddr));
int bindPort = 0; // 0: port unspecified
if (bindPortStr != NULL)
bindPort = atoi(bindPortStr);
if (!isBindingIPv6) {
struct sockaddr_in *bindSockaddr4 = (struct sockaddr_in *)&bindSockaddr;
bindSockaddr4->sin_family = AF_INET;
bindSockaddr4->sin_port = htons(bindPort);
if (bindAddrStr == NULL)
bindSockaddr4->sin_addr.s_addr = INADDR_ANY;
else
bindSockaddr4->sin_addr.s_addr = inet_addr(bindAddrStr);
} else {
struct sockaddr_in6 *bindSockaddr6 = (struct sockaddr_in6 *)&bindSockaddr;
bindSockaddr6->sin6_family = AF_INET6;
bindSockaddr6->sin6_port = htons(bindPort);
if (bindAddrStr == NULL)
bindSockaddr6->sin6_addr = in6addr_any;
else
inet_pton(AF_INET6, bindAddrStr, &(bindSockaddr6->sin6_addr));
}
int res = bind(*(SOCKET *)socket, (struct sockaddr *)&bindSockaddr, sizeof(bindSockaddr));
return (res >= 0);
}
#endif
+1
View File
@@ -62,6 +62,7 @@ typedef struct {
uint16_t client_exe_delay;
char *history_path;
pm3_device_t *current_device;
uint32_t timeout;
} session_arg_t;
extern session_arg_t g_session;
+66 -24
View File
@@ -759,25 +759,6 @@ float param_getfloat(const char *line, int paramnum, float deflt) {
return deflt;
}
int param_gethex(const char *line, int paramnum, uint8_t *data, int hexcnt) {
int bg, en, i;
uint32_t temp;
if (hexcnt & 1) return 1;
if (param_getptr(line, &bg, &en, paramnum)) return 1;
if (en - bg + 1 != hexcnt) return 1;
for (i = 0; i < hexcnt; i += 2) {
if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1]))) return 1;
sscanf((char[]) {line[bg + i], line[bg + i + 1], 0}, "%X", &temp);
data[i / 2] = temp & 0xff;
}
return 0;
}
int param_gethex_ex(const char *line, int paramnum, uint8_t *data, int *hexcnt) {
int bg, en, i;
uint32_t temp;
@@ -785,8 +766,11 @@ int param_gethex_ex(const char *line, int paramnum, uint8_t *data, int *hexcnt)
if (param_getptr(line, &bg, &en, paramnum)) return 1;
*hexcnt = en - bg + 1;
if (*hexcnt % 2) //error if not complete hex bytes
// error if not complete hex bytes
if (*hexcnt & 1) {
return 1;
}
for (i = 0; i < *hexcnt; i += 2) {
if (!(isxdigit(line[bg + i]) && isxdigit(line[bg + i + 1]))) return 1;
@@ -876,7 +860,7 @@ int param_getbin_to_eol(const char *line, int paramnum, uint8_t *data, int maxda
if (strlen(buf) > 0) {
uint32_t temp = 0;
sscanf(buf, "%d", &temp);
sscanf(buf, "%u", &temp);
data[*datalen] = (uint8_t)(temp & 0xff);
*buf = 0;
(*datalen)++;
@@ -944,11 +928,11 @@ int hextobinarray_n(char *target, char *source, int sourcelen) {
return count;
}
// convert hex to human readable binary string
// convert hexstring to human readable binary string
int hextobinstring(char *target, char *source) {
return hextobinstring_n(target, source, strlen(source));
}
// convert hexstring to human readable binary string
int hextobinstring_n(char *target, char *source, int sourcelen) {
int length = hextobinarray_n(target, source, sourcelen);
if (length == 0) {
@@ -958,6 +942,23 @@ int hextobinstring_n(char *target, char *source, int sourcelen) {
return length;
}
// convert bytes to binary string
void byte_2_binstr(char *target, const uint8_t *source, size_t sourcelen) {
//uint8_t *p = *source;
for (int i = 0 ; i < sourcelen; ++i) {
uint8_t b = *(source++);
*(target++) = ((b >> 7) & 0x1) + '0';
*(target++) = ((b >> 6) & 0x1) + '0';
*(target++) = ((b >> 5) & 0x1) + '0';
*(target++) = ((b >> 4) & 0x1) + '0';
*(target++) = ((b >> 3) & 0x1) + '0';
*(target++) = ((b >> 2) & 0x1) + '0';
*(target++) = ((b >> 1) & 0x1) + '0';
*(target++) = (b & 0x1) + '0';
}
*target = '\0';
}
// convert binary array of 0x00/0x01 values to hex
// return number of bits converted
int binarraytohex(char *target, const size_t targetlen, const char *source, size_t srclen) {
@@ -1007,8 +1008,9 @@ int binarraytohex(char *target, const size_t targetlen, const char *source, size
// convert binary array to human readable binary
void binarraytobinstring(char *target, char *source, int length) {
for (int i = 0 ; i < length; ++i)
for (int i = 0 ; i < length; ++i) {
*(target++) = *(source++) + '0';
}
*target = '\0';
}
@@ -1030,6 +1032,36 @@ int binstring2binarray(uint8_t *target, char *source, int length) {
return count;
}
void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src) {
size_t binlen = strlen(src);
if (binlen == 0) {
*targetlen = 0;
return;
}
// Calculate padding needed
size_t padding = (8 - (binlen % 8)) % 8;
// Determine the size of the hexadecimal array
*targetlen = (binlen + padding) / 8;
uint8_t b = 0;
size_t bit_cnt = padding;
size_t idx = 0;
// Process binary string
for (size_t i = 0; i < binlen; ++i) {
b = (b << 1) | (src[i] == '1');
++bit_cnt;
if (bit_cnt == 8) {
target[idx++] = b;
b = 0;
bit_cnt = 0;
}
}
}
// return parity bit required to match type
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length) {
int x;
@@ -1166,6 +1198,16 @@ char *str_ndup(const char *src, size_t len) {
return dest;
}
size_t str_nlen(const char *src, size_t maxlen) {
size_t len = 0;
if (src) {
for (char c = *src; (len < maxlen && c != '\0'); c = *++src) {
len++;
}
}
return len;
}
/**
* Converts a hex string to component "hi2", "hi" and "lo" 32-bit integers
* one nibble at a time.
+4 -1
View File
@@ -106,7 +106,6 @@ uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base);
float param_getfloat(const char *line, int paramnum, float deflt);
uint8_t param_getdec(const char *line, int paramnum, uint8_t *destination);
uint8_t param_isdec(const char *line, int paramnum);
int param_gethex(const char *line, int paramnum, uint8_t *data, int hexcnt);
int param_gethex_ex(const char *line, int paramnum, uint8_t *data, int *hexcnt);
int param_gethex_to_eol(const char *line, int paramnum, uint8_t *data, int maxdatalen, int *datalen);
int param_getbin_to_eol(const char *line, int paramnum, uint8_t *data, int maxdatalen, int *datalen);
@@ -122,6 +121,9 @@ int binarraytohex(char *target, const size_t targetlen, const char *source, size
void binarraytobinstring(char *target, char *source, int length);
int binstring2binarray(uint8_t *target, char *source, int length);
void byte_2_binstr(char *target, const uint8_t *source, size_t sourcelen);
void binstr_2_bytes(uint8_t *target, size_t *targetlen, const char *src);
uint8_t GetParity(const uint8_t *bits, uint8_t type, int length);
void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
void wiegand_add_parity_swapped(uint8_t *target, uint8_t *source, uint8_t length);
@@ -145,6 +147,7 @@ void strcleanrn(char *buf, size_t len);
void strcreplace(char *buf, size_t len, char from, char to);
char *str_dup(const char *src);
char *str_ndup(const char *src, size_t len);
size_t str_nlen(const char *src, size_t maxlen);
int hexstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str);
int binstring_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const char *str);
int binarray_to_u96(uint32_t *hi2, uint32_t *hi, uint32_t *lo, const uint8_t *arr, int arrlen);