annotate loader/pe_resource.c @ 448:198b46b739d8

qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
author arpi_esp
date Sun, 15 Apr 2001 20:31:58 +0000
parents 3b5f5d1c5041
children d8c1b0b38edc
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>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 /**********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 * HMODULE32toPE_MODREF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 * small helper function to get a PE_MODREF from a passed HMODULE32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 static PE_MODREF*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 HMODULE32toPE_MODREF(HMODULE hmod) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 wm = MODULE32_LookupHMODULE( hmod );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 if (!wm || wm->type!=MODULE32_PE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 return &(wm->binfmt.pe);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 }
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 * GetResDirEntryW
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 * Helper function - goes down one level of PE resource tree
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 LPCWSTR name,DWORD root,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 WIN_BOOL allowdefault)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 int entrynum;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 int namelen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 if (HIWORD(name)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 if (name[0]=='#') {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 char buf[10];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 lstrcpynWtoA(buf,name+1,10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 (BYTE *) resdirptr +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 namelen = lstrlenW(name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 PIMAGE_RESOURCE_DIR_STRING_U str =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 (PIMAGE_RESOURCE_DIR_STRING_U) (root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 entryTable[entrynum].u1.s.NameOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 if(namelen != str->Length)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 if(wcsnicmp(name,str->NameString,str->Length)==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 return (PIMAGE_RESOURCE_DIRECTORY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 entryTable[entrynum].u2.s.OffsetToDirectory);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 (BYTE *) resdirptr +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 sizeof(IMAGE_RESOURCE_DIRECTORY) +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 return (PIMAGE_RESOURCE_DIRECTORY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 entryTable[entrynum].u2.s.OffsetToDirectory);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 /* just use first entry if no default can be found */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 if (allowdefault && !name && resdirptr->NumberOfIdEntries)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 return (PIMAGE_RESOURCE_DIRECTORY) (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 root +
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 entryTable[0].u2.s.OffsetToDirectory);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 }
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 * GetResDirEntryA
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA( PIMAGE_RESOURCE_DIRECTORY resdirptr,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 LPCSTR name, DWORD root,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 WIN_BOOL allowdefault )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 PIMAGE_RESOURCE_DIRECTORY retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 LPWSTR nameW = HIWORD(name)? HEAP_strdupAtoW( GetProcessHeap(), 0, name )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 : (LPWSTR)name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 retv = GetResDirEntryW( resdirptr, nameW, root, allowdefault );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 if ( HIWORD(name) ) HeapFree( GetProcessHeap(), 0, nameW );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 return retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }
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 * PE_FindResourceEx32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 HANDLE PE_FindResourceExW(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 WINE_MODREF *wm,LPCWSTR name,LPCWSTR type,WORD lang
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 PIMAGE_RESOURCE_DIRECTORY resdirptr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 DWORD root;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 HANDLE result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 PE_MODREF *pem = &(wm->binfmt.pe);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 resdirptr = pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 root = (DWORD) resdirptr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 if ((resdirptr = GetResDirEntryW(resdirptr, type, root, FALSE)) == NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 if ((resdirptr = GetResDirEntryW(resdirptr, name, root, FALSE)) == NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 /* Try LANG_NEUTRAL, too */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 if(!result)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 return (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)0, root, TRUE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 return result;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 }
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 * PE_LoadResource32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 HANDLE PE_LoadResource( WINE_MODREF *wm, HANDLE hRsrc )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 if (!hRsrc || !wm || wm->type!=MODULE32_PE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 return (HANDLE) (wm->module + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 }
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 * PE_SizeofResource32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 DWORD PE_SizeofResource( HINSTANCE hModule, HANDLE hRsrc )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 /* we don't need hModule */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 if (!hRsrc)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 }
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 * PE_EnumResourceTypes32A
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 PE_EnumResourceTypesA(HMODULE hmod,ENUMRESTYPEPROCA lpfun,LONG lparam) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 HANDLE heap = GetProcessHeap();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 LPSTR name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 name = (LPSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 ret = lpfun(hmod,name,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 if (HIWORD(name))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 HeapFree(heap,0,name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 }
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 * PE_EnumResourceTypes32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 PE_EnumResourceTypesW(HMODULE hmod,ENUMRESTYPEPROCW lpfun,LONG lparam) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 LPWSTR type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 type = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 type = (LPWSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 ret = lpfun(hmod,type,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 }
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 * PE_EnumResourceNames32A
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 PE_EnumResourceNamesA(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 HMODULE hmod,LPCSTR type,ENUMRESNAMEPROCA lpfun,LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 HANDLE heap = GetProcessHeap();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 LPWSTR typeW;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 if (HIWORD(type))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 typeW = HEAP_strdupAtoW(heap,0,type);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 typeW = (LPWSTR)type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 if (HIWORD(typeW))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 HeapFree(heap,0,typeW);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 LPSTR name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 name = (LPSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 ret = lpfun(hmod,type,name,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 if (HIWORD(name)) HeapFree(heap,0,name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 }
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 * PE_EnumResourceNames32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 PE_EnumResourceNamesW(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 HMODULE hmod,LPCWSTR type,ENUMRESNAMEPROCW lpfun,LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 LPWSTR name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 if (et[i].u1.s.NameIsString)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 name = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 name = (LPWSTR)(int)et[i].u1.Id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 ret = lpfun(hmod,type,name,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 }
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 * PE_EnumResourceNames32A
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314 PE_EnumResourceLanguagesA(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 HMODULE hmod,LPCSTR name,LPCSTR type,ENUMRESLANGPROCA lpfun,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 HANDLE heap = GetProcessHeap();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 LPWSTR nameW,typeW;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 if (HIWORD(name))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 nameW = HEAP_strdupAtoW(heap,0,name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 nameW = (LPWSTR)name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 resdir = GetResDirEntryW(resdir,nameW,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 if (HIWORD(nameW))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 HeapFree(heap,0,nameW);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 if (HIWORD(type))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 typeW = HEAP_strdupAtoW(heap,0,type);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 typeW = (LPWSTR)type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 if (HIWORD(typeW))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 HeapFree(heap,0,typeW);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 /* languages are just ids... I hopem */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 }
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 * PE_EnumResourceLanguages32W
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 WIN_BOOL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 PE_EnumResourceLanguagesW(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 HMODULE hmod,LPCWSTR name,LPCWSTR type,ENUMRESLANGPROCW lpfun,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365 LONG lparam
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 PE_MODREF *pem = HMODULE32toPE_MODREF(hmod);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 PIMAGE_RESOURCE_DIRECTORY resdir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 PIMAGE_RESOURCE_DIRECTORY_ENTRY et;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 WIN_BOOL ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 if (!pem || !pem->pe_resource)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 resdir = GetResDirEntryW(resdir,name,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 if (!resdir)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 return FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 ret = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 if (!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390 return ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 }