]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Added indala demodulation command (indalademod) as well as offline
authoredouard@lafargue.name <edouard@lafargue.name@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Thu, 9 Apr 2009 09:37:34 +0000 (09:37 +0000)
committeredouard@lafargue.name <edouard@lafargue.name@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Thu, 9 Apr 2009 09:37:34 +0000 (09:37 +0000)
mode for the Linux client: if no proxmark is detected, the Linux client
will go on. Of course, do not issue Proxmark3 commands in this mode, the
client does not discriminate at this point...

Changelog [new file with mode: 0644]
linux/proxmark3.c
winsrc/command.cpp

diff --git a/Changelog b/Changelog
new file mode 100644 (file)
index 0000000..3bfe5a9
--- /dev/null
+++ b/Changelog
@@ -0,0 +1,4 @@
+2009-04-09 : Initial SVN commit plus:
+       - Added indala demodulation algorithm - full documentation on https://www.lafargue.name/proxmark3/
+       - losim should also be able to simulate an indala tag after indalademod
+
index 5a3d6f2d24f87c33666217186624fab42b0161aa..b3621af0af59a9736f5d633dde53a6f7853dacde 100644 (file)
@@ -18,6 +18,10 @@ struct usb_receiver_arg {
        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;
@@ -40,6 +44,7 @@ static void *usb_receiver(void *targ) {
 
 static void *main_loop(void *targ)
 {
+       struct main_loop_arg *arg = (struct main_loop_arg*)targ;
        char *cmd = NULL;
 
        while(1) {
@@ -47,11 +52,14 @@ static void *main_loop(void *targ)
                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) {
@@ -71,21 +79,26 @@ static void *main_loop(void *targ)
 
 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;
 }
index 1da1e1c2c7d1f0192e1c6a5cdc67ca144719a4af..43a8e2ac925509d41d2f70490c014fe933ddc317 100644 (file)
@@ -1302,6 +1302,146 @@ static void CmdVchdemod(char *str)
        }\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
@@ -1462,7 +1602,6 @@ static void Cmdaskdemod(char *str) {
 static void Cmdmanchesterdemod(char *str) {
        int i;
        int clock;
-       int grouping=16;
        int lastval;
        int lc = 0;
        int bitidx = 0;
@@ -1705,6 +1844,7 @@ static struct {
        "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
Impressum, Datenschutz