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