talloc.[ch]: remove "type safety" hack that violates C types
[mplayer.git] / TOOLS / realcodecs / sipr.c
blobee04f0b0821a24d4a55e74760c574fc270a6d78a
1 /*
2 * This is a small DLL that works as a wrapper for the actual realsipr.so.6.0
3 * DLL from RealPlayer 8.0.
5 * This file is part of MPlayer.
7 * MPlayer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * MPlayer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 Assuming that RACloseCodec is the last call.
25 0000000000001b8c g DF .text 000000000000002b G2 RASetPwd
26 0000000000001c6c g DF .text 000000000000003e G2 RAInitEncoder
27 0000000000001a8c g DF .text 0000000000000039 G2 RAOpenCodec2
28 0000000000001a50 g DF .text 0000000000000039 G2 RAOpenCodec
29 0000000000001ac8 g DF .text 000000000000002c G2 RACloseCodec
30 0000000000001af4 g DF .text 000000000000000a G2 RAGetNumberOfFlavors
31 0000000000001bdc g DF .text 0000000000000032 G2 RADecode
32 0000000000001cac g DF .text 0000000000000029 G2 RAEncode
33 0000000000001cd8 g DF .text 0000000000000023 G2 RAFreeEncoder
34 000000000000138c g DF .text 0000000000000029 G2 SetDLLAccessPath
35 0000000000001c48 g DF .text 0000000000000023 G2 RAFreeDecoder
36 0000000000001c10 g DF .text 0000000000000035 G2 RAFlush
37 0000000000001b00 g DF .text 0000000000000052 G2 RAGetFlavorProperty
38 0000000000001b54 g DF .text 0000000000000038 G2 RASetFlavor
39 0000000000001bb8 g DF .text 0000000000000023 G2 RAInitDecoder
43 #include <stddef.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <dlfcn.h>
48 #include <sys/time.h>
50 typedef unsigned long ulong;
52 ulong (*raCloseCodec)(ulong);
53 ulong (*raDecode)(ulong,ulong,ulong,ulong,ulong,ulong);
54 ulong (*raEncode)(ulong,ulong,ulong);
55 ulong (*raFlush)(ulong,ulong,ulong);
56 ulong (*raFreeDecoder)(ulong);
57 ulong (*raFreeEncoder)(ulong);
58 ulong (*raGetFlavorProperty)(ulong,ulong,ulong,ulong);
59 ulong (*raGetNumberOfFlavors)(void);
60 ulong (*raGetNumberOfFlavors2)(void);
61 ulong (*raInitDecoder)(ulong,ulong);
62 ulong (*raInitEncoder)(ulong,ulong);
63 ulong (*raOpenCodec)(ulong);
64 ulong (*raOpenCodec2)(ulong);
65 ulong (*raSetFlavor)(ulong,ulong,ulong);
66 void (*raSetDLLAccessPath)(ulong);
67 /* the following symbol will be _dlsym()ed by rarender.so,
68 but at least doesn't exist in cook.so
70 ulong (*raSetPwd)(ulong,ulong);
72 int b_dlOpened=0;
73 void *handle=NULL;
75 /* exits program when failure */
76 void loadSyms(void) {
77 fputs("loadSyms()\n", stderr);
78 if (!b_dlOpened) {
79 char *error;
81 // fputs("opening dll...\n");
82 handle = dlopen ("/usr/local/RealPlayer8/Codecs/realsipr.so.6.0", RTLD_LAZY);
83 if (!handle) {
84 fputs (dlerror(), stderr);
85 exit(1);
88 raCloseCodec = dlsym(handle, "RACloseCodec");
89 if ((error = dlerror()) != NULL) {
90 fprintf (stderr, "dlsym(RACloseCodec): %s\n", error);
91 exit(1);
93 raDecode = dlsym(handle, "RADecode");
94 if ((error = dlerror()) != NULL) {
95 fprintf (stderr, "dlsym(RADecode): %s\n", error);
96 exit(1);
98 raEncode = dlsym(handle, "RAEncode");
99 if ((error = dlerror()) != NULL) {
100 fprintf (stderr, "dlsym(RAEncode): %s\n", error);
101 exit(1);
103 raFlush = dlsym(handle, "RAFlush");
104 if ((error = dlerror()) != NULL) {
105 fprintf (stderr, "dlsym(RAFlush): %s\n", error);
106 exit(1);
108 raFreeDecoder = dlsym(handle, "RAFreeDecoder");
109 if ((error = dlerror()) != NULL) {
110 fprintf (stderr, "dlsym(RAFreeDecoder): %s\n", error);
111 exit(1);
113 raFreeEncoder = dlsym(handle, "RAFreeEncoder");
114 if ((error = dlerror()) != NULL) {
115 fprintf (stderr, "dlsym(RAFreeEncoder): %s\n", error);
116 exit(1);
118 raGetFlavorProperty = dlsym(handle, "RAGetFlavorProperty");
119 if ((error = dlerror()) != NULL) {
120 fprintf (stderr, "dlsym(RAGetFlavorProperty): %s\n", error);
121 exit(1);
123 raGetNumberOfFlavors = dlsym(handle, "RAGetNumberOfFlavors");
124 if ((error = dlerror()) != NULL) {
125 fprintf (stderr, "dlsym(RAGetNumberOfFlavors): %s\n", error);
126 exit(1);
128 // raGetNumberOfFlavors2 = dlsym(handle, "RAGetNumberOfFlavors2");
129 // if ((error = dlerror()) != NULL) {
130 // fprintf (stderr, "dlsym(RAGetNumberOfFlavors2): %s\n", error);
131 // exit(1);
132 // }
133 raInitDecoder = dlsym(handle, "RAInitDecoder");
134 if ((error = dlerror()) != NULL) {
135 fprintf (stderr, "dlsym(RAInitDecoder): %s\n", error);
136 exit(1);
138 raInitEncoder = dlsym(handle, "RAInitEncoder");
139 if ((error = dlerror()) != NULL) {
140 fprintf (stderr, "dlsym(RAInitEncoder): %s\n", error);
141 exit(1);
143 raOpenCodec = dlsym(handle, "RAOpenCodec");
144 if ((error = dlerror()) != NULL) {
145 fprintf (stderr, "dlsym(RAOpenCodec): %s\n", error);
146 exit(1);
148 raOpenCodec2 = dlsym(handle, "RAOpenCodec2");
149 if ((error = dlerror()) != NULL) {
150 fprintf (stderr, "dlsym(RAOpenCodec2): %s\n", error);
151 exit(1);
153 raSetFlavor = dlsym(handle, "RASetFlavor");
154 if ((error = dlerror()) != NULL) {
155 fprintf (stderr, "dlsym(RASetFlavor): %s\n", error);
156 exit(1);
158 raSetDLLAccessPath = dlsym(handle, "SetDLLAccessPath");
159 if ((error = dlerror()) != NULL) {
160 fprintf (stderr, "dlsym(SetDLLAccessPath): %s\n", error);
161 exit(1);
163 raSetPwd = dlsym(handle, "RASetPwd");
164 if ((error = dlerror()) != NULL) {
165 fprintf (stderr, "dlsym(RASetPwd): %s\n", error);
166 exit(1);
168 b_dlOpened=1;
172 void closeDll(void) {
173 if (handle) {
174 b_dlOpened=0;
175 dlclose(handle);
176 handle=NULL;
180 void _init(void) {
181 loadSyms();
184 struct timezone tz;
185 struct timeval tv1, tv2;
187 void tic(void) {
188 gettimeofday(&tv1, &tz);
191 void toc(void) {
192 long secs, usecs;
193 gettimeofday(&tv2, &tz);
194 secs=tv2.tv_sec-tv1.tv_sec;
195 usecs=tv2.tv_usec-tv1.tv_usec;
196 if (usecs<0) {
197 usecs+=1000000;
198 --secs;
200 fprintf(stderr, "Duration: %ld.%0.6lds\n", secs, usecs);
204 void hexdump(void *pos, int len) {
205 unsigned char *cpos=pos, *cpos1;
206 int lines=(len+15)>>4;
207 while(lines--) {
208 int len1=len, i;
209 fprintf(stderr, "%0x ", cpos);
210 cpos1=cpos;
211 for (i=0;i<16;i++) {
212 if (len1>0) {
213 fprintf(stderr, "%02x ", *(cpos++));
214 } else {
215 fprintf(stderr, " ");
217 len1--;
219 fputs(" ", stderr);
220 cpos=cpos1;
221 for (i=0;i<16;i++) {
222 if (len>0) {
223 unsigned char ch=(*(cpos++));
224 if ((ch<32)||(ch>127)) ch='.';
225 fputc(ch, stderr);
227 len--;
229 fputs("\n", stderr);
231 fputc('\n', stderr);
235 ulong RACloseCodec(ulong p1) {
236 ulong result;
237 fprintf(stderr, "RACloseCodec(ulong p1=0x%0lx(%ld))\n", p1, p1);
238 result=(*raCloseCodec)(p1);
239 // closeDll();
240 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
241 return result;
244 static int pkno=0;
246 ulong RADecode(ulong p1,ulong p2,ulong p3,ulong p4,ulong* p5,ulong p6) {
247 ulong result;
248 int x,y;
250 fprintf(stderr, "RADecode(ulong ctx=0x%0lx, ", p1);
251 fprintf(stderr, "ulong src=0x%0lx,\n", p2);
252 fprintf(stderr, "ulong len=0x%0lx,", p3);
253 fprintf(stderr, "ulong dst=0x%0lx,\n", p4);
254 fprintf(stderr, "ulong dstcnt=0x%0x, ",p5);
255 fprintf(stderr, "ulong p6=%ld)\n", p6);
256 // hexdump((void*)p1, 44);
257 // hexdump((void*)p2, p3);
258 // hexdump((void*)p4, 80);
259 // hexdump((void*)p5, 16);
260 // tic();
262 #if 0
263 hexdump(p2, 0x128);
264 #else
265 fprintf(stderr,"\n#CRC[%3d]",pkno++);
266 for(y=0;y<(0x128*2);y+=37){
267 unsigned short crc=0;
268 unsigned char* p=p2;
269 // p+=y;
270 for(x=0;x<37;x++){
271 int i=y+x;
272 int ib=p[(i>>1)];
273 if(i&1) ib>>=4; else ib&=15;
274 crc+=ib<<(x&7);
276 fprintf(stderr," %04X",crc);
277 // fprintf(stderr," %02X",p[0]);
279 fprintf(stderr,"\n");
280 #endif
282 { FILE *f=fopen("sipr.dump","a");
283 fwrite(p2,p3,1,f);
284 fclose(f);
287 result=(*raDecode)(p1,p2,p3,p4,p5,p6);
288 // toc();
289 // hexdump((void*)p1, 44);
290 // hexdump((void*)p4, 80);
291 // hexdump((void*)p5, 16);
292 fprintf(stderr, "--> 0x%0lx(%ld) decoded: %ld \n\n\n", result, result, p5[0]);
293 return result;
296 ulong RAEncode(ulong p1,ulong p2,ulong p3) {
297 ulong result;
298 fprintf(stderr, "RAEncode(ulong p1=0x%0lx(%ld), ", p1, p1);
299 fprintf(stderr, "ulong p2=0x%0lx(%ld),\n", p2, p2);
300 fprintf(stderr, "ulong p3=0x%0lx(%ld))\n", p3, p3);
301 result=(*raEncode)(p1,p2,p3);
302 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
303 return result;
306 ulong RAFlush(ulong p1,ulong p2,ulong p3) {
307 ulong result;
308 fprintf(stderr, "RAFlush(ulong p1=0x%0lx(%ld), ", p1, p1);
309 fprintf(stderr, "ulong p2=0x%0lx(%ld),\n", p2, p2);
310 fprintf(stderr, "ulong p3=0x%0lx(%ld))\n", p3, p3);
311 result=(*raFlush)(p1,p2,p3);
312 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
313 return result;
316 ulong RAFreeDecoder(ulong p1) {
317 ulong result;
318 fprintf(stderr, "RAFreeDecoder(ulong p1=0x%0lx(%ld))\n", p1, p1);
319 hexdump((void*)p1, 44);
320 result=(*raFreeDecoder)(p1);
321 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
322 return result;
325 ulong RAFreeEncoder(ulong p1) {
326 ulong result;
327 fprintf(stderr, "RAFreeEncoder(ulong p1=0x%0lx(%ld))\n", p1, p1);
328 result=(*raFreeEncoder)(p1);
329 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
330 return result;
333 ulong RAGetFlavorProperty(ulong p1,ulong p2,ulong p3, ulong p4) {
334 ulong result;
335 fprintf(stderr, "RAGetFlavorProperty(ulong p1=0x%0lx(%ld), ", p1, p1);
336 fprintf(stderr, "ulong p2=0x%0lx(%ld),\n", p2, p2);
337 fprintf(stderr, "ulong p3=0x%0lx(%ld), ", p3, p3);
338 fprintf(stderr, "ulong p4=0x%0lx(%ld))\n", p4, p4);
339 hexdump((void*)p4/*(void*)(*((void**)p4))*/,p2);
340 hexdump((void*)p1, 44);
341 tic();
342 result=(*raGetFlavorProperty)(p1,p2,p3,p4);
343 toc();
344 fprintf(stderr, "*p4=0x%0lx\n", *((ulong*)p4));
345 hexdump((void*)p4/*(void*)(*((void**)p4))*/,p2);
346 hexdump((void*)p1, 44);
347 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
348 return result;
351 ulong RAGetNumberOfFlavors(void) {
352 ulong result;
353 fprintf(stderr, "RAGetNumberOfFlavors(void)\n");
354 result=(*raGetNumberOfFlavors)();
355 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
356 return result;
359 ulong RAInitDecoder(ulong p1,ulong p2) {
360 ulong result;
361 // int temp[256];
362 // unsigned char temp2[256];
363 fprintf(stderr, "RAInitDecoder(ulong p1=0x%0lx(%ld), ", p1, p1);
364 fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
365 hexdump((void*)p2, 4*7);
366 // hexdump((void*)p1, 44);
368 #if 1
369 result=(*raInitDecoder)(p1,p2);
370 #else
371 memset(temp,0x77,256*4);
372 memcpy(temp,p2,4*7);
373 hexdump((void*)temp[6], 32);
375 memset(temp2,0x77,256);
376 memcpy(temp2,temp[6],16);
377 temp[6]=temp2;
379 result=(*raInitDecoder)(p1,temp);
380 hexdump((void*)temp[6], 32);
381 #endif
383 // memcpy(p2,temp,4*11);
384 // hexdump((void*)p1, 44);
385 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
386 return result;
389 ulong RAInitEncoder(ulong p1,ulong p2) {
390 ulong result;
391 fprintf(stderr, "RAInitEncoder(ulong p1=0x%0lx(%ld), ", p1, p1);
392 fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
393 result=(*raInitEncoder)(p1,p2);
394 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
395 return result;
398 ulong RAOpenCodec(ulong p1) {
399 ulong result;
400 // loadSyms();
401 fprintf(stderr, "RAOpenCodec(ulong p1=0x%0lx(%ld))\n", p1, p1);
402 result=(*raOpenCodec)(p1);
403 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
404 return result;
407 ulong RAOpenCodec2(ulong p1) {
408 ulong result;
409 // loadSyms();
410 fprintf(stderr, "RAOpenCodec2(ulong p1=0x%0lx(%ld))\n", p1, p1);
411 hexdump((void*)p1, 44);
412 result=(*raOpenCodec2)(p1);
413 hexdump((void*)p1, 44);
414 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
415 return result;
418 ulong RASetFlavor(ulong p1,ulong p2,ulong p3) {
419 ulong result, numprop=0, result1=0;
420 ulong numflavors, flavor;
421 unsigned short property;
422 fprintf(stderr, "RASetFlavor(ulong p1=0x%0lx(%ld), ", p1, p1);
423 fprintf(stderr, "ulong p2=0x%0lx(%ld))\n", p2, p2);
424 // hexdump((void*)p1, 44);
425 // hexdump((void*)p1, 44);
426 result=(*raSetFlavor)(p1,p2,p3);
427 fprintf(stderr, "--> 0x%0lx(%ld)\n\n\n", result, result);
429 fputs("######################## FLAVOR PROPERTIES ###################\n\n", stderr);
430 numflavors=3;//raGetNumberOfFlavors();
431 flavor=0;
432 while (flavor<numflavors) {
433 fprintf(stderr, "************ Flavor %ld *************\n\n", flavor);
434 numprop=0;
435 while (numprop<32) {
436 result1=raGetFlavorProperty(p1, flavor, numprop, (ulong)&property);
437 fprintf(stderr, "property %ld=%d, result=0x%0lx\n\n",
438 numprop, property, result1);
439 hexdump((void*)result1, property);
440 numprop++;
442 flavor++;
445 fputs("######################## FLAVOR PROPERTIES ###################\n\n", stderr);
447 return result;
450 void SetDLLAccessPath(ulong p1,ulong p2) {
451 // loadSyms();
452 char* ize=p1;
453 fprintf(stderr, "SetDLLAccessPath(ulong p1=0x%0lx(%ld) p2=%p)\n", p1, p1,p2);
454 while(*ize){
455 fprintf(stderr,"%s\n",ize);
456 ize+=strlen(ize)+1;
458 //hexdump((void*)p1, 244);
459 (*raSetDLLAccessPath)(p1);
460 // hexdump((void*)p1, 44);
461 fprintf(stderr, "--> void\n\n\n");
464 static char pwdtemp[1000];
466 void RASetPwd(ulong p1,ulong p2) {
467 // loadSyms();
468 fprintf(stderr, "RASetPwd(ulong p1=0x%0lx(%ld),ulong p2=0x%0lx(%ld))\n", p1, p1, p2, p2);
469 // hexdump((void*)p1, 44);
470 // hexdump((void*)p2, 44);
471 memset(pwdtemp,0x77,1000);
472 hexdump((void*)pwdtemp, 44);
473 (*raSetPwd)(pwdtemp,"Ardubancel Quazanga"); // set password... lol.
474 hexdump((void*)pwdtemp, 1000);
475 strcpy(p1,p2);
476 // hexdump((void*)p1, 44);
477 // hexdump((void*)p2, 44);
478 // hexdump((void*)p1, 44);
479 fprintf(stderr, "--> void\n\n\n");