cielavenir

m4c2m4a - Tap Tap m4c decrypter

Nov 27th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4.  
  5. typedef unsigned char u8;
  6. #define HEADSIZE 256
  7.  
  8. #define BUFLEN (1<<16)
  9. static u8 buf[BUFLEN];
  10.  
  11. static u8 key[8],head[HEADSIZE];
  12. int m4c2m4a(const int argc, const char **argv){
  13.     if(isatty(fileno(stdin))||isatty(fileno(stdout))){
  14.         fprintf(stderr,"m4c2m4a <in.m4c >out.m4a\n");
  15.         return 1;
  16.     }
  17.  
  18.     int i,j,readlen;
  19.     fread(head,1,HEADSIZE,stdin);
  20.  
  21.     //determine other than byte3
  22.     memcpy(key,head,8);
  23.     for(i=0;i<8;i++)key[i]^="\0\0\0?ftyp"[i];
  24.  
  25.     //determine byte3
  26.     u8 *p=head;
  27.     for(i=0;i<HEADSIZE/8;i++)
  28.         for(j=i+1;j<HEADSIZE/8;j++)
  29.             if(!memcmp(p+(i*8),p+(j*8),8))goto done;
  30.     fprintf(stderr,"key find failed\n");
  31.     return 2;
  32.  
  33. done:
  34.     key[3]=p[j*8+3];
  35.     fprintf(stderr,"key=");
  36.     for(i=0;i<8;i++)fprintf(stderr,"%02x",key[i]);
  37.     fprintf(stderr,"\n");
  38.  
  39.     //decrypt head
  40.     for(i=0;i<HEADSIZE;i++)head[i]^=key[i%8];
  41.     fwrite(head,1,HEADSIZE,stdout);
  42.  
  43.     //decrypt remaining data
  44.     for(;readlen=fread(buf,1,BUFLEN,stdin);){
  45.         for(i=0;i<readlen;i++)buf[i]^=key[i%8];
  46.         fwrite(buf,1,readlen,stdout);
  47.     }
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment