#include #include #include //run this on the file from a wget http://marc.ucis.ano/?get=0&version=3 #define M_TYPE_NULL 0 #define M_TYPE_STRING 1 #define M_TYPE_LIST 2 #define M_TYPE_DICT 3 //extension? #define M_TYPE_TRANSFERCHAIN 5 char *type[]={"NULL","string","list","dict"}; int indent; void pi() { int i; for(i=0;i>4&15],"0123456789abcdef"[(*data-'0')&15]); printf("%%%02x",*data); //"0123456789abcdef"[(*data-'0')>>4&15],"0123456789abcdef"[(*data-'0')&15]); } } } int marc_decode(unsigned char *data,int from_index,int length) { unsigned char *s; unsigned int cur_len=0; unsigned char m_type=data[from_index]; from_index++; char *key; if(!length) return printf("what the fuck? no length???"),-1; pi(); printf("length: %d\n",length); pi(); switch(m_type) { case M_TYPE_NULL: printf("[null]\n"); break; case M_TYPE_STRING: s=malloc(length); memcpy(s,data+from_index,length-1); s[length-1]=0; printf("string: "); printpercent(s,length); printf("\n"); break; case M_TYPE_LIST: printf("list:\n"); indent++; while(from_index < length) { cur_len=data[from_index+3]+(data[from_index+2]<<1)+(data[from_index+1]<<2)+(data[from_index+0]<<3); from_index+=4; marc_decode(data,from_index,cur_len); from_index+=cur_len; } indent--; break; case M_TYPE_DICT: printf("dict:\n"); indent++; while(from_index < length) { cur_len=data[from_index]; pi(); printf("len: %d\n",cur_len); from_index++; if(cur_len == 0) break; key=malloc(cur_len+1); memcpy(key,data+from_index,cur_len); key[cur_len]=0; from_index+=cur_len; pi(); printf("key: %s\n",key,cur_len); cur_len=data[from_index+3]+(data[from_index+2]<<1)+(data[from_index+1]<<2)+(data[from_index+0]<<3); from_index+=4; indent++; marc_decode(data,from_index,cur_len); indent--; from_index+=cur_len; } indent--; break; /*case M_TYPE_TRANSFERCHAIN: s=malloc(length); memcpy(s,data+from_index,length-1); s[length-1]=0; printf("transfer: %s\n",s); break;*/ default: printf("oh fuck. dahell is this!?!? mtype of %d!?!?\n",m_type); break; } return 0; } void printhex(unsigned char *data,int length) { for(;length;data++,length--) { printf("%02x",*data); } } void update_message_decode(unsigned char *data,int from_index,int length) { printf("\nupdate_message version: %d len: %d\n",data[from_index],length); if(data[from_index] != 2) return printf("this program only handles version 2 update messages.\n"); from_index++; char pkey[32]; int i; char *label; unsigned int thedate=0; unsigned char label_len=0,ext_type,num_extensions; short ext_data_len; memcpy(pkey,data+from_index,32); from_index+=32; char sig[64]; memcpy(sig,data+from_index,64); from_index+=64; printf("pkey: 0x"); printhex(pkey,32); printf("\n"); printf("sig: 0x"); printhex(sig,64); printf("\n"); //for(;from_index < length;) { //timestamp, 4 bytes thedate=(data[from_index]<<24)+(data[from_index+1]<<16)+(data[from_index+2]<<8)+(data[from_index+3]); printf("thedate: %d\n",thedate); from_index+=4; //label length, 1 byte label_len=data[from_index]; from_index++; printf("label len: %d\n",label_len); label=malloc(label_len); memcpy(label,data+from_index,label_len); label[label_len]=0; printf("label: "); printhex(label,label_len); printf("\n"); from_index+=label_len; num_extensions=data[from_index]; printf("num of extensions: %d\n",num_extensions); from_index++; for(i=0;i