Proxmark3 developers community

Research, development and trades concerning the powerful Proxmark3 device.

Remember; sharing is caring. Bring something back to the community.


"Learn the tools of the trade the hard way." +Fravia

You are not logged in.

#1 2012-01-02 17:28:47

meskio
Member
Registered: 2011-12-14
Posts: 1

my own cli program for scripting

I didn't manage to understand how the cli program on proxmark3 svn. So I wrote my own to make proxmark3 scriptable.

Here it is my cli.c code:

#include <stdio.h>
#include <string.h>
#include <pthread.h>

#include <usb_cmd.h>
#include <cmdmain.h>

int run;

int init() {
  // Make sure to initialize
  usb_init();
  run = 1;

  if (!OpenProxmark(1)) {
    fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
    return 0;
  } else {
    return 1;
  }
}

static void *reader(){
  while (run) {
    UsbCommand cmdbuf;
    if (ReceiveCommandPoll(&cmdbuf)) {
      UsbCommandReceived(&cmdbuf);
      fflush(NULL);
    }
  }

  pthread_exit(NULL);
  return NULL;
}

static void *writer(void *tcmd){
  char *cmd = (char *)tcmd;

  CommandReceived(cmd);
  run = 0;

  pthread_exit(NULL);
  return NULL;
}

int main(int argc, char **argv) {
  pthread_t reader_t;
  pthread_t writer_t;
  char cmd[128] = "";
  int i;

  if (!init()) {
    return 1;
  }

  for (i = 1; i < argc; i++) {
    strncat(cmd, argv[i], 127);
    strncat(cmd, " ", 127);
  }
  cmd[strlen(cmd) - 1] = '\0';

  pthread_create(&reader_t, NULL, &reader, NULL);
  pthread_create(&writer_t, NULL, &writer, cmd);

  pthread_join(writer_t, NULL);
  pthread_join(reader_t, NULL);
  CloseProxmark();
  return 0;
}

And the Makefile to compile it:

PROX_PATH = ../proxmark3
OBJDIR = ${PROX_PATH}/client/obj

CC = gcc
CFLAGS = -I${PROX_PATH}/include -I${PROX_PATH}/client
LDFLAGS = -lusb -lreadline -lpthread

CMDSRCS = \
                        nonce2key/crapto1.c\
                        nonce2key/crypto1.c\
                        nonce2key/nonce2key.c\
                        mifarehost.c\
                        crc16.c \
                        iso14443crc.c \
                        iso15693tools.c \
                        data.c \
                        graph.c \
                        ui.c \
                        util.c \
                        cmddata.c \
                        cmdhf.c \
                        cmdhf14a.c \
                        cmdhf14b.c \
                        cmdhf15.c \
                        cmdhflegic.c \
                        cmdhficlass.c \
                        cmdhfmf.c \
                        cmdhw.c \
                        cmdlf.c \
                        cmdlfem4x.c \
                        cmdlfhid.c \
                        cmdlfti.c \
                        cmdparser.c \
                        cmdmain.c

CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)

all: cli

cli: ${CMDOBJS} ${OBJDIR}/proxusb.o $(OBJDIR)/guidummy.o
        ${CC} ${CFLAGS} cli.c -o $@ ${LDFLAGS} $^

clean:
        rm cli

With it I can make scripts like this reader of the amount of cash in some card:

#!/bin/sh

data=`./cli hf mf rdbl 8 a ffffffffffff |grep isOk|sed 's/^.*data:\(.*\)$/\1/g'|tr -d " "`

hex_money=`echo $data |sed 's/^\(..\)\(..\).*$/\2\1/g'`
money=`python -c "print 0x${hex_money}"| sed 's/^\(.*\)\(...\)$/\1,\2/g'`
echo "You have: $money"

Last edited by meskio (2012-01-11 19:07:18)

Offline

Board footer

Powered by FluxBB