int run;
};
+struct main_loop_arg {
+ int usb_present;
+};
+
static void *usb_receiver(void *targ) {
struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ;
UsbCommand cmdbuf;
static void *main_loop(void *targ)
{
+ struct main_loop_arg *arg = (struct main_loop_arg*)targ;
char *cmd = NULL;
while(1) {
pthread_t reader_thread;
rarg.run=1;
- pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
-
+ if (arg->usb_present == 1) {
+ pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
+ }
cmd = readline(PROXPROMPT);
rarg.run=0;
- pthread_join(reader_thread, NULL);
+ if (arg->usb_present == 1) {
+ pthread_join(reader_thread, NULL);
+ }
if (cmd) {
if (cmd[0] != 0x00) {
int main(int argc, char **argv)
{
+ struct main_loop_arg marg;
pthread_t main_loop_t;
usb_init();
if (!(devh = OpenProxmark(1))) {
fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
- exit(1);
+ marg.usb_present = 0;
+ } else {
+ marg.usb_present = 1;
}
- pthread_create(&main_loop_t, NULL, &main_loop, NULL);
+ pthread_create(&main_loop_t, NULL, &main_loop, &marg);
InitGraphics(argc, argv);
MainGraphics();
pthread_join(main_loop_t, NULL);
- CloseProxmark();
+ if (marg.usb_present == 1) {
+ CloseProxmark();
+ }
return 0;
}
}\r
}\r
\r
+static void CmdIndalademod(char *str)\r
+{\r
+ // Usage: recover 64bit UID by default, specify "224" as arg to recover a 224bit UID\r
+\r
+ int state = -1;\r
+ int count = 0;\r
+ int i, j;\r
+ // worst case with GraphTraceLen=64000 is < 4096\r
+ // under normal conditions it's < 2048\r
+ BYTE rawbits[4096];\r
+ int rawbit = 0;\r
+ int worst = 0, worstPos = 0;\r
+ PrintToScrollback("Expecting a bit less than %d raw bits", GraphTraceLen/32);\r
+ for(i = 0; i < GraphTraceLen-1; i += 2) {\r
+ count+=1;\r
+ if((GraphBuffer[i] > GraphBuffer[i + 1]) && (state != 1)) {\r
+ if (state == 0) {\r
+ for(j = 0; j < count - 8; j += 16) {\r
+ rawbits[rawbit++] = 0;\r
+ }\r
+ if ((abs(count - j)) > worst) {\r
+ worst = abs(count - j);\r
+ worstPos = i;\r
+ }\r
+ }\r
+ state = 1;\r
+ count=0;\r
+ } else if((GraphBuffer[i] < GraphBuffer[i + 1]) && (state != 0)) {\r
+ if (state == 1) {\r
+ for(j = 0; j < count - 8; j += 16) {\r
+ rawbits[rawbit++] = 1;\r
+ }\r
+ if ((abs(count - j)) > worst) {\r
+ worst = abs(count - j);\r
+ worstPos = i;\r
+ }\r
+ }\r
+ state = 0;\r
+ count=0;\r
+ }\r
+ }\r
+ PrintToScrollback("Recovered %d raw bits", rawbit);\r
+ PrintToScrollback("worst metric (0=best..7=worst): %d at pos %d", worst, worstPos);\r
+\r
+ // Finding the start of a UID\r
+ int uidlen, long_wait;\r
+ if(strcmp(str, "224") == 0) {\r
+ uidlen=224;\r
+ long_wait=30;\r
+ } else {\r
+ uidlen=64;\r
+ long_wait=29;\r
+ }\r
+ int start;\r
+ int first = 0;\r
+ for(start = 0; start <= rawbit - uidlen; start++) {\r
+ first = rawbits[start];\r
+ for(i = start; i < start + long_wait; i++) {\r
+ if(rawbits[i] != first) {\r
+ break;\r
+ }\r
+ }\r
+ if(i == (start + long_wait)) {\r
+ break;\r
+ }\r
+ }\r
+ if(start == rawbit - uidlen + 1) {\r
+ PrintToScrollback("nothing to wait for");\r
+ return;\r
+ }\r
+\r
+ // Inverting signal if needed\r
+ if(first == 1) {\r
+ for(i = start; i < rawbit; i++) {\r
+ rawbits[i] = !rawbits[i];\r
+ }\r
+ }\r
+\r
+ // Dumping UID\r
+ BYTE bits[224];\r
+ char showbits[225];\r
+ showbits[uidlen]='\0';\r
+ int bit;\r
+ i = start;\r
+ int times = 0;\r
+ if(uidlen > rawbit) {\r
+ PrintToScrollback("Warning: not enough raw bits to get a full UID");\r
+ for(bit = 0; bit < rawbit; bit++) {\r
+ bits[bit] = rawbits[i++];\r
+ // As we cannot know the parity, let's use "." and "/"\r
+ showbits[bit] = '.' + bits[bit];\r
+ }\r
+ showbits[bit+1]='\0';\r
+ PrintToScrollback("Partial UID=%s", showbits);\r
+ return;\r
+ } else {\r
+ for(bit = 0; bit < uidlen; bit++) {\r
+ bits[bit] = rawbits[i++];\r
+ showbits[bit] = '0' + bits[bit];\r
+ }\r
+ times = 1;\r
+ }\r
+ PrintToScrollback("UID=%s", showbits);\r
+\r
+ // Checking UID against next occurences\r
+ for(; i + uidlen <= rawbit;) {\r
+ int failed = 0;\r
+ for(bit = 0; bit < uidlen; bit++) {\r
+ if(bits[bit] != rawbits[i++]) {\r
+ failed = 1;\r
+ break;\r
+ }\r
+ }\r
+ if (failed == 1) {\r
+ break;\r
+ }\r
+ times += 1;\r
+ }\r
+ PrintToScrollback("Occurences: %d (expected %d)", times, (rawbit - start) / uidlen);\r
+\r
+ // Remodulating for tag cloning\r
+ GraphTraceLen = 32*uidlen;\r
+ i = 0;\r
+ int phase = 0;\r
+ for(bit = 0; bit < uidlen; bit++) {\r
+ if(bits[bit] == 0) {\r
+ phase = 0;\r
+ } else {\r
+ phase = 1;\r
+ }\r
+ int j;\r
+ for(j = 0; j < 32; j++) {\r
+ GraphBuffer[i++] = phase;\r
+ phase = !phase;\r
+ }\r
+ }\r
+\r
+ RepaintGraphWindow();\r
+}\r
+\r
static void CmdFlexdemod(char *str)\r
{\r
int i;\r
static void Cmdmanchesterdemod(char *str) {
int i;
int clock;
- int grouping=16;
int lastval;
int lc = 0;
int bitidx = 0;
"ltrim", CmdLtrim, "trim from left of trace",\r
"scale", CmdScale, "set cursor display scale",\r
"flexdemod", CmdFlexdemod, "demod samples for FlexPass",\r
+ "indalademod", CmdIndalademod, "demod samples for Indala",\r
"save", CmdSave, "save trace (from graph window)",\r
"load", CmdLoad, "load trace (to graph window",\r
"hisimlisten", CmdHisimlisten, "get HF samples as fake tag",\r