annotate loader/pe_image.c @ 36589:7c0c1a5642f9

Improve the dialog for font settings. Prettify the dialog by moving the combox box for font encodings up, and place it below the font file selector. In this way, everything related to font selection and its encoding is grouped together.
author ib
date Tue, 21 Jan 2014 20:34:56 +0000
parents 0989cbea18b4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
1 /*
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * Copyright 1994 Eric Youndale & Erik Bos
23734
acfe034e5386 ISO8859-1 --> UTF-8
diego
parents: 21261
diff changeset
3 * Copyright 1995 Martin von Löwis
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 * Copyright 1996-98 Marcus Meissner
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 * based on Eric Youndale's pe-test and:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 * ftp.microsoft.com:/pub/developer/MSDN/CD8/PEFILE.ZIP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * make that:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 * ftp.microsoft.com:/developr/MSDN/OctCD/PEFILE.ZIP
15166
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 13375
diff changeset
11 *
18783
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 18486
diff changeset
12 * Modified for use with MPlayer, detailed changelog at
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 18486
diff changeset
13 * http://svn.mplayerhq.hu/mplayer/trunk/
15166
f5537cc95b02 Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents: 13375
diff changeset
14 *
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 /* Notes:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 * Before you start changing something in this file be aware of the following:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 *
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
19 * - There are several functions called recursively. In a very subtle and
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 * obscure way. DLLs can reference each other recursively etc.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 * - If you want to enhance, speed up or clean up something in here, think
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 * twice WHY it is implemented in that strange way. There is usually a reason.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 * Though sometimes it might just be lazyness ;)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
24 * - In PE_MapImage, right before fixup_imports() all external and internal
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 * state MUST be correct since this function can be called with the SAME image
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 * AGAIN. (Thats recursion for you.) That means MODREF.module and
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 * NE_MODULE.module32.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 * - Sometimes, we can't use Linux mmap() to mmap() the images directly.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 * The problem is, that there is not direct 1:1 mapping from a diskimage and
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 * a memoryimage. The headers at the start are mapped linear, but the sections
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 * are not. Older x86 pe binaries are 512 byte aligned in file and 4096 byte
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 * aligned in memory. Linux likes them 4096 byte aligned in memory (due to
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 * x86 pagesize, this cannot be fixed without a rather large kernel rewrite)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 * and 'blocksize' file-aligned (offsets). Since we have 512/1024/2048 (CDROM)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 * and other byte blocksizes, we can't always do this. We *can* do this for
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 * newer pe binaries produced by MSVC 5 and later, since they are also aligned
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 * to 4096 byte boundaries on disk.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 */
35905
0989cbea18b4 Add _BSD_SOURCE #define for getpagesize().
diego
parents: 34195
diff changeset
40
0989cbea18b4 Add _BSD_SOURCE #define for getpagesize().
diego
parents: 34195
diff changeset
41 #define _BSD_SOURCE
0989cbea18b4 Add _BSD_SOURCE #define for getpagesize().
diego
parents: 34195
diff changeset
42
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1411
diff changeset
43 #include "config.h"
21261
a2e02e6b6379 Rename config.h --> debug.h and include config.h explicitly.
diego
parents: 18783
diff changeset
44 #include "debug.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 #include <assert.h>
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
48 #include <stdio.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 #include <sys/types.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 #include <sys/stat.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 #include <fcntl.h>
33412
2a2e9b6551d8 configure: Convert HAVE_SYS_MMAN_H into a 0/1 definition.
diego
parents: 32537
diff changeset
55 #if HAVE_SYS_MMAN_H
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 #include <sys/mman.h>
26111
eb82d1524b6d #include osdep/mman.h if sys/mman.h is not available.
diego
parents: 25870
diff changeset
57 #else
eb82d1524b6d #include osdep/mman.h if sys/mman.h is not available.
diego
parents: 25870
diff changeset
58 #include "osdep/mmap.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 #endif
34195
5affa2074131 build: fix compilation on Solaris due to missing alloca.h #include
diego
parents: 33412
diff changeset
60 #ifdef HAVE_ALLOCA_H
5affa2074131 build: fix compilation on Solaris due to missing alloca.h #include
diego
parents: 33412
diff changeset
61 # include <alloca.h>
5affa2074131 build: fix compilation on Solaris due to missing alloca.h #include
diego
parents: 33412
diff changeset
62 #endif
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
63 #include "wine/windef.h"
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
64 #include "wine/winbase.h"
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
65 #include "wine/winerror.h"
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
66 #include "wine/heap.h"
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
67 #include "wine/pe_image.h"
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
68 #include "wine/module.h"
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
69 #include "wine/debugtools.h"
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1411
diff changeset
70 #include "ext.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 #include "win32.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 #define RVA(x) ((void *)((char *)load_addr+(unsigned int)(x)))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 #define AdjustPtr(ptr,delta) ((char *)(ptr) + (delta))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
77 static void dump_exports( HMODULE hModule )
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
78 {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 char *Module;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
80 unsigned int i, j;
28162
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
81 unsigned short *ordinal;
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
82 unsigned long *function,*functions;
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
83 unsigned char **name;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 unsigned int load_addr = hModule;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 DWORD rva_start = PE_HEADER(hModule)->OptionalHeader
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 DWORD rva_end = rva_start + PE_HEADER(hModule)->OptionalHeader
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 IMAGE_EXPORT_DIRECTORY *pe_exports = (IMAGE_EXPORT_DIRECTORY*)RVA(rva_start);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 Module = (char*)RVA(pe_exports->Name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 TRACE("*******EXPORT DATA*******\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
94 TRACE("Module name is %s, %ld functions, %ld names\n",
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 Module, pe_exports->NumberOfFunctions, pe_exports->NumberOfNames);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96
28162
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
97 ordinal=(unsigned short*) RVA(pe_exports->AddressOfNameOrdinals);
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
98 functions=function=(unsigned long*) RVA(pe_exports->AddressOfFunctions);
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
99 name=(unsigned char**) RVA(pe_exports->AddressOfNames);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 TRACE(" Ord RVA Addr Name\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 for (i=0;i<pe_exports->NumberOfFunctions;i++, function++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
104 if (!*function) continue;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 if (TRACE_ON(win32))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 {
25870
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
107 dbg_printf( "%4ld %08lx %p", i + pe_exports->Base, *function, RVA(*function) );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
108
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 for (j = 0; j < pe_exports->NumberOfNames; j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 if (ordinal[j] == i)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 {
25870
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
112 dbg_printf( " %s", (char*)RVA(name[j]) );
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 if ((*function >= rva_start) && (*function <= rva_end))
25870
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
116 dbg_printf(" (forwarded -> %s)", (char *)RVA(*function));
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
117 dbg_printf("\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 /* Look up the specified function or ordinal in the exportlist:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 * If it is a string:
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
124 * - look up the name in the Name list.
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 * - look up the ordinal with that index.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 * - use the ordinal as offset into the functionlist
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 * If it is a ordinal:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 * - use ordinal-pe_export->Base as offset into the functionlist
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
130 FARPROC PE_FindExportedFunction(
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
131 WINE_MODREF *wm,
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
132 LPCSTR funcName,
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 WIN_BOOL snoop )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 {
28162
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
135 unsigned short * ordinals;
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
136 unsigned long * function;
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
137 unsigned char ** name;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
138 const char *ename = NULL;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 int i, ordinal;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 PE_MODREF *pem = &(wm->binfmt.pe);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 IMAGE_EXPORT_DIRECTORY *exports = pem->pe_export;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 unsigned int load_addr = wm->module;
28162
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
143 unsigned long rva_start, rva_end, addr;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 char * forward;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 if (HIWORD(funcName))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 TRACE("(%s)\n",funcName);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 TRACE("(%d)\n",(int)funcName);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 if (!exports) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 /* Not a fatal problem, some apps do
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 * GetProcAddress(0,"RegisterPenApp") which triggers this
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 * case.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 WARN("Module %08x(%s)/MODREF %p doesn't have a exports table.\n",wm->module,wm->modname,pem);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 }
28162
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
158 ordinals= (unsigned short*) RVA(exports->AddressOfNameOrdinals);
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
159 function= (unsigned long*) RVA(exports->AddressOfFunctions);
f1be9f91cbd8 Avoid u_ BSD type names.
diego
parents: 26111
diff changeset
160 name = (unsigned char **) RVA(exports->AddressOfNames);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 forward = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 rva_start = PE_HEADER(wm->module)->OptionalHeader
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 rva_end = rva_start + PE_HEADER(wm->module)->OptionalHeader
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 if (HIWORD(funcName))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
169
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 int min = 0, max = exports->NumberOfNames - 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 while (min <= max)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 int res, pos = (min + max) / 2;
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
174 ename = (const char*) RVA(name[pos]);
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
175 if (!(res = strcmp( ename, funcName )))
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 ordinal = ordinals[pos];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 goto found;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 if (res > 0) max = pos - 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 else min = pos + 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
183
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
184 for (i = 0; i < exports->NumberOfNames; i++)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 {
7386
174e2a58b4cd avifile sync - 95% cosmetics 5% bug
arpi
parents: 2651
diff changeset
186 ename = (const char*) RVA(name[i]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 if (!strcmp( ename, funcName ))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 {
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1411
diff changeset
189 ERR( "%s.%s required a linear search\n", wm->modname, funcName );
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 ordinal = ordinals[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 goto found;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
196 else
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 ordinal = LOWORD(funcName) - exports->Base;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
199 if (snoop && name)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 for (i = 0; i < exports->NumberOfNames; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 if (ordinals[i] == ordinal)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 ename = RVA(name[i]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 found:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 if (ordinal >= exports->NumberOfFunctions)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 TRACE(" ordinal %ld out of range!\n", ordinal + exports->Base );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 addr = function[ordinal];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 if (!addr) return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 if ((addr < rva_start) || (addr >= rva_end))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 FARPROC proc = RVA(addr);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 if (snoop)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 if (!ename) ename = "@";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 // proc = SNOOP_GetProcAddress(wm->module,ename,ordinal,proc);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 TRACE("SNOOP_GetProcAddress n/a\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
226
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 return proc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
230 else
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 char *forward = RVA(addr);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 char module[256];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 char *end = strchr(forward, '.');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 if (!end) return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 if (end - forward >= sizeof(module)) return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 memcpy( module, forward, end - forward );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 module[end-forward] = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 if (!(wm = MODULE_FindModule( module )))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 ERR("module not found for forward '%s'\n", forward );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 return MODULE_GetProcAddress( wm->module, end + 1, snoop );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
250 static DWORD fixup_imports( WINE_MODREF *wm )
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 IMAGE_IMPORT_DESCRIPTOR *pe_imp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 PE_MODREF *pem;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 unsigned int load_addr = wm->module;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 int i,characteristics_detection=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 char *modname;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
257
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 assert(wm->type==MODULE32_PE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 pem = &(wm->binfmt.pe);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 if (pem->pe_export)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 modname = (char*) RVA(pem->pe_export->Name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 modname = "<unknown>";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
265
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 TRACE("Dumping imports list\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
268
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 pe_imp = pem->pe_import;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 if (!pe_imp) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 /* We assume that we have at least one import with !0 characteristics and
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 * detect broken imports with all characteristsics 0 (notably Borland) and
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 * switch the detection off for them.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 for (i = 0; pe_imp->Name ; pe_imp++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 if (!i && !pe_imp->u.Characteristics)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 characteristics_detection = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 if (characteristics_detection && !pe_imp->u.Characteristics)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 i++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
283 if (!i) return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
285
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 wm->nDeps = i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 wm->deps = HeapAlloc( GetProcessHeap(), 0, i*sizeof(WINE_MODREF *) );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
289 /* load the imported modules. They are automatically
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 * added to the modref list of the process.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
292
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 for (i = 0, pe_imp = pem->pe_import; pe_imp->Name ; pe_imp++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 IMAGE_IMPORT_BY_NAME *pe_name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 PIMAGE_THUNK_DATA import_list,thunk_list;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 char *name = (char *) RVA(pe_imp->Name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 if (characteristics_detection && !pe_imp->u.Characteristics)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300
32394
914208d188b9 Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents: 29263
diff changeset
301 /* FIXME: here we should fill imports */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 TRACE("Loading imports for %s.dll\n", name);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
303
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
304 if (pe_imp->u.OriginalFirstThunk != 0) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 TRACE("Microsoft style imports used\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 import_list =(PIMAGE_THUNK_DATA) RVA(pe_imp->u.OriginalFirstThunk);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 thunk_list = (PIMAGE_THUNK_DATA) RVA(pe_imp->FirstThunk);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 while (import_list->u1.Ordinal) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 if (IMAGE_SNAP_BY_ORDINAL(import_list->u1.Ordinal)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 int ordinal = IMAGE_ORDINAL(import_list->u1.Ordinal);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 // TRACE("--- Ordinal %s,%d\n", name, ordinal);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
314
2651
958d10763c34 partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents: 2069
diff changeset
315 thunk_list->u1.Function=LookupExternal(name, ordinal);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
316 } else {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 pe_name = (PIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 // TRACE("--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint);
2651
958d10763c34 partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents: 2069
diff changeset
319 thunk_list->u1.Function=LookupExternalByName(name, pe_name->Name);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 import_list++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 thunk_list++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
324 } else {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 TRACE("Borland style imports used\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 thunk_list = (PIMAGE_THUNK_DATA) RVA(pe_imp->FirstThunk);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 while (thunk_list->u1.Ordinal) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 if (IMAGE_SNAP_BY_ORDINAL(thunk_list->u1.Ordinal)) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
329
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 int ordinal = IMAGE_ORDINAL(thunk_list->u1.Ordinal);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 TRACE("--- Ordinal %s.%d\n",name,ordinal);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 thunk_list->u1.Function=LookupExternal(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 name, ordinal);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 pe_name=(PIMAGE_IMPORT_BY_NAME) RVA(thunk_list->u1.AddressOfData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 TRACE("--- %s %s.%d\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 pe_name->Name,name,pe_name->Hint);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 thunk_list->u1.Function=LookupExternalByName(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 name, pe_name->Name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 thunk_list++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 static int calc_vma_size( HMODULE hModule )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 int i,vma_size = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 IMAGE_SECTION_HEADER *pe_seg = PE_SECTIONS(hModule);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 TRACE("Dump of segment table\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 TRACE(" Name VSz Vaddr SzRaw Fileadr *Reloc *Lineum #Reloc #Linum Char\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 for (i = 0; i< PE_HEADER(hModule)->FileHeader.NumberOfSections; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
358 TRACE("%8s: %4.4lx %8.8lx %8.8lx %8.8lx %8.8lx %8.8lx %4.4x %4.4x %8.8lx\n",
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
359 pe_seg->Name,
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 pe_seg->Misc.VirtualSize,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 pe_seg->VirtualAddress,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 pe_seg->SizeOfRawData,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 pe_seg->PointerToRawData,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 pe_seg->PointerToRelocations,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365 pe_seg->PointerToLinenumbers,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 pe_seg->NumberOfRelocations,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 pe_seg->NumberOfLinenumbers,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 pe_seg->Characteristics);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 vma_size=max(vma_size, pe_seg->VirtualAddress+pe_seg->SizeOfRawData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 vma_size=max(vma_size, pe_seg->VirtualAddress+pe_seg->Misc.VirtualSize);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 pe_seg++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 return vma_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 static void do_relocations( unsigned int load_addr, IMAGE_BASE_RELOCATION *r )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 int delta = load_addr - PE_HEADER(load_addr)->OptionalHeader.ImageBase;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379 int hdelta = (delta >> 16) & 0xFFFF;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 int ldelta = delta & 0xFFFF;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 if(delta == 0)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
383
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 while(r->VirtualAddress)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 char *page = (char*) RVA(r->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 int count = (r->SizeOfBlock - 8)/2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390 TRACE_(fixup)("%x relocations for page %lx\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 count, r->VirtualAddress);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
392
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
393 for(i=0;i<count;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
394 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
395 int offset = r->TypeOffset[i] & 0xFFF;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
396 int type = r->TypeOffset[i] >> 12;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397 // TRACE_(fixup)("patching %x type %x\n", offset, type);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
398 switch(type)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
399 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
400 case IMAGE_REL_BASED_ABSOLUTE: break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
401 case IMAGE_REL_BASED_HIGH:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
402 *(short*)(page+offset) += hdelta;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
403 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
404 case IMAGE_REL_BASED_LOW:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405 *(short*)(page+offset) += ldelta;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407 case IMAGE_REL_BASED_HIGHLOW:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 *(int*)(page+offset) += delta;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
409
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
410 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
411 case IMAGE_REL_BASED_HIGHADJ:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
412 FIXME("Don't know what to do with IMAGE_REL_BASED_HIGHADJ\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
413 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 case IMAGE_REL_BASED_MIPS_JMPADDR:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
415 FIXME("Is this a MIPS machine ???\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
416 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
417 default:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
418 FIXME("Unknown fixup type\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
419 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
420 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
421 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
422 r = (IMAGE_BASE_RELOCATION*)((char*)r + r->SizeOfBlock);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
423 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
424 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
425
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
426
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
427
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
428
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
429
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
430 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
431 * PE_LoadImage
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
432 * Load one PE format DLL/EXE into memory
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
433 *
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
434 * Unluckily we can't just mmap the sections where we want them, for
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
435 * (at least) Linux does only support offsets which are page-aligned.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
436 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
437 * BUT we have to map the whole image anyway, for Win32 programs sometimes
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
438 * want to access them. (HMODULE32 point to the start of it)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
439 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
440 HMODULE PE_LoadImage( int handle, LPCSTR filename, WORD *version )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
441 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
442 HMODULE hModule;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
443 HANDLE mapping;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
444
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
445 IMAGE_NT_HEADERS *nt;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
446 IMAGE_SECTION_HEADER *pe_sec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
447 IMAGE_DATA_DIRECTORY *dir;
24381
be23b48b5cdd warning fixes:
diego
parents: 23961
diff changeset
448 // BY_HANDLE_FILE_INFORMATION bhfi;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
449 int i, rawsize, lowest_va, vma_size, file_size = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
450 DWORD load_addr = 0, aoep, reloc = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
451 // struct get_read_fd_request *req = get_req_buffer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
452 int unix_handle = handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
453 int page_size = getpagesize();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
454
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
455
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
456 // if ( GetFileInformationByHandle( hFile, &bhfi ) )
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
457 // file_size = bhfi.nFileSizeLow;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
458 file_size=lseek(handle, 0, SEEK_END);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
459 lseek(handle, 0, SEEK_SET);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
460
32394
914208d188b9 Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents: 29263
diff changeset
461 // fix CreateFileMappingA
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
462 mapping = CreateFileMappingA( handle, NULL, PAGE_READONLY | SEC_COMMIT,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
463 0, 0, NULL );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
464 if (!mapping)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
465 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
466 WARN("CreateFileMapping error %ld\n", GetLastError() );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
467 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
468 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
469 // hModule = (HMODULE)MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
470 hModule=(HMODULE)mapping;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
471 // CloseHandle( mapping );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
472 if (!hModule)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
473 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
474 WARN("MapViewOfFile error %ld\n", GetLastError() );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
475 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
476 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
477 if ( *(WORD*)hModule !=IMAGE_DOS_SIGNATURE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
478 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
479 WARN("%s image doesn't have DOS signature, but 0x%04x\n", filename,*(WORD*)hModule);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
480 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
481 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
482
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
483 nt = PE_HEADER( hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
484
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
485
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
486 if ( nt->Signature != IMAGE_NT_SIGNATURE )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
487 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
488 WARN("%s image doesn't have PE signature, but 0x%08lx\n", filename, nt->Signature );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
489 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
490 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
491
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
492
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
493 if ( nt->FileHeader.Machine != IMAGE_FILE_MACHINE_I386 )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
494 {
25870
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
495 dbg_printf("Trying to load PE image for unsupported architecture (");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
496 switch (nt->FileHeader.Machine)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
497 {
25870
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
498 case IMAGE_FILE_MACHINE_UNKNOWN: dbg_printf("Unknown"); break;
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
499 case IMAGE_FILE_MACHINE_I860: dbg_printf("I860"); break;
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
500 case IMAGE_FILE_MACHINE_R3000: dbg_printf("R3000"); break;
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
501 case IMAGE_FILE_MACHINE_R4000: dbg_printf("R4000"); break;
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
502 case IMAGE_FILE_MACHINE_R10000: dbg_printf("R10000"); break;
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
503 case IMAGE_FILE_MACHINE_ALPHA: dbg_printf("Alpha"); break;
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
504 case IMAGE_FILE_MACHINE_POWERPC: dbg_printf("PowerPC"); break;
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
505 default: dbg_printf("Unknown-%04x", nt->FileHeader.Machine); break;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
506 }
25870
b6fb25907033 Get rid of redundant dbg_printf redefinition. Fixes some warnings:
diego
parents: 25849
diff changeset
507 dbg_printf(")\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
508 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
509 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
510
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
511
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
512 pe_sec = PE_SECTIONS( hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
513 rawsize = 0; lowest_va = 0x10000;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
514 for (i = 0; i < nt->FileHeader.NumberOfSections; i++)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
515 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
516 if (lowest_va > pe_sec[i].VirtualAddress)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
517 lowest_va = pe_sec[i].VirtualAddress;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
518 if (pe_sec[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
519 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
520 if (pe_sec[i].PointerToRawData+pe_sec[i].SizeOfRawData > rawsize)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
521 rawsize = pe_sec[i].PointerToRawData+pe_sec[i].SizeOfRawData;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
522 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
523
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
524
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
525 if ( file_size && file_size < rawsize )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
526 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
527 ERR("PE module is too small (header: %d, filesize: %d), "
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
528 "probably truncated download?\n",
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
529 rawsize, file_size );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
530 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
531 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
532
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
533
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
534 aoep = nt->OptionalHeader.AddressOfEntryPoint;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
535 if (aoep && (aoep < lowest_va))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
536 FIXME("VIRUS WARNING: '%s' has an invalid entrypoint (0x%08lx) "
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
537 "below the first virtual address (0x%08x) "
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
538 "(possibly infected by Tchernobyl/SpaceFiller virus)!\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
539 filename, aoep, lowest_va );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
540
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
541
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
542 /* FIXME: Hack! While we don't really support shared sections yet,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
543 * this checks for those special cases where the whole DLL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
544 * consists only of shared sections and is mapped into the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
545 * shared address space > 2GB. In this case, we assume that
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
546 * the module got mapped at its base address. Thus we simply
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
547 * check whether the module has actually been mapped there
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
548 * and use it, if so. This is needed to get Win95 USER32.DLL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
549 * to work (until we support shared sections properly).
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
550 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
551
23961
4e22889a6e35 Ugly hack to make xanlib.dll work.
reimar
parents: 23734
diff changeset
552 if ( nt->OptionalHeader.ImageBase & 0x80000000 &&
4e22889a6e35 Ugly hack to make xanlib.dll work.
reimar
parents: 23734
diff changeset
553 !strstr(filename, "xanlib.dll"))
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
554 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
555 HMODULE sharedMod = (HMODULE)nt->OptionalHeader.ImageBase;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
556 IMAGE_NT_HEADERS *sharedNt = (PIMAGE_NT_HEADERS)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
557 ( (LPBYTE)sharedMod + ((LPBYTE)nt - (LPBYTE)hModule) );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
558
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
559 /* Well, this check is not really comprehensive,
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
560 but should be good enough for now ... */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
561 if ( !IsBadReadPtr( (LPBYTE)sharedMod, sizeof(IMAGE_DOS_HEADER) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
562 && memcmp( (LPBYTE)sharedMod, (LPBYTE)hModule, sizeof(IMAGE_DOS_HEADER) ) == 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
563 && !IsBadReadPtr( sharedNt, sizeof(IMAGE_NT_HEADERS) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
564 && memcmp( sharedNt, nt, sizeof(IMAGE_NT_HEADERS) ) == 0 )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
565 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
566 UnmapViewOfFile( (LPVOID)hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
567 return sharedMod;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
568 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
569 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
570
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1411
diff changeset
571
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
572
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
573 load_addr = nt->OptionalHeader.ImageBase;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
574 vma_size = calc_vma_size( hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
575
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
576 load_addr = (DWORD)VirtualAlloc( (void*)load_addr, vma_size,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
577 MEM_RESERVE | MEM_COMMIT,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
578 PAGE_EXECUTE_READWRITE );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
579 if (load_addr == 0)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
580 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
581
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
582 FIXME("We need to perform base relocations for %s\n", filename);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
583 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_BASERELOC;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
584 if (dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
585 reloc = dir->VirtualAddress;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
586 else
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
587 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
588 FIXME( "FATAL: Need to relocate %s, but no relocation records present (%s). Try to run that file directly !\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
589 filename,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
590 (nt->FileHeader.Characteristics&IMAGE_FILE_RELOCS_STRIPPED)?
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
591 "stripped during link" : "unknown reason" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
592 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
593 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
594
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
595 /* FIXME: If we need to relocate a system DLL (base > 2GB) we should
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
596 * really make sure that the *new* base address is also > 2GB.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
597 * Some DLLs really check the MSB of the module handle :-/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
598 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
599 if ( nt->OptionalHeader.ImageBase & 0x80000000 )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
600 ERR( "Forced to relocate system DLL (base > 2GB). This is not good.\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
601
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
602 load_addr = (DWORD)VirtualAlloc( NULL, vma_size,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
603 MEM_RESERVE | MEM_COMMIT,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
604 PAGE_EXECUTE_READWRITE );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
605 if (!load_addr) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
606 FIXME_(win32)(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
607 "FATAL: Couldn't load module %s (out of memory, %d needed)!\n", filename, vma_size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
608 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
609 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
610 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
611
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
612 TRACE("Load addr is %lx (base %lx), range %x\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
613 load_addr, nt->OptionalHeader.ImageBase, vma_size );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
614 TRACE_(segment)("Loading %s at %lx, range %x\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
615 filename, load_addr, vma_size );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
616
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
617 #if 0
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
618
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
619 *(PIMAGE_DOS_HEADER)load_addr = *(PIMAGE_DOS_HEADER)hModule;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
620 *PE_HEADER( load_addr ) = *nt;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
621 memcpy( PE_SECTIONS(load_addr), PE_SECTIONS(hModule),
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
622 sizeof(IMAGE_SECTION_HEADER) * nt->FileHeader.NumberOfSections );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
623
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
624
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
625 memcpy( load_addr, hModule, lowest_fa );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
626 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
627
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
628 if ((void*)FILE_dommap( handle, (void *)load_addr, 0, nt->OptionalHeader.SizeOfHeaders,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
629 0, 0, PROT_EXEC | PROT_WRITE | PROT_READ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
630 MAP_PRIVATE | MAP_FIXED ) != (void*)load_addr)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
631 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
632 ERR_(win32)( "Critical Error: failed to map PE header to necessary address.\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
633 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
634 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
635
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
636
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
637 pe_sec = PE_SECTIONS( hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
638 for (i = 0; i < nt->FileHeader.NumberOfSections; i++, pe_sec++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
639 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
640 if (!pe_sec->SizeOfRawData || !pe_sec->PointerToRawData) continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
641 TRACE("%s: mmaping section %s at %p off %lx size %lx/%lx\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
642 filename, pe_sec->Name, (void*)RVA(pe_sec->VirtualAddress),
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
643 pe_sec->PointerToRawData, pe_sec->SizeOfRawData, pe_sec->Misc.VirtualSize );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
644 if ((void*)FILE_dommap( unix_handle, (void*)RVA(pe_sec->VirtualAddress),
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
645 0, pe_sec->SizeOfRawData, 0, pe_sec->PointerToRawData,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
646 PROT_EXEC | PROT_WRITE | PROT_READ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
647 MAP_PRIVATE | MAP_FIXED ) != (void*)RVA(pe_sec->VirtualAddress))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
648 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
649
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
650 ERR_(win32)( "Critical Error: failed to map PE section to necessary address.\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
651 goto error;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
652 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
653 if ((pe_sec->SizeOfRawData < pe_sec->Misc.VirtualSize) &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
654 (pe_sec->SizeOfRawData & (page_size-1)))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
655 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
656 DWORD end = (pe_sec->SizeOfRawData & ~(page_size-1)) + page_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
657 if (end > pe_sec->Misc.VirtualSize) end = pe_sec->Misc.VirtualSize;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
658 TRACE("clearing %p - %p\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
659 RVA(pe_sec->VirtualAddress) + pe_sec->SizeOfRawData,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
660 RVA(pe_sec->VirtualAddress) + end );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
661 memset( (char*)RVA(pe_sec->VirtualAddress) + pe_sec->SizeOfRawData, 0,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
662 end - pe_sec->SizeOfRawData );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
663 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
664 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
665
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
666
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
667 if ( reloc )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
668 do_relocations( load_addr, (IMAGE_BASE_RELOCATION *)RVA(reloc) );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
669
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
670
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
671 *version = ( (nt->OptionalHeader.MajorSubsystemVersion & 0xff) << 8 )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
672 | (nt->OptionalHeader.MinorSubsystemVersion & 0xff);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
673
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
674
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
675 UnmapViewOfFile( (LPVOID)hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
676 return (HMODULE)load_addr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
677
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
678 error:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
679 if (unix_handle != -1) close( unix_handle );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
680 if (load_addr)
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
681 VirtualFree( (LPVOID)load_addr, 0, MEM_RELEASE );
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
682 UnmapViewOfFile( (LPVOID)hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
683 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
684 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
685
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
686 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
687 * PE_CreateModule
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
688 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
689 * Create WINE_MODREF structure for loaded HMODULE32, link it into
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
690 * process modref_list, and fixup all imports.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
691 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
692 * Note: hModule must point to a correctly allocated PE image,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
693 * with base relocations applied; the 16-bit dummy module
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
694 * associated to hModule must already exist.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
695 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
696 * Note: This routine must always be called in the context of the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
697 * process that is to own the module to be created.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
698 */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
699 WINE_MODREF *PE_CreateModule( HMODULE hModule,
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
700 LPCSTR filename, DWORD flags, WIN_BOOL builtin )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
701 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
702 DWORD load_addr = (DWORD)hModule;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
703 IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
704 IMAGE_DATA_DIRECTORY *dir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
705 IMAGE_IMPORT_DESCRIPTOR *pe_import = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
706 IMAGE_EXPORT_DIRECTORY *pe_export = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
707 IMAGE_RESOURCE_DIRECTORY *pe_resource = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
708 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
709
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
710
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
711
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
712
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
713 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
714 if (dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
715 pe_export = (PIMAGE_EXPORT_DIRECTORY)RVA(dir->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
716
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
717 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IMPORT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
718 if (dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
719 pe_import = (PIMAGE_IMPORT_DESCRIPTOR)RVA(dir->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
720
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
721 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_RESOURCE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
722 if (dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
723 pe_resource = (PIMAGE_RESOURCE_DIRECTORY)RVA(dir->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
724
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
725 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXCEPTION;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
726 if (dir->Size) FIXME("Exception directory ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
727
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
728 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_SECURITY;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
729 if (dir->Size) FIXME("Security directory ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
730
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
731
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
732
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
733
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
734 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_DEBUG;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
735 if (dir->Size) TRACE("Debug directory ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
736
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
737 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_COPYRIGHT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
738 if (dir->Size) FIXME("Copyright string ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
739
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
740 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_GLOBALPTR;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
741 if (dir->Size) FIXME("Global Pointer (MIPS) ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
742
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
743
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
744
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
745 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
746 if (dir->Size) FIXME("Load Configuration directory ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
747
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
748 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
749 if (dir->Size) TRACE("Bound Import directory ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
750
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
751 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IAT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
752 if (dir->Size) TRACE("Import Address Table directory ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
753
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
754 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
755 if (dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
756 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
757 TRACE("Delayed import, stub calls LoadLibrary\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
758 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
759 * Nothing to do here.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
760 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
761
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
762 #ifdef ImgDelayDescr
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
763 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
764 * This code is useful to observe what the heck is going on.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
765 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
766 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
767 ImgDelayDescr *pe_delay = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
768 pe_delay = (PImgDelayDescr)RVA(dir->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
769 TRACE_(delayhlp)("pe_delay->grAttrs = %08x\n", pe_delay->grAttrs);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
770 TRACE_(delayhlp)("pe_delay->szName = %s\n", pe_delay->szName);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
771 TRACE_(delayhlp)("pe_delay->phmod = %08x\n", pe_delay->phmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
772 TRACE_(delayhlp)("pe_delay->pIAT = %08x\n", pe_delay->pIAT);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
773 TRACE_(delayhlp)("pe_delay->pINT = %08x\n", pe_delay->pINT);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
774 TRACE_(delayhlp)("pe_delay->pBoundIAT = %08x\n", pe_delay->pBoundIAT);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
775 TRACE_(delayhlp)("pe_delay->pUnloadIAT = %08x\n", pe_delay->pUnloadIAT);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
776 TRACE_(delayhlp)("pe_delay->dwTimeStamp = %08x\n", pe_delay->dwTimeStamp);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
777 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
778 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
779 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
780
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
781 dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
782 if (dir->Size) FIXME("Unknown directory 14 ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
783
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
784 dir = nt->OptionalHeader.DataDirectory+15;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
785 if (dir->Size) FIXME("Unknown directory 15 ignored\n" );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
786
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
787
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
788
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
789
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
790 wm = (WINE_MODREF *)HeapAlloc( GetProcessHeap(),
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
791 HEAP_ZERO_MEMORY, sizeof(*wm) );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
792 wm->module = hModule;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
793
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
794 if ( builtin )
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
795 wm->flags |= WINE_MODREF_INTERNAL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
796 if ( flags & DONT_RESOLVE_DLL_REFERENCES )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
797 wm->flags |= WINE_MODREF_DONT_RESOLVE_REFS;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
798 if ( flags & LOAD_LIBRARY_AS_DATAFILE )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
799 wm->flags |= WINE_MODREF_LOAD_AS_DATAFILE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
800
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
801 wm->type = MODULE32_PE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
802 wm->binfmt.pe.pe_export = pe_export;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
803 wm->binfmt.pe.pe_import = pe_import;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
804 wm->binfmt.pe.pe_resource = pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
805 wm->binfmt.pe.tlsindex = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
806
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
807 wm->filename = malloc(strlen(filename)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
808 strcpy(wm->filename, filename );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
809 wm->modname = strrchr( wm->filename, '\\' );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
810 if (!wm->modname) wm->modname = wm->filename;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
811 else wm->modname++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
812
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
813 if ( pe_export )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
814 dump_exports( hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
815
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
816 /* Fixup Imports */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
817
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
818 if ( pe_import
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
819 && !( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE )
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
820 && !( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
821 && fixup_imports( wm ) )
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
822 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
823 /* remove entry from modref chain */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
824 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
825 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
826
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
827 return wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
828 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
829
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
830 /******************************************************************************
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
831 * The PE Library Loader frontend.
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
832 * FIXME: handle the flags.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
833 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
834 WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
835 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
836 HMODULE hModule32;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
837 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
838 char filename[256];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
839 int hFile;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
840 WORD version = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
841
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
842
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
843 strncpy(filename, name, sizeof(filename));
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
844 hFile=open(filename, O_RDONLY);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
845 if(hFile==-1)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
846 return NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
847
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
848
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
849 hModule32 = PE_LoadImage( hFile, filename, &version );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
850 if (!hModule32)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
851 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
852 SetLastError( ERROR_OUTOFMEMORY );
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
853 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
854 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
855
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
856 if ( !(wm = PE_CreateModule( hModule32, filename, flags, FALSE )) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
857 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
858 ERR( "can't load %s\n", filename );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
859 SetLastError( ERROR_OUTOFMEMORY );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
860 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
861 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
862 close(hFile);
2651
958d10763c34 partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents: 2069
diff changeset
863 //printf("^^^^^^^^^^^^^^^^Alloc VM1 %p\n", wm);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
864 return wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
865 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
866
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
867
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
868 /*****************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
869 * PE_UnloadLibrary
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
870 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
871 * Unload the library unmapping the image and freeing the modref structure.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
872 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
873 void PE_UnloadLibrary(WINE_MODREF *wm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
874 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
875 TRACE(" unloading %s\n", wm->filename);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
876
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 32394
diff changeset
877 free(wm->filename);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 32394
diff changeset
878 free(wm->short_filename);
2651
958d10763c34 partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents: 2069
diff changeset
879 HeapFree( GetProcessHeap(), 0, wm->deps );
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
880 VirtualFree( (LPVOID)wm->module, 0, MEM_RELEASE );
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
881 HeapFree( GetProcessHeap(), 0, wm );
2651
958d10763c34 partially synced with avifile... (TODO: migrate to new registry.c and driver.c)
arpi
parents: 2069
diff changeset
882 //printf("^^^^^^^^^^^^^^^^Free VM1 %p\n", wm);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
883 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
884
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
885 /*****************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
886 * Load the PE main .EXE. All other loading is done by PE_LoadLibraryExA
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
887 * FIXME: this function should use PE_LoadLibraryExA, but currently can't
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
888 * due to the PROCESS_Create stuff.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
889 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
890
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1411
diff changeset
891
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
892 /*
1411
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
893 * This is a dirty hack.
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
894 * The win32 DLLs contain an alloca routine, that first probes the soon
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
895 * to be allocated new memory *below* the current stack pointer in 4KByte
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
896 * increments. After the mem probing below the current %esp, the stack
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
897 * pointer is finally decremented to make room for the "alloca"ed memory.
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
898 * Maybe the probing code is intended to extend the stack on a windows box.
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
899 * Anyway, the linux kernel does *not* extend the stack by simply accessing
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
900 * memory below %esp; it segfaults.
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
901 * The extend_stack_for_dll_alloca() routine just preallocates a big chunk
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
902 * of memory on the stack, for use by the DLLs alloca routine.
13375
460281609f28 force compilers not to optimize/inline extend_stack_for_dll_alloca
reimar
parents: 7386
diff changeset
903 * Added the noinline attribute as e.g. gcc 3.2.2 inlines this function
460281609f28 force compilers not to optimize/inline extend_stack_for_dll_alloca
reimar
parents: 7386
diff changeset
904 * in a way that breaks it.
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
905 */
13375
460281609f28 force compilers not to optimize/inline extend_stack_for_dll_alloca
reimar
parents: 7386
diff changeset
906 static void __attribute__((noinline)) extend_stack_for_dll_alloca(void)
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
907 {
15566
3758536dcef3 DragonFly BSD support
diego
parents: 15166
diff changeset
908 #if !defined(__FreeBSD__) && !defined(__DragonFly__)
13375
460281609f28 force compilers not to optimize/inline extend_stack_for_dll_alloca
reimar
parents: 7386
diff changeset
909 volatile int* mem=alloca(0x20000);
460281609f28 force compilers not to optimize/inline extend_stack_for_dll_alloca
reimar
parents: 7386
diff changeset
910 *mem=0x1234;
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1411
diff changeset
911 #endif
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
912 }
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
913
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
914 /* Called if the library is loaded or freed.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
915 * NOTE: if a thread attaches a DLL, the current thread will only do
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
916 * DLL_PROCESS_ATTACH. Only new created threads do DLL_THREAD_ATTACH
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
917 * (SDK)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
918 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
919 WIN_BOOL PE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
920 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
921 WIN_BOOL retv = TRUE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
922 assert( wm->type == MODULE32_PE );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
923
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
924
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
925 if ((PE_HEADER(wm->module)->FileHeader.Characteristics & IMAGE_FILE_DLL) &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
926 (PE_HEADER(wm->module)->OptionalHeader.AddressOfEntryPoint)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
927 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
928 DLLENTRYPROC entry ;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
929 entry = (void*)PE_FindExportedFunction(wm, "DllMain", 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
930 if(entry==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
931 entry = (void*)RVA_PTR( wm->module,OptionalHeader.AddressOfEntryPoint );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
932
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
933 TRACE_(relay)("CallTo32(entryproc=%p,module=%08x,type=%ld,res=%p)\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
934 entry, wm->module, type, lpReserved );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
935
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
936
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
937 TRACE("Entering DllMain(");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
938 switch(type)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
939 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
940 case DLL_PROCESS_DETACH:
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
941 TRACE("DLL_PROCESS_DETACH) ");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
942 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
943 case DLL_PROCESS_ATTACH:
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
944 TRACE("DLL_PROCESS_ATTACH) ");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
945 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
946 case DLL_THREAD_DETACH:
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
947 TRACE("DLL_THREAD_DETACH) ");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
948 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
949 case DLL_THREAD_ATTACH:
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
950 TRACE("DLL_THREAD_ATTACH) ");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
951 break;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28162
diff changeset
952 }
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
953 TRACE("for %s\n", wm->filename);
1411
db849cee5777 Pre-allocate some stack space to work around a problem with DLL alloca() code
jkeil
parents: 1307
diff changeset
954 extend_stack_for_dll_alloca();
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
955 retv = entry( wm->module, type, lpReserved );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
956 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
957
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
958 return retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
959 }