4 * Copyright 2004 Jon Griffiths
5 * Copyright 2007 Eric Pouech
6 * Copyright 2007 Jacek Caban for CodeWeavers
7 * Copyright 2007 Alexandre Julliard
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
33 #define WIN32_NO_STATUS
36 #include "ntdll_misc.h"
37 #include "wine/exception.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(actctx
);
43 #define ACTCTX_FLAGS_ALL (\
44 ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID |\
45 ACTCTX_FLAG_LANGID_VALID |\
46 ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID |\
47 ACTCTX_FLAG_RESOURCE_NAME_VALID |\
48 ACTCTX_FLAG_SET_PROCESS_DEFAULT |\
49 ACTCTX_FLAG_APPLICATION_NAME_VALID |\
50 ACTCTX_FLAG_SOURCE_IS_ASSEMBLYREF |\
51 ACTCTX_FLAG_HMODULE_VALID )
53 #define ACTCTX_MAGIC 0xC07E3E11
55 /* we don't want to include winuser.h */
56 #define RT_MANIFEST ((ULONG_PTR)24)
57 #define CREATEPROCESS_MANIFEST_RESOURCE_ID ((ULONG_PTR)1)
77 struct assembly_version
85 struct assembly_identity
92 struct assembly_version version
;
136 unsigned int allocated
;
143 struct entity_array entities
;
148 APPLICATION_MANIFEST
,
150 ASSEMBLY_SHARED_MANIFEST
,
155 enum assembly_type type
;
156 struct assembly_identity id
;
157 struct file_info manifest
;
160 struct dll_redirect
*dlls
;
161 unsigned int num_dlls
;
162 unsigned int allocated_dlls
;
163 struct entity_array entities
;
166 typedef struct _ACTIVATION_CONTEXT
170 struct file_info config
;
171 struct file_info appdir
;
172 struct assembly
*assemblies
;
173 unsigned int num_assemblies
;
174 unsigned int allocated_assemblies
;
175 } ACTIVATION_CONTEXT
;
179 ACTIVATION_CONTEXT
*actctx
;
180 struct assembly_identity
*dependencies
;
181 unsigned int num_dependencies
;
182 unsigned int allocated_dependencies
;
185 static const WCHAR assemblyW
[] = {'a','s','s','e','m','b','l','y',0};
186 static const WCHAR assemblyIdentityW
[] = {'a','s','s','e','m','b','l','y','I','d','e','n','t','i','t','y',0};
187 static const WCHAR bindingRedirectW
[] = {'b','i','n','d','i','n','g','R','e','d','i','r','e','c','t',0};
188 static const WCHAR clrClassW
[] = {'c','l','r','C','l','a','s','s',0};
189 static const WCHAR clrSurrogateW
[] = {'c','l','r','S','u','r','r','o','g','a','t','e',0};
190 static const WCHAR comClassW
[] = {'c','o','m','C','l','a','s','s',0};
191 static const WCHAR comInterfaceExternalProxyStubW
[] = {'c','o','m','I','n','t','e','r','f','a','c','e','E','x','t','e','r','n','a','l','P','r','o','x','y','S','t','u','b',0};
192 static const WCHAR comInterfaceProxyStubW
[] = {'c','o','m','I','n','t','e','r','f','a','c','e','P','r','o','x','y','S','t','u','b',0};
193 static const WCHAR dependencyW
[] = {'d','e','p','e','n','d','e','n','c','y',0};
194 static const WCHAR dependentAssemblyW
[] = {'d','e','p','e','n','d','e','n','t','A','s','s','e','m','b','l','y',0};
195 static const WCHAR descriptionW
[] = {'d','e','s','c','r','i','p','t','i','o','n',0};
196 static const WCHAR fileW
[] = {'f','i','l','e',0};
197 static const WCHAR asmv2hashW
[] = {'a','s','m','v','2',':','h','a','s','h',0};
198 static const WCHAR noInheritW
[] = {'n','o','I','n','h','e','r','i','t',0};
199 static const WCHAR noInheritableW
[] = {'n','o','I','n','h','e','r','i','t','a','b','l','e',0};
200 static const WCHAR typelibW
[] = {'t','y','p','e','l','i','b',0};
201 static const WCHAR windowClassW
[] = {'w','i','n','d','o','w','C','l','a','s','s',0};
203 static const WCHAR clsidW
[] = {'c','l','s','i','d',0};
204 static const WCHAR hashW
[] = {'h','a','s','h',0};
205 static const WCHAR hashalgW
[] = {'h','a','s','h','a','l','g',0};
206 static const WCHAR helpdirW
[] = {'h','e','l','p','d','i','r',0};
207 static const WCHAR iidW
[] = {'i','i','d',0};
208 static const WCHAR languageW
[] = {'l','a','n','g','u','a','g','e',0};
209 static const WCHAR manifestVersionW
[] = {'m','a','n','i','f','e','s','t','V','e','r','s','i','o','n',0};
210 static const WCHAR nameW
[] = {'n','a','m','e',0};
211 static const WCHAR newVersionW
[] = {'n','e','w','V','e','r','s','i','o','n',0};
212 static const WCHAR oldVersionW
[] = {'o','l','d','V','e','r','s','i','o','n',0};
213 static const WCHAR optionalW
[] = {'o','p','t','i','o','n','a','l',0};
214 static const WCHAR processorArchitectureW
[] = {'p','r','o','c','e','s','s','o','r','A','r','c','h','i','t','e','c','t','u','r','e',0};
215 static const WCHAR publicKeyTokenW
[] = {'p','u','b','l','i','c','K','e','y','T','o','k','e','n',0};
216 static const WCHAR tlbidW
[] = {'t','l','b','i','d',0};
217 static const WCHAR typeW
[] = {'t','y','p','e',0};
218 static const WCHAR versionW
[] = {'v','e','r','s','i','o','n',0};
219 static const WCHAR xmlnsW
[] = {'x','m','l','n','s',0};
221 static const WCHAR xmlW
[] = {'?','x','m','l',0};
222 static const WCHAR manifestv1W
[] = {'u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','a','s','m','.','v','1',0};
223 static const WCHAR manifestv3W
[] = {'u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','a','s','m','.','v','3',0};
225 static const WCHAR dotManifestW
[] = {'.','m','a','n','i','f','e','s','t',0};
226 static const WCHAR version_formatW
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
228 static ACTIVATION_CONTEXT system_actctx
= { ACTCTX_MAGIC
, 1 };
229 static ACTIVATION_CONTEXT
*process_actctx
= &system_actctx
;
231 static WCHAR
*strdupW(const WCHAR
* str
)
235 if (!(ptr
= RtlAllocateHeap(GetProcessHeap(), 0, (strlenW(str
) + 1) * sizeof(WCHAR
))))
237 return strcpyW(ptr
, str
);
240 static WCHAR
*xmlstrdupW(const xmlstr_t
* str
)
244 if ((strW
= RtlAllocateHeap(GetProcessHeap(), 0, (str
->len
+ 1) * sizeof(WCHAR
))))
246 memcpy( strW
, str
->ptr
, str
->len
* sizeof(WCHAR
) );
252 static inline BOOL
xmlstr_cmp(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
254 return !strncmpW(xmlstr
->ptr
, str
, xmlstr
->len
) && !str
[xmlstr
->len
];
257 static inline BOOL
xmlstr_cmpi(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
259 return !strncmpiW(xmlstr
->ptr
, str
, xmlstr
->len
) && !str
[xmlstr
->len
];
262 static inline BOOL
xmlstr_cmp_end(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
264 return (xmlstr
->len
&& xmlstr
->ptr
[0] == '/' &&
265 !strncmpW(xmlstr
->ptr
+ 1, str
, xmlstr
->len
- 1) && !str
[xmlstr
->len
- 1]);
268 static inline BOOL
isxmlspace( WCHAR ch
)
270 return (ch
== ' ' || ch
== '\r' || ch
== '\n' || ch
== '\t');
273 static inline const char* debugstr_xmlstr(const xmlstr_t
* str
)
275 return debugstr_wn(str
->ptr
, str
->len
);
278 static inline const char* debugstr_version(const struct assembly_version
*ver
)
280 return wine_dbg_sprintf("%u.%u.%u.%u", ver
->major
, ver
->minor
, ver
->build
, ver
->revision
);
283 static struct assembly
*add_assembly(ACTIVATION_CONTEXT
*actctx
, enum assembly_type at
)
285 struct assembly
*assembly
;
287 if (actctx
->num_assemblies
== actctx
->allocated_assemblies
)
290 unsigned int new_count
;
291 if (actctx
->assemblies
)
293 new_count
= actctx
->allocated_assemblies
* 2;
294 ptr
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
295 actctx
->assemblies
, new_count
* sizeof(*assembly
) );
300 ptr
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*assembly
) );
302 if (!ptr
) return NULL
;
303 actctx
->assemblies
= ptr
;
304 actctx
->allocated_assemblies
= new_count
;
307 assembly
= &actctx
->assemblies
[actctx
->num_assemblies
++];
312 static struct dll_redirect
* add_dll_redirect(struct assembly
* assembly
)
314 if (assembly
->num_dlls
== assembly
->allocated_dlls
)
317 unsigned int new_count
;
320 new_count
= assembly
->allocated_dlls
* 2;
321 ptr
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
322 assembly
->dlls
, new_count
* sizeof(*assembly
->dlls
) );
327 ptr
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*assembly
->dlls
) );
329 if (!ptr
) return NULL
;
330 assembly
->dlls
= ptr
;
331 assembly
->allocated_dlls
= new_count
;
333 return &assembly
->dlls
[assembly
->num_dlls
++];
336 static void free_assembly_identity(struct assembly_identity
*ai
)
338 RtlFreeHeap( GetProcessHeap(), 0, ai
->name
);
339 RtlFreeHeap( GetProcessHeap(), 0, ai
->arch
);
340 RtlFreeHeap( GetProcessHeap(), 0, ai
->public_key
);
341 RtlFreeHeap( GetProcessHeap(), 0, ai
->language
);
342 RtlFreeHeap( GetProcessHeap(), 0, ai
->type
);
345 static struct entity
* add_entity(struct entity_array
*array
, DWORD kind
)
347 struct entity
* entity
;
349 if (array
->num
== array
->allocated
)
352 unsigned int new_count
;
355 new_count
= array
->allocated
* 2;
356 ptr
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
357 array
->base
, new_count
* sizeof(*array
->base
) );
362 ptr
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*array
->base
) );
364 if (!ptr
) return NULL
;
366 array
->allocated
= new_count
;
368 entity
= &array
->base
[array
->num
++];
373 static void free_entity_array(struct entity_array
*array
)
376 for (i
= 0; i
< array
->num
; i
++)
378 struct entity
*entity
= &array
->base
[i
];
379 switch (entity
->kind
)
381 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
:
382 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.comclass
.clsid
);
384 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
:
385 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.proxy
.iid
);
386 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.proxy
.name
);
388 case ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
:
389 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.typelib
.tlbid
);
390 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.typelib
.version
);
391 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.typelib
.helpdir
);
393 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
:
394 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.class.name
);
396 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
:
397 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrclass
.name
);
398 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrclass
.clsid
);
400 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
:
401 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrsurrogate
.name
);
402 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrsurrogate
.clsid
);
405 FIXME("Unknown entity kind %d\n", entity
->kind
);
408 RtlFreeHeap( GetProcessHeap(), 0, array
->base
);
411 static BOOL
is_matching_string( const WCHAR
*str1
, const WCHAR
*str2
)
413 if (!str1
) return !str2
;
414 return str2
&& !strcmpiW( str1
, str2
);
417 static BOOL
is_matching_identity( const struct assembly_identity
*id1
,
418 const struct assembly_identity
*id2
)
420 if (!is_matching_string( id1
->name
, id2
->name
)) return FALSE
;
421 if (!is_matching_string( id1
->arch
, id2
->arch
)) return FALSE
;
422 if (!is_matching_string( id1
->public_key
, id2
->public_key
)) return FALSE
;
424 if (id1
->language
&& id2
->language
&& strcmpiW( id1
->language
, id2
->language
))
426 static const WCHAR wildcardW
[] = {'*',0};
427 if (strcmpW( wildcardW
, id1
->language
) && strcmpW( wildcardW
, id2
->language
))
430 if (id1
->version
.major
!= id2
->version
.major
) return FALSE
;
431 if (id1
->version
.minor
!= id2
->version
.minor
) return FALSE
;
432 if (id1
->version
.build
> id2
->version
.build
) return FALSE
;
433 if (id1
->version
.build
== id2
->version
.build
&&
434 id1
->version
.revision
> id2
->version
.revision
) return FALSE
;
438 static BOOL
add_dependent_assembly_id(struct actctx_loader
* acl
,
439 struct assembly_identity
* ai
)
443 /* check if we already have that assembly */
445 for (i
= 0; i
< acl
->actctx
->num_assemblies
; i
++)
446 if (is_matching_identity( ai
, &acl
->actctx
->assemblies
[i
].id
))
448 TRACE( "reusing existing assembly for %s arch %s version %u.%u.%u.%u\n",
449 debugstr_w(ai
->name
), debugstr_w(ai
->arch
), ai
->version
.major
, ai
->version
.minor
,
450 ai
->version
.build
, ai
->version
.revision
);
454 for (i
= 0; i
< acl
->num_dependencies
; i
++)
455 if (is_matching_identity( ai
, &acl
->dependencies
[i
] ))
457 TRACE( "reusing existing dependency for %s arch %s version %u.%u.%u.%u\n",
458 debugstr_w(ai
->name
), debugstr_w(ai
->arch
), ai
->version
.major
, ai
->version
.minor
,
459 ai
->version
.build
, ai
->version
.revision
);
463 if (acl
->num_dependencies
== acl
->allocated_dependencies
)
466 unsigned int new_count
;
467 if (acl
->dependencies
)
469 new_count
= acl
->allocated_dependencies
* 2;
470 ptr
= RtlReAllocateHeap(GetProcessHeap(), 0, acl
->dependencies
,
471 new_count
* sizeof(acl
->dependencies
[0]));
476 ptr
= RtlAllocateHeap(GetProcessHeap(), 0, new_count
* sizeof(acl
->dependencies
[0]));
478 if (!ptr
) return FALSE
;
479 acl
->dependencies
= ptr
;
480 acl
->allocated_dependencies
= new_count
;
482 acl
->dependencies
[acl
->num_dependencies
++] = *ai
;
487 static void free_depend_manifests(struct actctx_loader
* acl
)
490 for (i
= 0; i
< acl
->num_dependencies
; i
++)
491 free_assembly_identity(&acl
->dependencies
[i
]);
492 RtlFreeHeap(GetProcessHeap(), 0, acl
->dependencies
);
495 static WCHAR
*build_assembly_dir(struct assembly_identity
* ai
)
497 static const WCHAR undW
[] = {'_',0};
498 static const WCHAR noneW
[] = {'n','o','n','e',0};
499 static const WCHAR mskeyW
[] = {'d','e','a','d','b','e','e','f',0};
501 const WCHAR
*arch
= ai
->arch
? ai
->arch
: noneW
;
502 const WCHAR
*key
= ai
->public_key
? ai
->public_key
: noneW
;
503 const WCHAR
*lang
= ai
->language
? ai
->language
: noneW
;
504 const WCHAR
*name
= ai
->name
? ai
->name
: noneW
;
505 SIZE_T size
= (strlenW(arch
) + 1 + strlenW(name
) + 1 + strlenW(key
) + 24 + 1 +
506 strlenW(lang
) + 1) * sizeof(WCHAR
) + sizeof(mskeyW
);
509 if (!(ret
= RtlAllocateHeap( GetProcessHeap(), 0, size
))) return NULL
;
511 strcpyW( ret
, arch
);
512 strcatW( ret
, undW
);
513 strcatW( ret
, name
);
514 strcatW( ret
, undW
);
516 strcatW( ret
, undW
);
517 sprintfW( ret
+ strlenW(ret
), version_formatW
,
518 ai
->version
.major
, ai
->version
.minor
, ai
->version
.build
, ai
->version
.revision
);
519 strcatW( ret
, undW
);
520 strcatW( ret
, lang
);
521 strcatW( ret
, undW
);
522 strcatW( ret
, mskeyW
);
526 static inline void append_string( WCHAR
*buffer
, const WCHAR
*prefix
, const WCHAR
*str
)
531 strcatW( buffer
, prefix
);
540 static WCHAR
*build_assembly_id( const struct assembly_identity
*ai
)
542 static const WCHAR archW
[] =
543 {',','p','r','o','c','e','s','s','o','r','A','r','c','h','i','t','e','c','t','u','r','e','=',0};
544 static const WCHAR public_keyW
[] =
545 {',','p','u','b','l','i','c','K','e','y','T','o','k','e','n','=',0};
546 static const WCHAR typeW
[] =
547 {',','t','y','p','e','=',0};
548 static const WCHAR versionW
[] =
549 {',','v','e','r','s','i','o','n','=',0};
551 WCHAR version
[64], *ret
;
554 sprintfW( version
, version_formatW
,
555 ai
->version
.major
, ai
->version
.minor
, ai
->version
.build
, ai
->version
.revision
);
556 if (ai
->name
) size
+= strlenW(ai
->name
) * sizeof(WCHAR
);
557 if (ai
->arch
) size
+= strlenW(archW
) + strlenW(ai
->arch
) + 2;
558 if (ai
->public_key
) size
+= strlenW(public_keyW
) + strlenW(ai
->public_key
) + 2;
559 if (ai
->type
) size
+= strlenW(typeW
) + strlenW(ai
->type
) + 2;
560 size
+= strlenW(versionW
) + strlenW(version
) + 2;
562 if (!(ret
= RtlAllocateHeap( GetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
) )))
565 if (ai
->name
) strcpyW( ret
, ai
->name
);
567 append_string( ret
, archW
, ai
->arch
);
568 append_string( ret
, public_keyW
, ai
->public_key
);
569 append_string( ret
, typeW
, ai
->type
);
570 append_string( ret
, versionW
, version
);
574 static ACTIVATION_CONTEXT
*check_actctx( HANDLE h
)
576 ACTIVATION_CONTEXT
*ret
= NULL
, *actctx
= h
;
578 if (!h
|| h
== INVALID_HANDLE_VALUE
) return NULL
;
581 if (actctx
->magic
== ACTCTX_MAGIC
) ret
= actctx
;
590 static inline void actctx_addref( ACTIVATION_CONTEXT
*actctx
)
592 interlocked_xchg_add( &actctx
->ref_count
, 1 );
595 static void actctx_release( ACTIVATION_CONTEXT
*actctx
)
597 if (interlocked_xchg_add( &actctx
->ref_count
, -1 ) == 1)
601 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
603 struct assembly
*assembly
= &actctx
->assemblies
[i
];
604 for (j
= 0; j
< assembly
->num_dlls
; j
++)
606 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
607 free_entity_array( &dll
->entities
);
608 RtlFreeHeap( GetProcessHeap(), 0, dll
->name
);
609 RtlFreeHeap( GetProcessHeap(), 0, dll
->hash
);
611 RtlFreeHeap( GetProcessHeap(), 0, assembly
->dlls
);
612 RtlFreeHeap( GetProcessHeap(), 0, assembly
->manifest
.info
);
613 RtlFreeHeap( GetProcessHeap(), 0, assembly
->directory
);
614 free_entity_array( &assembly
->entities
);
615 free_assembly_identity(&assembly
->id
);
617 RtlFreeHeap( GetProcessHeap(), 0, actctx
->config
.info
);
618 RtlFreeHeap( GetProcessHeap(), 0, actctx
->appdir
.info
);
619 RtlFreeHeap( GetProcessHeap(), 0, actctx
->assemblies
);
621 RtlFreeHeap( GetProcessHeap(), 0, actctx
);
625 static BOOL
next_xml_attr(xmlbuf_t
* xmlbuf
, xmlstr_t
* name
, xmlstr_t
* value
,
626 BOOL
* error
, BOOL
* end
)
632 while (xmlbuf
->ptr
< xmlbuf
->end
&& isxmlspace(*xmlbuf
->ptr
))
635 if (xmlbuf
->ptr
== xmlbuf
->end
) return FALSE
;
637 if (*xmlbuf
->ptr
== '/')
640 if (xmlbuf
->ptr
== xmlbuf
->end
|| *xmlbuf
->ptr
!= '>')
649 if (*xmlbuf
->ptr
== '>')
657 while (ptr
< xmlbuf
->end
&& *ptr
!= '=' && *ptr
!= '>' && !isxmlspace(*ptr
)) ptr
++;
659 if (ptr
== xmlbuf
->end
|| *ptr
!= '=') return FALSE
;
661 name
->ptr
= xmlbuf
->ptr
;
662 name
->len
= ptr
-xmlbuf
->ptr
;
666 if (ptr
== xmlbuf
->end
|| (*ptr
!= '"' && *ptr
!= '\'')) return FALSE
;
669 if (ptr
== xmlbuf
->end
) return FALSE
;
671 ptr
= memchrW(ptr
, ptr
[-1], xmlbuf
->end
- ptr
);
674 xmlbuf
->ptr
= xmlbuf
->end
;
678 value
->len
= ptr
- value
->ptr
;
679 xmlbuf
->ptr
= ptr
+ 1;
681 if (xmlbuf
->ptr
== xmlbuf
->end
) return FALSE
;
687 static BOOL
next_xml_elem(xmlbuf_t
* xmlbuf
, xmlstr_t
* elem
)
693 ptr
= memchrW(xmlbuf
->ptr
, '<', xmlbuf
->end
- xmlbuf
->ptr
);
696 xmlbuf
->ptr
= xmlbuf
->end
;
700 if (ptr
+ 3 < xmlbuf
->end
&& ptr
[0] == '!' && ptr
[1] == '-' && ptr
[2] == '-') /* skip comment */
702 for (ptr
+= 3; ptr
+ 3 <= xmlbuf
->end
; ptr
++)
703 if (ptr
[0] == '-' && ptr
[1] == '-' && ptr
[2] == '>') break;
705 if (ptr
+ 3 > xmlbuf
->end
)
707 xmlbuf
->ptr
= xmlbuf
->end
;
710 xmlbuf
->ptr
= ptr
+ 3;
716 while (ptr
< xmlbuf
->end
&& !isxmlspace(*ptr
) && *ptr
!= '>' && (*ptr
!= '/' || ptr
== xmlbuf
->ptr
))
719 elem
->ptr
= xmlbuf
->ptr
;
720 elem
->len
= ptr
- xmlbuf
->ptr
;
722 return xmlbuf
->ptr
!= xmlbuf
->end
;
725 static BOOL
parse_xml_header(xmlbuf_t
* xmlbuf
)
727 /* FIXME: parse attributes */
730 for (ptr
= xmlbuf
->ptr
; ptr
< xmlbuf
->end
- 1; ptr
++)
732 if (ptr
[0] == '?' && ptr
[1] == '>')
734 xmlbuf
->ptr
= ptr
+ 2;
741 static BOOL
parse_text_content(xmlbuf_t
* xmlbuf
, xmlstr_t
* content
)
743 const WCHAR
*ptr
= memchrW(xmlbuf
->ptr
, '<', xmlbuf
->end
- xmlbuf
->ptr
);
745 if (!ptr
) return FALSE
;
747 content
->ptr
= xmlbuf
->ptr
;
748 content
->len
= ptr
- xmlbuf
->ptr
;
754 static BOOL
parse_version(const xmlstr_t
*str
, struct assembly_version
*version
)
760 /* major.minor.build.revision */
761 ver
[0] = ver
[1] = ver
[2] = ver
[3] = pos
= 0;
762 for (curr
= str
->ptr
; curr
< str
->ptr
+ str
->len
; curr
++)
764 if (*curr
>= '0' && *curr
<= '9')
766 ver
[pos
] = ver
[pos
] * 10 + *curr
- '0';
767 if (ver
[pos
] >= 0x10000) goto error
;
769 else if (*curr
== '.')
771 if (++pos
>= 4) goto error
;
775 version
->major
= ver
[0];
776 version
->minor
= ver
[1];
777 version
->build
= ver
[2];
778 version
->revision
= ver
[3];
782 FIXME( "Wrong version definition in manifest file (%s)\n", debugstr_xmlstr(str
) );
786 static BOOL
parse_expect_elem(xmlbuf_t
* xmlbuf
, const WCHAR
* name
)
789 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
790 if (xmlstr_cmp(&elem
, name
)) return TRUE
;
791 FIXME( "unexpected element %s\n", debugstr_xmlstr(&elem
) );
795 static BOOL
parse_expect_no_attr(xmlbuf_t
* xmlbuf
, BOOL
* end
)
797 xmlstr_t attr_name
, attr_value
;
800 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, end
))
802 WARN("unexpected attr %s=%s\n", debugstr_xmlstr(&attr_name
),
803 debugstr_xmlstr(&attr_value
));
808 static BOOL
parse_end_element(xmlbuf_t
*xmlbuf
)
811 return parse_expect_no_attr(xmlbuf
, &end
) && !end
;
814 static BOOL
parse_expect_end_elem(xmlbuf_t
*xmlbuf
, const WCHAR
*name
)
817 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
818 if (!xmlstr_cmp_end(&elem
, name
))
820 FIXME( "unexpected element %s\n", debugstr_xmlstr(&elem
) );
823 return parse_end_element(xmlbuf
);
826 static BOOL
parse_unknown_elem(xmlbuf_t
*xmlbuf
, const xmlstr_t
*unknown_elem
)
828 xmlstr_t attr_name
, attr_value
, elem
;
829 BOOL end
= FALSE
, error
, ret
= TRUE
;
831 while(next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
));
832 if(error
|| end
) return end
;
834 while(ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
836 if(*elem
.ptr
== '/' && elem
.len
- 1 == unknown_elem
->len
&&
837 !strncmpW(elem
.ptr
+1, unknown_elem
->ptr
, unknown_elem
->len
))
840 ret
= parse_unknown_elem(xmlbuf
, &elem
);
843 return ret
&& parse_end_element(xmlbuf
);
846 static BOOL
parse_assembly_identity_elem(xmlbuf_t
* xmlbuf
, ACTIVATION_CONTEXT
* actctx
,
847 struct assembly_identity
* ai
)
849 xmlstr_t attr_name
, attr_value
;
850 BOOL end
= FALSE
, error
;
852 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
854 if (xmlstr_cmp(&attr_name
, nameW
))
856 if (!(ai
->name
= xmlstrdupW(&attr_value
))) return FALSE
;
858 else if (xmlstr_cmp(&attr_name
, typeW
))
860 if (!(ai
->type
= xmlstrdupW(&attr_value
))) return FALSE
;
862 else if (xmlstr_cmp(&attr_name
, versionW
))
864 if (!parse_version(&attr_value
, &ai
->version
)) return FALSE
;
866 else if (xmlstr_cmp(&attr_name
, processorArchitectureW
))
868 if (!(ai
->arch
= xmlstrdupW(&attr_value
))) return FALSE
;
870 else if (xmlstr_cmp(&attr_name
, publicKeyTokenW
))
872 if (!(ai
->public_key
= xmlstrdupW(&attr_value
))) return FALSE
;
874 else if (xmlstr_cmp(&attr_name
, languageW
))
876 WARN("Unsupported yet language attribute (%s)\n",
877 debugstr_xmlstr(&attr_value
));
878 if (!(ai
->language
= xmlstrdupW(&attr_value
))) return FALSE
;
882 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
),
883 debugstr_xmlstr(&attr_value
));
887 TRACE( "name=%s version=%s arch=%s\n",
888 debugstr_w(ai
->name
), debugstr_version(&ai
->version
), debugstr_w(ai
->arch
) );
890 if (error
|| end
) return end
;
891 return parse_expect_end_elem(xmlbuf
, assemblyIdentityW
);
894 static BOOL
parse_com_class_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
896 xmlstr_t elem
, attr_name
, attr_value
;
897 BOOL ret
, end
= FALSE
, error
;
898 struct entity
* entity
;
900 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
)))
903 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
905 if (xmlstr_cmp(&attr_name
, clsidW
))
907 if (!(entity
->u
.comclass
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
911 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
915 if (error
|| end
) return end
;
917 while ((ret
= next_xml_elem(xmlbuf
, &elem
)))
919 if (xmlstr_cmp_end(&elem
, comClassW
))
921 ret
= parse_end_element(xmlbuf
);
926 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
927 ret
= parse_unknown_elem(xmlbuf
, &elem
);
933 static BOOL
parse_cominterface_proxy_stub_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
935 xmlstr_t attr_name
, attr_value
;
936 BOOL end
= FALSE
, error
;
937 struct entity
* entity
;
939 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
)))
942 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
944 if (xmlstr_cmp(&attr_name
, iidW
))
946 if (!(entity
->u
.proxy
.iid
= xmlstrdupW(&attr_value
))) return FALSE
;
948 if (xmlstr_cmp(&attr_name
, nameW
))
950 if (!(entity
->u
.proxy
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
954 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
958 if (error
|| end
) return end
;
959 return parse_expect_end_elem(xmlbuf
, comInterfaceProxyStubW
);
962 static BOOL
parse_typelib_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
964 xmlstr_t attr_name
, attr_value
;
965 BOOL end
= FALSE
, error
;
966 struct entity
* entity
;
968 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
)))
971 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
973 if (xmlstr_cmp(&attr_name
, tlbidW
))
975 if (!(entity
->u
.typelib
.tlbid
= xmlstrdupW(&attr_value
))) return FALSE
;
977 if (xmlstr_cmp(&attr_name
, versionW
))
979 if (!(entity
->u
.typelib
.version
= xmlstrdupW(&attr_value
))) return FALSE
;
981 if (xmlstr_cmp(&attr_name
, helpdirW
))
983 if (!(entity
->u
.typelib
.helpdir
= xmlstrdupW(&attr_value
))) return FALSE
;
987 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
991 if (error
|| end
) return end
;
992 return parse_expect_end_elem(xmlbuf
, typelibW
);
995 static BOOL
parse_window_class_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
997 xmlstr_t elem
, content
;
998 BOOL end
= FALSE
, ret
= TRUE
;
999 struct entity
* entity
;
1001 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
)))
1004 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1005 if (end
) return FALSE
;
1007 if (!parse_text_content(xmlbuf
, &content
)) return FALSE
;
1009 if (!(entity
->u
.class.name
= xmlstrdupW(&content
))) return FALSE
;
1011 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1013 if (xmlstr_cmp_end(&elem
, windowClassW
))
1015 ret
= parse_end_element(xmlbuf
);
1020 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1021 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1028 static BOOL
parse_binding_redirect_elem(xmlbuf_t
* xmlbuf
)
1030 xmlstr_t attr_name
, attr_value
;
1031 BOOL end
= FALSE
, error
;
1033 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1035 if (xmlstr_cmp(&attr_name
, oldVersionW
))
1037 FIXME("Not stored yet oldVersion=%s\n", debugstr_xmlstr(&attr_value
));
1039 else if (xmlstr_cmp(&attr_name
, newVersionW
))
1041 FIXME("Not stored yet newVersion=%s\n", debugstr_xmlstr(&attr_value
));
1045 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1049 if (error
|| end
) return end
;
1050 return parse_expect_end_elem(xmlbuf
, bindingRedirectW
);
1053 static BOOL
parse_description_elem(xmlbuf_t
* xmlbuf
)
1055 xmlstr_t elem
, content
;
1056 BOOL end
= FALSE
, ret
= TRUE
;
1058 if (!parse_expect_no_attr(xmlbuf
, &end
) || end
||
1059 !parse_text_content(xmlbuf
, &content
))
1062 TRACE("Got description %s\n", debugstr_xmlstr(&content
));
1064 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1066 if (xmlstr_cmp_end(&elem
, descriptionW
))
1068 ret
= parse_end_element(xmlbuf
);
1073 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1074 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1081 static BOOL
parse_com_interface_external_proxy_stub_elem(xmlbuf_t
* xmlbuf
,
1082 struct assembly
* assembly
)
1084 xmlstr_t attr_name
, attr_value
;
1085 BOOL end
= FALSE
, error
;
1086 struct entity
* entity
;
1088 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
);
1089 if (!entity
) return FALSE
;
1091 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1093 if (xmlstr_cmp(&attr_name
, iidW
))
1095 if (!(entity
->u
.proxy
.iid
= xmlstrdupW(&attr_value
))) return FALSE
;
1097 if (xmlstr_cmp(&attr_name
, nameW
))
1099 if (!(entity
->u
.proxy
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1103 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1107 if (error
|| end
) return end
;
1108 return parse_expect_end_elem(xmlbuf
, comInterfaceExternalProxyStubW
);
1111 static BOOL
parse_clr_class_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1113 xmlstr_t attr_name
, attr_value
;
1114 BOOL end
= FALSE
, error
;
1115 struct entity
* entity
;
1117 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
);
1118 if (!entity
) return FALSE
;
1120 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1122 if (xmlstr_cmp(&attr_name
, nameW
))
1124 if (!(entity
->u
.clrclass
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1126 else if (xmlstr_cmp(&attr_name
, clsidW
))
1128 if (!(entity
->u
.clrclass
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
1132 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1136 if (error
|| end
) return end
;
1137 return parse_expect_end_elem(xmlbuf
, clrClassW
);
1140 static BOOL
parse_clr_surrogate_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1142 xmlstr_t attr_name
, attr_value
;
1143 BOOL end
= FALSE
, error
;
1144 struct entity
* entity
;
1146 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
);
1147 if (!entity
) return FALSE
;
1149 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1151 if (xmlstr_cmp(&attr_name
, nameW
))
1153 if (!(entity
->u
.clrsurrogate
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1155 else if (xmlstr_cmp(&attr_name
, clsidW
))
1157 if (!(entity
->u
.clrsurrogate
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
1161 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1165 if (error
|| end
) return end
;
1166 return parse_expect_end_elem(xmlbuf
, clrSurrogateW
);
1169 static BOOL
parse_dependent_assembly_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
, BOOL optional
)
1171 struct assembly_identity ai
;
1173 BOOL end
= FALSE
, ret
= TRUE
;
1175 if (!parse_expect_no_attr(xmlbuf
, &end
) || end
) return end
;
1177 memset(&ai
, 0, sizeof(ai
));
1178 ai
.optional
= optional
;
1180 if (!parse_expect_elem(xmlbuf
, assemblyIdentityW
) ||
1181 !parse_assembly_identity_elem(xmlbuf
, acl
->actctx
, &ai
))
1184 TRACE( "adding name=%s version=%s arch=%s\n",
1185 debugstr_w(ai
.name
), debugstr_version(&ai
.version
), debugstr_w(ai
.arch
) );
1187 /* store the newly found identity for later loading */
1188 if (!add_dependent_assembly_id(acl
, &ai
)) return FALSE
;
1190 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1192 if (xmlstr_cmp_end(&elem
, dependentAssemblyW
))
1194 ret
= parse_end_element(xmlbuf
);
1197 else if (xmlstr_cmp(&elem
, bindingRedirectW
))
1199 ret
= parse_binding_redirect_elem(xmlbuf
);
1203 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1204 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1211 static BOOL
parse_dependency_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
)
1213 xmlstr_t attr_name
, attr_value
, elem
;
1214 BOOL end
= FALSE
, ret
= TRUE
, error
, optional
= FALSE
;
1216 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1218 if (xmlstr_cmp(&attr_name
, optionalW
))
1220 static const WCHAR yesW
[] = {'y','e','s',0};
1221 optional
= xmlstr_cmpi( &attr_value
, yesW
);
1222 TRACE("optional=%s\n", debugstr_xmlstr(&attr_value
));
1226 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1230 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1232 if (xmlstr_cmp_end(&elem
, dependencyW
))
1234 ret
= parse_end_element(xmlbuf
);
1237 else if (xmlstr_cmp(&elem
, dependentAssemblyW
))
1239 ret
= parse_dependent_assembly_elem(xmlbuf
, acl
, optional
);
1243 WARN("unknown element %s\n", debugstr_xmlstr(&elem
));
1244 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1251 static BOOL
parse_noinherit_elem(xmlbuf_t
* xmlbuf
)
1255 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1256 return end
|| parse_expect_end_elem(xmlbuf
, noInheritW
);
1259 static BOOL
parse_noinheritable_elem(xmlbuf_t
* xmlbuf
)
1263 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1264 return end
|| parse_expect_end_elem(xmlbuf
, noInheritableW
);
1267 static BOOL
parse_file_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1269 xmlstr_t attr_name
, attr_value
, elem
;
1270 BOOL end
= FALSE
, error
, ret
= TRUE
;
1271 struct dll_redirect
* dll
;
1273 if (!(dll
= add_dll_redirect(assembly
))) return FALSE
;
1275 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1277 if (xmlstr_cmp(&attr_name
, nameW
))
1279 if (!(dll
->name
= xmlstrdupW(&attr_value
))) return FALSE
;
1280 TRACE("name=%s\n", debugstr_xmlstr(&attr_value
));
1282 else if (xmlstr_cmp(&attr_name
, hashW
))
1284 if (!(dll
->hash
= xmlstrdupW(&attr_value
))) return FALSE
;
1286 else if (xmlstr_cmp(&attr_name
, hashalgW
))
1288 static const WCHAR sha1W
[] = {'S','H','A','1',0};
1289 if (!xmlstr_cmpi(&attr_value
, sha1W
))
1290 FIXME("hashalg should be SHA1, got %s\n", debugstr_xmlstr(&attr_value
));
1294 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1298 if (error
|| !dll
->name
) return FALSE
;
1299 if (end
) return TRUE
;
1301 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1303 if (xmlstr_cmp_end(&elem
, fileW
))
1305 ret
= parse_end_element(xmlbuf
);
1308 else if (xmlstr_cmp(&elem
, comClassW
))
1310 ret
= parse_com_class_elem(xmlbuf
, dll
);
1312 else if (xmlstr_cmp(&elem
, comInterfaceProxyStubW
))
1314 ret
= parse_cominterface_proxy_stub_elem(xmlbuf
, dll
);
1316 else if (xmlstr_cmp(&elem
, asmv2hashW
))
1318 WARN("asmv2hash (undocumented) not supported\n");
1319 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1321 else if (xmlstr_cmp(&elem
, typelibW
))
1323 ret
= parse_typelib_elem(xmlbuf
, dll
);
1325 else if (xmlstr_cmp(&elem
, windowClassW
))
1327 ret
= parse_window_class_elem(xmlbuf
, dll
);
1331 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1332 ret
= parse_unknown_elem( xmlbuf
, &elem
);
1339 static BOOL
parse_assembly_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
,
1340 struct assembly
* assembly
,
1341 struct assembly_identity
* expected_ai
)
1343 xmlstr_t attr_name
, attr_value
, elem
;
1344 BOOL end
= FALSE
, error
, version
= FALSE
, xmlns
= FALSE
, ret
= TRUE
;
1346 TRACE("(%p)\n", xmlbuf
);
1348 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1350 if (xmlstr_cmp(&attr_name
, manifestVersionW
))
1352 static const WCHAR v10W
[] = {'1','.','0',0};
1353 if (!xmlstr_cmp(&attr_value
, v10W
))
1355 FIXME("wrong version %s\n", debugstr_xmlstr(&attr_value
));
1360 else if (xmlstr_cmp(&attr_name
, xmlnsW
))
1362 if (!xmlstr_cmp(&attr_value
, manifestv1W
) && !xmlstr_cmp(&attr_value
, manifestv3W
))
1364 FIXME("wrong namespace %s\n", debugstr_xmlstr(&attr_value
));
1371 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1375 if (error
|| end
|| !xmlns
|| !version
) return FALSE
;
1376 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
1378 if (assembly
->type
== APPLICATION_MANIFEST
&& xmlstr_cmp(&elem
, noInheritW
))
1380 if (!parse_noinherit_elem(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
))
1382 assembly
->no_inherit
= TRUE
;
1385 if (xmlstr_cmp(&elem
, noInheritableW
))
1387 if (!parse_noinheritable_elem(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
))
1390 else if ((assembly
->type
== ASSEMBLY_MANIFEST
|| assembly
->type
== ASSEMBLY_SHARED_MANIFEST
) &&
1391 assembly
->no_inherit
)
1396 if (xmlstr_cmp_end(&elem
, assemblyW
))
1398 ret
= parse_end_element(xmlbuf
);
1401 else if (xmlstr_cmp(&elem
, descriptionW
))
1403 ret
= parse_description_elem(xmlbuf
);
1405 else if (xmlstr_cmp(&elem
, comInterfaceExternalProxyStubW
))
1407 ret
= parse_com_interface_external_proxy_stub_elem(xmlbuf
, assembly
);
1409 else if (xmlstr_cmp(&elem
, dependencyW
))
1411 ret
= parse_dependency_elem(xmlbuf
, acl
);
1413 else if (xmlstr_cmp(&elem
, fileW
))
1415 ret
= parse_file_elem(xmlbuf
, assembly
);
1417 else if (xmlstr_cmp(&elem
, clrClassW
))
1419 ret
= parse_clr_class_elem(xmlbuf
, assembly
);
1421 else if (xmlstr_cmp(&elem
, clrSurrogateW
))
1423 ret
= parse_clr_surrogate_elem(xmlbuf
, assembly
);
1425 else if (xmlstr_cmp(&elem
, assemblyIdentityW
))
1427 if (!parse_assembly_identity_elem(xmlbuf
, acl
->actctx
, &assembly
->id
)) return FALSE
;
1431 /* FIXME: more tests */
1432 if (assembly
->type
== ASSEMBLY_MANIFEST
&&
1433 memcmp(&assembly
->id
.version
, &expected_ai
->version
, sizeof(assembly
->id
.version
)))
1435 FIXME("wrong version for assembly manifest: %u.%u.%u.%u / %u.%u.%u.%u\n",
1436 expected_ai
->version
.major
, expected_ai
->version
.minor
,
1437 expected_ai
->version
.build
, expected_ai
->version
.revision
,
1438 assembly
->id
.version
.major
, assembly
->id
.version
.minor
,
1439 assembly
->id
.version
.build
, assembly
->id
.version
.revision
);
1442 else if (assembly
->type
== ASSEMBLY_SHARED_MANIFEST
&&
1443 (assembly
->id
.version
.major
!= expected_ai
->version
.major
||
1444 assembly
->id
.version
.minor
!= expected_ai
->version
.minor
||
1445 assembly
->id
.version
.build
< expected_ai
->version
.build
||
1446 (assembly
->id
.version
.build
== expected_ai
->version
.build
&&
1447 assembly
->id
.version
.revision
< expected_ai
->version
.revision
)))
1449 FIXME("wrong version for shared assembly manifest\n");
1456 WARN("unknown element %s\n", debugstr_xmlstr(&elem
));
1457 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1459 if (ret
) ret
= next_xml_elem(xmlbuf
, &elem
);
1465 static NTSTATUS
parse_manifest_buffer( struct actctx_loader
* acl
, struct assembly
*assembly
,
1466 struct assembly_identity
* ai
, xmlbuf_t
*xmlbuf
)
1470 if (!next_xml_elem(xmlbuf
, &elem
)) return STATUS_SXS_CANT_GEN_ACTCTX
;
1472 if (xmlstr_cmp(&elem
, xmlW
) &&
1473 (!parse_xml_header(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
)))
1474 return STATUS_SXS_CANT_GEN_ACTCTX
;
1476 if (!xmlstr_cmp(&elem
, assemblyW
))
1478 FIXME("root element is %s, not <assembly>\n", debugstr_xmlstr(&elem
));
1479 return STATUS_SXS_CANT_GEN_ACTCTX
;
1482 if (!parse_assembly_elem(xmlbuf
, acl
, assembly
, ai
))
1484 FIXME("failed to parse manifest %s\n", debugstr_w(assembly
->manifest
.info
) );
1485 return STATUS_SXS_CANT_GEN_ACTCTX
;
1488 if (next_xml_elem(xmlbuf
, &elem
))
1490 FIXME("unexpected element %s\n", debugstr_xmlstr(&elem
));
1491 return STATUS_SXS_CANT_GEN_ACTCTX
;
1494 if (xmlbuf
->ptr
!= xmlbuf
->end
)
1496 FIXME("parse error\n");
1497 return STATUS_SXS_CANT_GEN_ACTCTX
;
1499 return STATUS_SUCCESS
;
1502 static NTSTATUS
parse_manifest( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1503 LPCWSTR filename
, LPCWSTR directory
, BOOL shared
,
1504 const void *buffer
, SIZE_T size
)
1508 struct assembly
*assembly
;
1511 TRACE( "parsing manifest loaded from %s base dir %s\n", debugstr_w(filename
), debugstr_w(directory
) );
1513 if (!(assembly
= add_assembly(acl
->actctx
, shared
? ASSEMBLY_SHARED_MANIFEST
: ASSEMBLY_MANIFEST
)))
1514 return STATUS_SXS_CANT_GEN_ACTCTX
;
1516 if (directory
&& !(assembly
->directory
= strdupW(directory
)))
1517 return STATUS_NO_MEMORY
;
1519 if (filename
) assembly
->manifest
.info
= strdupW( filename
+ 4 /* skip \??\ prefix */ );
1520 assembly
->manifest
.type
= assembly
->manifest
.info
? ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE
1521 : ACTIVATION_CONTEXT_PATH_TYPE_NONE
;
1523 unicode_tests
= IS_TEXT_UNICODE_SIGNATURE
| IS_TEXT_UNICODE_REVERSE_SIGNATURE
;
1524 if (RtlIsTextUnicode( buffer
, size
, &unicode_tests
))
1526 xmlbuf
.ptr
= buffer
;
1527 xmlbuf
.end
= xmlbuf
.ptr
+ size
/ sizeof(WCHAR
);
1528 status
= parse_manifest_buffer( acl
, assembly
, ai
, &xmlbuf
);
1530 else if (unicode_tests
& IS_TEXT_UNICODE_REVERSE_SIGNATURE
)
1532 const WCHAR
*buf
= buffer
;
1536 if (!(new_buff
= RtlAllocateHeap( GetProcessHeap(), 0, size
)))
1537 return STATUS_NO_MEMORY
;
1538 for (i
= 0; i
< size
/ sizeof(WCHAR
); i
++)
1539 new_buff
[i
] = RtlUshortByteSwap( buf
[i
] );
1540 xmlbuf
.ptr
= new_buff
;
1541 xmlbuf
.end
= xmlbuf
.ptr
+ size
/ sizeof(WCHAR
);
1542 status
= parse_manifest_buffer( acl
, assembly
, ai
, &xmlbuf
);
1543 RtlFreeHeap( GetProcessHeap(), 0, new_buff
);
1547 /* let's assume utf-8 for now */
1548 int len
= wine_utf8_mbstowcs( 0, buffer
, size
, NULL
, 0 );
1553 FIXME( "utf-8 conversion failed\n" );
1554 return STATUS_SXS_CANT_GEN_ACTCTX
;
1556 if (!(new_buff
= RtlAllocateHeap( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
1557 return STATUS_NO_MEMORY
;
1558 wine_utf8_mbstowcs( 0, buffer
, size
, new_buff
, len
);
1559 xmlbuf
.ptr
= new_buff
;
1560 xmlbuf
.end
= xmlbuf
.ptr
+ len
;
1561 status
= parse_manifest_buffer( acl
, assembly
, ai
, &xmlbuf
);
1562 RtlFreeHeap( GetProcessHeap(), 0, new_buff
);
1567 static NTSTATUS
open_nt_file( HANDLE
*handle
, UNICODE_STRING
*name
)
1569 OBJECT_ATTRIBUTES attr
;
1572 attr
.Length
= sizeof(attr
);
1573 attr
.RootDirectory
= 0;
1574 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1575 attr
.ObjectName
= name
;
1576 attr
.SecurityDescriptor
= NULL
;
1577 attr
.SecurityQualityOfService
= NULL
;
1578 return NtOpenFile( handle
, GENERIC_READ
, &attr
, &io
, FILE_SHARE_READ
, FILE_SYNCHRONOUS_IO_ALERT
);
1581 static NTSTATUS
get_module_filename( HMODULE module
, UNICODE_STRING
*str
, unsigned int extra_len
)
1587 LdrLockLoaderLock(0, NULL
, &magic
);
1588 status
= LdrFindEntryForAddress( module
, &pldr
);
1589 if (status
== STATUS_SUCCESS
)
1591 if ((str
->Buffer
= RtlAllocateHeap( GetProcessHeap(), 0,
1592 pldr
->FullDllName
.Length
+ extra_len
+ sizeof(WCHAR
) )))
1594 memcpy( str
->Buffer
, pldr
->FullDllName
.Buffer
, pldr
->FullDllName
.Length
+ sizeof(WCHAR
) );
1595 str
->Length
= pldr
->FullDllName
.Length
;
1596 str
->MaximumLength
= pldr
->FullDllName
.Length
+ extra_len
+ sizeof(WCHAR
);
1598 else status
= STATUS_NO_MEMORY
;
1600 LdrUnlockLoaderLock(0, magic
);
1604 static NTSTATUS
get_manifest_in_module( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1605 LPCWSTR filename
, LPCWSTR directory
, BOOL shared
,
1606 HANDLE hModule
, LPCWSTR resname
, ULONG lang
)
1609 UNICODE_STRING nameW
;
1610 LDR_RESOURCE_INFO info
;
1611 const IMAGE_RESOURCE_DATA_ENTRY
* entry
= NULL
;
1614 if (TRACE_ON(actctx
))
1616 if (!filename
&& !get_module_filename( hModule
, &nameW
, 0 ))
1618 TRACE( "looking for res %s in module %p %s\n", debugstr_w(resname
),
1619 hModule
, debugstr_w(nameW
.Buffer
) );
1620 RtlFreeUnicodeString( &nameW
);
1622 else TRACE( "looking for res %s in module %p %s\n", debugstr_w(resname
),
1623 hModule
, debugstr_w(filename
) );
1626 if (!resname
) return STATUS_INVALID_PARAMETER
;
1628 info
.Type
= RT_MANIFEST
;
1629 info
.Language
= lang
;
1630 if (!((ULONG_PTR
)resname
>> 16))
1632 info
.Name
= (ULONG_PTR
)resname
;
1633 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
1635 else if (resname
[0] == '#')
1638 RtlInitUnicodeString(&nameW
, resname
+ 1);
1639 if (RtlUnicodeStringToInteger(&nameW
, 10, &value
) != STATUS_SUCCESS
|| HIWORD(value
))
1640 return STATUS_INVALID_PARAMETER
;
1642 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
1646 RtlCreateUnicodeString(&nameW
, resname
);
1647 RtlUpcaseUnicodeString(&nameW
, &nameW
, FALSE
);
1648 info
.Name
= (ULONG_PTR
)nameW
.Buffer
;
1649 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
1650 RtlFreeUnicodeString(&nameW
);
1652 if (status
== STATUS_SUCCESS
) status
= LdrAccessResource(hModule
, entry
, &ptr
, NULL
);
1654 if (status
== STATUS_SUCCESS
)
1655 status
= parse_manifest(acl
, ai
, filename
, directory
, shared
, ptr
, entry
->Size
);
1660 static NTSTATUS
get_manifest_in_pe_file( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1661 LPCWSTR filename
, LPCWSTR directory
, BOOL shared
,
1662 HANDLE file
, LPCWSTR resname
, ULONG lang
)
1665 OBJECT_ATTRIBUTES attr
;
1667 LARGE_INTEGER offset
;
1672 TRACE( "looking for res %s in %s\n", debugstr_w(resname
), debugstr_w(filename
) );
1674 attr
.Length
= sizeof(attr
);
1675 attr
.RootDirectory
= 0;
1676 attr
.ObjectName
= NULL
;
1677 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
1678 attr
.SecurityDescriptor
= NULL
;
1679 attr
.SecurityQualityOfService
= NULL
;
1682 status
= NtCreateSection( &mapping
, STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
| SECTION_MAP_READ
,
1683 &attr
, &size
, PAGE_READONLY
, SEC_COMMIT
, file
);
1684 if (status
!= STATUS_SUCCESS
) return status
;
1686 offset
.QuadPart
= 0;
1689 status
= NtMapViewOfSection( mapping
, GetCurrentProcess(), &base
, 0, 0, &offset
,
1690 &count
, ViewShare
, 0, PAGE_READONLY
);
1692 if (status
!= STATUS_SUCCESS
) return status
;
1694 if (RtlImageNtHeader(base
)) /* we got a PE file */
1696 HANDLE module
= (HMODULE
)((ULONG_PTR
)base
| 1); /* make it a LOAD_LIBRARY_AS_DATAFILE handle */
1697 status
= get_manifest_in_module( acl
, ai
, filename
, directory
, shared
, module
, resname
, lang
);
1699 else status
= STATUS_INVALID_IMAGE_FORMAT
;
1701 NtUnmapViewOfSection( GetCurrentProcess(), base
);
1705 static NTSTATUS
get_manifest_in_manifest_file( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1706 LPCWSTR filename
, LPCWSTR directory
, BOOL shared
, HANDLE file
)
1708 FILE_END_OF_FILE_INFORMATION info
;
1711 OBJECT_ATTRIBUTES attr
;
1713 LARGE_INTEGER offset
;
1718 TRACE( "loading manifest file %s\n", debugstr_w(filename
) );
1720 attr
.Length
= sizeof(attr
);
1721 attr
.RootDirectory
= 0;
1722 attr
.ObjectName
= NULL
;
1723 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
1724 attr
.SecurityDescriptor
= NULL
;
1725 attr
.SecurityQualityOfService
= NULL
;
1728 status
= NtCreateSection( &mapping
, STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
| SECTION_MAP_READ
,
1729 &attr
, &size
, PAGE_READONLY
, SEC_COMMIT
, file
);
1730 if (status
!= STATUS_SUCCESS
) return status
;
1732 offset
.QuadPart
= 0;
1735 status
= NtMapViewOfSection( mapping
, GetCurrentProcess(), &base
, 0, 0, &offset
,
1736 &count
, ViewShare
, 0, PAGE_READONLY
);
1738 if (status
!= STATUS_SUCCESS
) return status
;
1740 status
= NtQueryInformationFile( file
, &io
, &info
, sizeof(info
), FileEndOfFileInformation
);
1741 if (status
== STATUS_SUCCESS
)
1742 status
= parse_manifest(acl
, ai
, filename
, directory
, shared
, base
, info
.EndOfFile
.QuadPart
);
1744 NtUnmapViewOfSection( GetCurrentProcess(), base
);
1748 /* try to load the .manifest file associated to the file */
1749 static NTSTATUS
get_manifest_in_associated_manifest( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1750 LPCWSTR filename
, LPCWSTR directory
, HMODULE module
, LPCWSTR resname
)
1752 static const WCHAR fmtW
[] = { '.','%','l','u',0 };
1755 UNICODE_STRING nameW
;
1757 ULONG_PTR resid
= CREATEPROCESS_MANIFEST_RESOURCE_ID
;
1759 if (!((ULONG_PTR
)resname
>> 16)) resid
= (ULONG_PTR
)resname
& 0xffff;
1761 TRACE( "looking for manifest associated with %s id %lu\n", debugstr_w(filename
), resid
);
1763 if (module
) /* use the module filename */
1765 UNICODE_STRING name
;
1767 if (!(status
= get_module_filename( module
, &name
, sizeof(dotManifestW
) + 10*sizeof(WCHAR
) )))
1769 if (resid
!= 1) sprintfW( name
.Buffer
+ strlenW(name
.Buffer
), fmtW
, resid
);
1770 strcatW( name
.Buffer
, dotManifestW
);
1771 if (!RtlDosPathNameToNtPathName_U( name
.Buffer
, &nameW
, NULL
, NULL
))
1772 status
= STATUS_RESOURCE_DATA_NOT_FOUND
;
1773 RtlFreeUnicodeString( &name
);
1775 if (status
) return status
;
1779 if (!(buffer
= RtlAllocateHeap( GetProcessHeap(), 0,
1780 (strlenW(filename
) + 10) * sizeof(WCHAR
) + sizeof(dotManifestW
) )))
1781 return STATUS_NO_MEMORY
;
1782 strcpyW( buffer
, filename
);
1783 if (resid
!= 1) sprintfW( buffer
+ strlenW(buffer
), fmtW
, resid
);
1784 strcatW( buffer
, dotManifestW
);
1785 RtlInitUnicodeString( &nameW
, buffer
);
1788 if (!open_nt_file( &file
, &nameW
))
1790 status
= get_manifest_in_manifest_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
);
1793 else status
= STATUS_RESOURCE_DATA_NOT_FOUND
;
1794 RtlFreeUnicodeString( &nameW
);
1798 static WCHAR
*lookup_manifest_file( HANDLE dir
, struct assembly_identity
*ai
)
1800 static const WCHAR lookup_fmtW
[] =
1801 {'%','s','_','%','s','_','%','s','_','%','u','.','%','u','.','*','.','*','_',
1803 '.','m','a','n','i','f','e','s','t',0};
1805 WCHAR
*lookup
, *ret
= NULL
;
1806 UNICODE_STRING lookup_us
;
1808 unsigned int data_pos
= 0, data_len
;
1811 if (!(lookup
= RtlAllocateHeap( GetProcessHeap(), 0,
1812 (strlenW(ai
->arch
) + strlenW(ai
->name
)
1813 + strlenW(ai
->public_key
) + 20) * sizeof(WCHAR
)
1814 + sizeof(lookup_fmtW
) )))
1817 sprintfW( lookup
, lookup_fmtW
, ai
->arch
, ai
->name
, ai
->public_key
, ai
->version
.major
, ai
->version
.minor
);
1818 RtlInitUnicodeString( &lookup_us
, lookup
);
1820 NtQueryDirectoryFile( dir
, 0, NULL
, NULL
, &io
, buffer
, sizeof(buffer
),
1821 FileBothDirectoryInformation
, FALSE
, &lookup_us
, TRUE
);
1822 if (io
.u
.Status
== STATUS_SUCCESS
)
1824 FILE_BOTH_DIR_INFORMATION
*dir_info
;
1826 ULONG build
, revision
;
1828 data_len
= io
.Information
;
1832 if (data_pos
>= data_len
)
1834 NtQueryDirectoryFile( dir
, 0, NULL
, NULL
, &io
, buffer
, sizeof(buffer
),
1835 FileBothDirectoryInformation
, FALSE
, &lookup_us
, FALSE
);
1836 if (io
.u
.Status
!= STATUS_SUCCESS
) break;
1837 data_len
= io
.Information
;
1840 dir_info
= (FILE_BOTH_DIR_INFORMATION
*)(buffer
+ data_pos
);
1842 if (dir_info
->NextEntryOffset
) data_pos
+= dir_info
->NextEntryOffset
;
1843 else data_pos
= data_len
;
1845 tmp
= (WCHAR
*)dir_info
->FileName
+ (strchrW(lookup
, '*') - lookup
);
1847 if (build
< ai
->version
.build
) continue;
1848 tmp
= strchrW(tmp
, '.') + 1;
1849 revision
= atoiW(tmp
);
1850 if (build
== ai
->version
.build
&& revision
< ai
->version
.revision
)
1852 ai
->version
.build
= build
;
1853 ai
->version
.revision
= revision
;
1854 if ((ret
= RtlAllocateHeap( GetProcessHeap(), 0, dir_info
->FileNameLength
+ sizeof(WCHAR
) )))
1856 memcpy( ret
, dir_info
->FileName
, dir_info
->FileNameLength
);
1857 ret
[dir_info
->FileNameLength
/sizeof(WCHAR
)] = 0;
1862 else WARN("no matching file for %s\n", debugstr_w(lookup
));
1863 RtlFreeHeap( GetProcessHeap(), 0, lookup
);
1867 static NTSTATUS
lookup_winsxs(struct actctx_loader
* acl
, struct assembly_identity
* ai
)
1869 struct assembly_identity sxs_ai
;
1870 UNICODE_STRING path_us
;
1871 OBJECT_ATTRIBUTES attr
;
1873 WCHAR
*path
, *file
= NULL
;
1876 static const WCHAR manifest_dirW
[] =
1877 {'\\','w','i','n','s','x','s','\\','m','a','n','i','f','e','s','t','s',0};
1879 if (!ai
->arch
|| !ai
->name
|| !ai
->public_key
) return STATUS_NO_SUCH_FILE
;
1881 if (!(path
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(manifest_dirW
) +
1882 strlenW(user_shared_data
->NtSystemRoot
) * sizeof(WCHAR
) )))
1883 return STATUS_NO_MEMORY
;
1885 strcpyW( path
, user_shared_data
->NtSystemRoot
);
1886 memcpy( path
+ strlenW(path
), manifest_dirW
, sizeof(manifest_dirW
) );
1888 if (!RtlDosPathNameToNtPathName_U( path
, &path_us
, NULL
, NULL
))
1890 RtlFreeHeap( GetProcessHeap(), 0, path
);
1891 return STATUS_NO_SUCH_FILE
;
1893 RtlFreeHeap( GetProcessHeap(), 0, path
);
1895 attr
.Length
= sizeof(attr
);
1896 attr
.RootDirectory
= 0;
1897 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1898 attr
.ObjectName
= &path_us
;
1899 attr
.SecurityDescriptor
= NULL
;
1900 attr
.SecurityQualityOfService
= NULL
;
1902 if (!NtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1903 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
))
1906 file
= lookup_manifest_file( handle
, &sxs_ai
);
1911 RtlFreeUnicodeString( &path_us
);
1912 return STATUS_NO_SUCH_FILE
;
1915 /* append file name to directory path */
1916 if (!(path
= RtlReAllocateHeap( GetProcessHeap(), 0, path_us
.Buffer
,
1917 path_us
.Length
+ (strlenW(file
) + 2) * sizeof(WCHAR
) )))
1919 RtlFreeHeap( GetProcessHeap(), 0, file
);
1920 RtlFreeUnicodeString( &path_us
);
1921 return STATUS_NO_MEMORY
;
1924 path
[path_us
.Length
/sizeof(WCHAR
)] = '\\';
1925 strcpyW( path
+ path_us
.Length
/sizeof(WCHAR
) + 1, file
);
1926 RtlInitUnicodeString( &path_us
, path
);
1927 *strrchrW(file
, '.') = 0; /* remove .manifest extension */
1929 if (!open_nt_file( &handle
, &path_us
))
1931 io
.u
.Status
= get_manifest_in_manifest_file(acl
, &sxs_ai
, path_us
.Buffer
, file
, TRUE
, handle
);
1934 else io
.u
.Status
= STATUS_NO_SUCH_FILE
;
1936 RtlFreeHeap( GetProcessHeap(), 0, file
);
1937 RtlFreeUnicodeString( &path_us
);
1941 static NTSTATUS
lookup_assembly(struct actctx_loader
* acl
,
1942 struct assembly_identity
* ai
)
1944 static const WCHAR dotDllW
[] = {'.','d','l','l',0};
1946 WCHAR
*buffer
, *p
, *directory
;
1948 UNICODE_STRING nameW
;
1951 TRACE( "looking for name=%s version=%s arch=%s\n",
1952 debugstr_w(ai
->name
), debugstr_version(&ai
->version
), debugstr_w(ai
->arch
) );
1954 if ((status
= lookup_winsxs(acl
, ai
)) != STATUS_NO_SUCH_FILE
) return status
;
1956 /* FIXME: add support for language specific lookup */
1958 nameW
.Buffer
= NULL
;
1959 if (!(buffer
= RtlAllocateHeap( GetProcessHeap(), 0,
1960 (strlenW(acl
->actctx
->appdir
.info
) + 2 * strlenW(ai
->name
) + 2) * sizeof(WCHAR
) + sizeof(dotManifestW
) )))
1961 return STATUS_NO_MEMORY
;
1963 if (!(directory
= build_assembly_dir( ai
)))
1965 RtlFreeHeap( GetProcessHeap(), 0, buffer
);
1966 return STATUS_NO_MEMORY
;
1969 /* lookup in appdir\name.dll
1970 * appdir\name.manifest
1971 * appdir\name\name.dll
1972 * appdir\name\name.manifest
1974 strcpyW( buffer
, acl
->actctx
->appdir
.info
);
1975 p
= buffer
+ strlenW(buffer
);
1976 for (i
= 0; i
< 2; i
++)
1979 strcpyW( p
, ai
->name
);
1982 strcpyW( p
, dotDllW
);
1983 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
1985 status
= open_nt_file( &file
, &nameW
);
1988 status
= get_manifest_in_pe_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
,
1989 (LPCWSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
, 0 );
1993 RtlFreeUnicodeString( &nameW
);
1996 strcpyW( p
, dotManifestW
);
1997 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
1999 status
= open_nt_file( &file
, &nameW
);
2002 status
= get_manifest_in_manifest_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
);
2006 RtlFreeUnicodeString( &nameW
);
2008 status
= STATUS_SXS_ASSEMBLY_NOT_FOUND
;
2010 RtlFreeUnicodeString( &nameW
);
2011 RtlFreeHeap( GetProcessHeap(), 0, directory
);
2012 RtlFreeHeap( GetProcessHeap(), 0, buffer
);
2016 static NTSTATUS
parse_depend_manifests(struct actctx_loader
* acl
)
2018 NTSTATUS status
= STATUS_SUCCESS
;
2021 for (i
= 0; i
< acl
->num_dependencies
; i
++)
2023 if (lookup_assembly(acl
, &acl
->dependencies
[i
]) != STATUS_SUCCESS
)
2025 if (!acl
->dependencies
[i
].optional
)
2027 FIXME( "Could not find dependent assembly %s (%s)\n",
2028 debugstr_w(acl
->dependencies
[i
].name
),
2029 debugstr_version(&acl
->dependencies
[i
].version
) );
2030 status
= STATUS_SXS_CANT_GEN_ACTCTX
;
2035 /* FIXME should now iterate through all refs */
2039 /* find the appropriate activation context for RtlQueryInformationActivationContext */
2040 static NTSTATUS
find_query_actctx( HANDLE
*handle
, DWORD flags
, ULONG
class )
2042 NTSTATUS status
= STATUS_SUCCESS
;
2044 if (flags
& QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX
)
2046 if (*handle
) return STATUS_INVALID_PARAMETER
;
2048 if (NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2049 *handle
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
->ActivationContext
;
2051 else if (flags
& (QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS
|QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
))
2056 if (!*handle
) return STATUS_INVALID_PARAMETER
;
2058 LdrLockLoaderLock( 0, NULL
, &magic
);
2059 if (!LdrFindEntryForAddress( *handle
, &pldr
))
2061 if ((flags
& QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
) && *handle
!= pldr
->BaseAddress
)
2062 status
= STATUS_DLL_NOT_FOUND
;
2064 *handle
= pldr
->ActivationContext
;
2066 else status
= STATUS_DLL_NOT_FOUND
;
2067 LdrUnlockLoaderLock( 0, magic
);
2069 else if (!*handle
&& (class != ActivationContextBasicInformation
))
2070 *handle
= process_actctx
;
2075 static NTSTATUS
fill_keyed_data(PACTCTX_SECTION_KEYED_DATA data
, PVOID v1
, PVOID v2
, unsigned int i
)
2077 data
->ulDataFormatVersion
= 1;
2079 data
->ulLength
= 20; /* FIXME */
2080 data
->lpSectionGlobalData
= NULL
; /* FIXME */
2081 data
->ulSectionGlobalDataLength
= 0; /* FIXME */
2082 data
->lpSectionBase
= v2
;
2083 data
->ulSectionTotalLength
= 0; /* FIXME */
2084 data
->hActCtx
= NULL
;
2085 if (data
->cbSize
>= offsetof(ACTCTX_SECTION_KEYED_DATA
, ulAssemblyRosterIndex
) + sizeof(ULONG
))
2086 data
->ulAssemblyRosterIndex
= i
+ 1;
2088 return STATUS_SUCCESS
;
2091 static NTSTATUS
find_dll_redirection(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2092 PACTCTX_SECTION_KEYED_DATA data
)
2094 unsigned int i
, j
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2096 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2098 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2099 for (j
= 0; j
< assembly
->num_dlls
; j
++)
2101 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
2102 if (!strncmpiW(section_name
->Buffer
, dll
->name
, snlen
) && !dll
->name
[snlen
])
2103 return fill_keyed_data(data
, dll
, assembly
, i
);
2106 return STATUS_SXS_KEY_NOT_FOUND
;
2109 static NTSTATUS
find_window_class(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2110 PACTCTX_SECTION_KEYED_DATA data
)
2112 unsigned int i
, j
, k
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2114 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2116 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2117 for (j
= 0; j
< assembly
->num_dlls
; j
++)
2119 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
2120 for (k
= 0; k
< dll
->entities
.num
; k
++)
2122 struct entity
*entity
= &dll
->entities
.base
[k
];
2123 if (entity
->kind
== ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
)
2125 if (!strncmpiW(section_name
->Buffer
, entity
->u
.class.name
, snlen
) && !entity
->u
.class.name
[snlen
])
2126 return fill_keyed_data(data
, entity
, dll
, i
);
2131 return STATUS_SXS_KEY_NOT_FOUND
;
2134 static NTSTATUS
find_string(ACTIVATION_CONTEXT
* actctx
, ULONG section_kind
,
2135 const UNICODE_STRING
*section_name
,
2136 DWORD flags
, PACTCTX_SECTION_KEYED_DATA data
)
2140 switch (section_kind
)
2142 case ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
:
2143 status
= find_dll_redirection(actctx
, section_name
, data
);
2145 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
:
2146 status
= find_window_class(actctx
, section_name
, data
);
2148 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
:
2149 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
:
2150 case ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
:
2151 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
:
2152 case ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE
:
2153 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
:
2154 FIXME("Unsupported yet section_kind %x\n", section_kind
);
2155 return STATUS_SXS_SECTION_NOT_FOUND
;
2157 WARN("Unknown section_kind %x\n", section_kind
);
2158 return STATUS_SXS_SECTION_NOT_FOUND
;
2161 if (status
!= STATUS_SUCCESS
) return status
;
2163 if (flags
& FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
)
2165 actctx_addref(actctx
);
2166 data
->hActCtx
= actctx
;
2168 return STATUS_SUCCESS
;
2171 /* initialize the activation context for the current process */
2172 void actctx_init(void)
2177 ctx
.cbSize
= sizeof(ctx
);
2178 ctx
.lpSource
= NULL
;
2179 ctx
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
| ACTCTX_FLAG_HMODULE_VALID
;
2180 ctx
.hModule
= NtCurrentTeb()->Peb
->ImageBaseAddress
;
2181 ctx
.lpResourceName
= (LPCWSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
2183 if (!RtlCreateActivationContext( &handle
, &ctx
)) process_actctx
= check_actctx(handle
);
2187 /***********************************************************************
2188 * RtlCreateActivationContext (NTDLL.@)
2190 * Create an activation context.
2192 * FIXME: function signature/prototype is wrong
2194 NTSTATUS WINAPI
RtlCreateActivationContext( HANDLE
*handle
, const void *ptr
)
2196 const ACTCTXW
*pActCtx
= ptr
; /* FIXME: not the right structure */
2197 const WCHAR
*directory
= NULL
;
2198 ACTIVATION_CONTEXT
*actctx
;
2199 UNICODE_STRING nameW
;
2201 NTSTATUS status
= STATUS_NO_MEMORY
;
2203 struct actctx_loader acl
;
2205 TRACE("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
2207 if (!pActCtx
|| pActCtx
->cbSize
< sizeof(*pActCtx
) ||
2208 (pActCtx
->dwFlags
& ~ACTCTX_FLAGS_ALL
))
2209 return STATUS_INVALID_PARAMETER
;
2211 if (!(actctx
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*actctx
) )))
2212 return STATUS_NO_MEMORY
;
2214 actctx
->magic
= ACTCTX_MAGIC
;
2215 actctx
->ref_count
= 1;
2216 actctx
->config
.type
= ACTIVATION_CONTEXT_PATH_TYPE_NONE
;
2217 actctx
->config
.info
= NULL
;
2218 actctx
->appdir
.type
= ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE
;
2219 if (pActCtx
->dwFlags
& ACTCTX_FLAG_APPLICATION_NAME_VALID
)
2221 if (!(actctx
->appdir
.info
= strdupW( pActCtx
->lpApplicationName
))) goto error
;
2229 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
) module
= pActCtx
->hModule
;
2230 else module
= NtCurrentTeb()->Peb
->ImageBaseAddress
;
2232 if ((status
= get_module_filename( module
, &dir
, 0 ))) goto error
;
2233 if ((p
= strrchrW( dir
.Buffer
, '\\' ))) p
[1] = 0;
2234 actctx
->appdir
.info
= dir
.Buffer
;
2237 nameW
.Buffer
= NULL
;
2238 if (pActCtx
->lpSource
)
2240 if (!RtlDosPathNameToNtPathName_U(pActCtx
->lpSource
, &nameW
, NULL
, NULL
))
2242 status
= STATUS_NO_SUCH_FILE
;
2245 status
= open_nt_file( &file
, &nameW
);
2248 RtlFreeUnicodeString( &nameW
);
2253 acl
.actctx
= actctx
;
2254 acl
.dependencies
= NULL
;
2255 acl
.num_dependencies
= 0;
2256 acl
.allocated_dependencies
= 0;
2258 if (pActCtx
->dwFlags
& ACTCTX_FLAG_LANGID_VALID
) lang
= pActCtx
->wLangId
;
2259 if (pActCtx
->dwFlags
& ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID
) directory
= pActCtx
->lpAssemblyDirectory
;
2261 if (pActCtx
->dwFlags
& ACTCTX_FLAG_RESOURCE_NAME_VALID
)
2263 /* if we have a resource it's a PE file */
2264 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
)
2266 status
= get_manifest_in_module( &acl
, NULL
, NULL
, directory
, FALSE
, pActCtx
->hModule
,
2267 pActCtx
->lpResourceName
, lang
);
2268 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2269 /* FIXME: what to do if pActCtx->lpSource is set */
2270 status
= get_manifest_in_associated_manifest( &acl
, NULL
, NULL
, directory
,
2271 pActCtx
->hModule
, pActCtx
->lpResourceName
);
2273 else if (pActCtx
->lpSource
)
2275 status
= get_manifest_in_pe_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
,
2276 file
, pActCtx
->lpResourceName
, lang
);
2277 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2278 status
= get_manifest_in_associated_manifest( &acl
, NULL
, nameW
.Buffer
, directory
,
2279 NULL
, pActCtx
->lpResourceName
);
2281 else status
= STATUS_INVALID_PARAMETER
;
2285 status
= get_manifest_in_manifest_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
, file
);
2288 if (file
) NtClose( file
);
2289 RtlFreeUnicodeString( &nameW
);
2291 if (status
== STATUS_SUCCESS
) status
= parse_depend_manifests(&acl
);
2292 free_depend_manifests( &acl
);
2294 if (status
== STATUS_SUCCESS
) *handle
= actctx
;
2295 else actctx_release( actctx
);
2299 if (file
) NtClose( file
);
2300 actctx_release( actctx
);
2305 /***********************************************************************
2306 * RtlAddRefActivationContext (NTDLL.@)
2308 void WINAPI
RtlAddRefActivationContext( HANDLE handle
)
2310 ACTIVATION_CONTEXT
*actctx
;
2312 if ((actctx
= check_actctx( handle
))) actctx_addref( actctx
);
2316 /******************************************************************
2317 * RtlReleaseActivationContext (NTDLL.@)
2319 void WINAPI
RtlReleaseActivationContext( HANDLE handle
)
2321 ACTIVATION_CONTEXT
*actctx
;
2323 if ((actctx
= check_actctx( handle
))) actctx_release( actctx
);
2327 /******************************************************************
2328 * RtlActivateActivationContext (NTDLL.@)
2330 NTSTATUS WINAPI
RtlActivateActivationContext( ULONG unknown
, HANDLE handle
, PULONG_PTR cookie
)
2332 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2334 if (!(frame
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*frame
) )))
2335 return STATUS_NO_MEMORY
;
2337 frame
->Previous
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
;
2338 frame
->ActivationContext
= handle
;
2340 NtCurrentTeb()->ActivationContextStack
.ActiveFrame
= frame
;
2341 RtlAddRefActivationContext( handle
);
2343 *cookie
= (ULONG_PTR
)frame
;
2344 TRACE( "%p cookie=%lx\n", handle
, *cookie
);
2345 return STATUS_SUCCESS
;
2349 /***********************************************************************
2350 * RtlDeactivateActivationContext (NTDLL.@)
2352 void WINAPI
RtlDeactivateActivationContext( ULONG flags
, ULONG_PTR cookie
)
2354 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
, *top
;
2356 TRACE( "%x cookie=%lx\n", flags
, cookie
);
2358 /* find the right frame */
2359 top
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
;
2360 for (frame
= top
; frame
; frame
= frame
->Previous
)
2361 if ((ULONG_PTR
)frame
== cookie
) break;
2364 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION
);
2366 if (frame
!= top
&& !(flags
& DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION
))
2367 RtlRaiseStatus( STATUS_SXS_EARLY_DEACTIVATION
);
2369 /* pop everything up to and including frame */
2370 NtCurrentTeb()->ActivationContextStack
.ActiveFrame
= frame
->Previous
;
2372 while (top
!= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2374 frame
= top
->Previous
;
2375 RtlReleaseActivationContext( top
->ActivationContext
);
2376 RtlFreeHeap( GetProcessHeap(), 0, top
);
2382 /******************************************************************
2383 * RtlFreeThreadActivationContextStack (NTDLL.@)
2385 void WINAPI
RtlFreeThreadActivationContextStack(void)
2387 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2389 frame
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
;
2392 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*prev
= frame
->Previous
;
2393 RtlReleaseActivationContext( frame
->ActivationContext
);
2394 RtlFreeHeap( GetProcessHeap(), 0, frame
);
2397 NtCurrentTeb()->ActivationContextStack
.ActiveFrame
= NULL
;
2401 /******************************************************************
2402 * RtlGetActiveActivationContext (NTDLL.@)
2404 NTSTATUS WINAPI
RtlGetActiveActivationContext( HANDLE
*handle
)
2406 if (NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2408 *handle
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
->ActivationContext
;
2409 RtlAddRefActivationContext( *handle
);
2414 return STATUS_SUCCESS
;
2418 /******************************************************************
2419 * RtlIsActivationContextActive (NTDLL.@)
2421 BOOLEAN WINAPI
RtlIsActivationContextActive( HANDLE handle
)
2423 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2425 for (frame
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
; frame
; frame
= frame
->Previous
)
2426 if (frame
->ActivationContext
== handle
) return TRUE
;
2431 /***********************************************************************
2432 * RtlQueryInformationActivationContext (NTDLL.@)
2434 * Get information about an activation context.
2435 * FIXME: function signature/prototype may be wrong
2437 NTSTATUS WINAPI
RtlQueryInformationActivationContext( ULONG flags
, HANDLE handle
, PVOID subinst
,
2438 ULONG
class, PVOID buffer
,
2439 SIZE_T bufsize
, SIZE_T
*retlen
)
2441 ACTIVATION_CONTEXT
*actctx
;
2444 TRACE("%08x %p %p %u %p %ld %p\n", flags
, handle
,
2445 subinst
, class, buffer
, bufsize
, retlen
);
2447 if (retlen
) *retlen
= 0;
2448 if ((status
= find_query_actctx( &handle
, flags
, class ))) return status
;
2452 case ActivationContextBasicInformation
:
2454 ACTIVATION_CONTEXT_BASIC_INFORMATION
*info
= buffer
;
2456 if (retlen
) *retlen
= sizeof(*info
);
2457 if (!info
|| bufsize
< sizeof(*info
)) return STATUS_BUFFER_TOO_SMALL
;
2459 info
->hActCtx
= handle
;
2460 info
->dwFlags
= 0; /* FIXME */
2461 if (!(flags
& QUERY_ACTCTX_FLAG_NO_ADDREF
)) RtlAddRefActivationContext( handle
);
2465 case ActivationContextDetailedInformation
:
2467 ACTIVATION_CONTEXT_DETAILED_INFORMATION
*acdi
= buffer
;
2468 struct assembly
*assembly
= NULL
;
2469 SIZE_T len
, manifest_len
= 0, config_len
= 0, appdir_len
= 0;
2472 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2474 if (actctx
->num_assemblies
) assembly
= actctx
->assemblies
;
2476 if (assembly
&& assembly
->manifest
.info
)
2477 manifest_len
= strlenW(assembly
->manifest
.info
) + 1;
2478 if (actctx
->config
.info
) config_len
= strlenW(actctx
->config
.info
) + 1;
2479 if (actctx
->appdir
.info
) appdir_len
= strlenW(actctx
->appdir
.info
) + 1;
2480 len
= sizeof(*acdi
) + (manifest_len
+ config_len
+ appdir_len
) * sizeof(WCHAR
);
2482 if (retlen
) *retlen
= len
;
2483 if (!buffer
|| bufsize
< len
) return STATUS_BUFFER_TOO_SMALL
;
2486 acdi
->ulFormatVersion
= assembly
? 1 : 0; /* FIXME */
2487 acdi
->ulAssemblyCount
= actctx
->num_assemblies
;
2488 acdi
->ulRootManifestPathType
= assembly
? assembly
->manifest
.type
: 0 /* FIXME */;
2489 acdi
->ulRootManifestPathChars
= assembly
&& assembly
->manifest
.info
? manifest_len
- 1 : 0;
2490 acdi
->ulRootConfigurationPathType
= actctx
->config
.type
;
2491 acdi
->ulRootConfigurationPathChars
= actctx
->config
.info
? config_len
- 1 : 0;
2492 acdi
->ulAppDirPathType
= actctx
->appdir
.type
;
2493 acdi
->ulAppDirPathChars
= actctx
->appdir
.info
? appdir_len
- 1 : 0;
2494 ptr
= (LPWSTR
)(acdi
+ 1);
2497 acdi
->lpRootManifestPath
= ptr
;
2498 memcpy(ptr
, assembly
->manifest
.info
, manifest_len
* sizeof(WCHAR
));
2499 ptr
+= manifest_len
;
2501 else acdi
->lpRootManifestPath
= NULL
;
2504 acdi
->lpRootConfigurationPath
= ptr
;
2505 memcpy(ptr
, actctx
->config
.info
, config_len
* sizeof(WCHAR
));
2508 else acdi
->lpRootConfigurationPath
= NULL
;
2511 acdi
->lpAppDirPath
= ptr
;
2512 memcpy(ptr
, actctx
->appdir
.info
, appdir_len
* sizeof(WCHAR
));
2514 else acdi
->lpAppDirPath
= NULL
;
2518 case AssemblyDetailedInformationInActivationContext
:
2520 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION
*afdi
= buffer
;
2521 struct assembly
*assembly
;
2524 SIZE_T len
, id_len
= 0, ad_len
= 0, path_len
= 0;
2527 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2528 if (!subinst
) return STATUS_INVALID_PARAMETER
;
2530 index
= *(DWORD
*)subinst
;
2531 if (!index
|| index
> actctx
->num_assemblies
) return STATUS_INVALID_PARAMETER
;
2533 assembly
= &actctx
->assemblies
[index
- 1];
2535 if (!(assembly_id
= build_assembly_id( &assembly
->id
))) return STATUS_NO_MEMORY
;
2536 id_len
= strlenW(assembly_id
) + 1;
2537 if (assembly
->directory
) ad_len
= strlenW(assembly
->directory
) + 1;
2539 if (assembly
->manifest
.info
&&
2540 (assembly
->type
== ASSEMBLY_MANIFEST
|| assembly
->type
== ASSEMBLY_SHARED_MANIFEST
))
2541 path_len
= strlenW(assembly
->manifest
.info
) + 1;
2543 len
= sizeof(*afdi
) + (id_len
+ ad_len
+ path_len
) * sizeof(WCHAR
);
2545 if (retlen
) *retlen
= len
;
2546 if (!buffer
|| bufsize
< len
)
2548 RtlFreeHeap( GetProcessHeap(), 0, assembly_id
);
2549 return STATUS_BUFFER_TOO_SMALL
;
2552 afdi
->ulFlags
= 0; /* FIXME */
2553 afdi
->ulEncodedAssemblyIdentityLength
= (id_len
- 1) * sizeof(WCHAR
);
2554 afdi
->ulManifestPathType
= assembly
->manifest
.type
;
2555 afdi
->ulManifestPathLength
= assembly
->manifest
.info
? (path_len
- 1) * sizeof(WCHAR
) : 0;
2556 /* FIXME afdi->liManifestLastWriteTime = 0; */
2557 afdi
->ulPolicyPathType
= ACTIVATION_CONTEXT_PATH_TYPE_NONE
; /* FIXME */
2558 afdi
->ulPolicyPathLength
= 0;
2559 /* FIXME afdi->liPolicyLastWriteTime = 0; */
2560 afdi
->ulMetadataSatelliteRosterIndex
= 0; /* FIXME */
2561 afdi
->ulManifestVersionMajor
= 1;
2562 afdi
->ulManifestVersionMinor
= 0;
2563 afdi
->ulPolicyVersionMajor
= 0; /* FIXME */
2564 afdi
->ulPolicyVersionMinor
= 0; /* FIXME */
2565 afdi
->ulAssemblyDirectoryNameLength
= ad_len
? (ad_len
- 1) * sizeof(WCHAR
) : 0;
2566 ptr
= (LPWSTR
)(afdi
+ 1);
2567 afdi
->lpAssemblyEncodedAssemblyIdentity
= ptr
;
2568 memcpy( ptr
, assembly_id
, id_len
* sizeof(WCHAR
) );
2572 afdi
->lpAssemblyManifestPath
= ptr
;
2573 memcpy(ptr
, assembly
->manifest
.info
, path_len
* sizeof(WCHAR
));
2575 } else afdi
->lpAssemblyManifestPath
= NULL
;
2576 afdi
->lpAssemblyPolicyPath
= NULL
; /* FIXME */
2579 afdi
->lpAssemblyDirectoryName
= ptr
;
2580 memcpy(ptr
, assembly
->directory
, ad_len
* sizeof(WCHAR
));
2583 else afdi
->lpAssemblyDirectoryName
= NULL
;
2584 RtlFreeHeap( GetProcessHeap(), 0, assembly_id
);
2588 case FileInformationInAssemblyOfAssemblyInActivationContext
:
2590 const ACTIVATION_CONTEXT_QUERY_INDEX
*acqi
= subinst
;
2591 ASSEMBLY_FILE_DETAILED_INFORMATION
*afdi
= buffer
;
2592 struct assembly
*assembly
;
2593 struct dll_redirect
*dll
;
2594 SIZE_T len
, dll_len
= 0;
2597 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2598 if (!acqi
) return STATUS_INVALID_PARAMETER
;
2600 if (acqi
->ulAssemblyIndex
>= actctx
->num_assemblies
)
2601 return STATUS_INVALID_PARAMETER
;
2602 assembly
= &actctx
->assemblies
[acqi
->ulAssemblyIndex
];
2604 if (acqi
->ulFileIndexInAssembly
>= assembly
->num_dlls
)
2605 return STATUS_INVALID_PARAMETER
;
2606 dll
= &assembly
->dlls
[acqi
->ulFileIndexInAssembly
];
2608 if (dll
->name
) dll_len
= strlenW(dll
->name
) + 1;
2609 len
= sizeof(*afdi
) + dll_len
* sizeof(WCHAR
);
2611 if (!buffer
|| bufsize
< len
)
2613 if (retlen
) *retlen
= len
;
2614 return STATUS_BUFFER_TOO_SMALL
;
2616 if (retlen
) *retlen
= 0; /* yes that's what native does !! */
2617 afdi
->ulFlags
= ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
;
2618 afdi
->ulFilenameLength
= dll_len
? (dll_len
- 1) * sizeof(WCHAR
) : 0;
2619 afdi
->ulPathLength
= 0; /* FIXME */
2620 ptr
= (LPWSTR
)(afdi
+ 1);
2623 afdi
->lpFileName
= ptr
;
2624 memcpy( ptr
, dll
->name
, dll_len
* sizeof(WCHAR
) );
2625 } else afdi
->lpFileName
= NULL
;
2626 afdi
->lpFilePath
= NULL
; /* FIXME */
2631 FIXME( "class %u not implemented\n", class );
2632 return STATUS_NOT_IMPLEMENTED
;
2634 return STATUS_SUCCESS
;
2637 /***********************************************************************
2638 * RtlFindActivationContextSectionString (NTDLL.@)
2640 * Find information about a string in an activation context.
2641 * FIXME: function signature/prototype may be wrong
2643 NTSTATUS WINAPI
RtlFindActivationContextSectionString( ULONG flags
, const GUID
*guid
, ULONG section_kind
,
2644 const UNICODE_STRING
*section_name
, PVOID ptr
)
2646 PACTCTX_SECTION_KEYED_DATA data
= ptr
;
2647 NTSTATUS status
= STATUS_SXS_KEY_NOT_FOUND
;
2649 TRACE("%08x %s %u %s %p\n", flags
, debugstr_guid(guid
), section_kind
,
2650 debugstr_us(section_name
), data
);
2654 FIXME("expected guid == NULL\n");
2655 return STATUS_INVALID_PARAMETER
;
2657 if (flags
& ~FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
)
2659 FIXME("unknown flags %08x\n", flags
);
2660 return STATUS_INVALID_PARAMETER
;
2662 if (!data
|| data
->cbSize
< offsetof(ACTCTX_SECTION_KEYED_DATA
, ulAssemblyRosterIndex
) ||
2663 !section_name
|| !section_name
->Buffer
)
2665 WARN("invalid parameter\n");
2666 return STATUS_INVALID_PARAMETER
;
2669 if (NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2671 ACTIVATION_CONTEXT
*actctx
= check_actctx(NtCurrentTeb()->ActivationContextStack
.ActiveFrame
->ActivationContext
);
2672 if (actctx
) status
= find_string( actctx
, section_kind
, section_name
, flags
, data
);
2675 if (status
!= STATUS_SUCCESS
)
2676 status
= find_string( process_actctx
, section_kind
, section_name
, flags
, data
);