Merge branch 'master' into experimental_varlen

* master:
  rework Dbprintf & add color support
  use color macros
  doc magic
  archive and fix hid-flasher
  update standalone readme
This commit is contained in:
Philippe Teuwen
2019-04-26 10:48:28 +02:00
32 changed files with 210 additions and 183 deletions
+2 -2
View File
@@ -96,10 +96,10 @@ void BigBuf_free_keep_EM(void) {
}
void BigBuf_print_status(void) {
Dbprintf("Memory");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Memory"));
Dbprintf(" BIGBUF_SIZE.............%d", BIGBUF_SIZE);
Dbprintf(" Available memory........%d", BigBuf_hi);
Dbprintf("Tracing");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Tracing"));
Dbprintf(" tracing ................%d", tracing);
Dbprintf(" traceLen ...............%d", traceLen);
}
File diff suppressed because it is too large Load Diff
+11 -11
View File
@@ -75,12 +75,12 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
// get UID from chip
if (workFlags & 0x01) {
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
DbprintfEx(FLAG_NOLOG, "Can't select card");
DbprintfEx(FLAG_NEWLINE, "Can't select card");
break;
};
if (mifare_classic_halt(NULL, cuid)) {
DbprintfEx(FLAG_NOLOG, "Halt error");
DbprintfEx(FLAG_NEWLINE, "Halt error");
break;
};
};
@@ -89,18 +89,18 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
if (needWipe) {
ReaderTransmitBitsPar(wupC1, 7, 0, NULL);
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
DbprintfEx(FLAG_NOLOG, "wupC1 error");
DbprintfEx(FLAG_NEWLINE, "wupC1 error");
break;
};
ReaderTransmit(wipeC, sizeof(wipeC), NULL);
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
DbprintfEx(FLAG_NOLOG, "wipeC error");
DbprintfEx(FLAG_NEWLINE, "wipeC error");
break;
};
if (mifare_classic_halt(NULL, cuid)) {
DbprintfEx(FLAG_NOLOG, "Halt error");
DbprintfEx(FLAG_NEWLINE, "Halt error");
break;
};
};
@@ -110,19 +110,19 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
if (workFlags & 0x02) {
ReaderTransmitBitsPar(wupC1, 7, 0, NULL);
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
DbprintfEx(FLAG_NOLOG, "wupC1 error");
DbprintfEx(FLAG_NEWLINE, "wupC1 error");
break;
};
ReaderTransmit(wupC2, sizeof(wupC2), NULL);
if (!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
DbprintfEx(FLAG_NOLOG, "wupC2 errorv");
DbprintfEx(FLAG_NEWLINE, "wupC2 errorv");
break;
};
}
if ((mifare_sendcmd_short(NULL, 0, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL) != 1) || (receivedAnswer[0] != 0x0a)) {
DbprintfEx(FLAG_NOLOG, "write block send command error");
DbprintfEx(FLAG_NEWLINE, "write block send command error");
break;
};
@@ -130,13 +130,13 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
AddCrc14A(d_block, 16);
ReaderTransmit(d_block, sizeof(d_block), NULL);
if ((ReaderReceive(receivedAnswer, receivedAnswerPar) != 1) || (receivedAnswer[0] != 0x0a)) {
DbprintfEx(FLAG_NOLOG, "write block send data error");
DbprintfEx(FLAG_NEWLINE, "write block send data error");
break;
};
if (workFlags & 0x04) {
if (mifare_classic_halt(NULL, cuid)) {
DbprintfEx(FLAG_NOLOG, "Halt error");
DbprintfEx(FLAG_NEWLINE, "Halt error");
break;
};
}
@@ -168,7 +168,7 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
/* no need for anticollision. just verify tag is still here */
// if (!iso14443a_fast_select_card(cjuid, 0)) {
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
DbprintfEx(FLAG_NOLOG, "FATAL : E_MF_LOSTTAG");
DbprintfEx(FLAG_NEWLINE, "FATAL : E_MF_LOSTTAG");
return -1;
}
+13 -13
View File
@@ -9,17 +9,17 @@ As it is now, you can only have one standalone mode installed at the time.
## Implementing a standalone mode
We suggest you keep your standalone code inside the Armsrc/Standalone folder. And that you name your files according to your standalone mode name.
We suggest you keep your standalone code inside the `armsrc/Standalone` folder. And that you name your files according to your standalone mode name.
The `standalone.h` states that you must have two function implemented.
The `standalone.h` states that you must have two functions implemented.
The ModInfo function, which is your identification of your standalone mode. This string will show when running the command `hw status` on the client.
The RunMod function, which is your "main" function when running. You need to check for Usb commands, in order to let the pm3 client break the standalone mode. See this basic skeleton of main function RunMod() and Modinfo() below.
The RunMod function, which is your "main" function when running. You need to check for Usb commands, in order to let the pm3 client break the standalone mode. See this basic skeleton of main function RunMod() and Modinfo() below.
````
void ModInfo(void) {
DbpString(" LF good description of your mode - aka FooRun (my name)");
DbpString(" LF good description of your mode - aka FooRun (your name)");
}
void RunMod(void) {
@@ -40,27 +40,27 @@ void RunMod(void) {
}
````
Each standalone mode needs to have its own compiler flag to be added in `armsrc\makefile`.
Each standalone mode needs to have its own compiler flag to be added in `armsrc/Makefile`.
## Naming your standalone mode
We suggest that you follow these guidelines,
- Use HF/LF to denote which frequence your mod is targeting.
We suggest that you follow these guidelines:
- Use HF/LF to denote which frequency your mode is targeting.
- Use you own github name/similar for perpetual honour to denote your mode.
sample:
`LF_FOORUN`
`LF_FOO`
Which indicates your mode targets LF and is called FOO.
This leads to your next step, your DEFINE name needed in Makefile.
`WITH_STANDALONE_LF_FOORUN`
`WITH_STANDALONE_LF_FOO`
## Update COMMON/MAKEFILE.HAL
Samples of directive flag used in the `common/Makefile.ha` and your suggested DEFINE.
Add your suggested DEFINE to the samples of directive flag provided in the `common/Makefile.hal`.
```
#PLATFORM_DEFS += -DWITH_STANDALONE_LF_SAMYRUN
#PLATFORM_DEFS += -DWITH_STANDALONE_LF_ICERUN
@@ -70,7 +70,7 @@ Samples of directive flag used in the `common/Makefile.ha` and your suggested DE
#PLATFORM_DEFS += -DWITH_STANDALONE_HF_MATTYRUN
#PLATFORM_DEFS += -DWITH_STANDALONE_HF_COLIN
#PLATFORM_DEFS += -DWITH_STANDALONE_HF_BOG
#PLATFORM_DEFS += -DWITH_STANDALONE_LF_FOORUN
#PLATFORM_DEFS += -DWITH_STANDALONE_LF_FOO
```
## Update ARMSRC/MAKEFILE
@@ -90,11 +90,11 @@ endif
## Adding identification string of your mode
Do please add a identification string in a function called `ModInfo` inside your source code file.
This will enable an easy way to detect on client side which standalone mods has been installed on the device.
This will enable an easy way to detect on client side which standalone mode has been installed on the device.
````
void ModInfo(void) {
DbpString(" LF good description of your mode - aka FooRun (my name)");
DbpString(" LF good description of your mode - aka FooRun (your name)");
}
````
+10 -10
View File
@@ -114,13 +114,13 @@ void print_result(char *name, uint8_t *buf, size_t len) {
// Debug print functions, to go out over USB, to the usual PC-side client.
//=============================================================================
void DbpStringEx(char *str, uint32_t cmd) {
void DbpStringEx(uint32_t flags, char *str) {
#if DEBUG
struct {
uint16_t flag;
uint8_t buf[USB_CMD_DATA_SIZE - sizeof(uint16_t)];
} PACKED data;
data.flag = cmd;
data.flag = flags;
uint16_t len = MIN(strlen(str), sizeof(data.buf));
memcpy(data.buf, str, len);
reply_ng(CMD_DEBUG_PRINT_STRING, PM3_SUCCESS, (uint8_t *)&data, sizeof(data.flag) + len);
@@ -129,7 +129,7 @@ void DbpStringEx(char *str, uint32_t cmd) {
void DbpString(char *str) {
#if DEBUG
DbpStringEx(str, 0);
DbpStringEx(FLAG_LOG, str);
#endif
}
@@ -138,7 +138,7 @@ void DbpIntegers(int x1, int x2, int x3) {
reply_old(CMD_DEBUG_PRINT_INTEGERS, x1, x2, x3, 0, 0);
}
#endif
void DbprintfEx(uint32_t cmd, const char *fmt, ...) {
void DbprintfEx(uint32_t flags, const char *fmt, ...) {
#if DEBUG
// should probably limit size here; oh well, let's just use a big buffer
char output_string[128] = {0x00};
@@ -147,7 +147,7 @@ void DbprintfEx(uint32_t cmd, const char *fmt, ...) {
kvsprintf(fmt, output_string, 10, ap);
va_end(ap);
DbpStringEx(output_string, cmd);
DbpStringEx(flags, output_string);
#endif
}
@@ -316,10 +316,10 @@ void MeasureAntennaTuningHf(void) {
} else {
volt = (MAX_ADC_HF_VOLTAGE_RDV40 * AvgAdc(ADC_CHAN_HF_RDV40)) >> 10;
}
DbprintfEx(FLAG_NONEWLINE, "%u mV / %5u V", volt, (uint16_t)(volt / 1000));
DbprintfEx(FLAG_INPLACE, "%u mV / %5u V", volt, (uint16_t)(volt / 1000));
}
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
DbprintfEx(FLAG_NOOPT, "\n[+] cancelled", 1);
DbprintfEx(FLAG_LOG, "\n[+] cancelled", 1);
}
void ReadMem(int addr) {
@@ -371,7 +371,7 @@ void SendVersion(void) {
// measure the USB Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
// Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the PacketCommandNG structure included.
void printUSBSpeed(void) {
Dbprintf("USB Speed");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("USB Speed"));
Dbprintf(" Sending USB packets to client...");
#define USB_SPEED_TEST_MIN_TIME 1500 // in milliseconds
@@ -412,12 +412,12 @@ void SendStatus(void) {
printT55xxConfig(); // LF T55XX Config
#endif
printUSBSpeed();
Dbprintf("Various");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Various"));
Dbprintf(" MF_DBGLEVEL.............%d", MF_DBGLEVEL);
Dbprintf(" ToSendMax...............%d", ToSendMax);
Dbprintf(" ToSendBit...............%d", ToSendBit);
Dbprintf(" ToSend BUFFERSIZE.......%d", TOSEND_BUFFER_SIZE);
DbpString("Installed StandAlone Mode");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Installed StandAlone Mode"));
ModInfo();
//DbpString("Running ");
+1
View File
@@ -45,6 +45,7 @@ void ReadMem(int addr);
void __attribute__((noreturn)) AppMain(void);
//void DbpIntegers(int a, int b, int c);
void DbpString(char *str);
void DbpStringEx(uint32_t cmd, char *str);
void Dbprintf(const char *fmt, ...);
void DbprintfEx(uint32_t cmd, const char *fmt, ...);
void Dbhexdump(int len, uint8_t *d, bool bAsci);
+1 -1
View File
@@ -512,7 +512,7 @@ void Flash_EraseChip(void) {
*/
void Flashmem_print_status(void) {
DbpString("Flash memory");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Flash memory"));
Dbprintf(" Baudrate................%dMHz", FLASHMEM_SPIBAUDRATE / 1000000);
if (!FlashInit()) {
+1 -1
View File
@@ -483,7 +483,7 @@ void SetAdcMuxFor(uint32_t whichGpio) {
}
void Fpga_print_status(void) {
Dbprintf("Currently loaded FPGA image");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("Currently loaded FPGA image"));
Dbprintf(" mode....................%s", fpga_version_information[downloaded_bitstream - 1]);
}
+1 -1
View File
@@ -55,7 +55,7 @@ Default LF T55xx config is set to:
t55xx_config t_config = { 29 * 8, 17 * 8, 15 * 8, 47 * 8, 15 * 8 } ;
void printT55xxConfig(void) {
Dbprintf("LF T55XX config");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("LF T55XX config"));
Dbprintf(" [a] startgap............%d*8 (%d)", t_config.start_gap / 8, t_config.start_gap);
Dbprintf(" [b] writegap............%d*8 (%d)", t_config.write_gap / 8, t_config.write_gap);
Dbprintf(" [c] write_0.............%d*8 (%d)", t_config.write_0 / 8, t_config.write_0);
+1 -1
View File
@@ -19,7 +19,7 @@ Default LF config is set to:
sample_config config = { 1, 8, 1, 95, 0 } ;
void printConfig() {
Dbprintf("LF Sampling config");
DbpStringEx(FLAG_LOG|FLAG_ANSI, _BLUE_("LF Sampling config"));
Dbprintf(" [q] divisor.............%d (%d KHz)", config.divisor, 12000 / (config.divisor + 1));
Dbprintf(" [b] bps.................%d", config.bits_per_sample);
Dbprintf(" [d] decimation..........%d", config.decimation);
+7
View File
@@ -18,6 +18,13 @@
#include "ticks.h"
// Basic macros
# define _BLUE_(s) "\x1b[34m" s "\x1b[0m "
# define _RED_(s) "\x1b[31m" s "\x1b[0m "
# define _GREEN_(s) "\x1b[32m" s "\x1b[0m "
# define _YELLOW_(s) "\x1b[33m" s "\x1b[0m "
# define _MAGENTA_(s) "\x1b[35m" s "\x1b[0m "
# define _CYAN_(s) "\x1b[36m" s "\x1b[0m "
#ifndef SHORT_COIL
#define SHORT_COIL() LOW(GPIO_SSC_DOUT)
#endif
+1 -5
View File
@@ -499,11 +499,7 @@ void pm3_version(bool verbose) {
#else
if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) {
#endif
#ifdef __WIN32
PrintAndLogEx(NORMAL, "\n [ Proxmark3 RFID instrument ]\n");
#else
PrintAndLogEx(NORMAL, "\n\e[34m [ Proxmark3 RFID instrument ]\e[0m\n");
#endif
PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n");
char s[60] = {0};
#if defined(WITH_FLASH) || defined(WITH_SMARTCARD) || defined(WITH_FPC)
strncat(s, "build for RDV40 with ", sizeof(s) - strlen(s) - 1);
+44 -18
View File
@@ -235,6 +235,39 @@ static int getReply(PacketResponseNG *packet) {
return 1;
}
static void memcpy_filtered(void *dest, const void *src, size_t n, bool filter) {
#if defined(__linux__) || (__APPLE__)
memcpy(dest, src, n);
#else
if (filter)
// Filter out ANSI sequences on these OS
uint16_t si=0;
for (uint16_t i=0; i < n; i++) {
if ((src[i] == '\x1b') && (i < n - 1) && (src[i+1] >= 0x40) && (src[i+1] <= 0x5F)) { // entering ANSI sequence
i++;
if ((src[i] == '[') && (i < n - 1)) { // entering CSI sequence
i++;
while ((i < n - 1) && (src[i] >= 0x30) && (src[i] <= 0x3F)) { // parameter bytes
i++;
}
while ((i < n - 1) && (src[i] >= 0x20) && (src[i] <= 0x2F)) { // intermediate bytes
i++;
}
if ((src[i] >= 0x40) && (src[i] <= 0x7F)) { // final byte
continue;
}
} else {
continue;
}
}
dest[si++] = src[i];
}
} else {
memcpy(dest, src, n);
}
#endif
}
//-----------------------------------------------------------------------------
// Entry point into our code: called whenever we received a packet over USB
// that we weren't necessarily expecting, for example a debug print.
@@ -263,31 +296,24 @@ static void PacketResponseReceived(PacketResponseNG *packet) {
} PACKED;
struct d *data = (struct d *)&packet->data.asBytes;
len = packet->length - sizeof(data->flag);
memcpy(s, data->buf, len);
flag = data->flag;
memcpy_filtered(s, data->buf, len, flag & FLAG_ANSI);
} else {
len = MIN(packet->oldarg[0], USB_CMD_DATA_SIZE);
memcpy(s, packet->data.asBytes, len);
flag = packet->oldarg[1];
memcpy_filtered(s, packet->data.asBytes, len, flag & FLAG_ANSI);
}
switch (flag) {
case FLAG_RAWPRINT:
printf("%s", s);
break;
case FLAG_NONEWLINE:
printf("\r%s", s);
break;
case FLAG_NOLOG:
printf("%s\r\n", s);
break;
//case FLAG_NOPROMPT:
// break;
case FLAG_NOOPT:
default:
PrintAndLogEx(NORMAL, "#db# %s", s);
break;
if (flag & FLAG_LOG) {
PrintAndLogEx(NORMAL, "#db# %s", s);
} else {
if (flag & FLAG_INPLACE)
printf("\r");
printf("%s", s);
if (flag & FLAG_NEWLINE)
printf("\r\n");
}
fflush(stdout);
break;
}
@@ -3,26 +3,23 @@
# at your option, any later version. See the LICENSE.txt file for the text of
# the license.
#-----------------------------------------------------------------------------
include ../../common/Makefile.common
CC=gcc
CXX=g++
#COMMON_FLAGS = -m32
VPATH = ../../common
OBJDIR = obj
LDLIBS = -lreadline -lpthread
CFLAGS = -std=gnu99 -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3
ifeq ($(platform),Darwin)
LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb-1.0 -lreadline -lpthread
CFLAGS = -std=gnu99 -I. -I../include -I../common -I/usr/local/include -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3
LDLIBS += -lusb-1.0
else
LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb -lreadline -lpthread
CFLAGS = -std=gnu99 -I. -I../include -I../common -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS) -g -O3
LDLIBS += -lusb
endif
LDFLAGS = $(COMMON_FLAGS)
CXXFLAGS =
QTLDLIBS =
RM = rm -f
BINS = flasher
@@ -11,11 +11,11 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "util_posix.h"
#include "proxusb.h"
#include "flash.h"
#include "elf.h"
#include "proxendian.h"
#include "sleep.h"
#define FLASH_START 0x100000
#define FLASH_SIZE (256*1024)
@@ -9,9 +9,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util_posix.h"
#include "proxusb.h"
#include "flash.h"
#include "sleep.h"
static void usage(char *argv0) {
fprintf(stderr, "Usage: %s [-b] image.elf [image.elf...]\n\n", argv0);

Some files were not shown because too many files have changed in this diff Show More