Mercurial > mplayer.hg
annotate loader/win32.c @ 1216:4059e05c480a
some info printfs moved stderr->stdout
author | arpi_esp |
---|---|
date | Sat, 23 Jun 2001 23:38:51 +0000 |
parents | bf973bffe240 |
children | d8c1b0b38edc |
rev | line source |
---|---|
1 | 1 /*********************************************************** |
2 | |
3 Win32 emulation code. Functions that emulate | |
4 responses from corresponding Win32 API calls. | |
5 Since we are not going to be able to load | |
6 virtually any DLL, we can only implement this | |
7 much, adding needed functions with each new codec. | |
128 | 8 |
9 Basic principle of implementation: it's not good | |
10 for DLL to know too much about its environment. | |
1 | 11 |
12 ************************************************************/ | |
13 | |
14 #include <config.h> | |
15 | |
16 #include "win32.h" | |
17 #include <stdio.h> | |
18 #include <pthread.h> | |
128 | 19 #include <errno.h> |
597 | 20 #include <ctype.h> |
21 #include <stdlib.h> | |
1 | 22 #ifdef HAVE_MALLOC_H |
23 #include <malloc.h> | |
24 #endif | |
25 #include <time.h> | |
128 | 26 #include <unistd.h> |
27 #include <fcntl.h> | |
1 | 28 #include <sys/types.h> |
29 #include <sys/time.h> | |
30 #include <sys/timeb.h> | |
31 | |
32 #include <wine/winbase.h> | |
33 #include <wine/winreg.h> | |
34 #include <wine/winnt.h> | |
35 #include <wine/winerror.h> | |
36 #include <wine/debugtools.h> | |
37 #include <wine/module.h> | |
38 | |
39 #include <registry.h> | |
40 #include <loader.h> | |
128 | 41 #include <com.h> |
42 | |
43 char* def_path=WIN32_PATH; | |
44 | |
45 static void do_cpuid(unsigned int *regs) | |
46 { | |
47 unsigned int ax; | |
48 ax=1; | |
49 __asm__ __volatile__( | |
50 "pushl %%ebx; pushl %%ecx; pushl %%edx; " | |
51 ".byte 0x0f, 0xa2;" | |
52 "movl %%eax, (%2);" | |
53 "movl %%ebx, 4(%2);" | |
54 "movl %%ecx, 8(%2);" | |
55 "movl %%edx, 12(%2);" | |
56 "popl %%edx; popl %%ecx; popl %%ebx; " | |
57 : "=a" (ax) | |
58 : "0" (ax), "S" (®s)); | |
59 } | |
60 static unsigned int c_localcount_tsc() | |
1 | 61 { |
62 int a; | |
63 __asm__ __volatile__("rdtsc\n\t" | |
64 :"=a"(a) | |
65 : | |
66 :"edx"); | |
67 return a; | |
68 } | |
128 | 69 static void c_longcount_tsc(long long* z) |
1 | 70 { |
71 __asm__ __volatile__( | |
72 "pushl %%ebx\n\t" | |
73 "movl %%eax, %%ebx\n\t" | |
74 "rdtsc\n\t" | |
75 "movl %%eax, 0(%%ebx)\n\t" | |
76 "movl %%edx, 4(%%ebx)\n\t" | |
77 "popl %%ebx\n\t" | |
78 ::"a"(z)); | |
79 } | |
80 #include <sys/time.h> | |
81 #include <unistd.h> | |
128 | 82 static unsigned int c_localcount_notsc() |
1 | 83 { |
84 struct timeval tv; | |
85 unsigned limit=~0; | |
86 limit/=1000000; | |
87 gettimeofday(&tv, 0); | |
88 return limit*tv.tv_usec; | |
89 } | |
128 | 90 static void c_longcount_notsc(long long* z) |
1 | 91 { |
92 struct timeval tv; | |
93 unsigned long long result; | |
94 unsigned limit=~0; | |
95 if(!z)return; | |
96 limit/=1000000; | |
97 gettimeofday(&tv, 0); | |
98 result=tv.tv_sec; | |
99 result<<=32; | |
100 result+=limit*tv.tv_usec; | |
101 *z=result; | |
102 } | |
128 | 103 static unsigned int localcount_stub(); |
104 static void longcount_stub(long long*); | |
105 static unsigned int (*localcount)()=localcount_stub; | |
106 static void (*longcount)(long long*)=longcount_stub; | |
1 | 107 |
128 | 108 static unsigned int localcount_stub() |
109 { | |
110 unsigned int regs[4]; | |
111 do_cpuid(regs); | |
112 if ((regs[3] & 0x00000010) == 0) | |
113 { | |
114 localcount=c_localcount_tsc; | |
115 longcount=c_longcount_tsc; | |
116 } | |
117 else | |
118 { | |
119 localcount=c_localcount_notsc; | |
120 longcount=c_longcount_notsc; | |
121 } | |
122 return localcount(); | |
123 } | |
124 static void longcount_stub(long long* z) | |
1 | 125 { |
128 | 126 unsigned int regs[4]; |
127 do_cpuid(regs); | |
128 if ((regs[3] & 0x00000010) == 0) | |
129 { | |
130 localcount=c_localcount_tsc; | |
131 longcount=c_longcount_tsc; | |
132 } | |
133 else | |
134 { | |
135 localcount=c_localcount_notsc; | |
136 longcount=c_longcount_notsc; | |
137 } | |
138 longcount(z); | |
139 } | |
140 | |
235 | 141 int LOADER_DEBUG=1; |
128 | 142 inline void dbgprintf(char* fmt, ...) |
143 { | |
235 | 144 #ifdef DETAILED_OUT |
128 | 145 if(LOADER_DEBUG) |
146 { | |
147 FILE* f; | |
148 va_list va; | |
149 va_start(va, fmt); | |
150 f=fopen("./log", "a"); | |
151 vprintf(fmt, va); | |
152 if(f) | |
153 { | |
154 vfprintf(f, fmt, va); | |
155 fsync(fileno(f)); | |
156 fclose(f); | |
157 } | |
158 va_end(va); | |
159 } | |
235 | 160 #endif |
1 | 161 } |
162 char export_names[500][30]={ | |
163 "name1", | |
164 //"name2", | |
165 //"name3" | |
166 }; | |
167 //#define min(x,y) ((x)<(y)?(x):(y)) | |
168 | |
169 static unsigned char* heap=NULL; | |
170 static int heap_counter=0; | |
171 void test_heap() | |
172 { | |
173 int offset=0; | |
174 if(heap==0) | |
175 return; | |
176 while(offset<heap_counter) | |
177 { | |
178 if(*(int*)(heap+offset)!=0x433476) | |
179 { | |
180 printf("Heap corruption at address %d\n", offset); | |
181 return; | |
182 } | |
183 offset+=8+*(int*)(heap+offset+4); | |
184 } | |
185 for(;offset<min(offset+1000, 20000000); offset++) | |
186 if(heap[offset]!=0xCC) | |
187 { | |
188 printf("Free heap corruption at address %d\n", offset); | |
189 } | |
190 } | |
191 #undef MEMORY_DEBUG | |
192 | |
193 #ifdef MEMORY_DEBUG | |
194 | |
195 void* my_mreq(int size, int to_zero) | |
196 { | |
197 static int test=0; | |
198 test++; | |
199 if(test%10==0)printf("Memory: %d bytes allocated\n", heap_counter); | |
200 // test_heap(); | |
201 if(heap==NULL) | |
202 { | |
203 heap=malloc(20000000); | |
204 memset(heap, 0xCC,20000000); | |
205 } | |
206 if(heap==0) | |
207 { | |
208 printf("No enough memory\n"); | |
209 return 0; | |
210 } | |
211 if(heap_counter+size>20000000) | |
212 { | |
213 printf("No enough memory\n"); | |
214 return 0; | |
215 } | |
216 *(int*)(heap+heap_counter)=0x433476; | |
217 heap_counter+=4; | |
218 *(int*)(heap+heap_counter)=size; | |
219 heap_counter+=4; | |
220 printf("Allocated %d bytes of memory: sys %d, user %d-%d\n", size, heap_counter-8, heap_counter, heap_counter+size); | |
221 if(to_zero) | |
222 memset(heap+heap_counter, 0, size); | |
223 heap_counter+=size; | |
224 return heap+heap_counter-size; | |
225 } | |
597 | 226 int my_release(void* memory) |
1 | 227 { |
228 // test_heap(); | |
229 if(memory==NULL) | |
230 { | |
231 printf("ERROR: free(0)\n"); | |
232 return 0; | |
233 } | |
234 if(*(int*)(memory-8)!=0x433476) | |
235 { | |
236 printf("MEMORY CORRUPTION !!!!!!!!!!!!!!!!!!!\n"); | |
237 return 0; | |
238 } | |
239 printf("Freed %d bytes of memory\n", *(int*)(memory-4)); | |
240 // memset(memory-8, *(int*)(memory-4), 0xCC); | |
241 return 0; | |
242 } | |
243 | |
244 #else | |
128 | 245 #define GARBAGE |
246 #ifdef GARBAGE | |
247 struct alc_list_t; | |
248 typedef struct alc_list_t { | |
249 int size; | |
597 | 250 void *addr; |
128 | 251 struct alc_list_t *prev; |
252 struct alc_list_t *next; | |
253 }alc_list; | |
254 static alc_list *alclist=NULL; | |
597 | 255 static int alccnt=0; |
128 | 256 #endif |
257 | |
1 | 258 void* my_mreq(int size, int to_zero) |
259 { | |
260 void* answer; | |
261 if(to_zero) | |
262 answer=calloc(size+4, 1); | |
263 else | |
264 answer=malloc(size+4); | |
265 *(int*)answer=size; | |
128 | 266 #ifdef GARBAGE |
267 if (alclist==NULL) { | |
268 alclist=malloc(sizeof(alc_list)); | |
269 alclist->prev=alclist->next=NULL; | |
270 } | |
271 else { | |
272 alclist->next=malloc(sizeof(alc_list)); | |
273 alclist->next->prev=alclist; | |
274 alclist->next->next=NULL; | |
275 alclist=alclist->next; | |
276 } | |
277 alclist->size=size; | |
278 alclist->addr=answer; | |
279 alccnt++; | |
280 #endif | |
281 return (int*)((int)answer+sizeof(int)); | |
1 | 282 } |
597 | 283 int my_release(void* memory) |
1 | 284 { |
128 | 285 #ifdef GARBAGE |
286 alc_list* pp; | |
1 | 287 if(memory==0)return 0; |
128 | 288 if(alclist!=NULL) |
289 { | |
290 pp=alclist; | |
291 if ((pp->prev==NULL) && (pp->next == NULL)){ | |
292 free(pp); | |
293 alclist=NULL; | |
294 } | |
295 else { | |
296 for(;pp;pp=pp->prev) { | |
297 if (pp->addr == memory-4) { | |
298 if (pp->prev) | |
299 pp->prev->next=pp->next; | |
300 if (pp->next) | |
301 pp->next->prev=pp->prev; | |
302 if (pp == alclist) | |
303 alclist=pp->prev; | |
304 free(pp); | |
305 alccnt--; | |
306 break; | |
307 } | |
308 } | |
309 if (pp == NULL) { | |
597 | 310 printf("Not Found %p %d\n",memory-4,alccnt); |
128 | 311 return 0; |
312 } | |
313 } | |
314 } | |
315 #endif | |
1 | 316 free(memory-4); |
317 return 0; | |
318 } | |
319 #endif | |
320 int my_size(char* memory) | |
321 { | |
322 return *(int*)(memory-4); | |
323 } | |
324 | |
325 extern int unk_exp1; | |
326 char extcode[20000];// place for 200 unresolved exports | |
327 int pos=0; | |
328 | |
329 int WINAPI ext_unknown() | |
330 { | |
331 printf("Unknown func called\n"); | |
332 return 0; | |
333 } | |
334 int WINAPI expIsBadWritePtr(void* ptr, unsigned int count) | |
335 { | |
128 | 336 int result; |
1 | 337 if(count==0) |
128 | 338 result=0; |
339 else | |
1 | 340 if(ptr==0) |
128 | 341 result=1; |
342 else | |
343 result=0; | |
344 dbgprintf("IsBadWritePtr(0x%x, 0x%x) => %d\n", ptr, count, result); | |
345 return result; | |
1 | 346 } |
347 int WINAPI expIsBadReadPtr(void* ptr, unsigned int count) | |
348 { | |
128 | 349 int result; |
1 | 350 if(count==0) |
128 | 351 result=0; |
352 else | |
1 | 353 if(ptr==0) |
128 | 354 result=1; |
355 else | |
356 result=0; | |
357 dbgprintf("IsBadReadPtr(0x%x, 0x%x) => %d\n", ptr, count, result); | |
358 return result; | |
1 | 359 } |
360 void* CDECL expmalloc(int size) | |
361 { | |
362 //printf("malloc"); | |
363 // return malloc(size); | |
364 void* result=my_mreq(size,0); | |
128 | 365 dbgprintf("malloc(0x%x) => 0x%x\n", size,result); |
1 | 366 if(result==0) |
367 printf("WARNING: malloc() failed\n"); | |
368 return result; | |
369 } | |
370 void CDECL expfree(void* mem) | |
371 { | |
372 // return free(mem); | |
128 | 373 dbgprintf("free(0x%x)\n", mem); |
1 | 374 my_release(mem); |
375 } | |
376 void* CDECL expnew(int size) | |
377 { | |
378 // printf("NEW:: Call from address %08x\n STACK DUMP:\n", *(-1+(int*)&size)); | |
379 // printf("%08x %08x %08x %08x\n", | |
380 // size, *(1+(int*)&size), | |
381 // *(2+(int*)&size),*(3+(int*)&size)); | |
128 | 382 void* result=my_mreq(size,0); |
383 dbgprintf("new(0x%x) => 0x%x\n", size, result); | |
1 | 384 if(result==0) |
128 | 385 printf("WARNING: new() failed\n"); |
1 | 386 return result; |
387 | |
388 } | |
389 int CDECL expdelete(void* memory) | |
390 { | |
128 | 391 dbgprintf("delete(0x%x)\n", memory); |
392 my_release(memory); | |
1 | 393 return 0; |
394 } | |
395 int WINAPI expDisableThreadLibraryCalls(int module) | |
396 { | |
128 | 397 dbgprintf("DisableThreadLibraryCalls(0x%x) => 0\n", module); |
1 | 398 return 0; |
399 } | |
400 int CDECL exp_initterm(int v1, int v2) | |
401 { | |
128 | 402 dbgprintf("_initterm(0x%x, 0x%x) => 0\n", v1, v2); |
1 | 403 return 0; |
404 } | |
405 | |
406 typedef struct { | |
407 unsigned int uDriverSignature; | |
408 void* hDriverModule; | |
409 void* DriverProc; | |
410 unsigned int dwDriverID; | |
411 } DRVR; | |
412 | |
413 void* WINAPI expGetDriverModuleHandle(DRVR* pdrv) | |
414 { | |
128 | 415 void* result; |
416 if (pdrv==NULL) result=NULL; | |
417 result=pdrv->hDriverModule; | |
418 dbgprintf("GetDriverModuleHandle(0x%x) => 0x%x\n", pdrv, result); | |
419 return result; | |
1 | 420 } |
421 | |
422 void* WINAPI expGetModuleHandleA(const char* name) | |
423 { | |
424 WINE_MODREF* wm; | |
128 | 425 void* result; |
426 if(!name) | |
427 result=0; | |
428 else | |
429 { | |
430 wm=MODULE_FindModule(name); | |
431 if(wm==0)result=0; | |
432 else | |
433 result=(void*)(wm->module); | |
434 } | |
435 if(!result) | |
436 { | |
437 if(strcasecmp(name, "kernel32")==0) | |
597 | 438 result=(void *) 0x120; |
128 | 439 } |
440 dbgprintf("GetModuleHandleA('%s') => 0x%x\n", name, result); | |
441 return result; | |
1 | 442 } |
128 | 443 |
1 | 444 struct th_list_t; |
445 typedef struct th_list_t{ | |
446 int id; | |
447 void* thread; | |
448 struct th_list_t* next; | |
449 struct th_list_t* prev; | |
450 }th_list; | |
451 | |
452 static th_list* list=NULL; | |
453 | |
454 | |
455 | |
456 void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress, | |
457 void* lpParameter, long dwFlags, long* dwThreadId) | |
458 { | |
459 pthread_t *pth; | |
460 // printf("CreateThread:"); | |
461 pth=my_mreq(sizeof(pthread_t), 0); | |
462 pthread_create(pth, NULL, (void*(*)(void*))lpStartAddress, lpParameter); | |
463 if(dwFlags) | |
128 | 464 printf( "WARNING: CreateThread flags not supported\n"); |
1 | 465 if(dwThreadId) |
466 *dwThreadId=(long)pth; | |
467 if(list==NULL) | |
468 { | |
469 list=my_mreq(sizeof(th_list), 1); | |
470 list->next=list->prev=NULL; | |
471 } | |
472 else | |
473 { | |
474 list->next=my_mreq(sizeof(th_list), 0); | |
475 list->next->prev=list; | |
476 list->next->next=NULL; | |
477 list=list->next; | |
478 } | |
479 list->thread=pth; | |
128 | 480 dbgprintf("CreateThread(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0x%x\n", |
481 pSecAttr, dwStackSize, lpStartAddress, lpParameter, dwFlags, dwThreadId, pth); | |
1 | 482 return pth; |
483 } | |
484 | |
485 struct mutex_list_t; | |
486 | |
487 struct mutex_list_t | |
488 { | |
128 | 489 char type; |
1 | 490 pthread_mutex_t *pm; |
128 | 491 pthread_cond_t *pc; |
492 char state; | |
493 char reset; | |
1 | 494 char name[64]; |
128 | 495 int semaphore; |
1 | 496 struct mutex_list_t* next; |
497 struct mutex_list_t* prev; | |
498 }; | |
499 typedef struct mutex_list_t mutex_list; | |
500 static mutex_list* mlist=NULL; | |
501 void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, | |
502 char bInitialState, const char* name) | |
503 { | |
504 pthread_mutex_t *pm; | |
128 | 505 pthread_cond_t *pc; |
1 | 506 if(mlist!=NULL) |
507 { | |
508 mutex_list* pp=mlist; | |
509 if(name!=NULL) | |
510 do | |
511 { | |
128 | 512 if((strcmp(pp->name, name)==0) && (pp->type==0)) |
513 { | |
514 dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n", | |
515 pSecAttr, bManualReset, bInitialState, name, name, pp->pm); | |
1 | 516 return pp->pm; |
128 | 517 } |
597 | 518 }while((pp=pp->prev)); |
1 | 519 } |
520 pm=my_mreq(sizeof(pthread_mutex_t), 0); | |
521 pthread_mutex_init(pm, NULL); | |
128 | 522 pc=my_mreq(sizeof(pthread_cond_t), 0); |
523 pthread_cond_init(pc, NULL); | |
1 | 524 if(mlist==NULL) |
525 { | |
526 mlist=my_mreq(sizeof(mutex_list), 00); | |
527 mlist->next=mlist->prev=NULL; | |
528 } | |
529 else | |
530 { | |
531 mlist->next=my_mreq(sizeof(mutex_list), 00); | |
128 | 532 mlist->next->prev=mlist; |
1 | 533 mlist->next->next=NULL; |
534 mlist=mlist->next; | |
535 } | |
128 | 536 mlist->type=0; /* Type Event */ |
1 | 537 mlist->pm=pm; |
128 | 538 mlist->pc=pc; |
539 mlist->state=bInitialState; | |
540 mlist->reset=bManualReset; | |
1 | 541 if(name!=NULL) |
542 strncpy(mlist->name, name, 64); | |
543 else | |
544 mlist->name[0]=0; | |
545 if(pm==NULL) | |
546 dbgprintf("ERROR::: CreateEventA failure\n"); | |
128 | 547 /* |
1 | 548 if(bInitialState) |
549 pthread_mutex_lock(pm); | |
128 | 550 */ |
551 if(name) | |
552 dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, 0x%x='%s') => 0x%x\n", | |
553 pSecAttr, bManualReset, bInitialState, name, name, mlist); | |
554 else | |
555 dbgprintf("CreateEventA(0x%x, 0x%x, 0x%x, NULL) => 0x%x\n", | |
556 pSecAttr, bManualReset, bInitialState, mlist); | |
557 return mlist; | |
1 | 558 } |
559 | |
560 void* WINAPI expSetEvent(void* event) | |
561 { | |
128 | 562 mutex_list *ml = (mutex_list *)event; |
563 dbgprintf("SetEvent(%x) => 0x1\n", event); | |
564 pthread_mutex_lock(ml->pm); | |
565 if (ml->state == 0) { | |
566 ml->state = 1; | |
567 pthread_cond_signal(ml->pc); | |
568 } | |
569 pthread_mutex_unlock(ml->pm); | |
570 | |
571 return (void *)1; | |
1 | 572 } |
573 void* WINAPI expResetEvent(void* event) | |
574 { | |
128 | 575 mutex_list *ml = (mutex_list *)event; |
576 dbgprintf("ResetEvent(0x%x) => 0x1\n", event); | |
577 pthread_mutex_lock(ml->pm); | |
578 ml->state = 0; | |
579 pthread_mutex_unlock(ml->pm); | |
580 | |
581 return (void *)1; | |
1 | 582 } |
583 | |
584 void* WINAPI expWaitForSingleObject(void* object, int duration) | |
585 { | |
128 | 586 mutex_list *ml = (mutex_list *)object; |
718 | 587 int ret=WAIT_FAILED; // fixed by Zdenek Kabelac |
128 | 588 mutex_list* pp=mlist; |
589 // dbgprintf("WaitForSingleObject(0x%x, duration %d) =>\n",object, duration); | |
718 | 590 // loop below was slightly fixed - its used just for checking if |
591 // this object really exists in our list | |
592 if (!ml) | |
593 return (void*) ret; | |
594 while (pp && (pp->pm != ml->pm)) | |
595 pp = pp->prev; | |
596 if (!pp) { | |
597 //dbgprintf("WaitForSingleObject: NotFound\n"); | |
598 return (void*)ret; | |
599 } | |
128 | 600 |
601 pthread_mutex_lock(ml->pm); | |
602 | |
603 switch(ml->type) { | |
604 case 0: /* Event */ | |
605 if (duration == 0) { /* Check Only */ | |
606 if (ml->state == 1) ret = WAIT_FAILED; | |
607 else ret = WAIT_OBJECT_0; | |
608 } | |
609 if (duration == -1) { /* INFINITE */ | |
610 if (ml->state == 0) | |
611 pthread_cond_wait(ml->pc,ml->pm); | |
612 if (ml->reset) | |
613 ml->state = 0; | |
614 ret = WAIT_OBJECT_0; | |
615 } | |
616 if (duration > 0) { /* Timed Wait */ | |
617 struct timespec abstime; | |
618 struct timeval now; | |
619 gettimeofday(&now, 0); | |
620 abstime.tv_sec = now.tv_sec + (now.tv_usec+duration)/1000000; | |
621 abstime.tv_nsec = ((now.tv_usec+duration)%1000000)*1000; | |
622 if (ml->state == 0) | |
623 ret=pthread_cond_timedwait(ml->pc,ml->pm,&abstime); | |
624 if (ret == ETIMEDOUT) ret = WAIT_TIMEOUT; | |
625 else ret = WAIT_OBJECT_0; | |
626 if (ml->reset) | |
627 ml->state = 0; | |
628 } | |
629 break; | |
630 case 1: /* Semaphore */ | |
631 if (duration == 0) { | |
632 if(ml->semaphore==0) ret = WAIT_FAILED; | |
633 else { | |
634 ml->semaphore++; | |
635 ret = WAIT_OBJECT_0; | |
636 } | |
637 } | |
638 if (duration == -1) { | |
639 if (ml->semaphore==0) | |
640 pthread_cond_wait(ml->pc,ml->pm); | |
641 ml->semaphore--; | |
642 } | |
643 break; | |
644 } | |
645 pthread_mutex_unlock(ml->pm); | |
646 | |
647 dbgprintf("WaitForSingleObject(0x%x, %d): 0x%x => 0x%x \n",object,duration,ml,ret); | |
648 return (void *)ret; | |
1 | 649 } |
650 | |
651 static BYTE PF[64] = {0,}; | |
652 | |
128 | 653 WIN_BOOL WINAPI expIsProcessorFeaturePresent(DWORD v) |
654 { | |
655 WIN_BOOL result; | |
656 if(v>63)result=0; | |
657 else result=PF[v]; | |
658 dbgprintf("IsProcessorFeaturePresent(0x%x) => 0x%x\n", v, result); | |
659 return result; | |
660 } | |
661 | |
662 static void DumpSystemInfo(const SYSTEM_INFO* si) | |
663 { | |
664 dbgprintf(" Processor architecture %d\n", si->u.s.wProcessorArchitecture); | |
665 dbgprintf(" Page size: %d\n", si->dwPageSize); | |
666 dbgprintf(" Minimum app address: %d\n", si->lpMinimumApplicationAddress); | |
667 dbgprintf(" Maximum app address: %d\n", si->lpMaximumApplicationAddress); | |
668 dbgprintf(" Active processor mask: 0x%x\n", si->dwActiveProcessorMask); | |
669 dbgprintf(" Number of processors: %d\n", si->dwNumberOfProcessors); | |
670 dbgprintf(" Processor type: 0x%x\n", si->dwProcessorType); | |
671 dbgprintf(" Allocation granularity: 0x%x\n", si->dwAllocationGranularity); | |
672 dbgprintf(" Processor level: 0x%x\n", si->wProcessorLevel); | |
673 dbgprintf(" Processor revision: 0x%x\n", si->wProcessorRevision); | |
674 } | |
675 | |
1 | 676 void WINAPI expGetSystemInfo(SYSTEM_INFO* si) |
677 { | |
678 /* FIXME: better values for the two entries below... */ | |
679 static int cache = 0; | |
680 static SYSTEM_INFO cachedsi; | |
128 | 681 unsigned int regs[4]; |
1 | 682 HKEY xhkey=0,hkey; |
128 | 683 dbgprintf("GetSystemInfo(0x%d) =>\n"); |
1 | 684 |
685 if (cache) { | |
686 memcpy(si,&cachedsi,sizeof(*si)); | |
128 | 687 DumpSystemInfo(si); |
1 | 688 return; |
689 } | |
690 memset(PF,0,sizeof(PF)); | |
691 | |
692 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL; | |
693 cachedsi.dwPageSize = getpagesize(); | |
694 | |
695 /* FIXME: better values for the two entries below... */ | |
128 | 696 cachedsi.lpMinimumApplicationAddress = (void *)0x00000000; |
1 | 697 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF; |
698 cachedsi.dwActiveProcessorMask = 1; | |
699 cachedsi.dwNumberOfProcessors = 1; | |
700 cachedsi.dwProcessorType = PROCESSOR_INTEL_386; | |
701 cachedsi.dwAllocationGranularity = 0x10000; | |
128 | 702 cachedsi.wProcessorLevel = 5; /* pentium */ |
703 cachedsi.wProcessorRevision = 0x0101; | |
1 | 704 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
705 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__svr4__) |
128 | 706 do_cpuid(regs); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
707 switch ((regs[0] >> 8) & 0xf) { // cpu family |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
708 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
709 cachedsi.wProcessorLevel= 3; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
710 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
711 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
712 cachedsi.wProcessorLevel= 4; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
713 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
714 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
715 cachedsi.wProcessorLevel= 5; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
716 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
717 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
718 cachedsi.wProcessorLevel= 5; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
719 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
720 default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
721 cachedsi.wProcessorLevel= 5; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
722 break; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
723 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
724 cachedsi.wProcessorRevision = regs[0] & 0xf; // stepping |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
725 if (regs[3] & (1 << 8)) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
726 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J«ärgen Keil <jk@tools.de>
arpi_esp
parents:
718
diff
changeset
|
727 if (regs[3] & (1 << 23)) |
128 | 728 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; |
1 | 729 cachedsi.dwNumberOfProcessors=1; |
730 #else | |
731 { | |
732 char buf[20]; | |
733 char line[200]; | |
734 FILE *f = fopen ("/proc/cpuinfo", "r"); | |
735 | |
736 if (!f) | |
737 return; | |
738 xhkey = 0; | |
739 while (fgets(line,200,f)!=NULL) { | |
740 char *s,*value; | |
741 | |
742 /* NOTE: the ':' is the only character we can rely on */ | |
743 if (!(value = strchr(line,':'))) | |
744 continue; | |
745 /* terminate the valuename */ | |
746 *value++ = '\0'; | |
747 /* skip any leading spaces */ | |
748 while (*value==' ') value++; | |
749 if ((s=strchr(value,'\n'))) | |
750 *s='\0'; | |
751 | |
752 /* 2.1 method */ | |
753 if (!lstrncmpiA(line, "cpu family",strlen("cpu family"))) { | |
754 if (isdigit (value[0])) { | |
755 switch (value[0] - '0') { | |
756 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; | |
757 cachedsi.wProcessorLevel= 3; | |
758 break; | |
759 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; | |
760 cachedsi.wProcessorLevel= 4; | |
761 break; | |
762 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
763 cachedsi.wProcessorLevel= 5; | |
764 break; | |
765 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
766 cachedsi.wProcessorLevel= 5; | |
767 break; | |
768 default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
769 cachedsi.wProcessorLevel= 5; | |
770 break; | |
771 } | |
772 } | |
773 /* set the CPU type of the current processor */ | |
1096 | 774 snprintf(buf,20,"CPU %ld",cachedsi.dwProcessorType); |
1 | 775 continue; |
776 } | |
777 /* old 2.0 method */ | |
778 if (!lstrncmpiA(line, "cpu",strlen("cpu"))) { | |
779 if ( isdigit (value[0]) && value[1] == '8' && | |
780 value[2] == '6' && value[3] == 0 | |
781 ) { | |
782 switch (value[0] - '0') { | |
783 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; | |
784 cachedsi.wProcessorLevel= 3; | |
785 break; | |
786 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; | |
787 cachedsi.wProcessorLevel= 4; | |
788 break; | |
789 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
790 cachedsi.wProcessorLevel= 5; | |
791 break; | |
792 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
793 cachedsi.wProcessorLevel= 5; | |
794 break; | |
795 default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; | |
796 cachedsi.wProcessorLevel= 5; | |
797 break; | |
798 } | |
799 } | |
800 /* set the CPU type of the current processor */ | |
1096 | 801 snprintf(buf,20,"CPU %ld",cachedsi.dwProcessorType); |
1 | 802 continue; |
803 } | |
804 if (!lstrncmpiA(line,"fdiv_bug",strlen("fdiv_bug"))) { | |
805 if (!lstrncmpiA(value,"yes",3)) | |
806 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE; | |
807 | |
808 continue; | |
809 } | |
810 if (!lstrncmpiA(line,"fpu",strlen("fpu"))) { | |
811 if (!lstrncmpiA(value,"no",2)) | |
812 PF[PF_FLOATING_POINT_EMULATED] = TRUE; | |
813 | |
814 continue; | |
815 } | |
816 if (!lstrncmpiA(line,"processor",strlen("processor"))) { | |
817 /* processor number counts up...*/ | |
818 int x; | |
819 | |
820 if (sscanf(value,"%d",&x)) | |
821 if (x+1>cachedsi.dwNumberOfProcessors) | |
822 cachedsi.dwNumberOfProcessors=x+1; | |
823 | |
824 /* Create a new processor subkey on a multiprocessor | |
825 * system | |
826 */ | |
1096 | 827 snprintf(buf,20,"%d",x); |
1 | 828 } |
829 if (!lstrncmpiA(line,"stepping",strlen("stepping"))) { | |
830 int x; | |
831 | |
832 if (sscanf(value,"%d",&x)) | |
833 cachedsi.wProcessorRevision = x; | |
834 } | |
128 | 835 if |
836 ( (!lstrncmpiA(line,"flags",strlen("flags"))) | |
837 || (!lstrncmpiA(line,"features",strlen("features"))) ) | |
838 { | |
1 | 839 if (strstr(value,"cx8")) |
840 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE; | |
841 if (strstr(value,"mmx")) | |
842 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE; | |
843 | |
844 } | |
845 } | |
846 fclose (f); | |
128 | 847 /* |
848 * ad hoc fix for smp machines. | |
849 * some problems on WaitForSingleObject,CreateEvent,SetEvent | |
850 * CreateThread ...etc.. | |
851 * | |
852 */ | |
853 cachedsi.dwNumberOfProcessors=1; | |
1 | 854 } |
855 #endif /* __FreeBSD__ */ | |
856 memcpy(si,&cachedsi,sizeof(*si)); | |
128 | 857 DumpSystemInfo(si); |
1 | 858 } |
859 | |
860 long WINAPI expGetVersion() | |
861 { | |
128 | 862 dbgprintf("GetVersion() => 0xC0000004\n"); |
863 return 0xC0000004;//Windows 95 | |
1 | 864 } |
865 | |
866 HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size) | |
867 { | |
868 // printf("HeapCreate:"); | |
128 | 869 HANDLE result; |
1 | 870 if(init_size==0) |
128 | 871 result=(HANDLE)my_mreq(0x110000, 0); |
1 | 872 else |
128 | 873 result=(HANDLE)my_mreq(init_size, 0); |
874 dbgprintf("HeapCreate(flags 0x%x, initial size %d, maximum size %d) => 0x%x\n", flags, init_size, max_size, result); | |
875 return result; | |
1 | 876 } |
877 void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size) | |
878 { | |
879 void* z; | |
880 // printf("HeapAlloc:"); | |
128 | 881 /** |
882 Morgan's m3jpeg32.dll v. 2.0 encoder expects that request for | |
883 HeapAlloc returns area larger than size argument :-/ | |
884 **/ | |
885 z=my_mreq(((size+4095)/4096)*4096, flags&8); | |
1 | 886 // z=HeapAlloc(heap,flags,size); |
887 if(z==0) | |
888 printf("HeapAlloc failure\n"); | |
128 | 889 dbgprintf("HeapAlloc(heap 0x%x, flags 0x%x, size 0x%x) => 0x%x\n", heap, flags, size, z); |
1 | 890 return z; |
891 } | |
892 long WINAPI expHeapDestroy(void* heap) | |
893 { | |
128 | 894 dbgprintf("HeapDestroy(heap 0x%x) => 1\n", heap); |
1 | 895 my_release(heap); |
896 return 1; | |
897 } | |
898 | |
899 long WINAPI expHeapFree(int arg1, int arg2, void* ptr) | |
900 { | |
128 | 901 dbgprintf("HeapFree(0x%x, 0x%x, pointer 0x%x) => 1\n", arg1, arg2, ptr); |
1 | 902 my_release(ptr); |
903 return 1; | |
904 } | |
905 long WINAPI expHeapSize(int heap, int flags, void* pointer) | |
906 { | |
128 | 907 long result=my_size(pointer); |
908 dbgprintf("HeapSize(heap 0x%x, flags 0x%x, pointer 0x%x) => %d\n", heap, flags, pointer, result); | |
909 return result; | |
1 | 910 } |
911 long WINAPI expGetProcessHeap(void) | |
912 { | |
128 | 913 dbgprintf("GetProcessHeap() => 1\n"); |
1 | 914 return 1; |
915 } | |
916 void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4) | |
917 { | |
918 void* z; | |
919 z=VirtualAlloc(v1, v2, v3, v4); | |
920 if(z==0) | |
921 printf("VirtualAlloc failure\n"); | |
128 | 922 dbgprintf("VirtualAlloc(0x%x, %d, %d, %d) => 0x%x \n",v1,v2,v3,v4, z); |
1 | 923 return z; |
924 } | |
925 int WINAPI expVirtualFree(void* v1, int v2, int v3) | |
926 { | |
128 | 927 int result=VirtualFree(v1,v2,v3); |
928 dbgprintf("VirtualFree(0x%x, %d, %d) => %d\n",v1,v2,v3, result); | |
929 return result; | |
1 | 930 } |
931 struct CRITSECT | |
932 { | |
933 pthread_t id; | |
934 pthread_mutex_t mutex; | |
935 int locked; | |
936 }; | |
937 void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c) | |
938 { | |
939 struct CRITSECT cs; | |
128 | 940 dbgprintf("InitializeCriticalSection(0x%x)\n", c); |
1 | 941 /* if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION)) |
942 { | |
943 printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!\n", | |
944 sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION)); | |
945 return; | |
946 }*/ | |
947 /* pthread_mutex_init((pthread_mutex_t*)c, NULL); */ | |
948 pthread_mutex_init(&cs.mutex, NULL); | |
949 cs.locked=0; | |
950 *(void**)c=malloc(sizeof cs); | |
951 memcpy(*(void**)c, &cs, sizeof cs); | |
952 return; | |
953 } | |
954 void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c) | |
955 { | |
128 | 956 struct CRITSECT* cs=*(struct CRITSECT**)c; |
957 dbgprintf("EnterCriticalSection(0x%x)\n",c); | |
1 | 958 // cs.id=pthread_self(); |
959 if(cs->locked) | |
960 if(cs->id==pthread_self()) | |
961 return; | |
962 pthread_mutex_lock(&(cs->mutex)); | |
963 cs->locked=1; | |
964 cs->id=pthread_self(); | |
965 return; | |
966 } | |
967 void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c) | |
968 { | |
128 | 969 struct CRITSECT* cs=*(struct CRITSECT**)c; |
970 // struct CRITSECT* cs=(struct CRITSECT*)c; | |
971 dbgprintf("LeaveCriticalSection(0x%x)\n",c); | |
1 | 972 cs->locked=0; |
973 pthread_mutex_unlock(&(cs->mutex)); | |
974 return; | |
975 } | |
976 void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c) | |
977 { | |
128 | 978 struct CRITSECT* cs=*(struct CRITSECT**)c; |
979 // struct CRITSECT* cs=(struct CRITSECT*)c; | |
980 dbgprintf("DeleteCriticalSection(0x%x)\n",c); | |
981 pthread_mutex_destroy(&(cs->mutex)); | |
982 free(cs); | |
1 | 983 return; |
984 } | |
985 int WINAPI expGetCurrentThreadId() | |
986 { | |
128 | 987 dbgprintf("GetCurrentThreadId() => %d\n", getpid()); |
988 return getpid(); | |
989 } | |
990 int WINAPI expGetCurrentProcess() | |
991 { | |
992 dbgprintf("GetCurrentProcess() => %d\n", getpid()); | |
1 | 993 return getpid(); |
994 } | |
995 struct tls_s; | |
996 typedef struct tls_s | |
997 { | |
998 void* value; | |
999 int used; | |
1000 struct tls_s* prev; | |
1001 struct tls_s* next; | |
1002 }tls_t; | |
1003 | |
1004 tls_t* g_tls=NULL; | |
1005 | |
1006 void* WINAPI expTlsAlloc() | |
1007 { | |
1008 if(g_tls==NULL) | |
1009 { | |
1010 g_tls=my_mreq(sizeof(tls_t), 0); | |
1011 g_tls->next=g_tls->prev=NULL; | |
1012 } | |
1013 else | |
1014 { | |
1015 g_tls->next=my_mreq(sizeof(tls_t), 0); | |
1016 g_tls->next->prev=g_tls; | |
1017 g_tls->next->next=NULL; | |
1018 g_tls=g_tls->next; | |
1019 } | |
128 | 1020 dbgprintf("TlsAlloc() => 0x%x\n", g_tls); |
1021 return g_tls; | |
1 | 1022 } |
1023 | |
1024 int WINAPI expTlsSetValue(tls_t* index, void* value) | |
1025 { | |
128 | 1026 int result; |
1 | 1027 if(index==0) |
128 | 1028 result=0; |
1029 else | |
1030 { | |
1031 index->value=value; | |
1032 result=1; | |
1033 } | |
1034 dbgprintf("TlsSetValue(index 0x%x, value 0x%x) => %d \n", index, value, result ); | |
1035 return result; | |
1 | 1036 } |
1037 void* WINAPI expTlsGetValue(tls_t* index) | |
1038 { | |
128 | 1039 void* result; |
1 | 1040 if(index==0) |
128 | 1041 result=0; |
1042 else | |
1043 result=index->value; | |
1044 dbgprintf("TlsGetValue(index 0x%x) => 0x%x\n", index, result); | |
1045 return result; | |
1 | 1046 } |
1047 int WINAPI expTlsFree(tls_t* index) | |
1048 { | |
128 | 1049 int result; |
1 | 1050 if(index==0) |
128 | 1051 result=0; |
1052 else | |
1053 { | |
1054 if(index->next) | |
1055 index->next->prev=index->prev; | |
1056 if(index->prev) | |
1057 index->prev->next=index->next; | |
1058 my_release((void*)index); | |
1059 result=1; | |
1060 } | |
1061 dbgprintf("TlsFree(index 0x%x) => %d\n", index, result); | |
1062 return result; | |
1 | 1063 } |
1064 void* WINAPI expLocalAlloc(int flags, int size) | |
1065 { | |
1066 void* z; | |
1067 if(flags&GMEM_ZEROINIT) | |
1068 z=my_mreq(size, 1); | |
1069 else | |
1070 z=my_mreq(size, 0); | |
1071 if(z==0) | |
1072 printf("LocalAlloc() failed\n"); | |
128 | 1073 dbgprintf("LocalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z); |
1 | 1074 return z; |
1075 } | |
1076 void* WINAPI expLocalLock(void* z) | |
1077 { | |
128 | 1078 dbgprintf("LocalLock(0x%x) => 0x%x\n", z, z); |
1 | 1079 return z; |
1080 } | |
128 | 1081 |
1 | 1082 void* WINAPI expGlobalAlloc(int flags, int size) |
1083 { | |
1084 void* z; | |
1085 dbgprintf("GlobalAlloc(%d, flags 0x%X)\n", size, flags); | |
1086 if(flags&GMEM_ZEROINIT) | |
128 | 1087 z=calloc(size, 1); |
1088 // z=my_mreq(size, 1); | |
1 | 1089 else |
128 | 1090 z=malloc(size); |
1091 // z=my_mreq(size, 0); | |
1 | 1092 if(z==0) |
128 | 1093 printf("GlobalAlloc() failed\n"); |
1094 dbgprintf("GlobalAlloc(%d, flags 0x%x) => 0x%x\n", size, flags, z); | |
1 | 1095 return z; |
1096 } | |
1097 void* WINAPI expGlobalLock(void* z) | |
1098 { | |
128 | 1099 dbgprintf("GlobalLock(0x%x) => 0x%x\n", z, z); |
1 | 1100 return z; |
1101 } | |
1102 int WINAPI expLoadStringA(long instance, long id, void* buf, long size) | |
1103 { | |
128 | 1104 int result=LoadStringA(instance, id, buf, size); |
1105 // if(buf) | |
1106 dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %d ( %s )\n", | |
1107 instance, id, buf, size, result, buf); | |
1108 // else | |
1109 // dbgprintf("LoadStringA(instance 0x%x, id 0x%x, buffer 0x%x, size %d) => %d\n", | |
1110 // instance, id, buf, size, result); | |
1111 return result; | |
1 | 1112 } |
1113 | |
128 | 1114 long WINAPI expMultiByteToWideChar(long v1, long v2, char* s1, long siz1, short* s2, int siz2) |
1 | 1115 { |
1116 #warning FIXME | |
128 | 1117 int i; |
1118 int result; | |
1 | 1119 if(s2==0) |
128 | 1120 result=1; |
1121 else | |
1122 { | |
1123 if(siz1>siz2/2)siz1=siz2/2; | |
1124 for(i=1; i<=siz1; i++) | |
1125 { | |
1126 *s2=*s1; | |
1127 if(!*s1)break; | |
1128 s2++; | |
1129 s1++; | |
1130 } | |
1131 result=i; | |
1132 } | |
1133 if(s1) | |
1134 dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string 0x%x='%s', | |
1135 size %d, dest buffer 0x%x, dest size %d) => %d\n", | |
1136 v1, v2, s1, s1, siz1, s2, siz2, result); | |
1137 else | |
1138 dbgprintf("MultiByteToWideChar(codepage %d, flags 0x%x, string NULL, | |
1139 size %d, dest buffer 0x%x, dest size %d) =>\n", | |
1140 v1, v2, siz1, s2, siz2, result); | |
1141 return result; | |
1142 } | |
1143 static void wch_print(const short* str) | |
1144 { | |
1145 dbgprintf(" src: "); | |
1146 while(*str)dbgprintf("%c", *str++); | |
1147 dbgprintf("\n"); | |
1 | 1148 } |
1149 long WINAPI expWideCharToMultiByte(long v1, long v2, short* s1, long siz1, char* s2, int siz2, char* c3, int* siz3) | |
1150 { | |
1151 int result; | |
128 | 1152 dbgprintf("WideCharToMultiByte(codepage %d, flags 0x%x, src 0x%x, src size %d, " |
1153 "dest 0x%x, dest size %d, defch 0x%x, used_defch 0x%x)", v1, v2, s1, siz1, s2, siz2, c3, siz3); | |
1 | 1154 result=WideCharToMultiByte(v1, v2, s1, siz1, s2, siz2, c3, siz3); |
1155 dbgprintf("=> %d\n", result); | |
128 | 1156 if(s1)wch_print(s1); |
1157 if(s2)dbgprintf(" dest: %s\n", s2); | |
1 | 1158 return result; |
1159 } | |
1160 long WINAPI expGetVersionExA(OSVERSIONINFOA* c) | |
1161 { | |
128 | 1162 dbgprintf("GetVersionExA(0x%x) => 1\n"); |
1163 c->dwOSVersionInfoSize=sizeof(*c); | |
1 | 1164 c->dwMajorVersion=4; |
128 | 1165 c->dwMinorVersion=0; |
1166 c->dwBuildNumber=0x4000457; | |
1 | 1167 c->dwPlatformId=VER_PLATFORM_WIN32_WINDOWS; |
128 | 1168 strcpy(c->szCSDVersion, " B"); |
1169 dbgprintf(" Major version: 4\n Minor version: 0\n Build number: 0x4000457\n" | |
1170 " Platform Id: VER_PLATFORM_WIN32_WINDOWS\n Version string: ' B'\n"); | |
1 | 1171 return 1; |
1172 } | |
1173 HANDLE WINAPI expCreateSemaphoreA(char* v1, long init_count, long max_count, char* name) | |
1174 { | |
128 | 1175 pthread_mutex_t *pm; |
1176 pthread_cond_t *pc; | |
1177 if(mlist!=NULL) | |
1 | 1178 { |
128 | 1179 mutex_list* pp=mlist; |
1180 if(name!=NULL) | |
1181 do | |
1182 { | |
1183 if((strcmp(pp->name, name)==0) && (pp->type==1)) | |
1184 { | |
1185 dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%x", | |
1186 v1, init_count, max_count, name, name, mlist); | |
1187 return (HANDLE)mlist; | |
1188 } | |
597 | 1189 }while((pp=pp->prev)); |
1 | 1190 } |
128 | 1191 pm=my_mreq(sizeof(pthread_mutex_t), 0); |
1192 pthread_mutex_init(pm, NULL); | |
1193 pc=my_mreq(sizeof(pthread_cond_t), 0); | |
1194 pthread_cond_init(pc, NULL); | |
1195 if(mlist==NULL) | |
1196 { | |
1197 mlist=my_mreq(sizeof(mutex_list), 00); | |
1198 mlist->next=mlist->prev=NULL; | |
1199 } | |
1200 else | |
1 | 1201 { |
128 | 1202 mlist->next=my_mreq(sizeof(mutex_list), 00); |
1203 mlist->next->prev=mlist; | |
1204 mlist->next->next=NULL; | |
1205 mlist=mlist->next; | |
1 | 1206 } |
128 | 1207 mlist->type=1; /* Type Semaphore */ |
1208 mlist->pm=pm; | |
1209 mlist->pc=pc; | |
1210 mlist->state=0; | |
1211 mlist->reset=0; | |
1212 mlist->semaphore=init_count; | |
1213 if(name!=NULL) | |
1214 strncpy(mlist->name, name, 64); | |
1215 else | |
1216 mlist->name[0]=0; | |
1217 if(pm==NULL) | |
1218 dbgprintf("ERROR::: CreateSemaphoreA failure\n"); | |
1219 if(name) | |
1220 dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0x%x='%s') => 0x%x", | |
1221 v1, init_count, max_count, name, name, mlist); | |
1222 else | |
1223 dbgprintf("CreateSemaphoreA(0x%x, init_count %d, max_count %d, name 0) => 0x%x", | |
1224 v1, init_count, max_count, mlist); | |
1225 return (HANDLE)mlist; | |
1 | 1226 } |
1227 | |
1228 long WINAPI expReleaseSemaphore(long hsem, long increment, long* prev_count) | |
1229 { | |
1230 // The state of a semaphore object is signaled when its count | |
1231 // is greater than zero and nonsignaled when its count is equal to zero | |
1232 // Each time a waiting thread is released because of the semaphore's signaled | |
1233 // state, the count of the semaphore is decreased by one. | |
128 | 1234 mutex_list *ml = (mutex_list *)hsem; |
1 | 1235 |
128 | 1236 pthread_mutex_lock(ml->pm); |
1237 if (prev_count != 0) *prev_count = ml->semaphore; | |
1238 if (ml->semaphore == 0) pthread_cond_signal(ml->pc); | |
1239 ml->semaphore += increment; | |
1240 pthread_mutex_unlock(ml->pm); | |
1241 dbgprintf("ReleaseSemaphore(semaphore 0x%x, increment %d, prev_count 0x%x) => 1\n", | |
1242 hsem, increment, prev_count); | |
1243 return 1; | |
1 | 1244 } |
1245 | |
1246 | |
1247 long WINAPI expRegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey) | |
1248 { | |
128 | 1249 long result=RegOpenKeyExA(key, subkey, reserved, access, newkey); |
1250 dbgprintf("RegOpenKeyExA(key 0x%x, subkey %s, reserved %d, access 0x%x, pnewkey 0x%x) => %d\n", | |
1251 key, subkey, reserved, access, newkey, result); | |
1252 if(newkey)dbgprintf(" New key: 0x%x\n", *newkey); | |
1253 return result; | |
1 | 1254 } |
1255 long WINAPI expRegCloseKey(long key) | |
1256 { | |
128 | 1257 long result=RegCloseKey(key); |
1258 dbgprintf("RegCloseKey(0x%x) => %d\n", key, result); | |
1259 return result; | |
1 | 1260 } |
1261 long WINAPI expRegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count) | |
1262 { | |
128 | 1263 long result=RegQueryValueExA(key, value, reserved, type, data, count); |
1264 dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)" | |
1265 " => 0x%x\n", key, value, reserved, data, count, result); | |
1266 if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data); | |
1267 return result; | |
1 | 1268 } |
1269 long WINAPI expRegCreateKeyExA(long key, const char* name, long reserved, | |
1270 void* classs, long options, long security, | |
1271 void* sec_attr, int* newkey, int* status) | |
1272 { | |
128 | 1273 long result=RegCreateKeyExA(key, name, reserved, classs, options, security, sec_attr, newkey, status); |
1274 dbgprintf("RegCreateKeyExA(key 0x%x, name 0x%x='%s', reserved=0x%x," | |
1275 " 0x%x, 0x%x, 0x%x, newkey=0x%x, status=0x%x) => %d\n", | |
1276 key, name, name, reserved, classs, options, security, sec_attr, newkey, status, result); | |
1277 if(!result && newkey) dbgprintf(" New key: 0x%x\n", *newkey); | |
1278 if(!result && status) dbgprintf(" New key status: 0x%x\n", *status); | |
1279 return result; | |
1 | 1280 } |
1281 long WINAPI expRegSetValueExA(long key, const char* name, long v1, long v2, void* data, long size) | |
1282 { | |
128 | 1283 long result=RegSetValueExA(key, name, v1, v2, data, size); |
1284 dbgprintf("RegSetValueExA(key 0x%x, name '%s', 0x%x, 0x%x, data 0x%x -> 0x%x '%s', size=%d) => %d", | |
1285 key, name, v1, v2, data, *(int*)data, data, size, result); | |
1286 return result; | |
1 | 1287 } |
1288 | |
1289 long WINAPI expRegOpenKeyA ( | |
1290 long hKey, | |
1291 LPCSTR lpSubKey, | |
1292 int* phkResult | |
1293 ){ | |
128 | 1294 long result=RegOpenKeyExA(hKey, lpSubKey, 0, 0, phkResult); |
1295 dbgprintf("RegOpenKeyExA(key 0x%x, subkey '%s', 0x%x) => %d\n", | |
1296 hKey, lpSubKey, phkResult, result); | |
1297 if(!result && phkResult) dbgprintf(" New key: 0x%x\n", *phkResult); | |
1298 return result; | |
1 | 1299 } |
1300 | |
1301 long WINAPI expQueryPerformanceCounter(long long* z) | |
1302 { | |
1303 longcount(z); | |
128 | 1304 dbgprintf("QueryPerformanceCounter(0x%x) => 1 ( %Ld )\n", z, *z); |
1 | 1305 return 1; |
1306 } | |
1307 | |
1308 static double old_freq() | |
1309 { | |
128 | 1310 static double ofreq=0.0; |
1311 int i; | |
1 | 1312 int x,y; |
128 | 1313 i=time(NULL); |
1314 if (ofreq != 0.0) return ofreq; | |
1 | 1315 while(i==time(NULL)); |
1316 x=localcount(); | |
1317 i++; | |
1318 while(i==time(NULL)); | |
1319 y=localcount(); | |
128 | 1320 ofreq = (double)(y-x)/1000.; |
1321 return ofreq; | |
1 | 1322 } |
1323 static double CPU_Freq() | |
1324 { | |
128 | 1325 //#ifdef USE_TSC |
1 | 1326 FILE *f = fopen ("/proc/cpuinfo", "r"); |
1327 char line[200]; | |
1328 char model[200]="unknown"; | |
1329 char flags[500]=""; | |
1330 char *s,*value; | |
1331 double freq=-1; | |
1332 | |
1333 if (!f) | |
1334 { | |
128 | 1335 //printf("Can't open /proc/cpuinfo for reading\n"); |
1 | 1336 return old_freq(); |
1337 } | |
1338 while (fgets(line,200,f)!=NULL) | |
1339 { | |
1340 /* NOTE: the ':' is the only character we can rely on */ | |
1341 if (!(value = strchr(line,':'))) | |
1342 continue; | |
1343 /* terminate the valuename */ | |
1344 *value++ = '\0'; | |
1345 /* skip any leading spaces */ | |
1346 while (*value==' ') value++; | |
1347 if ((s=strchr(value,'\n'))) | |
1348 *s='\0'; | |
1349 | |
1350 if (!strncasecmp(line, "cpu MHz",strlen("cpu MHz"))) | |
1351 { | |
1352 sscanf(value, "%lf", &freq); | |
1353 freq*=1000; | |
1354 break; | |
1355 } | |
1356 continue; | |
1357 | |
1358 } | |
1359 fclose(f); | |
1360 if(freq<0)return old_freq(); | |
1361 return freq; | |
128 | 1362 //#else |
1363 // return old_freq(); | |
1364 //#endif | |
1 | 1365 } |
1366 | |
1367 long WINAPI expQueryPerformanceFrequency(long long* z) | |
1368 { | |
1369 *z=(long long)CPU_Freq(); | |
128 | 1370 dbgprintf("QueryPerformanceFrequency(0x%x) => 1 ( %Ld )\n", z, *z); |
1 | 1371 return 1; |
1372 } | |
1373 long WINAPI exptimeGetTime() | |
1374 { | |
1375 struct timeval t; | |
128 | 1376 long result; |
1 | 1377 gettimeofday(&t, 0); |
128 | 1378 result=1000*t.tv_sec+t.tv_usec/1000; |
1379 dbgprintf("timeGetTime() => %d\n", result); | |
1380 return result; | |
1 | 1381 } |
1382 void* WINAPI expLocalHandle(void* v) | |
1383 { | |
128 | 1384 dbgprintf("LocalHandle(0x%x) => 0x%x\n", v, v); |
1 | 1385 return v; |
1386 } | |
1387 void* WINAPI expGlobalHandle(void* v) | |
1388 { | |
128 | 1389 dbgprintf("GlobalHandle(0x%x) => 0x%x\n", v, v); |
1 | 1390 return v; |
1391 } | |
1392 int WINAPI expGlobalUnlock(void* v) | |
1393 { | |
128 | 1394 dbgprintf("GlobalUnlock(0x%x) => 1\n", v); |
1 | 1395 return 1; |
1396 } | |
1397 // | |
1398 void* WINAPI expGlobalFree(void* v) | |
1399 { | |
128 | 1400 dbgprintf("GlobalFree(0x%x) => 0\n", v); |
1401 //my_release(v); | |
1402 free(v); | |
1 | 1403 return 0; |
128 | 1404 } |
1405 | |
1406 | |
1407 void* WINAPI expGlobalReAlloc(void* v, int size, int flags) | |
1408 { | |
1409 void* result=realloc(v, size); | |
1410 dbgprintf("GlobalReAlloc(0x%x, size %d, flags 0x%x) => 0x%x\n", v,size,flags,result); | |
1411 return result; | |
1412 } | |
1 | 1413 |
1414 int WINAPI expLocalUnlock(void* v) | |
1415 { | |
128 | 1416 dbgprintf("LocalUnlock(0x%x) => 1\n", v); |
1 | 1417 return 1; |
1418 } | |
128 | 1419 // |
1 | 1420 void* WINAPI expLocalFree(void* v) |
1421 { | |
128 | 1422 dbgprintf("LocalFree(0x%x) => 0\n", v); |
1 | 1423 my_release(v); |
1424 return 0; | |
1425 } | |
1426 HRSRC WINAPI expFindResourceA(HMODULE module, char* name, char* type) | |
1427 { | |
128 | 1428 HRSRC result=FindResourceA(module, name, type); |
1429 dbgprintf("FindResourceA(module 0x%x, name 0x%x, type 0x%x) => 0x%x\n", module, name, type, result); | |
1430 return result; | |
1 | 1431 } |
128 | 1432 extern HRSRC WINAPI LoadResource(HMODULE, HRSRC); |
1 | 1433 HGLOBAL WINAPI expLoadResource(HMODULE module, HRSRC res) |
1434 { | |
128 | 1435 HGLOBAL result=LoadResource(module, res); |
1436 dbgprintf("LoadResource(module 0x%x, resource 0x%x) => 0x%x\n", module, res, result); | |
1437 return result; | |
1 | 1438 } |
1439 void* WINAPI expLockResource(long res) | |
1440 { | |
128 | 1441 void* result=LockResource(res); |
1442 dbgprintf("LockResource(0x%x) => 0x%x\n", res, result); | |
1443 return result; | |
1 | 1444 } |
1445 int WINAPI expFreeResource(long res) | |
1446 { | |
128 | 1447 int result=FreeResource(res); |
1448 dbgprintf("FreeResource(0x%x) => %d\n", res, result); | |
1449 return result; | |
1 | 1450 } |
1451 //bool fun(HANDLE) | |
1452 //!0 on success | |
1453 int WINAPI expCloseHandle(long v1) | |
1454 { | |
128 | 1455 dbgprintf("CloseHandle(0x%x) => 1\n", v1); |
1 | 1456 return 1; |
1457 } | |
1458 | |
1459 const char* WINAPI expGetCommandLineA() | |
1460 { | |
128 | 1461 dbgprintf("GetCommandLineA() => \"c:\\aviplay.exe\"\n"); |
1 | 1462 return "c:\\aviplay.exe"; |
1463 } | |
128 | 1464 static short envs[]={'p', 'a', 't', 'h', ' ', 'c', ':', '\\', 0, 0}; |
1 | 1465 LPWSTR WINAPI expGetEnvironmentStringsW() |
1466 { | |
128 | 1467 dbgprintf("GetEnvironmentStringsW() => 0\n", envs); |
1468 return 0; | |
1 | 1469 } |
121 | 1470 void * WINAPI expRtlZeroMemory(void *p, size_t len) |
1471 { | |
1472 void* result=memset(p,0,len); | |
1473 dbgprintf("RtlZeroMemory(0x%x, len %d) => 0x%x\n",p,len,result); | |
1474 return result; | |
1475 } | |
1476 void * WINAPI expRtlMoveMemory(void *dst, void *src, size_t len) | |
1477 { | |
1478 void* result=memmove(dst,src,len); | |
1479 dbgprintf("RtlMoveMemory (dest 0x%x, src 0x%x, len %d) => 0x%x\n",dst,src,len,result); | |
1480 return result; | |
1481 } | |
1482 | |
1483 void * WINAPI expRtlFillMemory(void *p, int ch, size_t len) | |
1484 { | |
1485 void* result=memset(p,ch,len); | |
1486 dbgprintf("RtlFillMemory(0x%x, char 0x%x, len %d) => 0x%x\n",p,ch,len,result); | |
1487 return result; | |
1488 } | |
1 | 1489 int WINAPI expFreeEnvironmentStringsW(short* strings) |
1490 { | |
128 | 1491 dbgprintf("FreeEnvironmentStringsW(0x%x) => 1\n", strings); |
1 | 1492 return 1; |
1493 } | |
128 | 1494 int WINAPI expFreeEnvironmentStringsA(char* strings) |
1495 { | |
1496 dbgprintf("FreeEnvironmentStringsA(0x%x) => 1\n", strings); | |
1497 return 1; | |
1498 } | |
1499 static const char ch_envs[]= | |
1500 "__MSVCRT_HEAP_SELECT=__GLOBAL_HEAP_SELECTED,1\r\n" | |
1501 "PATH=C:\\;C:\\windows\\;C:\\windows\\system\r\n"; | |
1 | 1502 LPCSTR WINAPI expGetEnvironmentStrings() |
1503 { | |
128 | 1504 dbgprintf("GetEnvironmentStrings() => 0x%x\n", ch_envs); |
1505 return (LPCSTR)ch_envs; | |
1506 // dbgprintf("GetEnvironmentStrings() => 0\n"); | |
1507 // return 0; | |
1 | 1508 } |
1509 | |
1510 int WINAPI expGetStartupInfoA(STARTUPINFOA *s) | |
1511 { | |
1512 int i; | |
128 | 1513 dbgprintf("GetStartupInfoA(0x%x) => 1\n"); |
1 | 1514 memset(s, 0, sizeof(*s)); |
1515 s->cb=sizeof(*s); | |
128 | 1516 // s->lpReserved="Reserved"; |
1517 // s->lpDesktop="Desktop"; | |
1518 // s->lpTitle="Title"; | |
1519 // s->dwX=s->dwY=0; | |
1520 // s->dwXSize=s->dwYSize=200; | |
1521 s->dwFlags=s->wShowWindow=1; | |
1522 // s->hStdInput=s->hStdOutput=s->hStdError=0x1234; | |
1523 dbgprintf(" cb=%d\n", s->cb); | |
1524 dbgprintf(" lpReserved='%s'\n", s->lpReserved); | |
1525 dbgprintf(" lpDesktop='%s'\n", s->lpDesktop); | |
1526 dbgprintf(" lpTitle='%s'\n", s->lpTitle); | |
1527 dbgprintf(" dwX=%d dwY=%d dwXSize=%d dwYSize=%d\n", | |
1528 s->dwX, s->dwY, s->dwXSize, s->dwYSize); | |
1529 dbgprintf(" dwXCountChars=%d dwYCountChars=%d dwFillAttribute=%d\n", | |
1530 s->dwXCountChars, s->dwYCountChars, s->dwFillAttribute); | |
1531 dbgprintf(" dwFlags=0x%x wShowWindow=0x%x cbReserved2=0x%x\n", | |
1532 s->dwFlags, s->wShowWindow, s->cbReserved2); | |
1533 dbgprintf(" lpReserved2=0x%x hStdInput=0x%x hStdOutput=0x%x hStdError=0x%x\n", | |
1534 s->lpReserved2, s->hStdInput, s->hStdOutput, s->hStdError); | |
1 | 1535 return 1; |
1536 } | |
1537 | |
1538 int WINAPI expGetStdHandle(int z) | |
1539 { | |
128 | 1540 dbgprintf("GetStdHandle(0x%x) => 0x%x\n", z+0x1234); |
1541 return z+0x1234; | |
1 | 1542 } |
1543 int WINAPI expGetFileType(int handle) | |
1544 { | |
128 | 1545 dbgprintf("GetFileType(0x%x) => 0x3 = pipe\n", handle); |
1546 return 0x3; | |
1 | 1547 } |
1548 int WINAPI expSetHandleCount(int count) | |
1549 { | |
128 | 1550 dbgprintf("SetHandleCount(0x%x) => 1\n", count); |
1 | 1551 return 1; |
1552 } | |
1553 int WINAPI expGetACP() | |
1554 { | |
128 | 1555 dbgprintf("GetACP() => 0\n"); |
1 | 1556 return 0; |
1557 } | |
1558 extern WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m); | |
1559 int WINAPI expGetModuleFileNameA(int module, char* s, int len) | |
1560 { | |
1561 WINE_MODREF *mr; | |
128 | 1562 int result; |
1 | 1563 // printf("File name of module %X requested\n", module); |
1564 if(s==0) | |
128 | 1565 result=0; |
1566 else | |
1 | 1567 if(len<35) |
128 | 1568 result=0; |
1569 else | |
1 | 1570 { |
128 | 1571 result=1; |
1572 strcpy(s, "c:\\windows\\system\\"); | |
1573 mr=MODULE32_LookupHMODULE(module); | |
1574 if(mr==0)//oops | |
1575 strcat(s, "aviplay.dll"); | |
1576 else | |
1577 if(strrchr(mr->filename, '/')==NULL) | |
1578 strcat(s, mr->filename); | |
1579 else | |
1580 strcat(s, strrchr(mr->filename, '/')+1); | |
1581 } | |
1582 if(!s) | |
1583 dbgprintf("GetModuleFileNameA(0x%x, 0x%x, %d) => %d\n", | |
1584 module, s, len, result); | |
1 | 1585 else |
128 | 1586 dbgprintf("GetModuleFileNameA(0x%x, 0x%x, %d) => %d ( '%s' )", |
1587 module, s, len, result, s); | |
1588 return result; | |
1 | 1589 } |
1590 | |
1591 int WINAPI expSetUnhandledExceptionFilter(void* filter) | |
1592 { | |
128 | 1593 dbgprintf("SetUnhandledExceptionFilter(0x%x) => 1\n", filter); |
1 | 1594 return 1;//unsupported and probably won't ever be supported |
1595 } | |
1596 extern char* def_path; | |
1597 int WINAPI expLoadLibraryA(char* name) | |
1598 { | |
1599 char qq[256]; | |
128 | 1600 int result; |
713 | 1601 char* lastbc; |
1602 if (!name) | |
1603 return -1; | |
1604 // we skip to the last backslash | |
1605 // this is effectively eliminating weird characters in | |
1606 // the text output windows | |
1607 lastbc = strrchr(name, '\\'); | |
1608 if (lastbc) | |
1609 { | |
1610 int i; | |
1611 lastbc++; | |
1612 for (i = 0; 1 ;i++) | |
1613 { | |
1614 name[i] = *lastbc++; | |
1615 if (!name[i]) | |
1616 break; | |
1617 } | |
1618 } | |
1619 // printf("LoadLibrary wants: %s/%s\n", def_path, name); | |
1620 | |
128 | 1621 if(strncmp(name, "c:\\windows\\", 11)==0)name+=11; |
1622 if(name[0]!='/') | |
1623 { | |
1624 strcpy(qq, def_path); | |
1625 strcat(qq, "/"); | |
1626 if(strncmp(name, ".\\", 2)==0) | |
1627 strcat(qq, name+2); | |
1628 else | |
1629 strcat(qq, name); | |
1630 } | |
341 | 1631 printf("Loading DLL: %s", qq);fflush(stdout); |
340 | 1632 // printf("Entering LoadLibraryA(%s)\n", name); |
128 | 1633 result=LoadLibraryA(qq); |
341 | 1634 if(!result) printf(" FAILED!\n"); else printf(" OK\n"); |
340 | 1635 // printf("Returned LoadLibraryA(0x%x='%s'), def_path=%s => 0x%x\n", name, name, def_path, result); |
128 | 1636 return result; |
1 | 1637 } |
1638 int WINAPI expFreeLibrary(int module) | |
1639 { | |
128 | 1640 int result=FreeLibrary(module); |
1641 dbgprintf("FreeLibrary(0x%x) => %d\n", module, result); | |
1642 return result; | |
1 | 1643 } |
597 | 1644 void* LookupExternalByName(const char* library, const char* name); |
1 | 1645 void* WINAPI expGetProcAddress(HMODULE mod, char* name) |
1646 { | |
597 | 1647 void *result; |
128 | 1648 if(mod!=0x120) |
1649 result=GetProcAddress(mod, name); | |
1650 else | |
1651 result=LookupExternalByName("kernel32.dll", name); | |
1652 dbgprintf("GetProcAddress(0x%x, '%s') => 0x%x\n", mod, name, result); | |
1653 return result; | |
1 | 1654 } |
1655 | |
1656 long WINAPI expCreateFileMappingA(int hFile, void* lpAttr, | |
1657 long flProtect, long dwMaxHigh, long dwMaxLow, const char* name) | |
1658 { | |
128 | 1659 long result=CreateFileMappingA(hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name); |
1660 if(!name) | |
1661 dbgprintf("CreateFileMappingA(file 0x%x, lpAttr 0x%x, | |
1662 flProtect 0x%x, dwMaxHigh 0x%x, dwMaxLow 0x%x, name 0) => %d\n", | |
1663 hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, result); | |
1664 else | |
1665 dbgprintf("CreateFileMappingA(file 0x%x, lpAttr 0x%x, | |
1666 flProtect 0x%x, dwMaxHigh 0x%x, dwMaxLow 0x%x, name 0x%x='%s') => %d\n", | |
1667 hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name, name, result); | |
1668 return result; | |
1 | 1669 } |
1670 | |
1671 long WINAPI expOpenFileMappingA(long hFile, long hz, const char* name) | |
1672 { | |
128 | 1673 long result=OpenFileMappingA(hFile, hz, name); |
1674 if(!name) | |
1675 dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0) => %d\n", | |
1676 hFile, hz, result); | |
1677 else | |
1678 dbgprintf("OpenFileMappingA(0x%x, 0x%x, 0x%x='%s') => %d\n", | |
1679 hFile, hz, name, name, result); | |
1680 return result; | |
1 | 1681 } |
1682 | |
1683 void* WINAPI expMapViewOfFile(HANDLE file, DWORD mode, DWORD offHigh, DWORD offLow, DWORD size) | |
1684 { | |
128 | 1685 dbgprintf("MapViewOfFile(0x%x, 0x%x, 0x%x, 0x%x, size %d) => 0x%x\n", |
1686 file,mode,offHigh,offLow,size,(char*)file+offLow); | |
1 | 1687 return (char*)file+offLow; |
1688 } | |
1689 | |
1690 void* WINAPI expUnmapViewOfFile(void* view) | |
1691 { | |
128 | 1692 dbgprintf("UnmapViewOfFile(0x%x) => 0\n", view); |
1 | 1693 return 0; |
1694 } | |
1695 | |
1696 void* WINAPI expSleep(int time) | |
1697 { | |
128 | 1698 dbgprintf("Sleep(%d) => 0\n", time); |
1 | 1699 usleep(time); |
1700 return 0; | |
1701 } | |
1702 // why does IV32 codec want to call this? I don't know ... | |
1703 void* WINAPI expCreateCompatibleDC(int hdc) | |
1704 { | |
128 | 1705 dbgprintf("CreateCompatibleDC(%d) => 0x81\n", hdc); |
1706 return (void*)0x81; | |
1 | 1707 } |
1708 | |
1709 int WINAPI expGetDeviceCaps(int hdc, int unk) | |
1710 { | |
128 | 1711 dbgprintf("GetDeviceCaps(0x%x, %d) => 0\n", hdc, unk); |
1 | 1712 return 0; |
1713 } | |
1714 | |
1715 WIN_BOOL WINAPI expDeleteDC(int hdc) | |
1716 { | |
128 | 1717 dbgprintf("DeleteDC(0x%x) => 0\n", hdc); |
1 | 1718 return 0; |
1719 } | |
1720 | |
1721 int expwsprintfA(char* string, char* format, ...) | |
1722 { | |
1723 va_list va; | |
128 | 1724 int result; |
1 | 1725 va_start(va, format); |
128 | 1726 result=vsprintf(string, format, va); |
1727 dbgprintf("wsprintfA(0x%x, '%s', ...) => %d\n", string, format, result); | |
1728 va_end(va); | |
1729 return result; | |
1 | 1730 } |
1731 | |
1732 int WINAPI expGetPrivateProfileIntA(const char* appname, const char* keyname, int default_value, const char* filename) | |
1733 { | |
1734 int size=255; | |
1735 char buffer[256]; | |
1736 char* fullname; | |
1737 int result; | |
1738 | |
1739 buffer[255]=0; | |
128 | 1740 if(!(appname && keyname && filename) ) |
1741 { | |
1742 dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %d\n", appname, keyname, default_value, filename, default_value ); | |
1743 return default_value; | |
1744 } | |
1 | 1745 fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename)); |
1746 strcpy(fullname, "Software\\IniFileMapping\\"); | |
1747 strcat(fullname, appname); | |
1748 strcat(fullname, "\\"); | |
1749 strcat(fullname, keyname); | |
1750 strcat(fullname, "\\"); | |
1751 strcat(fullname, filename); | |
1752 result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)buffer, &size); | |
1753 if((size>=0)&&(size<256)) | |
1754 buffer[size]=0; | |
1755 // printf("GetPrivateProfileIntA(%s, %s, %s) -> %s\n", appname, keyname, filename, buffer); | |
1756 free(fullname); | |
1757 if(result) | |
128 | 1758 result=default_value; |
1 | 1759 else |
128 | 1760 result=atoi(buffer); |
1761 dbgprintf("GetPrivateProfileIntA('%s', '%s', %d, '%s') => %d\n", appname, keyname, default_value, filename, result); | |
1762 return result; | |
1 | 1763 } |
128 | 1764 int WINAPI expGetProfileIntA(const char* appname, const char* keyname, int default_value) |
1765 { | |
1766 dbgprintf("GetProfileIntA -> "); | |
1767 // dbgprintf("GetProfileIntA(%s, %s, %d)\n", appname, keyname, default_value); | |
1768 return expGetPrivateProfileIntA(appname, keyname, default_value, "default"); | |
1769 } | |
1770 | |
1 | 1771 int WINAPI expGetPrivateProfileStringA(const char* appname, const char* keyname, |
1772 const char* def_val, char* dest, unsigned int len, const char* filename) | |
1773 { | |
1774 int result; | |
1775 int size; | |
1776 char* fullname; | |
128 | 1777 dbgprintf("GetPrivateProfileStringA('%s', '%s', def_val '%s', 0x%x, 0x%x, '%s')", appname, keyname, def_val, dest, len, filename ); |
1 | 1778 if(!(appname && keyname && filename) ) return 0; |
1779 fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename)); | |
1780 strcpy(fullname, "Software\\IniFileMapping\\"); | |
1781 strcat(fullname, appname); | |
1782 strcat(fullname, "\\"); | |
1783 strcat(fullname, keyname); | |
1784 strcat(fullname, "\\"); | |
1785 strcat(fullname, filename); | |
1786 size=len; | |
1787 result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)dest, &size); | |
1788 // printf("GetPrivateProfileStringA(%s, %s, %s, %X, %X, %s)\n", appname, keyname, def_val, dest, len, filename ); | |
1789 free(fullname); | |
128 | 1790 if(result) |
1791 { | |
1792 strncpy(dest, def_val, size); | |
1793 if (strlen(def_val)< size) size = strlen(def_val); | |
1794 } | |
1795 dbgprintf(" => %d ( '%s' )\n", size, dest); | |
1 | 1796 return size; |
1797 } | |
1798 int WINAPI expWritePrivateProfileStringA(const char* appname, const char* keyname, | |
1799 const char* string, const char* filename) | |
1800 { | |
1801 int size=256; | |
1802 char* fullname; | |
128 | 1803 dbgprintf("WritePrivateProfileStringA('%s', '%s', '%s', '%s')", appname, keyname, string, filename ); |
1804 if(!(appname && keyname && filename) ) | |
1805 { | |
1806 dbgprintf(" => -1\n"); | |
1807 return -1; | |
1808 } | |
1 | 1809 fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename)); |
1810 strcpy(fullname, "Software\\IniFileMapping\\"); | |
1811 strcat(fullname, appname); | |
1812 strcat(fullname, "\\"); | |
1813 strcat(fullname, keyname); | |
1814 strcat(fullname, "\\"); | |
1815 strcat(fullname, filename); | |
1816 RegSetValueExA(HKEY_LOCAL_MACHINE, fullname, 0, REG_SZ, (int*)string, strlen(string)); | |
1817 // printf("RegSetValueExA(%s,%d)\n", string, strlen(string)); | |
1818 // printf("WritePrivateProfileStringA(%s, %s, %s, %s)\n", appname, keyname, string, filename ); | |
1819 free(fullname); | |
128 | 1820 dbgprintf(" => 0\n"); |
1 | 1821 return 0; |
1822 } | |
1823 | |
1824 unsigned int _GetPrivateProfileIntA(const char* appname, const char* keyname, INT default_value, const char* filename) | |
1825 { | |
1826 return expGetPrivateProfileIntA(appname, keyname, default_value, filename); | |
1827 } | |
1828 int _GetPrivateProfileStringA(const char* appname, const char* keyname, | |
1829 const char* def_val, char* dest, unsigned int len, const char* filename) | |
1830 { | |
1831 return expGetPrivateProfileStringA(appname, keyname, def_val, dest, len, filename); | |
1832 } | |
1833 int _WritePrivateProfileStringA(const char* appname, const char* keyname, | |
1834 const char* string, const char* filename) | |
1835 { | |
1836 return expWritePrivateProfileStringA(appname, keyname, string, filename); | |
1837 } | |
1838 | |
1839 | |
128 | 1840 |
1 | 1841 int WINAPI expDefDriverProc(int _private, int id, int msg, int arg1, int arg2) |
1842 { | |
128 | 1843 dbgprintf("DefDriverProc(0x%x, 0x%x, 0x%x, 0x%x, 0x%x) => 0\n", _private, id, msg, arg1, arg2); |
1 | 1844 return 0; |
1845 } | |
1846 | |
1847 int WINAPI expSizeofResource(int v1, int v2) | |
1848 { | |
128 | 1849 int result=SizeofResource(v1, v2); |
1850 dbgprintf("SizeofResource(0x%x, 0x%x) => %d\n", v1, v2, result); | |
1851 return result; | |
1 | 1852 } |
1853 | |
1854 int WINAPI expGetLastError() | |
1855 { | |
128 | 1856 int result=GetLastError(); |
1857 dbgprintf("GetLastError() => 0x%x\n", result); | |
1858 return result; | |
1 | 1859 } |
1860 | |
1861 void WINAPI expSetLastError(int error) | |
1862 { | |
128 | 1863 dbgprintf("SetLastError(0x%x)\n", error); |
1 | 1864 SetLastError(error); |
1865 } | |
1866 | |
1867 char* expstrrchr(char* string, int value) | |
1868 { | |
128 | 1869 char* result=strrchr(string, value); |
1870 if(result) | |
1871 dbgprintf("strrchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result); | |
1872 else | |
1873 dbgprintf("strrchr(0x%x='%s', %d) => 0", string, string, value); | |
1874 return result; | |
1 | 1875 } |
1876 | |
1877 char* expstrchr(char* string, int value) | |
1878 { | |
128 | 1879 char* result=strchr(string, value); |
1880 if(result) | |
1881 dbgprintf("strchr(0x%x='%s', %d) => 0x%x='%s'", string, string, value, result, result); | |
1882 else | |
1883 dbgprintf("strchr(0x%x='%s', %d) => 0", string, string, value); | |
1884 return result; | |
1 | 1885 } |
128 | 1886 int expstrlen(char* str) |
1887 { | |
1888 int result=strlen(str); | |
1889 dbgprintf("strlen(0x%x='%s') => %d\n", str, str, result); | |
1890 return result; | |
1891 } | |
713 | 1892 int expstrcpy(char* str1, const char* str2) |
128 | 1893 { |
713 | 1894 int result= (int) strcpy(str1, str2); |
1895 dbgprintf("strcpy(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result); | |
128 | 1896 return result; |
1897 } | |
1898 int expstrcmp(const char* str1, const char* str2) | |
1899 { | |
1900 int result=strcmp(str1, str2); | |
1901 dbgprintf("strcmp(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result); | |
1902 return result; | |
1903 } | |
713 | 1904 int expstrcat(char* str1, const char* str2) |
128 | 1905 { |
713 | 1906 int result= (int) strcat(str1, str2); |
1907 dbgprintf("strcat(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result); | |
128 | 1908 return result; |
1909 } | |
713 | 1910 int expisalnum(int c) |
128 | 1911 { |
713 | 1912 int result= (int) isalnum(c); |
1913 dbgprintf("isalnum(0x%x='%c' => %d\n", c, c, result); | |
1914 return result; | |
1915 } | |
1916 int expmemmove(void* dest, void* src, int n) | |
1917 { | |
1918 int result= (int) memmove(dest, src, n); | |
1919 dbgprintf("memmove(0x%x, 0x%x, %d) => %d\n", dest, src, n, result); | |
1920 return result; | |
128 | 1921 } |
1922 int expmemcmp(void* dest, void* src, int n) | |
1923 { | |
1924 int result=memcmp(dest, src, n); | |
1925 dbgprintf("memcmp(0x%x, 0x%x, %d) => %d\n", dest, src, n, result); | |
1926 return result; | |
1927 } | |
597 | 1928 void *expmemcpy(void* dest, void* src, int n) |
130 | 1929 { |
597 | 1930 void *result=memcpy(dest, src, n); |
1931 dbgprintf("memcpy(0x%x, 0x%x, %d) => %p\n", dest, src, n, result); | |
130 | 1932 return result; |
1933 } | |
128 | 1934 time_t exptime(time_t* t) |
1935 { | |
1936 time_t result=time(t); | |
1937 dbgprintf("time(0x%x) => %d\n", t, result); | |
1938 return result; | |
1939 } | |
1940 | |
1941 int WINAPI expStringFromGUID2(GUID* guid, char* str, int cbMax) | |
1942 { | |
597 | 1943 int result=snprintf(str, cbMax, "%.8lx-%.4x-%.4x-%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", |
128 | 1944 guid->f1, guid->f2, guid->f3, |
1945 (unsigned char)guid->f4[0], (unsigned char)guid->f4[1], (unsigned char)guid->f4[2], (unsigned char)guid->f4[3], | |
1946 (unsigned char)guid->f4[4], (unsigned char)guid->f4[5], (unsigned char)guid->f4[6], (unsigned char)guid->f4[7]); | |
1947 dbgprintf("StringFromGUID2(0x%x, 0x%x='%s', %d) => %d\n", guid, str, str, cbMax, result); | |
1948 return result; | |
1949 } | |
1950 | |
1 | 1951 |
1952 int WINAPI expGetFileVersionInfoSizeA(const char* name, int* lpHandle) | |
1953 { | |
128 | 1954 dbgprintf("GetFileVersionInfoSizeA(0x%x='%s', 0x%X) => 0\n", name, name, lpHandle); |
1 | 1955 return 0; |
1956 } | |
1957 | |
1958 int WINAPI expIsBadStringPtrW(const short* string, int nchars) | |
1959 { | |
128 | 1960 int result; |
1961 if(string==0)result=1; else result=0; | |
1962 dbgprintf("IsBadStringPtrW(0x%x, %d) => %d", string, nchars, result); | |
1963 if(string)wch_print(string); | |
1964 return result; | |
1 | 1965 } |
713 | 1966 |
1967 int WINAPI expIsBadStringPtrA(const char* string, int nchars) | |
1968 { | |
1969 int result; | |
1970 // if(string==0)result=1; else result=0; | |
1971 // dbgprintf("IsBadStringPtrW(0x%x, %d) => %d", string, nchars, result); | |
1972 // if(string)wch_print(string); | |
1973 return result; | |
1974 } | |
1975 | |
1 | 1976 extern long WINAPI InterlockedExchangeAdd( long* dest, long incr ) |
1977 { | |
1978 long ret; | |
1979 __asm__ __volatile__( "lock; xaddl %0,(%1)" | |
1980 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" ); | |
1981 return ret; | |
1982 } | |
1983 | |
1984 extern long WINAPI expInterlockedIncrement( long* dest ) | |
1985 { | |
128 | 1986 long result=InterlockedExchangeAdd( dest, 1 ) + 1; |
1987 dbgprintf("InterlockedIncrement(0x%x => %d) => %d\n", dest, *dest, result); | |
1988 return result; | |
1 | 1989 } |
1990 extern long WINAPI expInterlockedDecrement( long* dest ) | |
1991 { | |
128 | 1992 long result=InterlockedExchangeAdd( dest, -1 ) - 1; |
1993 dbgprintf("InterlockedDecrement(0x%x => %d) => %d\n", dest, *dest, result); | |
1994 return result; | |
1 | 1995 } |
1996 | |
1997 extern void WINAPI expOutputDebugStringA( const char* string ) | |
1998 { | |
128 | 1999 dbgprintf("OutputDebugStringA(0x%x='%s')\n", string); |
1 | 2000 fprintf(stderr, "DEBUG: %s\n", string); |
2001 } | |
2002 | |
2003 int WINAPI expGetDC(int hwnd) | |
2004 { | |
128 | 2005 dbgprintf("GetDC(0x%x) => 0\n", hwnd); |
1 | 2006 return 0; |
2007 } | |
2008 | |
2009 int WINAPI expGetDesktopWindow() | |
2010 { | |
128 | 2011 dbgprintf("GetDesktopWindow() => 0\n"); |
1 | 2012 return 0; |
2013 } | |
2014 | |
2015 int WINAPI expReleaseDC(int hwnd, int hdc) | |
2016 { | |
128 | 2017 dbgprintf("ReleaseDC(0x%x, 0x%x) => 0\n", hwnd, hdc); |
2018 return 0; | |
2019 } | |
2020 static int cursor[100]; | |
2021 | |
2022 int WINAPI expLoadCursorA(int handle,LPCSTR name) | |
2023 { | |
2024 dbgprintf("LoadCursorA(%d, 0x%x='%s') => 0x%x\n", handle, name, (int)&cursor[0]); | |
2025 return (int)&cursor[0]; | |
2026 } | |
2027 int WINAPI expSetCursor(void *cursor) | |
2028 { | |
2029 dbgprintf("SetCursor(0x%x) => 0x%x\n", cursor, cursor); | |
2030 return (int)cursor; | |
2031 } | |
2032 int WINAPI expGetSystemPaletteEntries(int hdc, int iStartIndex, int nEntries, void* lppe) | |
2033 { | |
2034 dbgprintf("GetSystemPaletteEntries(0x%x, 0x%x, 0x%x, 0x%x) => 0\n", | |
2035 hdc, iStartIndex, nEntries, lppe); | |
1 | 2036 return 0; |
2037 } | |
2038 | |
2039 /* | |
2040 typedef struct _TIME_ZONE_INFORMATION { | |
2041 long Bias; | |
2042 char StandardName[32]; | |
2043 SYSTEMTIME StandardDate; | |
2044 long StandardBias; | |
2045 char DaylightName[32]; | |
2046 SYSTEMTIME DaylightDate; | |
2047 long DaylightBias; | |
2048 } TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION; | |
2049 */ | |
2050 | |
2051 int WINAPI expGetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation) | |
2052 { | |
128 | 2053 const short name[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'S', 't', 'a', |
2054 'n', 'd', 'a', 'r', 'd', ' ', 'T', 'i', 'm', 'e', 0}; | |
2055 const short pname[]={'C', 'e', 'n', 't', 'r', 'a', 'l', ' ', 'D', 'a', 'y', | |
2056 'l', 'i', 'g', 'h', 't', ' ', 'T', 'i', 'm', 'e', 0}; | |
2057 dbgprintf("GetTimeZoneInformation(0x%x) => TIME_ZONE_ID_STANDARD\n"); | |
1 | 2058 memset(lpTimeZoneInformation, 0, sizeof(TIME_ZONE_INFORMATION)); |
128 | 2059 lpTimeZoneInformation->Bias=360;//GMT-6 |
2060 memcpy(lpTimeZoneInformation->StandardName, name, sizeof(name)); | |
2061 lpTimeZoneInformation->StandardDate.wMonth=10; | |
2062 lpTimeZoneInformation->StandardDate.wDay=5; | |
2063 lpTimeZoneInformation->StandardDate.wHour=2; | |
2064 lpTimeZoneInformation->StandardBias=0; | |
2065 memcpy(lpTimeZoneInformation->DaylightName, pname, sizeof(pname)); | |
2066 lpTimeZoneInformation->DaylightDate.wMonth=4; | |
2067 lpTimeZoneInformation->DaylightDate.wDay=1; | |
2068 lpTimeZoneInformation->DaylightDate.wHour=2; | |
2069 lpTimeZoneInformation->DaylightBias=-60; | |
2070 return TIME_ZONE_ID_STANDARD; | |
1 | 2071 } |
2072 | |
2073 void WINAPI expGetLocalTime(SYSTEMTIME* systime) | |
2074 { | |
2075 time_t local_time; | |
2076 struct tm *local_tm; | |
2077 struct timeval tv; | |
2078 | |
128 | 2079 dbgprintf("GetLocalTime(0x%x)\n"); |
1 | 2080 gettimeofday(&tv, NULL); |
2081 local_time=tv.tv_sec; | |
2082 local_tm=localtime(&local_time); | |
2083 | |
2084 systime->wYear = local_tm->tm_year + 1900; | |
2085 systime->wMonth = local_tm->tm_mon + 1; | |
2086 systime->wDayOfWeek = local_tm->tm_wday; | |
2087 systime->wDay = local_tm->tm_mday; | |
2088 systime->wHour = local_tm->tm_hour; | |
2089 systime->wMinute = local_tm->tm_min; | |
2090 systime->wSecond = local_tm->tm_sec; | |
2091 systime->wMilliseconds = (tv.tv_usec / 1000) % 1000; | |
128 | 2092 dbgprintf(" Year: %d\n Month: %d\n Day of week: %d\n" |
2093 " Day: %d\n Hour: %d\n Minute: %d\n Second: %d\n" | |
2094 " Milliseconds: %d\n", | |
2095 systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay, | |
2096 systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds); | |
1 | 2097 } |
2098 | |
2099 int WINAPI expGetSystemTime(SYSTEMTIME* systime) | |
2100 { | |
2101 time_t local_time; | |
2102 struct tm *local_tm; | |
2103 struct timeval tv; | |
2104 | |
128 | 2105 dbgprintf("GetSystemTime(0x%x)\n", systime); |
1 | 2106 gettimeofday(&tv, NULL); |
2107 local_time=tv.tv_sec; | |
2108 local_tm=gmtime(&local_time); | |
2109 | |
2110 systime->wYear = local_tm->tm_year + 1900; | |
2111 systime->wMonth = local_tm->tm_mon + 1; | |
2112 systime->wDayOfWeek = local_tm->tm_wday; | |
2113 systime->wDay = local_tm->tm_mday; | |
2114 systime->wHour = local_tm->tm_hour; | |
2115 systime->wMinute = local_tm->tm_min; | |
2116 systime->wSecond = local_tm->tm_sec; | |
2117 systime->wMilliseconds = (tv.tv_usec / 1000) % 1000; | |
128 | 2118 dbgprintf(" Year: %d\n Month: %d\n Day of week: %d\n" |
2119 " Day: %d\n Hour: %d\n Minute: %d\n Second: %d\n" | |
2120 " Milliseconds: %d\n", | |
2121 systime->wYear, systime->wMonth, systime->wDayOfWeek, systime->wDay, | |
2122 systime->wHour, systime->wMinute, systime->wSecond, systime->wMilliseconds); | |
1 | 2123 } |
2124 | |
2125 int WINAPI expGetEnvironmentVariableA(const char* name, char* field, int size) | |
2126 { | |
128 | 2127 char *p; |
2128 // printf("%s %x %x\n", name, field, size); | |
1 | 2129 if(field)field[0]=0; |
128 | 2130 /* |
2131 p = getenv(name); | |
2132 if (p) strncpy(field,p,size); | |
2133 */ | |
2134 if (strcmp(name,"__MSVCRT_HEAP_SELECT")==0) | |
2135 strcpy(field,"__GLOBAL_HEAP_SELECTED,1"); | |
2136 dbgprintf("GetEnvironmentVariableA(0x%x='%s', 0x%x, %d) => %d\n", name, name, field, size, strlen(field)); | |
2137 return strlen(field); | |
2138 } | |
2139 | |
2140 void* WINAPI expCoTaskMemAlloc(ULONG cb) | |
2141 { | |
2142 return my_mreq(cb, 0); | |
2143 } | |
2144 void WINAPI expCoTaskMemFree(void* cb) | |
2145 { | |
2146 my_release(cb); | |
2147 } | |
2148 | |
2149 void* CoTaskMemAlloc(ULONG cb){return expCoTaskMemAlloc(cb);} | |
2150 void CoTaskMemFree(void* cb){expCoTaskMemFree(cb);} | |
2151 | |
2152 struct COM_OBJECT_INFO | |
2153 { | |
2154 GUID clsid; | |
2155 long (*GetClassObject) (GUID* clsid, GUID* iid, void** ppv); | |
2156 }; | |
2157 | |
2158 static struct COM_OBJECT_INFO* com_object_table=0; | |
2159 static int com_object_size=0; | |
2160 int RegisterComClass(GUID* clsid, GETCLASSOBJECT gcs) | |
2161 { | |
2162 if(!clsid)return -1; | |
2163 if(!gcs)return -1; | |
2164 com_object_table=realloc(com_object_table, sizeof(struct COM_OBJECT_INFO)*(++com_object_size)); | |
2165 com_object_table[com_object_size-1].clsid=*clsid; | |
2166 com_object_table[com_object_size-1].GetClassObject=gcs; | |
2167 return 0; | |
2168 } | |
2169 | |
2170 GUID IID_IUnknown={0x00000000, 0x0000, 0x0000, | |
2171 {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; | |
2172 GUID IID_IClassFactory={0x00000001, 0x0000, 0x0000, | |
2173 {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; | |
2174 | |
2175 long WINAPI expCoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter, | |
2176 long dwClsContext, GUID* riid, void** ppv) | |
2177 { | |
2178 int i; | |
2179 struct COM_OBJECT_INFO* ci=0; | |
2180 for(i=0; i<com_object_size; i++) | |
2181 if(!memcmp(rclsid, &com_object_table[i].clsid, sizeof(GUID))) | |
2182 ci=&com_object_table[i]; | |
2183 if(!ci)return 0x80040154; | |
2184 // in 'real' world we should mess with IClassFactory here | |
2185 i=ci->GetClassObject(rclsid, riid, ppv); | |
2186 return i; | |
2187 } | |
2188 | |
2189 long CoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter, | |
2190 long dwClsContext, GUID* riid, void** ppv) | |
2191 { | |
2192 return expCoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv); | |
2193 } | |
2194 | |
2195 int WINAPI | |
2196 expIsRectEmpty( | |
2197 CONST RECT *lprc) | |
2198 { | |
2199 dbgprintf("IsRectEmpty(0x%x)"); | |
2200 if((!lprc) || (lprc->right==lprc->left) || (lprc->top==lprc->bottom)) | |
2201 { | |
2202 dbgprintf(" => TRUE\n"); | |
2203 return TRUE; | |
2204 } | |
2205 dbgprintf(" => FALSE\n"); | |
2206 return FALSE; | |
2207 } | |
2208 | |
2209 int _adjust_fdiv=0; //what's this? | |
2210 | |
2211 | |
2212 | |
2213 | |
2214 unsigned int WINAPI expGetTempPathA(unsigned int len, char* path) | |
2215 { | |
2216 dbgprintf("GetTempPathA(%d, 0x%x)", len, path); | |
2217 if(len<5) | |
2218 { | |
2219 dbgprintf(" => 0\n"); | |
2220 return 0; | |
2221 } | |
2222 strcpy(path, "/tmp"); | |
2223 dbgprintf(" => 5 ( '/tmp' )\n"); | |
2224 return 5; | |
2225 } | |
2226 /* | |
2227 FYI: | |
2228 typedef struct | |
2229 { | |
2230 DWORD dwFileAttributes; | |
2231 FILETIME ftCreationTime; | |
2232 FILETIME ftLastAccessTime; | |
2233 FILETIME ftLastWriteTime; | |
2234 DWORD nFileSizeHigh; | |
2235 DWORD nFileSizeLow; | |
2236 DWORD dwReserved0; | |
2237 DWORD dwReserved1; | |
2238 CHAR cFileName[260]; | |
2239 CHAR cAlternateFileName[14]; | |
2240 } WIN32_FIND_DATAA, *LPWIN32_FIND_DATAA; | |
2241 */ | |
2242 | |
2243 HANDLE WINAPI expFindFirstFileA(LPCSTR s, LPWIN32_FIND_DATAA lpfd) | |
2244 { | |
2245 dbgprintf("FindFirstFileA(0x%x='%s', 0x%x) => 0\n", s, s, lpfd); | |
2246 strcpy(lpfd->cFileName, "msms001.vwp"); | |
2247 strcpy(lpfd->cAlternateFileName, "msms001.vwp"); | |
2248 return (HANDLE)0; | |
2249 } | |
2250 WIN_BOOL WINAPI expFindNextFileA(HANDLE h,LPWIN32_FIND_DATAA p) | |
2251 { | |
2252 dbgprintf("FindNextFileA(0x%x, 0x%x) => 0\n", h, p); | |
1 | 2253 return 0; |
2254 } | |
128 | 2255 WIN_BOOL WINAPI expFindClose(HANDLE h) |
2256 { | |
2257 dbgprintf("FindClose(0x%x) => 0\n", h); | |
2258 return 0; | |
2259 } | |
2260 UINT WINAPI expSetErrorMode(UINT i) | |
2261 { | |
2262 dbgprintf("SetErrorMode(%d) => 0\n", i); | |
2263 return 0; | |
2264 } | |
2265 UINT WINAPI expGetWindowsDirectoryA(LPSTR s,UINT c) | |
2266 { | |
2267 char windir[]="c:\\windows"; | |
2268 int result; | |
2269 strncpy(s, windir, c); | |
2270 result=1+((c<strlen(windir))?c:strlen(windir)); | |
2271 dbgprintf("GetWindowsDirectoryA(0x%x, %d) => %d\n", s, c, result); | |
2272 return result; | |
2273 } | |
2274 | |
2275 WIN_BOOL WINAPI expDeleteFileA(LPCSTR s) | |
2276 { | |
2277 dbgprintf("DeleteFileA(0x%x='%s') => 0\n", s, s); | |
2278 return 0; | |
2279 } | |
2280 WIN_BOOL WINAPI expFileTimeToLocalFileTime(const FILETIME* cpf, LPFILETIME pf) | |
2281 { | |
2282 dbgprintf("FileTimeToLocalFileTime(0x%x, 0x%x) => 0\n", cpf, pf); | |
2283 return 0; | |
2284 } | |
2285 | |
2286 UINT WINAPI expGetTempFileNameA(LPCSTR cs1,LPCSTR cs2,UINT i,LPSTR ps) | |
2287 { | |
2288 char mask[16]="/tmp/AP_XXXXXX"; | |
2289 int result; | |
2290 dbgprintf("GetTempFileNameA(0x%x='%s', 0x%x='%s', %d, 0x%x)", cs1, cs1, cs2, cs2, i, ps); | |
2291 if(i && i<10) | |
2292 { | |
2293 dbgprintf(" => -1\n"); | |
2294 return -1; | |
2295 } | |
2296 result=mkstemp(mask); | |
2297 sprintf(ps, "AP%d", result); | |
2298 dbgprintf(" => %d\n", strlen(ps)); | |
2299 return strlen(ps); | |
2300 } | |
2301 // | |
2302 // This func might need proper implementation if we want AngelPotion codec. | |
2303 // They try to open APmpeg4v1.apl with it. | |
2304 // DLL will close opened file with CloseHandle(). | |
2305 // | |
2306 HANDLE WINAPI expCreateFileA(LPCSTR cs1,DWORD i1,DWORD i2, | |
2307 LPSECURITY_ATTRIBUTES p1, DWORD i3,DWORD i4,HANDLE i5) | |
2308 { | |
2309 dbgprintf("CreateFileA(0x%x='%s', %d, %d, 0x%x, %d, %d, 0x%x)\n", cs1, cs1, i1, | |
2310 i2, p1, i3, i4, i5); | |
2311 if((!cs1) || (strlen(cs1)<2))return -1; | |
2312 if(strncmp(cs1, "AP", 2)) | |
2313 { | |
2314 int result; | |
2315 char* tmp=(char*)malloc(strlen(def_path)+50); | |
2316 strcpy(tmp, def_path); | |
2317 strcat(tmp, "/"); | |
2318 strcat(tmp, "APmpg4v1.apl"); | |
2319 result=open(tmp, O_RDONLY); | |
2320 free(tmp); | |
2321 return result; | |
2322 }; | |
2323 return atoi(cs1+2); | |
2324 } | |
2325 static char sysdir[]="."; | |
2326 LPCSTR WINAPI expGetSystemDirectoryA() | |
2327 { | |
2328 dbgprintf("GetSystemDirectoryA() => 0x%x='%s'\n", sysdir, sysdir); | |
2329 return sysdir; | |
2330 } | |
2331 WIN_BOOL WINAPI expReadFile(HANDLE h,LPVOID pv,DWORD size,LPDWORD rd,LPOVERLAPPED unused) | |
2332 { | |
2333 int result; | |
2334 dbgprintf("ReadFile(%d, 0x%x, %d -> 0x%x)\n", h, pv, size, rd); | |
2335 result=read(h, pv, size); | |
2336 if(rd)*rd=result; | |
2337 if(!result)return 0; | |
2338 return 1; | |
2339 } | |
2340 | |
2341 WIN_BOOL WINAPI expWriteFile(HANDLE h,LPCVOID pv,DWORD size,LPDWORD wr,LPOVERLAPPED unused) | |
2342 { | |
2343 int result; | |
2344 dbgprintf("WriteFile(%d, 0x%x, %d -> 0x%x)\n", h, pv, size, wr); | |
2345 if(h==1234)h=1; | |
2346 result=write(h, pv, size); | |
2347 if(wr)*wr=result; | |
2348 if(!result)return 0; | |
2349 return 1; | |
2350 } | |
2351 DWORD WINAPI expSetFilePointer(HANDLE h, LONG val, LPLONG ext, DWORD whence) | |
2352 { | |
2353 int wh; | |
2354 dbgprintf("SetFilePointer(%d, %d, 0x%x, %d)\n", h, val, ext, whence); | |
2355 //why would DLL want temporary file with >2Gb size? | |
2356 switch(whence) | |
2357 { | |
2358 case FILE_BEGIN: | |
2359 wh=SEEK_SET;break; | |
2360 case FILE_END: | |
2361 wh=SEEK_END;break; | |
2362 case FILE_CURRENT: | |
2363 wh=SEEK_CUR;break; | |
2364 default: | |
2365 return -1; | |
2366 } | |
2367 return lseek(h, val, wh); | |
2368 } | |
2369 | |
2370 HDRVR WINAPI expOpenDriverA(LPCSTR szDriverName, LPCSTR szSectionName, | |
2371 LPARAM lParam2) | |
2372 { | |
2373 dbgprintf("OpenDriverA(0x%x='%s', 0x%x='%s', 0x%x) => -1\n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2); | |
2374 return -1; | |
2375 } | |
2376 HDRVR WINAPI expOpenDriver(LPCSTR szDriverName, LPCSTR szSectionName, | |
2377 LPARAM lParam2) | |
2378 { | |
2379 dbgprintf("OpenDriver(0x%x='%s', 0x%x='%s', 0x%x) => -1\n", szDriverName, szDriverName, szSectionName, szSectionName, lParam2); | |
2380 return -1; | |
2381 } | |
1 | 2382 |
2383 | |
128 | 2384 WIN_BOOL |
2385 WINAPI | |
2386 expGetProcessAffinityMask( | |
2387 HANDLE hProcess, | |
2388 LPDWORD lpProcessAffinityMask, | |
2389 LPDWORD lpSystemAffinityMask | |
2390 ) | |
2391 { | |
2392 dbgprintf("GetProcessAffinityMask(0x%x, 0x%x, 0x%x) => 1\n", | |
2393 hProcess, lpProcessAffinityMask, lpSystemAffinityMask); | |
2394 if(lpProcessAffinityMask)*lpProcessAffinityMask=1; | |
2395 if(lpSystemAffinityMask)*lpSystemAffinityMask=1; | |
2396 return 1; | |
1 | 2397 } |
2398 | |
2399 | |
295
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2400 /****************************************************************************** |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2401 * RegEnumValueA [ADVAPI32.@] |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2402 */ |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2403 DWORD WINAPI expRegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2404 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count ) |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2405 { |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2406 |
340 | 2407 // printf("RegEnumValueA(%x,%ld,%p,%p,%p,%p,%p,%p)\n", |
2408 // hkey, index, value, val_count, reserved, type, data, count ); | |
128 | 2409 |
295
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2410 return -1; |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2411 } |
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2412 |
128 | 2413 |
713 | 2414 #if 0 |
2415 INT WINAPI expMulDiv(int nNumber,int nNumerator,int nDenominator) | |
2416 { | |
2417 return ((long long)nNumber * (long long)nNumerator) / nDenominator; | |
2418 } | |
2419 #endif | |
2420 | |
2421 int WINAPI expMulDiv(int nNumber, int nNumerator, int nDenominator) | |
2422 { | |
2423 static const long long max_int=0x7FFFFFFFLL; | |
2424 static const long long min_int=-0x80000000LL; | |
2425 long long tmp=(long long)nNumber*(long long)nNumerator; | |
2426 if(!nDenominator)return 1; | |
2427 tmp/=nDenominator; | |
2428 if(tmp<min_int) return 1; | |
2429 if(tmp>max_int) return 1; | |
2430 return (int)tmp; | |
2431 } | |
2432 | |
2433 LONG WINAPI explstrcmpiA(const char* str1, const char* str2) | |
2434 { | |
2435 LONG result=strcasecmp(str1, str2); | |
2436 dbgprintf("strcmpi(0x%x='%s', 0x%x='%s') => %d\n", str1, str1, str2, str2, result); | |
2437 return result; | |
2438 } | |
2439 | |
2440 LONG WINAPI explstrlenA(const char* str1) | |
2441 { | |
2442 LONG result=strlen(str1); | |
2443 dbgprintf("strlen(0x%x='%s') => %d\n", str1, str1, result); | |
2444 return result; | |
2445 } | |
2446 | |
2447 LONG WINAPI explstrcpyA(char* str1, const char* str2) | |
2448 { | |
2449 int result= (int) strcpy(str1, str2); | |
2450 dbgprintf("strcpy(0x%x, 0x%x='%s') => %d\n", str1, str2, str2, result); | |
2451 return result; | |
2452 } | |
128 | 2453 |
497 | 2454 LONG WINAPI expInterlockedExchange(long *dest, long l) |
2455 { | |
2456 long retval; | |
2457 retval = *dest; | |
2458 *dest = l; | |
2459 return retval; | |
2460 } | |
2461 | |
1 | 2462 struct exports |
2463 { | |
2464 char name[64]; | |
2465 int id; | |
2466 void* func; | |
2467 }; | |
2468 struct libs | |
2469 { | |
2470 char name[64]; | |
2471 int length; | |
2472 struct exports* exps; | |
2473 }; | |
2474 | |
2475 #define FF(X,Y) \ | |
2476 {#X, Y, (void*)exp##X}, | |
2477 | |
2478 struct exports exp_kernel32[]={ | |
2479 FF(IsBadWritePtr, 357) | |
2480 FF(IsBadReadPtr, 354) | |
2481 FF(IsBadStringPtrW, -1) | |
713 | 2482 FF(IsBadStringPtrA, -1) |
1 | 2483 FF(DisableThreadLibraryCalls, -1) |
2484 FF(CreateThread, -1) | |
2485 FF(CreateEventA, -1) | |
2486 FF(SetEvent, -1) | |
2487 FF(ResetEvent, -1) | |
2488 FF(WaitForSingleObject, -1) | |
2489 FF(GetSystemInfo, -1) | |
2490 FF(GetVersion, 332) | |
2491 FF(HeapCreate, 461) | |
2492 FF(HeapAlloc, -1) | |
2493 FF(HeapDestroy, -1) | |
2494 FF(HeapFree, -1) | |
2495 FF(HeapSize, -1) | |
2496 FF(GetProcessHeap, -1) | |
2497 FF(VirtualAlloc, -1) | |
2498 FF(VirtualFree, -1) | |
2499 FF(InitializeCriticalSection, -1) | |
2500 FF(EnterCriticalSection, -1) | |
2501 FF(LeaveCriticalSection, -1) | |
2502 FF(DeleteCriticalSection, -1) | |
2503 FF(TlsAlloc, -1) | |
2504 FF(TlsFree, -1) | |
2505 FF(TlsGetValue, -1) | |
2506 FF(TlsSetValue, -1) | |
2507 FF(GetCurrentThreadId, -1) | |
128 | 2508 FF(GetCurrentProcess, -1) |
1 | 2509 FF(LocalAlloc, -1) |
2510 FF(LocalLock, -1) | |
2511 FF(GlobalAlloc, -1) | |
128 | 2512 FF(GlobalReAlloc, -1) |
1 | 2513 FF(GlobalLock, -1) |
2514 FF(MultiByteToWideChar, 427) | |
2515 FF(WideCharToMultiByte, -1) | |
2516 FF(GetVersionExA, -1) | |
2517 FF(CreateSemaphoreA, -1) | |
2518 FF(QueryPerformanceCounter, -1) | |
2519 FF(QueryPerformanceFrequency, -1) | |
2520 FF(LocalHandle, -1) | |
2521 FF(LocalUnlock, -1) | |
2522 FF(LocalFree, -1) | |
2523 FF(GlobalHandle, -1) | |
2524 FF(GlobalUnlock, -1) | |
2525 FF(GlobalFree, -1) | |
2526 FF(LoadResource, -1) | |
2527 FF(ReleaseSemaphore, -1) | |
2528 FF(FindResourceA, -1) | |
2529 FF(LockResource, -1) | |
2530 FF(FreeResource, -1) | |
2531 FF(SizeofResource, -1) | |
2532 FF(CloseHandle, -1) | |
2533 FF(GetCommandLineA, -1) | |
2534 FF(GetEnvironmentStringsW, -1) | |
2535 FF(FreeEnvironmentStringsW, -1) | |
128 | 2536 FF(FreeEnvironmentStringsA, -1) |
1 | 2537 FF(GetEnvironmentStrings, -1) |
2538 FF(GetStartupInfoA, -1) | |
2539 FF(GetStdHandle, -1) | |
2540 FF(GetFileType, -1) | |
2541 FF(SetHandleCount, -1) | |
2542 FF(GetACP, -1) | |
2543 FF(GetModuleFileNameA, -1) | |
2544 FF(SetUnhandledExceptionFilter, -1) | |
2545 FF(LoadLibraryA, -1) | |
2546 FF(GetProcAddress, -1) | |
2547 FF(FreeLibrary, -1) | |
2548 FF(CreateFileMappingA, -1) | |
2549 FF(OpenFileMappingA, -1) | |
2550 FF(MapViewOfFile, -1) | |
2551 FF(UnmapViewOfFile, -1) | |
2552 FF(Sleep, -1) | |
2553 FF(GetModuleHandleA, -1) | |
128 | 2554 FF(GetProfileIntA, -1) |
1 | 2555 FF(GetPrivateProfileIntA, -1) |
2556 FF(GetPrivateProfileStringA, -1) | |
2557 FF(WritePrivateProfileStringA, -1) | |
2558 FF(GetLastError, -1) | |
2559 FF(SetLastError, -1) | |
2560 FF(InterlockedIncrement, -1) | |
2561 FF(InterlockedDecrement, -1) | |
2562 FF(GetTimeZoneInformation, -1) | |
2563 FF(OutputDebugStringA, -1) | |
2564 FF(GetLocalTime, -1) | |
2565 FF(GetSystemTime, -1) | |
2566 FF(GetEnvironmentVariableA, -1) | |
121 | 2567 FF(RtlZeroMemory,-1) |
2568 FF(RtlMoveMemory,-1) | |
2569 FF(RtlFillMemory,-1) | |
128 | 2570 FF(GetTempPathA,-1) |
2571 FF(FindFirstFileA,-1) | |
2572 FF(FindNextFileA,-1) | |
2573 FF(FindClose,-1) | |
2574 FF(FileTimeToLocalFileTime,-1) | |
2575 FF(DeleteFileA,-1) | |
2576 FF(ReadFile,-1) | |
2577 FF(WriteFile,-1) | |
2578 FF(SetFilePointer,-1) | |
2579 FF(GetTempFileNameA,-1) | |
2580 FF(CreateFileA,-1) | |
2581 FF(GetSystemDirectoryA,-1) | |
2582 FF(GetWindowsDirectoryA,-1) | |
2583 FF(SetErrorMode, -1) | |
2584 FF(IsProcessorFeaturePresent, -1) | |
2585 FF(GetProcessAffinityMask, -1) | |
497 | 2586 FF(InterlockedExchange, -1) |
2587 FF(MulDiv, -1) | |
713 | 2588 FF(lstrcmpiA, -1) |
2589 FF(lstrlenA, -1) | |
2590 FF(lstrcpyA, -1) | |
1 | 2591 }; |
2592 | |
2593 struct exports exp_msvcrt[]={ | |
2594 FF(malloc, -1) | |
2595 FF(_initterm, -1) | |
2596 FF(free, -1) | |
2597 {"??3@YAXPAX@Z", -1, expdelete}, | |
2598 {"??2@YAPAXI@Z", -1, expnew}, | |
128 | 2599 {"_adjust_fdiv", -1, (void*)&_adjust_fdiv}, |
1 | 2600 FF(strrchr, -1) |
2601 FF(strchr, -1) | |
128 | 2602 FF(strlen, -1) |
2603 FF(strcpy, -1) | |
2604 FF(strcmp, -1) | |
2605 FF(strcat, -1) | |
713 | 2606 FF(isalnum, -1) |
128 | 2607 FF(memmove, -1) |
2608 FF(memcmp, -1) | |
2609 FF(time, -1) | |
1 | 2610 }; |
2611 struct exports exp_winmm[]={ | |
2612 FF(GetDriverModuleHandle, -1) | |
2613 FF(timeGetTime, -1) | |
2614 FF(DefDriverProc, -1) | |
128 | 2615 FF(OpenDriverA, -1) |
1 | 2616 FF(OpenDriver, -1) |
2617 }; | |
2618 struct exports exp_user32[]={ | |
2619 FF(LoadStringA, -1) | |
2620 FF(wsprintfA, -1) | |
2621 FF(GetDC, -1) | |
2622 FF(GetDesktopWindow, -1) | |
2623 FF(ReleaseDC, -1) | |
128 | 2624 FF(IsRectEmpty, -1) |
2625 FF(LoadCursorA,-1) | |
2626 FF(SetCursor,-1) | |
1 | 2627 }; |
2628 struct exports exp_advapi32[]={ | |
2629 FF(RegOpenKeyA, -1) | |
2630 FF(RegOpenKeyExA, -1) | |
2631 FF(RegCreateKeyExA, -1) | |
2632 FF(RegQueryValueExA, -1) | |
2633 FF(RegSetValueExA, -1) | |
2634 FF(RegCloseKey, -1) | |
295
c017b21a1990
added expRegEnumValueA(), fixed expWaitForSingleObject()
arpi_esp
parents:
235
diff
changeset
|
2635 //FF(RegEnumValueA, -1) |
1 | 2636 }; |
2637 struct exports exp_gdi32[]={ | |
2638 FF(CreateCompatibleDC, -1) | |
2639 FF(GetDeviceCaps, -1) | |
2640 FF(DeleteDC, -1) | |
2641 FF(GetSystemPaletteEntries, -1) | |
2642 }; | |
2643 struct exports exp_version[]={ | |
2644 FF(GetFileVersionInfoSizeA, -1) | |
2645 }; | |
128 | 2646 struct exports exp_ole32[]={ |
2647 FF(CoTaskMemAlloc, -1) | |
2648 FF(CoTaskMemFree, -1) | |
2649 FF(CoCreateInstance, -1) | |
2650 FF(StringFromGUID2, -1) | |
2651 }; | |
130 | 2652 struct exports exp_crtdll[]={ |
2653 FF(memcpy, -1) | |
2654 }; | |
2655 | |
1 | 2656 #define LL(X) \ |
2657 {#X".dll", sizeof(exp_##X)/sizeof(struct exports), exp_##X}, | |
2658 | |
2659 struct libs libraries[]={ | |
2660 LL(kernel32) | |
2661 LL(msvcrt) | |
2662 LL(winmm) | |
2663 LL(user32) | |
2664 LL(advapi32) | |
2665 LL(gdi32) | |
2666 LL(version) | |
128 | 2667 LL(ole32) |
130 | 2668 LL(crtdll) |
1 | 2669 }; |
2670 | |
2671 void* LookupExternal(const char* library, int ordinal) | |
2672 { | |
2673 char* answ; | |
2674 int i,j; | |
2675 if(library==0) | |
2676 { | |
2677 printf("ERROR: library=0\n"); | |
2678 return (void*)ext_unknown; | |
2679 } | |
2680 printf("External func %s:%d\n", library, ordinal); | |
2681 // printf("%x %x\n", &unk_exp1, &unk_exp2); | |
2682 | |
2683 for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++) | |
2684 { | |
2685 if(strcasecmp(library, libraries[i].name)) | |
2686 continue; | |
2687 for(j=0; j<libraries[i].length; j++) | |
2688 { | |
2689 if(ordinal!=libraries[i].exps[j].id) | |
2690 continue; | |
2691 printf("Hit: 0x%08X\n", libraries[i].exps[j].func); | |
2692 return libraries[i].exps[j].func; | |
2693 } | |
2694 } | |
2695 if(pos>150)return 0; | |
2696 answ=(char*)extcode+pos*0x64; | |
2697 memcpy(answ, &unk_exp1, 0x64); | |
2698 *(int*)(answ+9)=pos; | |
2699 *(int*)(answ+47)-=((int)answ-(int)&unk_exp1); | |
2700 sprintf(export_names[pos], "%s:%d", library, ordinal); | |
2701 pos++; | |
2702 return (void*)answ; | |
2703 } | |
2704 | |
2705 void* LookupExternalByName(const char* library, const char* name) | |
2706 { | |
2707 char* answ; | |
2708 int i,j; | |
2709 // return (void*)ext_unknown; | |
2710 if(library==0) | |
2711 { | |
2712 printf("ERROR: library=0\n"); | |
2713 return (void*)ext_unknown; | |
2714 } | |
2715 if(name==0) | |
2716 { | |
2717 printf("ERROR: name=0\n"); | |
2718 return (void*)ext_unknown; | |
2719 } | |
2720 // printf("External func %s:%s\n", library, name); | |
2721 for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++) | |
2722 { | |
2723 if(strcasecmp(library, libraries[i].name)) | |
2724 continue; | |
2725 for(j=0; j<libraries[i].length; j++) | |
2726 { | |
2727 if(strcmp(name, libraries[i].exps[j].name)) | |
2728 continue; | |
2729 // printf("Hit: 0x%08X\n", libraries[i].exps[j].func); | |
2730 return libraries[i].exps[j].func; | |
2731 } | |
2732 } | |
128 | 2733 // printf("%s %s\n", library, name); |
2734 if(pos>150)return 0; | |
1 | 2735 strcpy(export_names[pos], name); |
2736 answ=(char*)extcode+pos*0x64; | |
2737 memcpy(answ, &unk_exp1, 0x64); | |
2738 *(int*)(answ+9)=pos; | |
2739 *(int*)(answ+47)-=((int)answ-(int)&unk_exp1); | |
2740 pos++; | |
2741 return (void*)answ; | |
2742 // memcpy(extcode, &unk_exp1, 0x64); | |
2743 // *(int*)(extcode+52)-=((int)extcode-(int)&unk_exp1); | |
2744 // return (void*)extcode; | |
2745 // printf("Unknown func %s:%s\n", library, name); | |
2746 // return (void*)ext_unknown; | |
2747 } | |
2748 | |
128 | 2749 int my_garbagecollection() |
2750 { | |
2751 #ifdef GARBAGE | |
2752 alc_list* pp,*ppsv; | |
2753 mutex_list* pm,*pmsv; | |
2754 int unfree,unfreecnt; | |
2755 if (mlist != NULL) { | |
2756 pm=mlist; | |
2757 for(;pm;) { | |
2758 if (pm->prev) pm->prev->next=pm->next; | |
2759 if (pm->next) pm->next->prev=pm->prev; | |
2760 if (pm == mlist) mlist=pm->prev; | |
2761 if (pm->pm) { | |
2762 pthread_mutex_destroy(pm->pm); | |
2763 my_release(pm->pm); | |
2764 } | |
2765 if (pm->pc) { | |
2766 pthread_cond_destroy(pm->pc); | |
2767 my_release(pm->pc); | |
2768 } | |
2769 pmsv = pm; | |
2770 pm=pm->prev; | |
2771 my_release(pmsv); | |
2772 } | |
2773 } | |
2774 | |
2775 if (alclist==NULL) return 0; | |
2776 | |
2777 pp=alclist; | |
2778 unfree=unfreecnt=0; | |
2779 for(;pp;) { | |
2780 unfree+=pp->size; | |
2781 unfreecnt++; | |
2782 if (pp->prev) | |
2783 pp->prev->next=pp->next; | |
2784 if (pp->next) | |
2785 pp->next->prev=pp->prev; | |
2786 if (pp == alclist) | |
2787 alclist=pp->prev; | |
2788 free(pp->addr); | |
2789 ppsv = pp; | |
2790 pp=pp->prev; | |
2791 free(ppsv); | |
2792 alccnt--; | |
2793 } | |
597 | 2794 printf("Total Unfree %d bytes cnt %d [%p,%d]\n",unfree,unfreecnt,alclist,alccnt); |
128 | 2795 #endif |
2796 } |