Skip to content

Commit

Permalink
modified the CLI prompt to also show if TCP/UDP is used in the commun…
Browse files Browse the repository at this point in the history
…ication
  • Loading branch information
iceman1001 committed Oct 20, 2023
1 parent b9ae38f commit a35bfbb
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...

## [unreleased][unreleased]
- Changed the CLI prompt to show tcp/udp if used (@iceman1001)
- Changed `hw ping` - now shows transfer time (@doegox)
- Added `hf mf encodehid` - writes HID legacy credential to a empty MFC (@iceman1001)
- Added `hf iclass sam` - Added support for HID SAM Picopass communications (@iceman1001)
- Add support for quoted arguments in the CLI, allowing spaces in them which
Expand Down
9 changes: 9 additions & 0 deletions client/src/comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ typedef enum {
FPGA_MEM,
} DeviceMemType_t;

typedef enum {
PM3_TCPv4,
PM3_TCPv6,
PM3_UDPv4,
PM3_NONE,
} CommunicationProtol_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
Expand All @@ -62,6 +69,8 @@ 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/TCPv6
CommunicationProtol_t send_via_ip;
// To memorise baudrate
uint32_t uart_speed;
uint16_t last_command;
Expand Down
34 changes: 26 additions & 8 deletions client/src/proxmark3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -265,10 +266,27 @@ 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_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;
}
Expand Down Expand Up @@ -341,7 +359,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
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;
Expand Down Expand Up @@ -391,7 +409,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
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));
Expand Down
7 changes: 6 additions & 1 deletion client/src/proxmark3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -35,6 +35,11 @@
#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 PROXHISTORY "history.txt"
#define PROXLOG "log_%Y%m%d%H%M%S.txt"
#define MAX_NESTED_CMDSCRIPT 10
Expand Down
8 changes: 8 additions & 0 deletions client/src/uart/uart_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
free(sp);
return INVALID_SERIAL_PORT;
}

g_conn.send_via_ip = PM3_TCPv4;
return sp;
}

Expand Down Expand Up @@ -313,6 +315,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
sp->fd = sfd;
sp->udpBuffer = RingBuf_create(MAX(sizeof(PacketResponseNGRaw), sizeof(PacketResponseOLD)) * 30);

g_conn.send_via_ip = PM3_UDPv4;
return sp;
}

Expand Down Expand Up @@ -360,6 +363,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");
Expand Down Expand Up @@ -411,6 +416,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
}

sp->fd = localsocket;

g_conn.send_via_ip = PM3_NONE;
return sp;
}

Expand Down Expand Up @@ -480,6 +487,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;
}

Expand Down
3 changes: 3 additions & 0 deletions client/src/uart/uart_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
free(sp);
return INVALID_SERIAL_PORT;
}
g_conn.send_via_ip = PM3_TCPv4;
return sp;
}

Expand Down Expand Up @@ -345,6 +346,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
sp->hSocket = hSocket;
sp->udpBuffer = RingBuf_create(MAX(sizeof(PacketResponseNGRaw), sizeof(PacketResponseOLD)) * 30);

g_conn.send_via_ip = PM3_UDPv4;
return sp;
}

Expand Down Expand Up @@ -390,6 +392,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;
}

Expand Down

0 comments on commit a35bfbb

Please sign in to comment.