7110
|
1 /*
|
|
2 GPL v2 blah blah
|
|
3
|
|
4 This is a small dll that works as a wrapper for the actual cook.so.6.0
|
|
5 dll from real player 8.0.
|
|
6 */
|
|
7
|
|
8 /*
|
|
9 Assuming that RACloseCodec is the last call.
|
|
10 */
|
|
11
|
|
12 #include <stddef.h>
|
|
13 #include <stdio.h>
|
|
14 #include <dlfcn.h>
|
|
15 #include <sys/time.h>
|
|
16
|
|
17 typedef unsigned long ulong;
|
|
18
|
|
19 //000000000000a410 g DF .text 0000000000000043 G2 RV20toYUV420Free
|
|
20 //000000000000a6c0 g DF .text 0000000000000060 G2 RV20toYUV420CustomMessage
|
|
21 //000000000000a200 g DF .text 000000000000020c G2 RV20toYUV420Init
|
|
22 //000000000000a724 g DF .text 0000000000000132 G2 RV20toYUV420HiveMessage
|
|
23 //000000000000a458 g DF .text 0000000000000262 G2 RV20toYUV420Transform
|
|
24
|
|
25 ulong (*rvyuvCustomMessage)(ulong,ulong);
|
|
26 ulong (*rvyuvFree)(ulong);
|
|
27 ulong (*rvyuvHiveMessage)(ulong,ulong);
|
|
28 ulong (*rvyuvInit)(ulong,ulong);
|
|
29 ulong (*rvyuvTransform)(ulong,ulong,ulong,ulong,ulong);
|
|
30
|
|
31 //void (*setDLLAccessPath)(ulong);
|
|
32
|
|
33 int b_dlOpened=0;
|
|
34 void *handle=NULL;
|
|
35
|
|
36 /* exits program when failure */
|
|
37 void loadSyms() {
|
|
38 fputs("loadSyms()\n", stderr);
|
|
39 if (!b_dlOpened) {
|
|
40 char *error;
|
|
41
|
|
42 fputs("opening dll...\n",stderr);
|
|
43 handle = dlopen ("/usr/local/RealPlayer8/Codecs/realdrv4.so.6.0", RTLD_LAZY);
|
|
44 if (!handle) {
|
|
45 fputs (dlerror(), stderr);
|
|
46 exit(1);
|
|
47 }
|
|
48
|
|
49 rvyuvCustomMessage = dlsym(handle, "RV20toYUV420CustomMessage");
|
|
50 if ((error = dlerror()) != NULL) {
|
|
51 fprintf (stderr, "dlsym(rvyuvCustomMessage): %s\n", error);
|
|
52 exit(1);
|
|
53 }
|
|
54 fprintf(stderr, "RV20toYUV420CustomMessage()=0x%0x\n", rvyuvCustomMessage);
|
|
55 rvyuvFree = dlsym(handle, "RV20toYUV420Free");
|
|
56 if ((error = dlerror()) != NULL) {
|
|
57 fprintf (stderr, "dlsym(rvyuvFree): %s\n", error);
|
|
58 exit(1);
|
|
59 }
|
|
60 fprintf(stderr, "RV20toYUV420Free()=0x%0x\n", rvyuvFree);
|
|
61 rvyuvHiveMessage = dlsym(handle, "RV20toYUV420HiveMessage");
|
|
62 if ((error = dlerror()) != NULL) {
|
|
63 fprintf (stderr, "dlsym(rvyuvHiveMessage): %s\n", error);
|
|
64 exit(1);
|
|
65 }
|
|
66 fprintf(stderr, "RV20toYUV420HiveMessage()=0x%0x\n", rvyuvHiveMessage);
|
|
67 rvyuvInit = dlsym(handle, "RV20toYUV420Init");
|
|
68 if ((error = dlerror()) != NULL) {
|
|
69 fprintf (stderr, "dlsym(rvyuvInit): %s\n", error);
|
|
70 exit(1);
|
|
71 }
|
|
72 fprintf(stderr, "RV20toYUV420Init()=0x%0x\n", rvyuvInit);
|
|
73 rvyuvTransform = dlsym(handle, "RV20toYUV420Transform");
|
|
74 if ((error = dlerror()) != NULL) {
|
|
75 fprintf (stderr, "dlsym(rvyuvTransform): %s\n", error);
|
|
76 exit(1);
|
|
77 }
|
|
78 fprintf(stderr, "RV20toYUV420Transform()=0x%0x\n", rvyuvTransform);
|
|
79 b_dlOpened=1;
|
|
80 }
|
|
81 }
|
|
82
|
|
83 void closeDll() {
|
|
84 if (handle) {
|
|
85 b_dlOpened=0;
|
|
86 dlclose(handle);
|
|
87 handle=NULL;
|
|
88 }
|
|
89 }
|
|
90
|
|
91 void _init(void) {
|
|
92 loadSyms();
|
|
93 }
|
|
94
|
|
95 struct timezone tz;
|
|
96 struct timeval tv1, tv2;
|
|
97
|
|
98 void tic() {
|
|
99 gettimeofday(&tv1, &tz);
|
|
100 }
|
|
101
|
|
102 void toc() {
|
|
103 long secs, usecs;
|
|
104 gettimeofday(&tv2, &tz);
|
|
105 secs=tv2.tv_sec-tv1.tv_sec;
|
|
106 usecs=tv2.tv_usec-tv1.tv_usec;
|
|
107 if (usecs<0) {
|
|
108 usecs+=1000000;
|
|
109 --secs;
|
|
110 }
|
|
111 // fprintf(stderr, "Duration: %d.%0.6ds\n", secs, usecs);
|
|
112 }
|
|
113
|
|
114
|
|
115 static void hexdump(void *pos, int len) {
|
|
116 unsigned char *cpos=pos, *cpos1;
|
|
117 int lines=(len+15)>>4;
|
|
118 while(lines--) {
|
|
119 int len1=len, i;
|
|
120 fprintf(stderr, "#R# %0x ", (int)cpos-(int)pos);
|
|
121 cpos1=cpos;
|
|
122 for (i=0;i<16;i++) {
|
|
123 if (len1>0) {
|
|
124 fprintf(stderr, "%02x ", *(cpos++));
|
|
125 } else {
|
|
126 fprintf(stderr, " ");
|
|
127 }
|
|
128 len1--;
|
|
129 }
|
|
130 fputs(" ", stderr);
|
|
131 cpos=cpos1;
|
|
132 for (i=0;i<16;i++) {
|
|
133 if (len>0) {
|
|
134 unsigned char ch=(*(cpos++));
|
|
135 if ((ch<32)||(ch>127)) ch='.';
|
|
136 fputc(ch, stderr);
|
|
137 }
|
|
138 len--;
|
|
139 }
|
|
140 fputs("\n", stderr);
|
|
141 }
|
|
142 fputc('\n', stderr);
|
|
143 }
|
|
144
|
|
145
|
|
146 ulong RV20toYUV420CustomMessage(ulong* p1,ulong p2) {
|
|
147 ulong result;
|
|
148 ulong *pp1=p1;
|
|
149 ulong temp[16];
|
|
150 fprintf(stderr, "#R# => RV20toYUV420CustomMessage(%p,%p) [%d,%d,%d] \n", p1, p2, p1[0],p1[1],p1[2]);
|
|
151 #if 0
|
|
152 if(p1[0]==0x24){
|
|
153 hexdump(p1[2],64);
|
|
154 memset(temp,0x77,16*4);
|
|
155 memcpy(temp,p1[2],16);
|
|
156 p1[2]=temp;
|
|
157 } else {
|
|
158 return 0;
|
|
159 }
|
|
160 #endif
|
|
161
|
|
162 // fprintf(stderr, "ulong p2=0x%0x(%d))\n", p2, p2);
|
|
163 // hexdump((void*)p1, 12);
|
|
164 // if (pp1[0]==0x24) {
|
|
165 // hexdump((void*)(pp1[2]),128);
|
|
166 // }
|
|
167 // tic();
|
|
168 result=(*rvyuvCustomMessage)(p1,p2);
|
|
169 // toc();
|
|
170 fprintf(stderr, "#R# <= RV20toYUV420CustomMessage --> 0x%0x(%d)\n", result, result);
|
|
171 return result;
|
|
172 }
|
|
173
|
|
174 ulong RV20toYUV420Free(ulong p1) {
|
|
175 ulong result;
|
|
176 fprintf(stderr, "RV20toYUV420Free(ulong p1=0x%0x(%d))\n", p1, p1);
|
|
177 // hexdump((void*)p1, 44);
|
|
178 tic();
|
|
179 result=(*rvyuvFree)(p1);
|
|
180 toc();
|
|
181 // hexdump((void*)p1, 44);
|
|
182 fprintf(stderr, "RV20toYUV420Free --> 0x%0x(%d)\n\n\n", result, result);
|
|
183 return result;
|
|
184 }
|
|
185
|
|
186 char h_temp[32768];
|
|
187
|
|
188 ulong RV20toYUV420HiveMessage(ulong *p1,ulong p2) {
|
|
189 ulong result;
|
|
190 fprintf(stderr, "#R# RV20toYUV420HiveMessage(%p,%p)\n", p1, p2);
|
|
191 // p1->constant,p1->width,p1->height,p1->format1,p1->format2);
|
|
192 // fprintf(stderr, "ulong p2=0x%0x(%d))\n", p2, p2);
|
|
193 // hexdump((void*)p1, sizeof(struct init_data));
|
|
194
|
|
195 fprintf(stderr,">HIVE %d %p\n",p1[0],p1[1]);
|
|
196
|
|
197 fprintf(stderr,"COPY INIT DATA!\n");
|
|
198 memset(h_temp,0x77,1000);
|
|
199 memcpy(h_temp,p1,4);
|
|
200 fprintf(stderr,"COPY OK!\n");
|
|
201
|
|
202 // tic();
|
|
203 // result=(*rvyuvHiveMessage)(p1,p2);
|
|
204 result=(*rvyuvHiveMessage)(h_temp,p2);
|
|
205 // toc();
|
|
206
|
|
207 fprintf(stderr,"COPY INIT DATA!\n");
|
|
208 memcpy(p1,h_temp,8);
|
|
209 fprintf(stderr,"COPY OK!\n");
|
|
210
|
|
211 memset(h_temp,0x77,1000);
|
|
212
|
|
213 // p1[0]=0;
|
|
214 // p1[1]=0x20000000;
|
|
215
|
|
216 fprintf(stderr,"<HIVE %d %p\n",p1[0],p1[1]);
|
|
217
|
|
218 // hexdump((void*)p1, sizeof(struct init_data));
|
|
219 // hexdump((void*)p1, 8);
|
|
220 fprintf(stderr, "#R# RV20toYUV420HiveMessage --> 0x%0x(%d)\n\n", result, result);
|
|
221 return result;
|
|
222 }
|
|
223
|
|
224 struct init_data {
|
|
225 short constant; //=0xb;
|
|
226 short width, height;
|
|
227 short x1,x2,x3;
|
|
228 // 12
|
|
229 ulong format1;
|
|
230 long x4;
|
|
231 ulong format2;
|
|
232 // long unknown[32];
|
|
233 };
|
|
234
|
|
235 static char i_temp[32768];
|
|
236
|
|
237 ulong RV20toYUV420Init(ulong p1,ulong p2) {
|
|
238 ulong result;
|
|
239 fprintf(stderr, "#R# RV20toYUV420Init(ulong p1=0x%0x(%d), ", p1, p1);
|
|
240 fprintf(stderr, "ulong p2=0x%0x(%d))\n", p2, p2);
|
|
241
|
|
242 fprintf(stderr,"COPY INIT DATA!\n");
|
|
243 memcpy(i_temp,p1,24);
|
|
244 p1=i_temp;
|
|
245 fprintf(stderr,"COPY OK!\n");
|
|
246
|
|
247 hexdump((void*)p1, 24);
|
|
248 tic();
|
|
249 result=(*rvyuvInit)(p1,p2);
|
|
250 toc();
|
|
251 hexdump((void*)p1, 24);
|
|
252
|
|
253 memset(i_temp,0x77,1000);
|
|
254
|
|
255 // hexdump(*((void**)p2), 512);
|
|
256 fprintf(stderr, "#R# RV20toYUV420Init --> 0x%0x(%d)\n\n\n", result, result);
|
|
257 return result;
|
|
258 }
|
|
259
|
|
260 unsigned long build_crc(unsigned char *pch, unsigned long len) {
|
|
261 unsigned long crc=0, a, b;
|
|
262 // it's not the real crc function, but so what...
|
|
263 while (len--) {
|
|
264 a=*(pch++);
|
|
265 // a=a+(a<<6);
|
|
266 // a^=0x555;
|
|
267 // b=(crc>>29)&7;
|
|
268 // crc=((crc<<3)+b)^a;
|
|
269 crc^=a;
|
|
270 }
|
|
271 return crc;
|
|
272 }
|
|
273
|
|
274 #define MIN(a,b) ((a)<(b)?(a):(b))
|
|
275
|
|
276 // p1=input data (stream)
|
|
277 // p2=output buffer
|
|
278 // p3=input struct
|
|
279 // p4=output struct
|
|
280 // p5=rvyuv_main
|
|
281 ulong RV20toYUV420Transform(ulong p1,ulong p2,ulong p3,ulong p4,ulong p5) {
|
|
282
|
|
283 //result=RV20toYUV420Transform(char *input_stream, char *output_data,
|
|
284 // struct transin *, struct transout *, struct rvyuvMain *);
|
|
285
|
|
286 ulong result;
|
|
287 ulong *pp3=p3;
|
|
288 ulong *pp4=p4;
|
|
289 void *v;
|
|
290 ulong temp[128];
|
|
291 int i;
|
|
292
|
|
293 unsigned long len,crc_src, crc0, crc1, crc2;
|
|
294 unsigned char *pch=(char *)p1;
|
|
295 fprintf(stderr, "#R# RV20toYUV420Transform(in=%p,out=%p,tin=%p,tout=%p,yuv=%p)\n",p1,p2,p3,p4,p5);
|
|
296 // input data, length=*p3
|
|
297 // hexdump((void*)p1, /*MIN(64,*/ *((ulong*)p3) /*)*/ );
|
|
298 // v=p5;
|
|
299 // v+=0x3c;
|
|
300 // v=*((void **)v);
|
|
301 // pp3=v;
|
|
302 // len=pp3[3]*pp3[4]*3/2;
|
|
303 // pch=p2;
|
|
304 // while(--len) *(pch++)=0;
|
|
305 // hexdump((char*)p2, 64);
|
|
306 // hexdump((void*)p3, 32);
|
|
307 // hexdump((void*)p5, 64);
|
|
308 // pp3=p3;
|
|
309 // if (pp3[3]>1024) {
|
|
310 // hexdump((void*)(pp3[3]),32);
|
|
311 // pp3=pp3[3];
|
|
312 // }
|
|
313
|
|
314 pp3=p3;
|
|
315 // it's not the real crc function, but so what...
|
|
316 pch=p1;
|
|
317 crc_src=build_crc(pch, pp3[0]);
|
|
318
|
|
319 pp4=pp3[3];
|
|
320 fprintf(stderr,"transin1[%p]: {%d/%d} ",pp4,pp3[2],pp3[0]);
|
|
321 // pp4[0],pp4[1],pp4[2],pp4[3],
|
|
322 // pp4[4],pp4[5],pp4[6],pp4[7]);
|
|
323
|
|
324 memset(temp,0x77,128*4);
|
|
325
|
|
326 memcpy(temp,pp4,8*(pp3[2]+1));
|
|
327 for(i=0;i<=pp3[2];i++){
|
|
328 fprintf(stderr," %p(%d)",temp[i*2],temp[i*2+1]);
|
|
329 }
|
|
330 fprintf(stderr,"\n");
|
|
331
|
|
332
|
|
333 pp3[3]=pp4=temp;
|
|
334
|
|
335 // pp4[2]=
|
|
336 // pp4[3]=
|
|
337 // pp4[4]=NULL;
|
|
338
|
|
339 //pp4[6]=pp4[5];
|
|
340
|
|
341 v=p5;
|
|
342 /* fprintf(stderr, "rvyuvMain=0x%0x\n", v);
|
|
343 v+=0x3c;
|
|
344 v=*((void **)v);
|
|
345 fprintf(stderr, "[$+3ch]=0x%0x\n", v);
|
|
346 hexdump(v, 512);
|
|
347 v+=0x60;
|
|
348 v=*((void **)v);
|
|
349 fprintf(stderr, "[$+60h]=0x%0x\n", v);
|
|
350 hexdump(v, 512);
|
|
351 v+=0x28;
|
|
352 v=*((void **)v);
|
|
353 fprintf(stderr, "[$+28h]=0x%0x\n", v);
|
|
354 hexdump(v, 512);
|
|
355 */
|
|
356 /* v+=0x178;
|
|
357 hexdump(v, 16);
|
|
358 v=*((void **)v);
|
|
359 if (v>0x8000000) {
|
|
360 fprintf(stderr, "[$+178h]=0x%0x\n", v);
|
|
361 hexdump(v, 128);
|
|
362 }
|
|
363 */
|
|
364 // tic();
|
|
365 result=(*rvyuvTransform)(p1,p2,p3,p4,p5);
|
|
366 // toc();
|
|
367
|
|
368 crc0=build_crc(p2, 176*144);
|
|
369 // crc1=build_crc(p2+pp4[3]*pp4[4]/2, pp4[3]*pp4[4]/2);
|
|
370 // crc2=build_crc(p2+pp4[3]*pp4[4], pp4[3]*pp4[4]/2);
|
|
371
|
|
372 // pp3=p3;
|
|
373 // TRANSFORM: <timestamp> <numblocks> <len> <crc_src> <crc_dest> <p4[4]>
|
|
374 // fprintf(stderr, "TRAFO:\t%d\t%d\t%d\t%.8X\t%.8X\t%d\n",
|
|
375 // pp3[5], pp3[2], pp3[0], crc_src, crc0, pp3[4]);
|
|
376 fprintf(stderr, "#R# Decode: %d(%d) [%08X] pts=%d -> %d [%08X]\n",
|
|
377 pp3[0],pp3[2],crc_src,pp3[5],
|
|
378 result,crc0);
|
|
379
|
|
380 // output
|
|
381 // hexdump((char*)p2, /*64*/ pp4[3]*pp4[4]/2);
|
|
382 // hexdump((void*)p4, 20);
|
|
383 // hexdump((void*)p5, 512);
|
|
384 // fprintf(stderr, "RV20toYUV420Transform --> 0x%0x(%d)\n\n\n", result, result);
|
|
385 return result;
|
|
386 }
|
|
387
|