Mercurial > hg > anonet-resdb
annotate contrib/marc/marc.c @ 1233:1b7ce27f434c draft
added as 1234 and cidr 21.44.44.0/24
Committer: ano <ano@x>
author | ano <root@x> |
---|---|
date | Sun, 02 Dec 2018 23:01:26 +0000 |
parents | 98707534e274 |
children |
rev | line source |
---|---|
1173 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 | |
5 //run this on the file from a wget http://marc.ucis.ano/?get=0&version=3 | |
6 | |
7 #define M_TYPE_NULL 0 | |
8 #define M_TYPE_STRING 1 | |
9 #define M_TYPE_LIST 2 | |
10 #define M_TYPE_DICT 3 | |
11 | |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
12 //extension? |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
13 #define M_TYPE_TRANSFERCHAIN 5 |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
14 |
1173 | 15 char *type[]={"NULL","string","list","dict"}; |
16 | |
17 int indent; | |
18 | |
19 void pi() { | |
20 int i; | |
21 for(i=0;i<indent;i++) { | |
22 printf("%s"," "); | |
23 } | |
24 } | |
25 | |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
26 void printpercent(unsigned char *data,int length) { |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
27 for(;length;data++,length--) { |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
28 if(isprint(*data)) printf("%c",*data); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
29 else { |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
30 // printf("%%%c%c","0123456789abcdef"[(*data-'0')>>4&15],"0123456789abcdef"[(*data-'0')&15]); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
31 printf("%%%02x",*data); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
32 //"0123456789abcdef"[(*data-'0')>>4&15],"0123456789abcdef"[(*data-'0')&15]); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
33 } |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
34 } |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
35 } |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
36 |
1173 | 37 int marc_decode(unsigned char *data,int from_index,int length) { |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
38 unsigned char *s; |
1173 | 39 unsigned int cur_len=0; |
40 unsigned char m_type=data[from_index]; | |
41 from_index++; | |
42 char *key; | |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
43 if(!length) return printf("what the fuck? no length???"),-1; |
1173 | 44 pi(); |
45 printf("length: %d\n",length); | |
46 pi(); | |
47 switch(m_type) { | |
48 case M_TYPE_NULL: | |
49 printf("[null]\n"); | |
50 break; | |
51 case M_TYPE_STRING: | |
52 s=malloc(length); | |
53 memcpy(s,data+from_index,length-1); | |
54 s[length-1]=0; | |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
55 printf("string: "); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
56 printpercent(s,length); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
57 printf("\n"); |
1173 | 58 break; |
59 case M_TYPE_LIST: | |
60 printf("list:\n"); | |
61 indent++; | |
62 while(from_index < length) { | |
1186
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
63 |
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
64 // old code. testing 16 bit lengths. |
1173 | 65 cur_len=data[from_index+3]+(data[from_index+2]<<1)+(data[from_index+1]<<2)+(data[from_index+0]<<3); |
66 from_index+=4; | |
1186
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
67 |
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
68 // cur_len=data[from_index+1]+(data[from_index+0]<<1); |
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
69 // from_index+=2; |
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
70 |
1173 | 71 marc_decode(data,from_index,cur_len); |
72 from_index+=cur_len; | |
73 } | |
74 indent--; | |
75 break; | |
76 case M_TYPE_DICT: | |
77 printf("dict:\n"); | |
78 indent++; | |
79 while(from_index < length) { | |
80 cur_len=data[from_index]; | |
81 pi(); | |
82 printf("len: %d\n",cur_len); | |
83 from_index++; | |
84 if(cur_len == 0) break; | |
85 key=malloc(cur_len+1); | |
86 memcpy(key,data+from_index,cur_len); | |
87 key[cur_len]=0; | |
88 from_index+=cur_len; | |
89 pi(); | |
90 printf("key: %s\n",key,cur_len); | |
91 cur_len=data[from_index+3]+(data[from_index+2]<<1)+(data[from_index+1]<<2)+(data[from_index+0]<<3); | |
92 from_index+=4; | |
93 indent++; | |
94 marc_decode(data,from_index,cur_len); | |
95 indent--; | |
96 from_index+=cur_len; | |
97 } | |
98 indent--; | |
99 break; | |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
100 /*case M_TYPE_TRANSFERCHAIN: |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
101 s=malloc(length); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
102 memcpy(s,data+from_index,length-1); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
103 s[length-1]=0; |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
104 printf("transfer: %s\n",s); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
105 break;*/ |
1173 | 106 default: |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
107 printf("oh fuck. dahell is this!?!? mtype of %d!?!?\n",m_type); |
1173 | 108 break; |
109 } | |
110 return 0; | |
111 } | |
112 | |
113 void printhex(unsigned char *data,int length) { | |
114 for(;length;data++,length--) { | |
115 printf("%02x",*data); | |
116 } | |
117 } | |
118 | |
119 void update_message_decode(unsigned char *data,int from_index,int length) { | |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
120 printf("\nupdate_message version: %d len: %d\n",data[from_index],length); |
1173 | 121 if(data[from_index] != 2) return printf("this program only handles version 2 update messages.\n"); |
122 from_index++; | |
123 char pkey[32]; | |
124 int i; | |
125 char *label; | |
126 unsigned int thedate=0; | |
127 unsigned char label_len=0,ext_type,num_extensions; | |
128 short ext_data_len; | |
129 memcpy(pkey,data+from_index,32); | |
130 from_index+=32; | |
131 char sig[64]; | |
132 memcpy(sig,data+from_index,64); | |
133 from_index+=64; | |
134 printf("pkey: 0x"); | |
135 printhex(pkey,32); | |
136 printf("\n"); | |
137 printf("sig: 0x"); | |
138 printhex(sig,64); | |
139 printf("\n"); | |
140 //for(;from_index < length;) { | |
141 //timestamp, 4 bytes | |
142 thedate=(data[from_index]<<24)+(data[from_index+1]<<16)+(data[from_index+2]<<8)+(data[from_index+3]); | |
143 printf("thedate: %d\n",thedate); | |
144 from_index+=4; | |
145 //label length, 1 byte | |
146 label_len=data[from_index]; | |
147 from_index++; | |
148 printf("label len: %d\n",label_len); | |
149 label=malloc(label_len); | |
150 memcpy(label,data+from_index,label_len); | |
151 label[label_len]=0; | |
152 printf("label: "); | |
153 printhex(label,label_len); | |
154 printf("\n"); | |
155 from_index+=label_len; | |
156 num_extensions=data[from_index]; | |
157 printf("num of extensions: %d\n",num_extensions); | |
158 from_index++; | |
159 for(i=0;i<num_extensions;i++) { | |
160 ext_type=data[from_index]; | |
161 from_index++; | |
1186
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
162 // is this right? |
98707534e274
added a chan domain. changed some marc stuff. anocheck script for watching for ASN downages.
epoch <epoch@hacking.allowed.ano>
parents:
1185
diff
changeset
|
163 // ext_data_len=(data[from_index+1]) + (data[from_index+0]<<8); |
1173 | 164 ext_data_len=(data[from_index]<<8) + (data[from_index+1]); |
165 from_index+=2; | |
166 from_index+=ext_data_len;//skip this for now... fuck it. | |
167 printf(" ext %d type: %d len: %d\n",i,ext_type,ext_data_len); | |
1185
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
168 if(ext_type != 1 && ext_type != 4 && ext_type != 5) {//let's pretend 5 is transfer chain? |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
169 printf("fuck. unknown ext_type: %d @ %d\n",ext_type,from_index); |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
170 return; |
97ed67f3a20d
changed some ns stuff. added ice's resources. some leftover files from playing with marc.c
epoch <epoch@hacking.allowed.ano>
parents:
1173
diff
changeset
|
171 } |
1173 | 172 } |
173 marc_decode(data+from_index,0,length); | |
174 //} | |
175 return; | |
176 } | |
177 | |
178 void interactive_http_sync(unsigned char *data,int from_index,int length) { | |
179 int i; | |
180 unsigned int update_length; | |
181 unsigned char ext_type; | |
182 unsigned short ext_data_len; | |
183 unsigned char version=data[from_index]; | |
184 from_index++; | |
185 unsigned char num_extensions=data[from_index]; | |
186 from_index++; | |
187 printf("interactive_http_sync version: %d\n",version); | |
188 printf("num_extensions: %d\n",num_extensions); | |
189 for(i=0;i<num_extensions;i++) { | |
190 ext_type=data[from_index]; | |
191 from_index++; | |
192 ext_data_len=(data[from_index]<<8)+data[from_index+1]; | |
193 from_index+=2; | |
194 printf("extension: type:%d data_len:%d\n",ext_type,ext_data_len); | |
195 from_index+=ext_data_len; | |
196 } | |
197 for(;from_index < length;) { | |
198 printf("from_index: %d\n",from_index); | |
199 update_length=(data[from_index]<<24)+(data[from_index+1]<<16)+(data[from_index+2]<<8)+(data[from_index+3]); | |
200 from_index+=4; | |
201 if(update_length == 0) return printf("ohfuck.\n"); | |
202 update_message_decode(data,from_index,update_length); | |
203 from_index += update_length; | |
204 } | |
205 } | |
206 | |
207 int main(int argc,char *argv[]) { | |
208 indent=0; | |
209 if(argc < 2) return printf("usage: %s filename\n",argv[0]),0; | |
210 FILE *fp=fopen(argv[1],"r"); | |
211 fseek(fp,0L,SEEK_END); | |
212 long len=ftell(fp); | |
213 fseek(fp,0L,SEEK_SET); | |
214 unsigned char *db; | |
215 db=malloc(len+1); | |
216 if((int)db == -1) return printf("failed to malloc(%d)",len),0; | |
217 fread(db,1,len,fp); | |
218 interactive_http_sync(db,0,len); | |
219 /* | |
220 marc_decode("\x01\x41\x41\x41",0,4); | |
221 printf("\n"); | |
222 marc_decode("\x02\x00\x00\x00\x04\x01\x41\x41\x41\x00\x00\x00\x04\x01\x42\x41\x42",0,17); | |
223 printf("\n"); | |
224 // \x04BLAH == KLAH dafuq? | |
225 marc_decode("\x03\x04\x42LAH\x00\x00\x00\x05\x01""foOo\x04NoPe\x00\x00\x00\x07\x01wtfftw",0,31); | |
226 */ | |
227 return 0; | |
228 } |