1 | /*
|
---|
2 | *
|
---|
3 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
4 | *
|
---|
5 | */
|
---|
6 | /*
|
---|
7 | * Win32 thunking API functions (mostly stubs)
|
---|
8 | *
|
---|
9 | * Copyright 1998 Patrick Haller (stubs + Wine port) (?)
|
---|
10 | *
|
---|
11 | * Original WINE code (win32\kernel32.c)
|
---|
12 | *
|
---|
13 | * KERNEL32 thunks and other undocumented stuff
|
---|
14 | *
|
---|
15 | * Copyright 1997-1998 Marcus Meissner
|
---|
16 | * Copyright 1998 Ulrich Weigand
|
---|
17 | */
|
---|
18 | #include <os2win.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <builtin.h>
|
---|
21 | #include "thunk.h"
|
---|
22 |
|
---|
23 | //******************************************************************************
|
---|
24 | //******************************************************************************
|
---|
25 | DWORD WIN32API MapLS(void *address)
|
---|
26 | {
|
---|
27 | // _interrupt(3);
|
---|
28 | dprintf(("MapLS %X, not supported\n", address));
|
---|
29 | return((DWORD)address);
|
---|
30 | }
|
---|
31 | //******************************************************************************
|
---|
32 | //******************************************************************************
|
---|
33 | DWORD WIN32API ThunkProc(DWORD arg1)
|
---|
34 | {
|
---|
35 | dprintf(("ThunkProc - stub\n"));
|
---|
36 | return(0);
|
---|
37 | }
|
---|
38 | //******************************************************************************
|
---|
39 | //******************************************************************************
|
---|
40 | void WIN32API FT_Prolog(CONTEXT *context)
|
---|
41 | {
|
---|
42 | dprintf(("FT_Prolog - stub\n"));
|
---|
43 | }
|
---|
44 | //******************************************************************************
|
---|
45 | //******************************************************************************
|
---|
46 | /**********************************************************************
|
---|
47 | * QT_Thunk (KERNEL32)
|
---|
48 | *
|
---|
49 | * The target address is in EDX.
|
---|
50 | * The 16 bit arguments start at ESP+4.
|
---|
51 | * The number of 16bit argumentbytes is EBP-ESP-0x44 (68 Byte thunksetup).
|
---|
52 | * [ok]
|
---|
53 | */
|
---|
54 | VOID WIN32API QT_Thunk(CONTEXT *context)
|
---|
55 | {
|
---|
56 | dprintf(("QT_Thunk\n"));
|
---|
57 | #if 0
|
---|
58 | CONTEXT context16;
|
---|
59 | DWORD argsize;
|
---|
60 |
|
---|
61 | memcpy(&context16,context,sizeof(context16));
|
---|
62 |
|
---|
63 | CS_reg(&context16) = HIWORD(EDX_reg(context));
|
---|
64 | IP_reg(&context16) = LOWORD(EDX_reg(context));
|
---|
65 |
|
---|
66 | argsize = EBP_reg(context)-ESP_reg(context)-0x44;
|
---|
67 |
|
---|
68 | /* additional 4 bytes used by the relaycode for storing the stackptr */
|
---|
69 | memcpy( ((LPBYTE)CURRENT_STACK16)-argsize-4,
|
---|
70 | (LPBYTE)ESP_reg(context)+4,
|
---|
71 | argsize
|
---|
72 | );
|
---|
73 | EAX_reg(context) = CallTo16_regs_short(&context16,-argsize);
|
---|
74 | #endif
|
---|
75 | }
|
---|
76 | //******************************************************************************
|
---|
77 | /***********************************************************************
|
---|
78 | * Generates a FT_Prolog call.
|
---|
79 | *
|
---|
80 | * 0FB6D1 movzbl edx,cl
|
---|
81 | * 8B1495xxxxxxxx mov edx,[4*edx + xxxxxxxx]
|
---|
82 | * 68xxxxxxxx push FT_Prolog
|
---|
83 | * C3 lret
|
---|
84 | */
|
---|
85 | static void _write_ftprolog(LPBYTE thunk,DWORD thunkstart)
|
---|
86 | {
|
---|
87 | LPBYTE x;
|
---|
88 |
|
---|
89 | x = thunk;
|
---|
90 | *x++ = 0x0f;*x++=0xb6;*x++=0xd1; /* movzbl edx,cl */
|
---|
91 | *x++ = 0x8B;*x++=0x14;*x++=0x95;*(DWORD*)x= thunkstart;
|
---|
92 | x+=4; /* mov edx, [4*edx + thunkstart] */
|
---|
93 | *x++ = 0x68; *(DWORD*)x = (DWORD)FT_Prolog;
|
---|
94 | x+=4; /* push FT_Prolog */
|
---|
95 | *x++ = 0xC3; /* lret */
|
---|
96 | /* fill rest with 0xCC / int 3 */
|
---|
97 | }
|
---|
98 | //******************************************************************************
|
---|
99 | /***********************************************************************
|
---|
100 | * Generates a QT_Thunk style call.
|
---|
101 | *
|
---|
102 | * 33C9 xor ecx, ecx
|
---|
103 | * 8A4DFC mov cl , [ebp-04]
|
---|
104 | * 8B148Dxxxxxxxx mov edx, [4*ecx + (EAX+EDX)]
|
---|
105 | * B8yyyyyyyy mov eax, QT_Thunk
|
---|
106 | * FFE0 jmp eax
|
---|
107 | */
|
---|
108 | static void _write_qtthunk(LPBYTE start,DWORD thunkstart)
|
---|
109 | {
|
---|
110 | LPBYTE x;
|
---|
111 |
|
---|
112 | x = start;
|
---|
113 | *x++ = 0x33;*x++=0xC9; /* xor ecx,ecx */
|
---|
114 | *x++ = 0x8A;*x++=0x4D;*x++=0xFC; /* movb cl,[ebp-04] */
|
---|
115 | *x++ = 0x8B;*x++=0x14;*x++=0x8D;*(DWORD*)x= thunkstart;
|
---|
116 | x+=4; /* mov edx, [4*ecx + (EAX+EDX) */
|
---|
117 | *x++ = 0xB8; *(DWORD*)x = (DWORD)QT_Thunk;
|
---|
118 | x+=4; /* mov eax , QT_Thunk */
|
---|
119 | *x++ = 0xFF; *x++ = 0xE0; /* jmp eax */
|
---|
120 | /* should fill the rest of the 32 bytes with 0xCC */
|
---|
121 | }
|
---|
122 |
|
---|
123 | //******************************************************************************
|
---|
124 | //******************************************************************************
|
---|
125 | DWORD WIN32API ThunkConnect32(thunkstruct *ths, LPSTR thunkfun16,
|
---|
126 | LPSTR module16, LPSTR module32, HMODULE hmod32,
|
---|
127 | DWORD dllinitarg1 )
|
---|
128 | {
|
---|
129 | thunkstruct *ths16;
|
---|
130 |
|
---|
131 | // _interrupt(3);
|
---|
132 | dprintf(("ThunkConnect32 %s %s %s not supported\n", thunkfun16, module16, module32));
|
---|
133 |
|
---|
134 | if(strncmp(ths->magic,"SL01",4) && strncmp(ths->magic,"LS01",4))
|
---|
135 | return 0;
|
---|
136 |
|
---|
137 | ths16 = (thunkstruct *)LocalAlloc(LPTR, ths->length);
|
---|
138 | ths16->length = ths->length;
|
---|
139 | ths16->ptr = (DWORD)ThunkProc;
|
---|
140 |
|
---|
141 | if(!strncmp(ths->magic,"SL01",4)) {
|
---|
142 | ths->x0C = (DWORD)ths16;
|
---|
143 | *(DWORD *)ths16->magic = 0x0000304C;
|
---|
144 | }
|
---|
145 | if(!strncmp(ths->magic,"LS01",4)) {
|
---|
146 | ths->ptr = ths16->ptr;
|
---|
147 | /* code offset for QT_Thunk is at 0x1C... */
|
---|
148 | _write_qtthunk (((LPBYTE)ths) + ths->x1C,ths->ptr);
|
---|
149 |
|
---|
150 | /* code offset for FT_Prolog is at 0x20... */
|
---|
151 | _write_ftprolog(((LPBYTE)ths) + ths->x20,ths->ptr);
|
---|
152 | return 1;
|
---|
153 | }
|
---|
154 | return TRUE;
|
---|
155 | }
|
---|
156 | //******************************************************************************
|
---|
157 | //******************************************************************************
|
---|
158 | DWORD WIN32API K32Thk1632Prolog(DWORD arg1)
|
---|
159 | {
|
---|
160 | dprintf(("OS2K32Thk1632Prolog %X not supported\n", arg1));
|
---|
161 | return(0);
|
---|
162 | }
|
---|
163 | //******************************************************************************
|
---|
164 | //******************************************************************************
|
---|
165 | DWORD WIN32API K32Thk1632Epilog(DWORD arg1)
|
---|
166 | {
|
---|
167 | dprintf(("K32Thk1632Epilog %X not supported\n", arg1));
|
---|
168 | return(0);
|
---|
169 | }
|
---|
170 | //******************************************************************************
|
---|
171 | //******************************************************************************
|
---|
172 | DWORD WIN32API MapSLFix(DWORD arg1)
|
---|
173 | {
|
---|
174 | dprintf(("MapSLFix %X not supported\n", arg1));
|
---|
175 | return(0);
|
---|
176 | }
|
---|
177 | //******************************************************************************
|
---|
178 | //******************************************************************************
|
---|