Skip to content

Commit

Permalink
Merge pull request RfidResearchGroup#40 from RfidResearchGroup/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
mwalker33 committed Apr 17, 2020
2 parents 29ae24f + 367ae69 commit 7adf47d
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 19 deletions.
13 changes: 9 additions & 4 deletions .gitignore
Expand Up @@ -30,16 +30,17 @@ version.c
*.json
*.old
*.swp
*.json.bak

# new build file for add-ons.
Makefile.platform
# Cache for detecting platform def changes
.Makefile.options.cache

!client/hardnested/*.bin
!client/hardnested/tables/*.z
client/ui/ui_overlays.h
client/reveng/bmptst
!client/resources/hardnested/*.bin
!client/resources/hardnested_tables/*.z
client/src/ui/ui_overlays.h
client/deps/reveng/bmptst

hardnested_stats.txt
proxmark3
Expand All @@ -64,10 +65,14 @@ fpga/*
!fpga/xst_hf.scr
!fpga/go.bat
!fpga/sim.tcl
# offcial dumps folder
dumps/*

#client/*
# my own traces folder
client/traces/*
# my own dumps folder
client/dumps/*
*.ice
*.new
armsrc/TEMP EMV/*
Expand Down
22 changes: 14 additions & 8 deletions armsrc/mifaresim.c
Expand Up @@ -557,7 +557,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
int res = EmGetCmd(receivedCmd, &receivedCmd_len, receivedCmd_par);

if (res == 2) { //Field is off!
FpgaDisableTracing();
//FpgaDisableTracing();
LEDsoff();
cardSTATE = MFEMUL_NOFIELD;
if (DBGLEVEL >= DBG_EXTENDED)
Expand Down Expand Up @@ -595,14 +595,16 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
}

switch (cardSTATE) {
case MFEMUL_NOFIELD:
case MFEMUL_NOFIELD: {
if (DBGLEVEL >= DBG_EXTENDED)
Dbprintf("MFEMUL_NOFIELD");
break;
case MFEMUL_HALTED:
}
case MFEMUL_HALTED: {
if (DBGLEVEL >= DBG_EXTENDED)
Dbprintf("MFEMUL_HALTED");
break;
}
case MFEMUL_IDLE: {
LogTrace(uart->output, uart->len, uart->startTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->endTime * 16 - DELAY_AIR2ARM_AS_TAG, uart->parity, true);
if (DBGLEVEL >= DBG_EXTENDED)
Expand Down Expand Up @@ -706,8 +708,9 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
// WORK
case MFEMUL_WORK: {

if (DBGLEVEL >= DBG_EXTENDED)
if (DBGLEVEL >= DBG_EXTENDED) {
Dbprintf("[MFEMUL_WORK] Enter in case");
}

if (receivedCmd_len == 0) {
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] NO CMD received");
Expand All @@ -718,13 +721,14 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
if (encrypted_data) {
// decrypt seqence
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec);
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Decrypt seqence");
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] Decrypt sequence");
} else {
// Data in clear
memcpy(receivedCmd_dec, receivedCmd, receivedCmd_len);
}

if (!CheckCrc14A(receivedCmd_dec, receivedCmd_len)) { // all commands must have a valid CRC
// all commands must have a valid CRC
if (!CheckCrc14A(receivedCmd_dec, receivedCmd_len)) {
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
FpgaDisableTracing();

Expand Down Expand Up @@ -1251,8 +1255,10 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1

} // End While Loop

FpgaDisableTracing();

// NR AR ATTACK
// mfkey32
if (((flags & FLAG_NR_AR_ATTACK) == FLAG_NR_AR_ATTACK) && (DBGLEVEL >= DBG_INFO)) {
for (uint8_t i = 0; i < ATTACK_KEY_COUNT; i++) {
if (ar_nr_collected[i] == 2) {
Expand All @@ -1268,7 +1274,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
}
}
}


// mfkey32 v2
for (uint8_t i = ATTACK_KEY_COUNT; i < ATTACK_KEY_COUNT * 2; i++) {
if (ar_nr_collected[i] == 2) {
Dbprintf("Collected two pairs of AR/NR which can be used to extract %s from reader for sector %d:", (i < ATTACK_KEY_COUNT / 2) ? "keyA" : "keyB", ar_nr_resp[i].sector);
Expand All @@ -1288,7 +1295,6 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen());
}


if ((flags & FLAG_INTERACTIVE) == FLAG_INTERACTIVE) { // Interactive mode flag, means we need to send ACK
//Send the collected ar_nr in the response
reply_mix(CMD_ACK, CMD_HF_MIFARE_SIMULATE, button_pushed, 0, &ar_nr_resp, sizeof(ar_nr_resp));
Expand Down
5 changes: 3 additions & 2 deletions client/deps/cliparser/argtable3.c
Expand Up @@ -83,8 +83,9 @@ enum {
EMINCOUNT = 1,
EMAXCOUNT,
EBADINT,
// The same name define EOVERFLOW in errno.h on windows platform
#ifdef __STDC_WANT_SECURE_LIB__

// The same name define EOVERFLOW in errno.h on windows platform or android
#if defined(__STDC_WANT_SECURE_LIB__) || defined(__ANDROID__) || defined(ANDROID)
EOVERFLOW_,
#else
EOVERFLOW,
Expand Down
8 changes: 6 additions & 2 deletions client/deps/jansson/jansson_config.h
Expand Up @@ -33,9 +33,13 @@
#define JSON_INTEGER_IS_LONG_LONG 1

/* If locale.h and localeconv() are available, define to 1,
otherwise to 0. */
otherwise to 0. tips: android don't support localeconv()
*/
#if defined(__ANDROID__) || defined(ANDROID)
#define JSON_HAVE_LOCALECONV 0
#else
#define JSON_HAVE_LOCALECONV 1

#endif
/* If __atomic builtins are available they will be used to manage
reference counts of json_t. */
#define JSON_HAVE_ATOMIC_BUILTINS 1
Expand Down
5 changes: 3 additions & 2 deletions client/deps/tinycbor/open_memstream.c
Expand Up @@ -35,7 +35,8 @@
#if defined(__unix__) || defined(__APPLE__)
# include <unistd.h>
#endif
#ifdef __APPLE__

#ifdef __APPLE__ || defined(__ANDROID__) || defined(ANDROID)
typedef int RetType;
typedef int LenType;
#elif __GLIBC__
Expand Down Expand Up @@ -101,7 +102,7 @@ FILE *open_memstream(char **bufptr, size_t *lenptr) {
*bufptr = NULL;
*lenptr = 0;

#ifdef __APPLE__
#ifdef __APPLE__ || defined(__ANDROID__) || defined(ANDROID)
return funopen(b, NULL, write_to_buffer, NULL, close_buffer);
#elif __GLIBC__
static const cookie_io_functions_t vtable = {
Expand Down
47 changes: 47 additions & 0 deletions client/src/uart/uart_posix.c
Expand Up @@ -48,6 +48,8 @@
#include <fcntl.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include "sys/socket.h"
#include "sys/un.h"

#include "comms.h"

Expand Down Expand Up @@ -156,6 +158,51 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
return sp;
}

// The socket for abstract namespace implement.
// Is local socket buffer, not a TCP or any net connection!
// so, you can't connect with address like: 127.0.0.1, or any IP
// see http://man7.org/linux/man-pages/man7/unix.7.html
if (memcmp(pcPortName, "socket:", 7) == 0) {
if (strlen(pcPortName) <= 7) {
free(sp);
return INVALID_SERIAL_PORT;
}

// we must use max timeout!
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;

size_t servernameLen = (strlen(pcPortName) - 7) + 1;
char serverNameBuf[servernameLen];
memset(serverNameBuf, '\0', servernameLen);
for (int i = 7, j = 0; j < servernameLen; ++i, ++j) {
serverNameBuf[j] = pcPortName[i];
}
serverNameBuf[servernameLen - 1] = '\0';

int localsocket, len;
struct sockaddr_un remote;

remote.sun_path[0] = '\0'; // abstract namespace
strcpy(remote.sun_path + 1, serverNameBuf);
remote.sun_family = AF_LOCAL;
int nameLen = strlen(serverNameBuf);
len = 1 + nameLen + offsetof(struct sockaddr_un, sun_path);

if ((localsocket = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) {
free(sp);
return INVALID_SERIAL_PORT;
}

if (connect(localsocket, (struct sockaddr *) &remote, len) == -1) {
free(sp);
return INVALID_SERIAL_PORT;
}

sp->fd = localsocket;

return sp;
}

sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (sp->fd == -1) {
uart_close(sp);
Expand Down
6 changes: 6 additions & 0 deletions client/src/ui.c
Expand Up @@ -21,15 +21,21 @@
#include <stdio.h> // for Mingw readline
#include <stdarg.h>
#include <stdlib.h>

#ifndef ANDROID
#include <readline/readline.h>
#endif

#include <complex.h>
#include "util.h"
#include "proxmark3.h" // PROXLOG
#include "fileutils.h"
#include "pm3_cmd.h"

#ifdef _WIN32
# include <direct.h> // _mkdir
#endif

#include <time.h>
#include "emojis.h"
#include "emojis_alt.h"
Expand Down
Expand Up @@ -13,7 +13,8 @@ For further questions about Mac & Homebrew, contact @Chrisfu (https://github.c
- (Optional) `export HOMEBREW_PROXMARK3_PLATFORM=xxxxxx` to specify [platform](https://github.com/RfidResearchGroup/proxmark3/blob/master/doc/md/Use_of_Proxmark/4_Advanced-compilation-parameters.md#platform), default value is `PM3RDV4` if none
- `brew install proxmark3` for stable release
- `brew install --HEAD proxmark3` for latest non-stable from GitHub (use this if previous command fails)
- `brew install --with-blueshark proxmark3` for blueshark support
- `brew install --with-blueshark proxmark3` for blueshark support, stable release
- `brew install --HEAD --with-blueshark proxmark3` for blueshark support, latest non-stable from GitHub (use this if previous command fails)

For more info, go to https://github.com/RfidResearchGroup/homebrew-proxmark3

Expand Down

0 comments on commit 7adf47d

Please sign in to comment.