annotate loader/pe_resource.c @ 7362:8ae490fbf89d

TGA images (-mf on:type=tga) support patch by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
author arpi
date Tue, 10 Sep 2002 20:59:52 +0000
parents d8c1b0b38edc
children 174e2a58b4cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * PE (Portable Execute) File Resources
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 * Copyright 1995 Thomas Sandford
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 * Copyright 1996 Martin von Loewis
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 * Based on the Win16 resource handling code in loader/resource.c
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 * Copyright 1993 Robert J. Amstadt
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * Copyright 1995 Alexandre Julliard
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 * Copyright 1997 Marcus Meissner
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <config.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <sys/types.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #include <wine/winestring.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <wine/windef.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #include <wine/pe_image.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 #include <wine/module.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include <wine/heap.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 //#include "task.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 //#include "process.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 //#include "stackframe.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #include <wine/debugtools.h>
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 1
diff changeset
25 #include <ext.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 * HMODULE32toPE_MODREF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 * small helper function to get a PE_MODREF from a passed HMODULE32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 static PE_MODREF*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 HMODULE32toPE_MODREF(HMODULE hmod) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 wm = MODULE32_LookupHMODULE( hmod );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 if (!wm || wm->type!=MODULE32_PE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 return &(wm->binfmt.pe);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 * GetResDirEntryW
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 * Helper function - goes down one level of PE resource tree
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 LPCWSTR name,DWORD root,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 WIN_BOOL allowdefault)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 int entrynum;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 int namelen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 if (HIWORD(name)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 if (name[0]=='#') {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 char buf[10];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 lstrcpynWtoA(buf,name+1,10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 (BYTE *) resdirptr +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 namelen = lstrlenW(name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 PIMAGE_RESOURCE_DIR_STRING_U str =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 (PIMAGE_RESOURCE_DIR_STRING_U) (root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 entryTable[entrynum].u1.s.NameOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 if(namelen != str->Length)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 if(wcsnicmp(name,str->NameString,str->Length)==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 return (PIMAGE_RESOURCE_DIRECTORY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 entryTable[entrynum].u2.s.OffsetToDirectory);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 (BYTE *) resdirptr +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 sizeof(IMAGE_RESOURCE_DIRECTORY) +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 return (PIMAGE_RESOURCE_DIRECTORY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 entryTable[entrynum].u2.s.OffsetToDirectory);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 /* just use first entry if no default can be found */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 if (allowdefault && !name && resdirptr->NumberOfIdEntries)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 return (PIMAGE_RESOURCE_DIRECTORY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 entryTable[0].u2.s.OffsetToDirectory);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 * GetResDirEntryA
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA( PIMAGE_RESOURCE_DIRECTORY resdirptr,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 LPCSTR name, DWORD root,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 WIN_BOOL allowdefault )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 PIMAGE_RESOURCE_DIRECTORY retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 LPWSTR nameW = HIWORD(name)? HEAP_strdupAtoW( GetProcessHeap(), 0, name )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 : (LPWSTR)name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 retv = GetResDirEntryW( resdirptr, nameW, root, allowdefault );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 if ( HIWORD(name) ) HeapFree( GetProcessHeap(), 0, nameW );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 return retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 * PE_FindResourceEx32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 HANDLE PE_FindResourceExW(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 WINE_MODREF *wm,LPCWSTR name,LPCWSTR type,WORD lang
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 PIMAGE_RESOURCE_DIRECTORY resdirptr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 DWORD root;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 HANDLE result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 PE_MODREF *pem = &(wm->binfmt.pe);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 resdirptr = pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 root = (DWORD) resdirptr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 if ((resdirptr = GetResDirEntryW(resdirptr, type, root, FALSE)) == NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 if ((resdirptr = GetResDirEntryW(resdirptr, name, root, FALSE)) == NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 /* Try LANG_NEUTRAL, too */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 if(!result)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 return (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)0, root, TRUE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 return result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 * PE_LoadResource32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 HANDLE PE_LoadResource( WINE_MODREF *wm, HANDLE hRsrc )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 if (!hRsrc || !wm || wm->type!=MODULE32_PE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 return (HANDLE) (wm->module + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 * PE_SizeofResource32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 DWORD PE_SizeofResource( HINSTANCE hModule, HANDLE hRsrc )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 /* we don't need hModule */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 if (!hRsrc)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 * PE_EnumResourceTypes32A
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 PE_EnumResourceTypesA(HMODULE hmod,ENUMRESTYPEPROCA lpfun,LONG lparam) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 HANDLE heap = GetProcessHeap();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 LPSTR name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 name = (LPSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 ret = lpfun(hmod,name,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 if (HIWORD(name))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 HeapFree(heap,0,name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 * PE_EnumResourceTypes32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 PE_EnumResourceTypesW(HMODULE hmod,ENUMRESTYPEPROCW lpfun,LONG lparam) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 LPWSTR type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 type = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 type = (LPWSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 ret = lpfun(hmod,type,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 * PE_EnumResourceNames32A
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 PE_EnumResourceNamesA(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 HMODULE hmod,LPCSTR type,ENUMRESNAMEPROCA lpfun,LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 HANDLE heap = GetProcessHeap();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 LPWSTR typeW;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 if (HIWORD(type))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 typeW = HEAP_strdupAtoW(heap,0,type);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 typeW = (LPWSTR)type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 if (HIWORD(typeW))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 HeapFree(heap,0,typeW);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 LPSTR name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 name = (LPSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 ret = lpfun(hmod,type,name,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 if (HIWORD(name)) HeapFree(heap,0,name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 * PE_EnumResourceNames32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 PE_EnumResourceNamesW(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 HMODULE hmod,LPCWSTR type,ENUMRESNAMEPROCW lpfun,LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 LPWSTR name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 name = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 name = (LPWSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 ret = lpfun(hmod,type,name,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 * PE_EnumResourceNames32A
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 PE_EnumResourceLanguagesA(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 HMODULE hmod,LPCSTR name,LPCSTR type,ENUMRESLANGPROCA lpfun,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 HANDLE heap = GetProcessHeap();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 LPWSTR nameW,typeW;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 if (HIWORD(name))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 nameW = HEAP_strdupAtoW(heap,0,name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 nameW = (LPWSTR)name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 resdir = GetResDirEntryW(resdir,nameW,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 if (HIWORD(nameW))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 HeapFree(heap,0,nameW);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 if (HIWORD(type))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 typeW = HEAP_strdupAtoW(heap,0,type);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 typeW = (LPWSTR)type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 if (HIWORD(typeW))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 HeapFree(heap,0,typeW);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 /* languages are just ids... I hopem */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 * PE_EnumResourceLanguages32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 PE_EnumResourceLanguagesW(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365 HMODULE hmod,LPCWSTR name,LPCWSTR type,ENUMRESLANGPROCW lpfun,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 resdir = GetResDirEntryW(resdir,name,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
392 }