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
35 #include "ntdll_misc.h"
36 #include "wine/exception.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(actctx
);
42 #define ACTCTX_FLAGS_ALL (\
43 ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID |\
44 ACTCTX_FLAG_LANGID_VALID |\
45 ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID |\
46 ACTCTX_FLAG_RESOURCE_NAME_VALID |\
47 ACTCTX_FLAG_SET_PROCESS_DEFAULT |\
48 ACTCTX_FLAG_APPLICATION_NAME_VALID |\
49 ACTCTX_FLAG_SOURCE_IS_ASSEMBLYREF |\
50 ACTCTX_FLAG_HMODULE_VALID )
52 #define ACTCTX_MAGIC 0xC07E3E11
54 /* we don't want to include winuser.h */
55 #define RT_MANIFEST ((ULONG_PTR)24)
56 #define CREATEPROCESS_MANIFEST_RESOURCE_ID ((ULONG_PTR)1)
76 struct assembly_version
84 struct assembly_identity
91 struct assembly_version version
;
135 unsigned int allocated
;
142 struct entity_array entities
;
147 APPLICATION_MANIFEST
,
149 ASSEMBLY_SHARED_MANIFEST
,
154 enum assembly_type type
;
155 struct assembly_identity id
;
156 struct file_info manifest
;
159 struct dll_redirect
*dlls
;
160 unsigned int num_dlls
;
161 unsigned int allocated_dlls
;
162 struct entity_array entities
;
165 typedef struct _ACTIVATION_CONTEXT
169 struct file_info config
;
170 struct file_info appdir
;
171 struct assembly
*assemblies
;
172 unsigned int num_assemblies
;
173 unsigned int allocated_assemblies
;
174 } ACTIVATION_CONTEXT
;
178 ACTIVATION_CONTEXT
*actctx
;
179 struct assembly_identity
*dependencies
;
180 unsigned int num_dependencies
;
181 unsigned int allocated_dependencies
;
184 static const WCHAR assemblyW
[] = {'a','s','s','e','m','b','l','y',0};
185 static const WCHAR assemblyIdentityW
[] = {'a','s','s','e','m','b','l','y','I','d','e','n','t','i','t','y',0};
186 static const WCHAR bindingRedirectW
[] = {'b','i','n','d','i','n','g','R','e','d','i','r','e','c','t',0};
187 static const WCHAR clrClassW
[] = {'c','l','r','C','l','a','s','s',0};
188 static const WCHAR clrSurrogateW
[] = {'c','l','r','S','u','r','r','o','g','a','t','e',0};
189 static const WCHAR comClassW
[] = {'c','o','m','C','l','a','s','s',0};
190 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};
191 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};
192 static const WCHAR dependencyW
[] = {'d','e','p','e','n','d','e','n','c','y',0};
193 static const WCHAR dependentAssemblyW
[] = {'d','e','p','e','n','d','e','n','t','A','s','s','e','m','b','l','y',0};
194 static const WCHAR descriptionW
[] = {'d','e','s','c','r','i','p','t','i','o','n',0};
195 static const WCHAR fileW
[] = {'f','i','l','e',0};
196 static const WCHAR asmv2hashW
[] = {'a','s','m','v','2',':','h','a','s','h',0};
197 static const WCHAR noInheritW
[] = {'n','o','I','n','h','e','r','i','t',0};
198 static const WCHAR noInheritableW
[] = {'n','o','I','n','h','e','r','i','t','a','b','l','e',0};
199 static const WCHAR typelibW
[] = {'t','y','p','e','l','i','b',0};
200 static const WCHAR windowClassW
[] = {'w','i','n','d','o','w','C','l','a','s','s',0};
202 static const WCHAR clsidW
[] = {'c','l','s','i','d',0};
203 static const WCHAR hashW
[] = {'h','a','s','h',0};
204 static const WCHAR hashalgW
[] = {'h','a','s','h','a','l','g',0};
205 static const WCHAR helpdirW
[] = {'h','e','l','p','d','i','r',0};
206 static const WCHAR iidW
[] = {'i','i','d',0};
207 static const WCHAR languageW
[] = {'l','a','n','g','u','a','g','e',0};
208 static const WCHAR manifestVersionW
[] = {'m','a','n','i','f','e','s','t','V','e','r','s','i','o','n',0};
209 static const WCHAR nameW
[] = {'n','a','m','e',0};
210 static const WCHAR newVersionW
[] = {'n','e','w','V','e','r','s','i','o','n',0};
211 static const WCHAR oldVersionW
[] = {'o','l','d','V','e','r','s','i','o','n',0};
212 static const WCHAR optionalW
[] = {'o','p','t','i','o','n','a','l',0};
213 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};
214 static const WCHAR publicKeyTokenW
[] = {'p','u','b','l','i','c','K','e','y','T','o','k','e','n',0};
215 static const WCHAR tlbidW
[] = {'t','l','b','i','d',0};
216 static const WCHAR typeW
[] = {'t','y','p','e',0};
217 static const WCHAR versionW
[] = {'v','e','r','s','i','o','n',0};
218 static const WCHAR xmlnsW
[] = {'x','m','l','n','s',0};
220 static const WCHAR xmlW
[] = {'?','x','m','l',0};
221 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};
222 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};
224 static const WCHAR dotManifestW
[] = {'.','m','a','n','i','f','e','s','t',0};
225 static const WCHAR version_formatW
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
227 static ACTIVATION_CONTEXT system_actctx
= { ACTCTX_MAGIC
, 1 };
228 static ACTIVATION_CONTEXT
*process_actctx
= &system_actctx
;
230 static WCHAR
*strdupW(const WCHAR
* str
)
234 if (!(ptr
= RtlAllocateHeap(GetProcessHeap(), 0, (strlenW(str
) + 1) * sizeof(WCHAR
))))
236 return strcpyW(ptr
, str
);
239 static WCHAR
*xmlstrdupW(const xmlstr_t
* str
)
243 if ((strW
= RtlAllocateHeap(GetProcessHeap(), 0, (str
->len
+ 1) * sizeof(WCHAR
))))
245 memcpy( strW
, str
->ptr
, str
->len
* sizeof(WCHAR
) );
251 static inline BOOL
xmlstr_cmp(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
253 return !strncmpW(xmlstr
->ptr
, str
, xmlstr
->len
) && !str
[xmlstr
->len
];
256 static inline BOOL
xmlstr_cmpi(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
258 return !strncmpiW(xmlstr
->ptr
, str
, xmlstr
->len
) && !str
[xmlstr
->len
];
261 static inline BOOL
xmlstr_cmp_end(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
263 return (xmlstr
->len
&& xmlstr
->ptr
[0] == '/' &&
264 !strncmpW(xmlstr
->ptr
+ 1, str
, xmlstr
->len
- 1) && !str
[xmlstr
->len
- 1]);
267 static inline BOOL
isxmlspace( WCHAR ch
)
269 return (ch
== ' ' || ch
== '\r' || ch
== '\n' || ch
== '\t');
272 static inline const char* debugstr_xmlstr(const xmlstr_t
* str
)
274 return debugstr_wn(str
->ptr
, str
->len
);
277 static inline const char* debugstr_version(const struct assembly_version
*ver
)
279 return wine_dbg_sprintf("%u.%u.%u.%u", ver
->major
, ver
->minor
, ver
->build
, ver
->revision
);
282 static struct assembly
*add_assembly(ACTIVATION_CONTEXT
*actctx
, enum assembly_type at
)
284 struct assembly
*assembly
;
286 if (actctx
->num_assemblies
== actctx
->allocated_assemblies
)
289 unsigned int new_count
;
290 if (actctx
->assemblies
)
292 new_count
= actctx
->allocated_assemblies
* 2;
293 ptr
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
294 actctx
->assemblies
, new_count
* sizeof(*assembly
) );
299 ptr
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*assembly
) );
301 if (!ptr
) return NULL
;
302 actctx
->assemblies
= ptr
;
303 actctx
->allocated_assemblies
= new_count
;
306 assembly
= &actctx
->assemblies
[actctx
->num_assemblies
++];
311 static struct dll_redirect
* add_dll_redirect(struct assembly
* assembly
)
313 if (assembly
->num_dlls
== assembly
->allocated_dlls
)
316 unsigned int new_count
;
319 new_count
= assembly
->allocated_dlls
* 2;
320 ptr
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
321 assembly
->dlls
, new_count
* sizeof(*assembly
->dlls
) );
326 ptr
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*assembly
->dlls
) );
328 if (!ptr
) return NULL
;
329 assembly
->dlls
= ptr
;
330 assembly
->allocated_dlls
= new_count
;
332 return &assembly
->dlls
[assembly
->num_dlls
++];
335 static void free_assembly_identity(struct assembly_identity
*ai
)
337 RtlFreeHeap( GetProcessHeap(), 0, ai
->name
);
338 RtlFreeHeap( GetProcessHeap(), 0, ai
->arch
);
339 RtlFreeHeap( GetProcessHeap(), 0, ai
->public_key
);
340 RtlFreeHeap( GetProcessHeap(), 0, ai
->language
);
343 static struct entity
* add_entity(struct entity_array
*array
, DWORD kind
)
345 struct entity
* entity
;
347 if (array
->num
== array
->allocated
)
350 unsigned int new_count
;
353 new_count
= array
->allocated
* 2;
354 ptr
= RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
,
355 array
->base
, new_count
* sizeof(*array
->base
) );
360 ptr
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*array
->base
) );
362 if (!ptr
) return NULL
;
364 array
->allocated
= new_count
;
366 entity
= &array
->base
[array
->num
++];
371 static void free_entity_array(struct entity_array
*array
)
374 for (i
= 0; i
< array
->num
; i
++)
376 struct entity
*entity
= &array
->base
[i
];
377 switch (entity
->kind
)
379 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
:
380 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.comclass
.clsid
);
382 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
:
383 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.proxy
.iid
);
384 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.proxy
.name
);
386 case ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
:
387 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.typelib
.tlbid
);
388 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.typelib
.version
);
389 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.typelib
.helpdir
);
391 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
:
392 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.class.name
);
394 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
:
395 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrclass
.name
);
396 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrclass
.clsid
);
398 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
:
399 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrsurrogate
.name
);
400 RtlFreeHeap(GetProcessHeap(), 0, entity
->u
.clrsurrogate
.clsid
);
403 FIXME("Unknown entity kind %d\n", entity
->kind
);
406 RtlFreeHeap( GetProcessHeap(), 0, array
->base
);
409 static BOOL
is_matching_string( const WCHAR
*str1
, const WCHAR
*str2
)
411 if (!str1
) return !str2
;
412 return str2
&& !strcmpiW( str1
, str2
);
415 static BOOL
is_matching_identity( const struct assembly_identity
*id1
,
416 const struct assembly_identity
*id2
)
418 if (!is_matching_string( id1
->name
, id2
->name
)) return FALSE
;
419 if (!is_matching_string( id1
->arch
, id2
->arch
)) return FALSE
;
420 if (!is_matching_string( id1
->public_key
, id2
->public_key
)) return FALSE
;
422 if (id1
->language
&& id2
->language
&& strcmpiW( id1
->language
, id2
->language
))
424 static const WCHAR wildcardW
[] = {'*',0};
425 if (strcmpW( wildcardW
, id1
->language
) && strcmpW( wildcardW
, id2
->language
))
428 if (id1
->version
.major
!= id2
->version
.major
) return FALSE
;
429 if (id1
->version
.minor
!= id2
->version
.minor
) return FALSE
;
430 if (id1
->version
.build
> id2
->version
.build
) return FALSE
;
431 if (id1
->version
.build
== id2
->version
.build
&&
432 id1
->version
.revision
> id2
->version
.revision
) return FALSE
;
436 static BOOL
add_dependent_assembly_id(struct actctx_loader
* acl
,
437 struct assembly_identity
* ai
)
441 /* check if we already have that assembly */
443 for (i
= 0; i
< acl
->actctx
->num_assemblies
; i
++)
444 if (is_matching_identity( ai
, &acl
->actctx
->assemblies
[i
].id
))
446 TRACE( "reusing existing assembly for %s arch %s version %u.%u.%u.%u\n",
447 debugstr_w(ai
->name
), debugstr_w(ai
->arch
), ai
->version
.major
, ai
->version
.minor
,
448 ai
->version
.build
, ai
->version
.revision
);
452 for (i
= 0; i
< acl
->num_dependencies
; i
++)
453 if (is_matching_identity( ai
, &acl
->dependencies
[i
] ))
455 TRACE( "reusing existing dependency for %s arch %s version %u.%u.%u.%u\n",
456 debugstr_w(ai
->name
), debugstr_w(ai
->arch
), ai
->version
.major
, ai
->version
.minor
,
457 ai
->version
.build
, ai
->version
.revision
);
461 if (acl
->num_dependencies
== acl
->allocated_dependencies
)
464 unsigned int new_count
;
465 if (acl
->dependencies
)
467 new_count
= acl
->allocated_dependencies
* 2;
468 ptr
= RtlReAllocateHeap(GetProcessHeap(), 0, acl
->dependencies
,
469 new_count
* sizeof(acl
->dependencies
[0]));
474 ptr
= RtlAllocateHeap(GetProcessHeap(), 0, new_count
* sizeof(acl
->dependencies
[0]));
476 if (!ptr
) return FALSE
;
477 acl
->dependencies
= ptr
;
478 acl
->allocated_dependencies
= new_count
;
480 acl
->dependencies
[acl
->num_dependencies
++] = *ai
;
485 static void free_depend_manifests(struct actctx_loader
* acl
)
488 for (i
= 0; i
< acl
->num_dependencies
; i
++)
489 free_assembly_identity(&acl
->dependencies
[i
]);
490 RtlFreeHeap(GetProcessHeap(), 0, acl
->dependencies
);
493 static WCHAR
*build_assembly_dir(struct assembly_identity
* ai
)
495 static const WCHAR undW
[] = {'_',0};
496 static const WCHAR noneW
[] = {'n','o','n','e',0};
497 static const WCHAR mskeyW
[] = {'d','e','a','d','b','e','e','f',0};
499 const WCHAR
*arch
= ai
->arch
? ai
->arch
: noneW
;
500 const WCHAR
*key
= ai
->public_key
? ai
->public_key
: noneW
;
501 const WCHAR
*lang
= ai
->language
? ai
->language
: noneW
;
502 const WCHAR
*name
= ai
->name
? ai
->name
: noneW
;
503 SIZE_T size
= (strlenW(arch
) + 1 + strlenW(name
) + 1 + strlenW(key
) + 24 + 1 +
504 strlenW(lang
) + 1) * sizeof(WCHAR
) + sizeof(mskeyW
);
507 if (!(ret
= RtlAllocateHeap( GetProcessHeap(), 0, size
))) return NULL
;
509 strcpyW( ret
, arch
);
510 strcatW( ret
, undW
);
511 strcatW( ret
, name
);
512 strcatW( ret
, undW
);
514 strcatW( ret
, undW
);
515 sprintfW( ret
+ strlenW(ret
), version_formatW
,
516 ai
->version
.major
, ai
->version
.minor
, ai
->version
.build
, ai
->version
.revision
);
517 strcatW( ret
, undW
);
518 strcatW( ret
, lang
);
519 strcatW( ret
, undW
);
520 strcatW( ret
, mskeyW
);
524 static inline void append_string( WCHAR
*buffer
, const WCHAR
*prefix
, const WCHAR
*str
)
529 strcatW( buffer
, prefix
);
538 static WCHAR
*build_assembly_id( const struct assembly_identity
*ai
)
540 static const WCHAR archW
[] =
541 {',','p','r','o','c','e','s','s','o','r','A','r','c','h','i','t','e','c','t','u','r','e','=',0};
542 static const WCHAR public_keyW
[] =
543 {',','p','u','b','l','i','c','K','e','y','T','o','k','e','n','=',0};
544 static const WCHAR typeW
[] =
545 {',','t','y','p','e','=',0};
546 static const WCHAR versionW
[] =
547 {',','v','e','r','s','i','o','n','=',0};
549 WCHAR version
[64], *ret
;
552 sprintfW( version
, version_formatW
,
553 ai
->version
.major
, ai
->version
.minor
, ai
->version
.build
, ai
->version
.revision
);
554 if (ai
->name
) size
+= strlenW(ai
->name
) * sizeof(WCHAR
);
555 if (ai
->arch
) size
+= strlenW(archW
) + strlenW(ai
->arch
) + 2;
556 if (ai
->public_key
) size
+= strlenW(public_keyW
) + strlenW(ai
->public_key
) + 2;
557 if (ai
->type
) size
+= strlenW(typeW
) + strlenW(ai
->type
) + 2;
558 size
+= strlenW(versionW
) + strlenW(version
) + 2;
560 if (!(ret
= RtlAllocateHeap( GetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
) )))
563 if (ai
->name
) strcpyW( ret
, ai
->name
);
565 append_string( ret
, archW
, ai
->arch
);
566 append_string( ret
, public_keyW
, ai
->public_key
);
567 append_string( ret
, typeW
, ai
->type
);
568 append_string( ret
, versionW
, version
);
572 static ACTIVATION_CONTEXT
*check_actctx( HANDLE h
)
574 ACTIVATION_CONTEXT
*ret
= NULL
, *actctx
= h
;
576 if (!h
|| h
== INVALID_HANDLE_VALUE
) return NULL
;
579 if (actctx
->magic
== ACTCTX_MAGIC
) ret
= actctx
;
588 static inline void actctx_addref( ACTIVATION_CONTEXT
*actctx
)
590 interlocked_xchg_add( &actctx
->ref_count
, 1 );
593 static void actctx_release( ACTIVATION_CONTEXT
*actctx
)
595 if (interlocked_xchg_add( &actctx
->ref_count
, -1 ) == 1)
599 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
601 struct assembly
*assembly
= &actctx
->assemblies
[i
];
602 for (j
= 0; j
< assembly
->num_dlls
; j
++)
604 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
605 free_entity_array( &dll
->entities
);
606 RtlFreeHeap( GetProcessHeap(), 0, dll
->name
);
607 RtlFreeHeap( GetProcessHeap(), 0, dll
->hash
);
609 RtlFreeHeap( GetProcessHeap(), 0, assembly
->dlls
);
610 RtlFreeHeap( GetProcessHeap(), 0, assembly
->manifest
.info
);
611 RtlFreeHeap( GetProcessHeap(), 0, assembly
->directory
);
612 free_entity_array( &assembly
->entities
);
613 free_assembly_identity(&assembly
->id
);
615 RtlFreeHeap( GetProcessHeap(), 0, actctx
->config
.info
);
616 RtlFreeHeap( GetProcessHeap(), 0, actctx
->appdir
.info
);
617 RtlFreeHeap( GetProcessHeap(), 0, actctx
->assemblies
);
619 RtlFreeHeap( GetProcessHeap(), 0, actctx
);
623 static BOOL
next_xml_attr(xmlbuf_t
* xmlbuf
, xmlstr_t
* name
, xmlstr_t
* value
,
624 BOOL
* error
, BOOL
* end
)
630 while (xmlbuf
->ptr
< xmlbuf
->end
&& isxmlspace(*xmlbuf
->ptr
))
633 if (xmlbuf
->ptr
== xmlbuf
->end
) return FALSE
;
635 if (*xmlbuf
->ptr
== '/')
638 if (xmlbuf
->ptr
== xmlbuf
->end
|| *xmlbuf
->ptr
!= '>')
647 if (*xmlbuf
->ptr
== '>')
655 while (ptr
< xmlbuf
->end
&& *ptr
!= '=' && *ptr
!= '>' && !isxmlspace(*ptr
)) ptr
++;
657 if (ptr
== xmlbuf
->end
|| *ptr
!= '=') return FALSE
;
659 name
->ptr
= xmlbuf
->ptr
;
660 name
->len
= ptr
-xmlbuf
->ptr
;
664 if (ptr
== xmlbuf
->end
|| (*ptr
!= '"' && *ptr
!= '\'')) return FALSE
;
667 if (ptr
== xmlbuf
->end
) return FALSE
;
669 ptr
= memchrW(ptr
, ptr
[-1], xmlbuf
->end
- ptr
);
672 xmlbuf
->ptr
= xmlbuf
->end
;
676 value
->len
= ptr
- value
->ptr
;
677 xmlbuf
->ptr
= ptr
+ 1;
679 if (xmlbuf
->ptr
== xmlbuf
->end
) return FALSE
;
685 static BOOL
next_xml_elem(xmlbuf_t
* xmlbuf
, xmlstr_t
* elem
)
691 ptr
= memchrW(xmlbuf
->ptr
, '<', xmlbuf
->end
- xmlbuf
->ptr
);
694 xmlbuf
->ptr
= xmlbuf
->end
;
698 if (ptr
+ 3 < xmlbuf
->end
&& ptr
[0] == '!' && ptr
[1] == '-' && ptr
[2] == '-') /* skip comment */
700 for (ptr
+= 3; ptr
+ 3 <= xmlbuf
->end
; ptr
++)
701 if (ptr
[0] == '-' && ptr
[1] == '-' && ptr
[2] == '>') break;
703 if (ptr
+ 3 > xmlbuf
->end
)
705 xmlbuf
->ptr
= xmlbuf
->end
;
708 xmlbuf
->ptr
= ptr
+ 3;
714 while (ptr
< xmlbuf
->end
&& !isxmlspace(*ptr
) && *ptr
!= '>' && (*ptr
!= '/' || ptr
== xmlbuf
->ptr
))
717 elem
->ptr
= xmlbuf
->ptr
;
718 elem
->len
= ptr
- xmlbuf
->ptr
;
720 return xmlbuf
->ptr
!= xmlbuf
->end
;
723 static BOOL
parse_xml_header(xmlbuf_t
* xmlbuf
)
725 /* FIXME: parse attributes */
728 for (ptr
= xmlbuf
->ptr
; ptr
< xmlbuf
->end
- 1; ptr
++)
730 if (ptr
[0] == '?' && ptr
[1] == '>')
732 xmlbuf
->ptr
= ptr
+ 2;
739 static BOOL
parse_text_content(xmlbuf_t
* xmlbuf
, xmlstr_t
* content
)
741 const WCHAR
*ptr
= memchrW(xmlbuf
->ptr
, '<', xmlbuf
->end
- xmlbuf
->ptr
);
743 if (!ptr
) return FALSE
;
745 content
->ptr
= xmlbuf
->ptr
;
746 content
->len
= ptr
- xmlbuf
->ptr
;
752 static BOOL
parse_version(const xmlstr_t
*str
, struct assembly_version
*version
)
758 /* major.minor.build.revision */
759 ver
[0] = ver
[1] = ver
[2] = ver
[3] = pos
= 0;
760 for (curr
= str
->ptr
; curr
< str
->ptr
+ str
->len
; curr
++)
762 if (*curr
>= '0' && *curr
<= '9')
764 ver
[pos
] = ver
[pos
] * 10 + *curr
- '0';
765 if (ver
[pos
] >= 0x10000) goto error
;
767 else if (*curr
== '.')
769 if (++pos
>= 4) goto error
;
773 version
->major
= ver
[0];
774 version
->minor
= ver
[1];
775 version
->build
= ver
[2];
776 version
->revision
= ver
[3];
780 FIXME( "Wrong version definition in manifest file (%s)\n", debugstr_xmlstr(str
) );
784 static BOOL
parse_expect_elem(xmlbuf_t
* xmlbuf
, const WCHAR
* name
)
787 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
788 if (xmlstr_cmp(&elem
, name
)) return TRUE
;
789 FIXME( "unexpected element %s\n", debugstr_xmlstr(&elem
) );
793 static BOOL
parse_expect_no_attr(xmlbuf_t
* xmlbuf
, BOOL
* end
)
795 xmlstr_t attr_name
, attr_value
;
798 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, end
))
800 WARN("unexpected attr %s=%s\n", debugstr_xmlstr(&attr_name
),
801 debugstr_xmlstr(&attr_value
));
806 static BOOL
parse_end_element(xmlbuf_t
*xmlbuf
)
809 return parse_expect_no_attr(xmlbuf
, &end
) && !end
;
812 static BOOL
parse_expect_end_elem(xmlbuf_t
*xmlbuf
, const WCHAR
*name
)
815 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
816 if (!xmlstr_cmp_end(&elem
, name
))
818 FIXME( "unexpected element %s\n", debugstr_xmlstr(&elem
) );
821 return parse_end_element(xmlbuf
);
824 static BOOL
parse_unknown_elem(xmlbuf_t
*xmlbuf
, const xmlstr_t
*unknown_elem
)
826 xmlstr_t attr_name
, attr_value
, elem
;
827 BOOL end
= FALSE
, error
, ret
= TRUE
;
829 while(next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
));
830 if(error
|| end
) return end
;
832 while(ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
834 if(*elem
.ptr
== '/' && elem
.len
- 1 == unknown_elem
->len
&&
835 !strncmpW(elem
.ptr
+1, unknown_elem
->ptr
, unknown_elem
->len
))
838 ret
= parse_unknown_elem(xmlbuf
, &elem
);
841 return ret
&& parse_end_element(xmlbuf
);
844 static BOOL
parse_assembly_identity_elem(xmlbuf_t
* xmlbuf
, ACTIVATION_CONTEXT
* actctx
,
845 struct assembly_identity
* ai
)
847 xmlstr_t attr_name
, attr_value
;
848 BOOL end
= FALSE
, error
;
850 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
852 if (xmlstr_cmp(&attr_name
, nameW
))
854 if (!(ai
->name
= xmlstrdupW(&attr_value
))) return FALSE
;
856 else if (xmlstr_cmp(&attr_name
, typeW
))
858 if (!(ai
->type
= xmlstrdupW(&attr_value
))) return FALSE
;
860 else if (xmlstr_cmp(&attr_name
, versionW
))
862 if (!parse_version(&attr_value
, &ai
->version
)) return FALSE
;
864 else if (xmlstr_cmp(&attr_name
, processorArchitectureW
))
866 if (!(ai
->arch
= xmlstrdupW(&attr_value
))) return FALSE
;
868 else if (xmlstr_cmp(&attr_name
, publicKeyTokenW
))
870 if (!(ai
->public_key
= xmlstrdupW(&attr_value
))) return FALSE
;
872 else if (xmlstr_cmp(&attr_name
, languageW
))
874 WARN("Unsupported yet language attribute (%s)\n",
875 debugstr_xmlstr(&attr_value
));
876 if (!(ai
->language
= xmlstrdupW(&attr_value
))) return FALSE
;
880 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
),
881 debugstr_xmlstr(&attr_value
));
885 TRACE( "name=%s version=%s arch=%s\n",
886 debugstr_w(ai
->name
), debugstr_version(&ai
->version
), debugstr_w(ai
->arch
) );
888 if (error
|| end
) return end
;
889 return parse_expect_end_elem(xmlbuf
, assemblyIdentityW
);
892 static BOOL
parse_com_class_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
894 xmlstr_t elem
, attr_name
, attr_value
;
895 BOOL ret
, end
= FALSE
, error
;
896 struct entity
* entity
;
898 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
)))
901 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
903 if (xmlstr_cmp(&attr_name
, clsidW
))
905 if (!(entity
->u
.comclass
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
909 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
913 if (error
|| end
) return end
;
915 while ((ret
= next_xml_elem(xmlbuf
, &elem
)))
917 if (xmlstr_cmp_end(&elem
, comClassW
))
919 ret
= parse_end_element(xmlbuf
);
924 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
925 ret
= parse_unknown_elem(xmlbuf
, &elem
);
931 static BOOL
parse_cominterface_proxy_stub_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
933 xmlstr_t attr_name
, attr_value
;
934 BOOL end
= FALSE
, error
;
935 struct entity
* entity
;
937 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
)))
940 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
942 if (xmlstr_cmp(&attr_name
, iidW
))
944 if (!(entity
->u
.proxy
.iid
= xmlstrdupW(&attr_value
))) return FALSE
;
946 if (xmlstr_cmp(&attr_name
, nameW
))
948 if (!(entity
->u
.proxy
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
952 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
956 if (error
|| end
) return end
;
957 return parse_expect_end_elem(xmlbuf
, comInterfaceProxyStubW
);
960 static BOOL
parse_typelib_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
962 xmlstr_t attr_name
, attr_value
;
963 BOOL end
= FALSE
, error
;
964 struct entity
* entity
;
966 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
)))
969 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
971 if (xmlstr_cmp(&attr_name
, tlbidW
))
973 if (!(entity
->u
.typelib
.tlbid
= xmlstrdupW(&attr_value
))) return FALSE
;
975 if (xmlstr_cmp(&attr_name
, versionW
))
977 if (!(entity
->u
.typelib
.version
= xmlstrdupW(&attr_value
))) return FALSE
;
979 if (xmlstr_cmp(&attr_name
, helpdirW
))
981 if (!(entity
->u
.typelib
.helpdir
= xmlstrdupW(&attr_value
))) return FALSE
;
985 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
989 if (error
|| end
) return end
;
990 return parse_expect_end_elem(xmlbuf
, typelibW
);
993 static BOOL
parse_window_class_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
995 xmlstr_t elem
, content
;
996 BOOL end
= FALSE
, ret
= TRUE
;
997 struct entity
* entity
;
999 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
)))
1002 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1003 if (end
) return FALSE
;
1005 if (!parse_text_content(xmlbuf
, &content
)) return FALSE
;
1007 if (!(entity
->u
.class.name
= xmlstrdupW(&content
))) return FALSE
;
1009 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1011 if (xmlstr_cmp_end(&elem
, windowClassW
))
1013 ret
= parse_end_element(xmlbuf
);
1018 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1019 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1026 static BOOL
parse_binding_redirect_elem(xmlbuf_t
* xmlbuf
)
1028 xmlstr_t attr_name
, attr_value
;
1029 BOOL end
= FALSE
, error
;
1031 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1033 if (xmlstr_cmp(&attr_name
, oldVersionW
))
1035 FIXME("Not stored yet oldVersion=%s\n", debugstr_xmlstr(&attr_value
));
1037 else if (xmlstr_cmp(&attr_name
, newVersionW
))
1039 FIXME("Not stored yet newVersion=%s\n", debugstr_xmlstr(&attr_value
));
1043 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1047 if (error
|| end
) return end
;
1048 return parse_expect_end_elem(xmlbuf
, bindingRedirectW
);
1051 static BOOL
parse_description_elem(xmlbuf_t
* xmlbuf
)
1053 xmlstr_t elem
, content
;
1054 BOOL end
= FALSE
, ret
= TRUE
;
1056 if (!parse_expect_no_attr(xmlbuf
, &end
) || end
||
1057 !parse_text_content(xmlbuf
, &content
))
1060 TRACE("Got description %s\n", debugstr_xmlstr(&content
));
1062 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1064 if (xmlstr_cmp_end(&elem
, descriptionW
))
1066 ret
= parse_end_element(xmlbuf
);
1071 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1072 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1079 static BOOL
parse_com_interface_external_proxy_stub_elem(xmlbuf_t
* xmlbuf
,
1080 struct assembly
* assembly
)
1082 xmlstr_t attr_name
, attr_value
;
1083 BOOL end
= FALSE
, error
;
1084 struct entity
* entity
;
1086 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
);
1087 if (!entity
) return FALSE
;
1089 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1091 if (xmlstr_cmp(&attr_name
, iidW
))
1093 if (!(entity
->u
.proxy
.iid
= xmlstrdupW(&attr_value
))) return FALSE
;
1095 if (xmlstr_cmp(&attr_name
, nameW
))
1097 if (!(entity
->u
.proxy
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1101 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1105 if (error
|| end
) return end
;
1106 return parse_expect_end_elem(xmlbuf
, comInterfaceExternalProxyStubW
);
1109 static BOOL
parse_clr_class_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1111 xmlstr_t attr_name
, attr_value
;
1112 BOOL end
= FALSE
, error
;
1113 struct entity
* entity
;
1115 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
);
1116 if (!entity
) return FALSE
;
1118 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1120 if (xmlstr_cmp(&attr_name
, nameW
))
1122 if (!(entity
->u
.clrclass
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1124 else if (xmlstr_cmp(&attr_name
, clsidW
))
1126 if (!(entity
->u
.clrclass
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
1130 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1134 if (error
|| end
) return end
;
1135 return parse_expect_end_elem(xmlbuf
, clrClassW
);
1138 static BOOL
parse_clr_surrogate_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1140 xmlstr_t attr_name
, attr_value
;
1141 BOOL end
= FALSE
, error
;
1142 struct entity
* entity
;
1144 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
);
1145 if (!entity
) return FALSE
;
1147 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1149 if (xmlstr_cmp(&attr_name
, nameW
))
1151 if (!(entity
->u
.clrsurrogate
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1153 else if (xmlstr_cmp(&attr_name
, clsidW
))
1155 if (!(entity
->u
.clrsurrogate
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
1159 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1163 if (error
|| end
) return end
;
1164 return parse_expect_end_elem(xmlbuf
, clrSurrogateW
);
1167 static BOOL
parse_dependent_assembly_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
, BOOL optional
)
1169 struct assembly_identity ai
;
1171 BOOL end
= FALSE
, ret
= TRUE
;
1173 if (!parse_expect_no_attr(xmlbuf
, &end
) || end
) return end
;
1175 memset(&ai
, 0, sizeof(ai
));
1176 ai
.optional
= optional
;
1178 if (!parse_expect_elem(xmlbuf
, assemblyIdentityW
) ||
1179 !parse_assembly_identity_elem(xmlbuf
, acl
->actctx
, &ai
))
1182 TRACE( "adding name=%s version=%s arch=%s\n",
1183 debugstr_w(ai
.name
), debugstr_version(&ai
.version
), debugstr_w(ai
.arch
) );
1185 /* store the newly found identity for later loading */
1186 if (!add_dependent_assembly_id(acl
, &ai
)) return FALSE
;
1188 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1190 if (xmlstr_cmp_end(&elem
, dependentAssemblyW
))
1192 ret
= parse_end_element(xmlbuf
);
1195 else if (xmlstr_cmp(&elem
, bindingRedirectW
))
1197 ret
= parse_binding_redirect_elem(xmlbuf
);
1201 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1202 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1209 static BOOL
parse_dependency_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
)
1211 xmlstr_t attr_name
, attr_value
, elem
;
1212 BOOL end
= FALSE
, ret
= TRUE
, error
, optional
= FALSE
;
1214 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1216 if (xmlstr_cmp(&attr_name
, optionalW
))
1218 static const WCHAR yesW
[] = {'y','e','s',0};
1219 optional
= xmlstr_cmpi( &attr_value
, yesW
);
1220 TRACE("optional=%s\n", debugstr_xmlstr(&attr_value
));
1224 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1228 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1230 if (xmlstr_cmp_end(&elem
, dependencyW
))
1232 ret
= parse_end_element(xmlbuf
);
1235 else if (xmlstr_cmp(&elem
, dependentAssemblyW
))
1237 ret
= parse_dependent_assembly_elem(xmlbuf
, acl
, optional
);
1241 WARN("unknown element %s\n", debugstr_xmlstr(&elem
));
1242 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1249 static BOOL
parse_noinherit_elem(xmlbuf_t
* xmlbuf
)
1253 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1254 return end
|| parse_expect_end_elem(xmlbuf
, noInheritW
);
1257 static BOOL
parse_noinheritable_elem(xmlbuf_t
* xmlbuf
)
1261 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1262 return end
|| parse_expect_end_elem(xmlbuf
, noInheritableW
);
1265 static BOOL
parse_file_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1267 xmlstr_t attr_name
, attr_value
, elem
;
1268 BOOL end
= FALSE
, error
, ret
= TRUE
;
1269 struct dll_redirect
* dll
;
1271 if (!(dll
= add_dll_redirect(assembly
))) return FALSE
;
1273 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1275 if (xmlstr_cmp(&attr_name
, nameW
))
1277 if (!(dll
->name
= xmlstrdupW(&attr_value
))) return FALSE
;
1278 TRACE("name=%s\n", debugstr_xmlstr(&attr_value
));
1280 else if (xmlstr_cmp(&attr_name
, hashW
))
1282 if (!(dll
->hash
= xmlstrdupW(&attr_value
))) return FALSE
;
1284 else if (xmlstr_cmp(&attr_name
, hashalgW
))
1286 static const WCHAR sha1W
[] = {'S','H','A','1',0};
1287 if (!xmlstr_cmpi(&attr_value
, sha1W
))
1288 FIXME("hashalg should be SHA1, got %s\n", debugstr_xmlstr(&attr_value
));
1292 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1296 if (error
|| !dll
->name
) return FALSE
;
1297 if (end
) return TRUE
;
1299 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1301 if (xmlstr_cmp_end(&elem
, fileW
))
1303 ret
= parse_end_element(xmlbuf
);
1306 else if (xmlstr_cmp(&elem
, comClassW
))
1308 ret
= parse_com_class_elem(xmlbuf
, dll
);
1310 else if (xmlstr_cmp(&elem
, comInterfaceProxyStubW
))
1312 ret
= parse_cominterface_proxy_stub_elem(xmlbuf
, dll
);
1314 else if (xmlstr_cmp(&elem
, asmv2hashW
))
1316 WARN("asmv2hash (undocumented) not supported\n");
1317 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1319 else if (xmlstr_cmp(&elem
, typelibW
))
1321 ret
= parse_typelib_elem(xmlbuf
, dll
);
1323 else if (xmlstr_cmp(&elem
, windowClassW
))
1325 ret
= parse_window_class_elem(xmlbuf
, dll
);
1329 WARN("unknown elem %s\n", debugstr_xmlstr(&elem
));
1330 ret
= parse_unknown_elem( xmlbuf
, &elem
);
1337 static BOOL
parse_assembly_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
,
1338 struct assembly
* assembly
,
1339 struct assembly_identity
* expected_ai
)
1341 xmlstr_t attr_name
, attr_value
, elem
;
1342 BOOL end
= FALSE
, error
, version
= FALSE
, xmlns
= FALSE
, ret
= TRUE
;
1344 TRACE("(%p)\n", xmlbuf
);
1346 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1348 if (xmlstr_cmp(&attr_name
, manifestVersionW
))
1350 static const WCHAR v10W
[] = {'1','.','0',0};
1351 if (!xmlstr_cmp(&attr_value
, v10W
))
1353 FIXME("wrong version %s\n", debugstr_xmlstr(&attr_value
));
1358 else if (xmlstr_cmp(&attr_name
, xmlnsW
))
1360 if (!xmlstr_cmp(&attr_value
, manifestv1W
) && !xmlstr_cmp(&attr_value
, manifestv3W
))
1362 FIXME("wrong namespace %s\n", debugstr_xmlstr(&attr_value
));
1369 WARN("unknown attr %s=%s\n", debugstr_xmlstr(&attr_name
), debugstr_xmlstr(&attr_value
));
1373 if (error
|| end
|| !xmlns
|| !version
) return FALSE
;
1374 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
1376 if (assembly
->type
== APPLICATION_MANIFEST
&& xmlstr_cmp(&elem
, noInheritW
))
1378 if (!parse_noinherit_elem(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
))
1380 assembly
->no_inherit
= TRUE
;
1383 if (xmlstr_cmp(&elem
, noInheritableW
))
1385 if (!parse_noinheritable_elem(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
))
1388 else if ((assembly
->type
== ASSEMBLY_MANIFEST
|| assembly
->type
== ASSEMBLY_SHARED_MANIFEST
) &&
1389 assembly
->no_inherit
)
1392 if (xmlstr_cmp(&elem
, assemblyIdentityW
))
1394 if (!parse_assembly_identity_elem(xmlbuf
, acl
->actctx
, &assembly
->id
)) return FALSE
;
1395 ret
= next_xml_elem(xmlbuf
, &elem
);
1399 /* FIXME: more tests */
1400 if (assembly
->type
== ASSEMBLY_MANIFEST
&&
1401 memcmp(&assembly
->id
.version
, &expected_ai
->version
, sizeof(assembly
->id
.version
)))
1403 FIXME("wrong version for assembly manifest: %u.%u.%u.%u / %u.%u.%u.%u\n",
1404 expected_ai
->version
.major
, expected_ai
->version
.minor
,
1405 expected_ai
->version
.build
, expected_ai
->version
.revision
,
1406 assembly
->id
.version
.major
, assembly
->id
.version
.minor
,
1407 assembly
->id
.version
.build
, assembly
->id
.version
.revision
);
1410 else if (assembly
->type
== ASSEMBLY_SHARED_MANIFEST
&&
1411 (assembly
->id
.version
.major
!= expected_ai
->version
.major
||
1412 assembly
->id
.version
.minor
!= expected_ai
->version
.minor
||
1413 assembly
->id
.version
.build
< expected_ai
->version
.build
||
1414 (assembly
->id
.version
.build
== expected_ai
->version
.build
&&
1415 assembly
->id
.version
.revision
< expected_ai
->version
.revision
)))
1417 FIXME("wrong version for shared assembly manifest\n");
1425 if (xmlstr_cmp_end(&elem
, assemblyW
))
1427 ret
= parse_end_element(xmlbuf
);
1430 else if (xmlstr_cmp(&elem
, descriptionW
))
1432 ret
= parse_description_elem(xmlbuf
);
1434 else if (xmlstr_cmp(&elem
, comInterfaceExternalProxyStubW
))
1436 ret
= parse_com_interface_external_proxy_stub_elem(xmlbuf
, assembly
);
1438 else if (xmlstr_cmp(&elem
, dependencyW
))
1440 ret
= parse_dependency_elem(xmlbuf
, acl
);
1442 else if (xmlstr_cmp(&elem
, fileW
))
1444 ret
= parse_file_elem(xmlbuf
, assembly
);
1446 else if (xmlstr_cmp(&elem
, clrClassW
))
1448 ret
= parse_clr_class_elem(xmlbuf
, assembly
);
1450 else if (xmlstr_cmp(&elem
, clrSurrogateW
))
1452 ret
= parse_clr_surrogate_elem(xmlbuf
, assembly
);
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, windows_dir
.Length
+ sizeof(manifest_dirW
) )))
1882 return STATUS_NO_MEMORY
;
1884 memcpy( path
, windows_dir
.Buffer
, windows_dir
.Length
);
1885 memcpy( path
+ windows_dir
.Length
/sizeof(WCHAR
), manifest_dirW
, sizeof(manifest_dirW
) );
1887 if (!RtlDosPathNameToNtPathName_U( path
, &path_us
, NULL
, NULL
))
1889 RtlFreeHeap( GetProcessHeap(), 0, path
);
1890 return STATUS_NO_SUCH_FILE
;
1892 RtlFreeHeap( GetProcessHeap(), 0, path
);
1894 attr
.Length
= sizeof(attr
);
1895 attr
.RootDirectory
= 0;
1896 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1897 attr
.ObjectName
= &path_us
;
1898 attr
.SecurityDescriptor
= NULL
;
1899 attr
.SecurityQualityOfService
= NULL
;
1901 if (!NtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1902 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
))
1905 file
= lookup_manifest_file( handle
, &sxs_ai
);
1910 RtlFreeUnicodeString( &path_us
);
1911 return STATUS_NO_SUCH_FILE
;
1914 /* append file name to directory path */
1915 if (!(path
= RtlReAllocateHeap( GetProcessHeap(), 0, path_us
.Buffer
,
1916 path_us
.Length
+ (strlenW(file
) + 2) * sizeof(WCHAR
) )))
1918 RtlFreeHeap( GetProcessHeap(), 0, file
);
1919 RtlFreeUnicodeString( &path_us
);
1920 return STATUS_NO_MEMORY
;
1923 path
[path_us
.Length
/sizeof(WCHAR
)] = '\\';
1924 strcpyW( path
+ path_us
.Length
/sizeof(WCHAR
) + 1, file
);
1925 RtlInitUnicodeString( &path_us
, path
);
1926 *strrchrW(file
, '.') = 0; /* remove .manifest extension */
1928 if (!open_nt_file( &handle
, &path_us
))
1930 io
.u
.Status
= get_manifest_in_manifest_file(acl
, &sxs_ai
, path_us
.Buffer
, file
, TRUE
, handle
);
1933 else io
.u
.Status
= STATUS_NO_SUCH_FILE
;
1935 RtlFreeHeap( GetProcessHeap(), 0, file
);
1936 RtlFreeUnicodeString( &path_us
);
1940 static NTSTATUS
lookup_assembly(struct actctx_loader
* acl
,
1941 struct assembly_identity
* ai
)
1943 static const WCHAR dotDllW
[] = {'.','d','l','l',0};
1945 WCHAR
*buffer
, *p
, *directory
;
1947 UNICODE_STRING nameW
;
1950 TRACE( "looking for name=%s version=%s arch=%s\n",
1951 debugstr_w(ai
->name
), debugstr_version(&ai
->version
), debugstr_w(ai
->arch
) );
1953 if ((status
= lookup_winsxs(acl
, ai
)) != STATUS_NO_SUCH_FILE
) return status
;
1955 /* FIXME: add support for language specific lookup */
1957 nameW
.Buffer
= NULL
;
1958 if (!(buffer
= RtlAllocateHeap( GetProcessHeap(), 0,
1959 (strlenW(acl
->actctx
->appdir
.info
) + 2 * strlenW(ai
->name
) + 2) * sizeof(WCHAR
) + sizeof(dotManifestW
) )))
1960 return STATUS_NO_MEMORY
;
1962 if (!(directory
= build_assembly_dir( ai
)))
1964 RtlFreeHeap( GetProcessHeap(), 0, buffer
);
1965 return STATUS_NO_MEMORY
;
1968 /* lookup in appdir\name.dll
1969 * appdir\name.manifest
1970 * appdir\name\name.dll
1971 * appdir\name\name.manifest
1973 strcpyW( buffer
, acl
->actctx
->appdir
.info
);
1974 p
= buffer
+ strlenW(buffer
);
1975 for (i
= 0; i
< 2; i
++)
1978 strcpyW( p
, ai
->name
);
1981 strcpyW( p
, dotDllW
);
1982 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
1984 status
= open_nt_file( &file
, &nameW
);
1987 status
= get_manifest_in_pe_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
,
1988 (LPCWSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
, 0 );
1992 RtlFreeUnicodeString( &nameW
);
1995 strcpyW( p
, dotManifestW
);
1996 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
1998 status
= open_nt_file( &file
, &nameW
);
2001 status
= get_manifest_in_manifest_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
);
2005 RtlFreeUnicodeString( &nameW
);
2007 status
= STATUS_SXS_ASSEMBLY_NOT_FOUND
;
2009 RtlFreeUnicodeString( &nameW
);
2010 RtlFreeHeap( GetProcessHeap(), 0, directory
);
2011 RtlFreeHeap( GetProcessHeap(), 0, buffer
);
2015 static NTSTATUS
parse_depend_manifests(struct actctx_loader
* acl
)
2017 NTSTATUS status
= STATUS_SUCCESS
;
2020 for (i
= 0; i
< acl
->num_dependencies
; i
++)
2022 if (lookup_assembly(acl
, &acl
->dependencies
[i
]) != STATUS_SUCCESS
)
2024 if (!acl
->dependencies
[i
].optional
)
2026 FIXME( "Could not find dependent assembly %s\n", debugstr_w(acl
->dependencies
[i
].name
) );
2027 status
= STATUS_SXS_CANT_GEN_ACTCTX
;
2032 /* FIXME should now iterate through all refs */
2036 /* find the appropriate activation context for RtlQueryInformationActivationContext */
2037 static NTSTATUS
find_query_actctx( HANDLE
*handle
, DWORD flags
, ULONG
class )
2039 NTSTATUS status
= STATUS_SUCCESS
;
2041 if (flags
& QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX
)
2043 if (*handle
) return STATUS_INVALID_PARAMETER
;
2045 if (NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2046 *handle
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
->ActivationContext
;
2048 else if (flags
& (QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS
|QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
))
2053 if (!*handle
) return STATUS_INVALID_PARAMETER
;
2055 LdrLockLoaderLock( 0, NULL
, &magic
);
2056 if (!LdrFindEntryForAddress( *handle
, &pldr
))
2058 if ((flags
& QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
) && *handle
!= pldr
->BaseAddress
)
2059 status
= STATUS_DLL_NOT_FOUND
;
2061 *handle
= pldr
->ActivationContext
;
2063 else status
= STATUS_DLL_NOT_FOUND
;
2064 LdrUnlockLoaderLock( 0, magic
);
2066 else if (!*handle
&& (class != ActivationContextBasicInformation
))
2067 *handle
= process_actctx
;
2072 static NTSTATUS
fill_keyed_data(PACTCTX_SECTION_KEYED_DATA data
, PVOID v1
, PVOID v2
, unsigned int i
)
2074 data
->ulDataFormatVersion
= 1;
2076 data
->ulLength
= 20; /* FIXME */
2077 data
->lpSectionGlobalData
= NULL
; /* FIXME */
2078 data
->ulSectionGlobalDataLength
= 0; /* FIXME */
2079 data
->lpSectionBase
= v2
;
2080 data
->ulSectionTotalLength
= 0; /* FIXME */
2081 data
->hActCtx
= NULL
;
2082 if (data
->cbSize
>= offsetof(ACTCTX_SECTION_KEYED_DATA
, ulAssemblyRosterIndex
) + sizeof(ULONG
))
2083 data
->ulAssemblyRosterIndex
= i
+ 1;
2085 return STATUS_SUCCESS
;
2088 static NTSTATUS
find_dll_redirection(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2089 PACTCTX_SECTION_KEYED_DATA data
)
2091 unsigned int i
, j
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2093 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2095 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2096 for (j
= 0; j
< assembly
->num_dlls
; j
++)
2098 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
2099 if (!strncmpiW(section_name
->Buffer
, dll
->name
, snlen
) && !dll
->name
[snlen
])
2100 return fill_keyed_data(data
, dll
, assembly
, i
);
2103 return STATUS_SXS_KEY_NOT_FOUND
;
2106 static NTSTATUS
find_window_class(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2107 PACTCTX_SECTION_KEYED_DATA data
)
2109 unsigned int i
, j
, k
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2111 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2113 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2114 for (j
= 0; j
< assembly
->num_dlls
; j
++)
2116 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
2117 for (k
= 0; k
< dll
->entities
.num
; k
++)
2119 struct entity
*entity
= &dll
->entities
.base
[k
];
2120 if (entity
->kind
== ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
)
2122 if (!strncmpiW(section_name
->Buffer
, entity
->u
.class.name
, snlen
) && !entity
->u
.class.name
[snlen
])
2123 return fill_keyed_data(data
, entity
, dll
, i
);
2128 return STATUS_SXS_KEY_NOT_FOUND
;
2131 static NTSTATUS
find_string(ACTIVATION_CONTEXT
* actctx
, ULONG section_kind
,
2132 const UNICODE_STRING
*section_name
,
2133 DWORD flags
, PACTCTX_SECTION_KEYED_DATA data
)
2137 switch (section_kind
)
2139 case ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
:
2140 status
= find_dll_redirection(actctx
, section_name
, data
);
2142 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
:
2143 status
= find_window_class(actctx
, section_name
, data
);
2145 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
:
2146 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
:
2147 case ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
:
2148 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
:
2149 case ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE
:
2150 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
:
2151 FIXME("Unsupported yet section_kind %x\n", section_kind
);
2152 return STATUS_SXS_SECTION_NOT_FOUND
;
2154 WARN("Unknown section_kind %x\n", section_kind
);
2155 return STATUS_SXS_SECTION_NOT_FOUND
;
2158 if (status
!= STATUS_SUCCESS
) return status
;
2160 if (flags
& FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
)
2162 actctx_addref(actctx
);
2163 data
->hActCtx
= actctx
;
2165 return STATUS_SUCCESS
;
2168 /* initialize the activation context for the current process */
2169 void actctx_init(void)
2174 ctx
.cbSize
= sizeof(ctx
);
2175 ctx
.lpSource
= NULL
;
2176 ctx
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
| ACTCTX_FLAG_HMODULE_VALID
;
2177 ctx
.hModule
= NtCurrentTeb()->Peb
->ImageBaseAddress
;
2178 ctx
.lpResourceName
= (LPCWSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
2180 if (!RtlCreateActivationContext( &handle
, &ctx
)) process_actctx
= check_actctx(handle
);
2184 /***********************************************************************
2185 * RtlCreateActivationContext (NTDLL.@)
2187 * Create an activation context.
2189 * FIXME: function signature/prototype is wrong
2191 NTSTATUS WINAPI
RtlCreateActivationContext( HANDLE
*handle
, const void *ptr
)
2193 const ACTCTXW
*pActCtx
= ptr
; /* FIXME: not the right structure */
2194 const WCHAR
*directory
= NULL
;
2195 ACTIVATION_CONTEXT
*actctx
;
2196 UNICODE_STRING nameW
;
2198 NTSTATUS status
= STATUS_NO_MEMORY
;
2200 struct actctx_loader acl
;
2202 TRACE("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
2204 if (!pActCtx
|| pActCtx
->cbSize
< sizeof(*pActCtx
) ||
2205 (pActCtx
->dwFlags
& ~ACTCTX_FLAGS_ALL
))
2206 return STATUS_INVALID_PARAMETER
;
2208 if (!(actctx
= RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*actctx
) )))
2209 return STATUS_NO_MEMORY
;
2211 actctx
->magic
= ACTCTX_MAGIC
;
2212 actctx
->ref_count
= 1;
2213 actctx
->config
.type
= ACTIVATION_CONTEXT_PATH_TYPE_NONE
;
2214 actctx
->config
.info
= NULL
;
2215 actctx
->appdir
.type
= ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE
;
2216 if (pActCtx
->dwFlags
& ACTCTX_FLAG_APPLICATION_NAME_VALID
)
2218 if (!(actctx
->appdir
.info
= strdupW( pActCtx
->lpApplicationName
))) goto error
;
2226 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
) module
= pActCtx
->hModule
;
2227 else module
= NtCurrentTeb()->Peb
->ImageBaseAddress
;
2229 if ((status
= get_module_filename( module
, &dir
, 0 ))) goto error
;
2230 if ((p
= strrchrW( dir
.Buffer
, '\\' ))) p
[1] = 0;
2231 actctx
->appdir
.info
= dir
.Buffer
;
2234 nameW
.Buffer
= NULL
;
2235 if (pActCtx
->lpSource
)
2237 if (!RtlDosPathNameToNtPathName_U(pActCtx
->lpSource
, &nameW
, NULL
, NULL
))
2239 status
= STATUS_NO_SUCH_FILE
;
2242 status
= open_nt_file( &file
, &nameW
);
2245 RtlFreeUnicodeString( &nameW
);
2250 acl
.actctx
= actctx
;
2251 acl
.dependencies
= NULL
;
2252 acl
.num_dependencies
= 0;
2253 acl
.allocated_dependencies
= 0;
2255 if (pActCtx
->dwFlags
& ACTCTX_FLAG_LANGID_VALID
) lang
= pActCtx
->wLangId
;
2256 if (pActCtx
->dwFlags
& ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID
) directory
= pActCtx
->lpAssemblyDirectory
;
2258 if (pActCtx
->dwFlags
& ACTCTX_FLAG_RESOURCE_NAME_VALID
)
2260 /* if we have a resource it's a PE file */
2261 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
)
2263 status
= get_manifest_in_module( &acl
, NULL
, NULL
, directory
, FALSE
, pActCtx
->hModule
,
2264 pActCtx
->lpResourceName
, lang
);
2265 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2266 /* FIXME: what to do if pActCtx->lpSource is set */
2267 status
= get_manifest_in_associated_manifest( &acl
, NULL
, NULL
, directory
,
2268 pActCtx
->hModule
, pActCtx
->lpResourceName
);
2270 else if (pActCtx
->lpSource
)
2272 status
= get_manifest_in_pe_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
,
2273 file
, pActCtx
->lpResourceName
, lang
);
2274 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2275 status
= get_manifest_in_associated_manifest( &acl
, NULL
, nameW
.Buffer
, directory
,
2276 NULL
, pActCtx
->lpResourceName
);
2278 else status
= STATUS_INVALID_PARAMETER
;
2282 status
= get_manifest_in_manifest_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
, file
);
2285 if (file
) NtClose( file
);
2286 RtlFreeUnicodeString( &nameW
);
2288 if (status
== STATUS_SUCCESS
) status
= parse_depend_manifests(&acl
);
2289 free_depend_manifests( &acl
);
2291 if (status
== STATUS_SUCCESS
) *handle
= actctx
;
2292 else actctx_release( actctx
);
2296 if (file
) NtClose( file
);
2297 actctx_release( actctx
);
2302 /***********************************************************************
2303 * RtlAddRefActivationContext (NTDLL.@)
2305 void WINAPI
RtlAddRefActivationContext( HANDLE handle
)
2307 ACTIVATION_CONTEXT
*actctx
;
2309 if ((actctx
= check_actctx( handle
))) actctx_addref( actctx
);
2313 /******************************************************************
2314 * RtlReleaseActivationContext (NTDLL.@)
2316 void WINAPI
RtlReleaseActivationContext( HANDLE handle
)
2318 ACTIVATION_CONTEXT
*actctx
;
2320 if ((actctx
= check_actctx( handle
))) actctx_release( actctx
);
2324 /******************************************************************
2325 * RtlActivateActivationContext (NTDLL.@)
2327 NTSTATUS WINAPI
RtlActivateActivationContext( ULONG unknown
, HANDLE handle
, PULONG_PTR cookie
)
2329 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2331 if (!(frame
= RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*frame
) )))
2332 return STATUS_NO_MEMORY
;
2334 frame
->Previous
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
;
2335 frame
->ActivationContext
= handle
;
2337 NtCurrentTeb()->ActivationContextStack
.ActiveFrame
= frame
;
2338 RtlAddRefActivationContext( handle
);
2340 *cookie
= (ULONG_PTR
)frame
;
2341 TRACE( "%p cookie=%lx\n", handle
, *cookie
);
2342 return STATUS_SUCCESS
;
2346 /***********************************************************************
2347 * RtlDeactivateActivationContext (NTDLL.@)
2349 void WINAPI
RtlDeactivateActivationContext( ULONG flags
, ULONG_PTR cookie
)
2351 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
, *top
;
2353 TRACE( "%x cookie=%lx\n", flags
, cookie
);
2355 /* find the right frame */
2356 top
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
;
2357 for (frame
= top
; frame
; frame
= frame
->Previous
)
2358 if ((ULONG_PTR
)frame
== cookie
) break;
2361 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION
);
2363 if (frame
!= top
&& !(flags
& DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION
))
2364 RtlRaiseStatus( STATUS_SXS_EARLY_DEACTIVATION
);
2366 /* pop everything up to and including frame */
2367 NtCurrentTeb()->ActivationContextStack
.ActiveFrame
= frame
->Previous
;
2369 while (top
!= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2371 frame
= top
->Previous
;
2372 RtlReleaseActivationContext( top
->ActivationContext
);
2373 RtlFreeHeap( GetProcessHeap(), 0, top
);
2379 /******************************************************************
2380 * RtlFreeThreadActivationContextStack (NTDLL.@)
2382 void WINAPI
RtlFreeThreadActivationContextStack(void)
2384 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2386 frame
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
;
2389 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*prev
= frame
->Previous
;
2390 RtlReleaseActivationContext( frame
->ActivationContext
);
2391 RtlFreeHeap( GetProcessHeap(), 0, frame
);
2394 NtCurrentTeb()->ActivationContextStack
.ActiveFrame
= NULL
;
2398 /******************************************************************
2399 * RtlGetActiveActivationContext (NTDLL.@)
2401 NTSTATUS WINAPI
RtlGetActiveActivationContext( HANDLE
*handle
)
2403 if (NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2405 *handle
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
->ActivationContext
;
2406 RtlAddRefActivationContext( *handle
);
2411 return STATUS_SUCCESS
;
2415 /******************************************************************
2416 * RtlIsActivationContextActive (NTDLL.@)
2418 BOOLEAN WINAPI
RtlIsActivationContextActive( HANDLE handle
)
2420 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2422 for (frame
= NtCurrentTeb()->ActivationContextStack
.ActiveFrame
; frame
; frame
= frame
->Previous
)
2423 if (frame
->ActivationContext
== handle
) return TRUE
;
2428 /***********************************************************************
2429 * RtlQueryInformationActivationContext (NTDLL.@)
2431 * Get information about an activation context.
2432 * FIXME: function signature/prototype may be wrong
2434 NTSTATUS WINAPI
RtlQueryInformationActivationContext( ULONG flags
, HANDLE handle
, PVOID subinst
,
2435 ULONG
class, PVOID buffer
,
2436 SIZE_T bufsize
, SIZE_T
*retlen
)
2438 ACTIVATION_CONTEXT
*actctx
;
2441 TRACE("%08x %p %p %u %p %ld %p\n", flags
, handle
,
2442 subinst
, class, buffer
, bufsize
, retlen
);
2444 if (retlen
) *retlen
= 0;
2445 if ((status
= find_query_actctx( &handle
, flags
, class ))) return status
;
2449 case ActivationContextBasicInformation
:
2451 ACTIVATION_CONTEXT_BASIC_INFORMATION
*info
= buffer
;
2453 if (retlen
) *retlen
= sizeof(*info
);
2454 if (!info
|| bufsize
< sizeof(*info
)) return STATUS_BUFFER_TOO_SMALL
;
2456 info
->hActCtx
= handle
;
2457 info
->dwFlags
= 0; /* FIXME */
2458 if (!(flags
& QUERY_ACTCTX_FLAG_NO_ADDREF
)) RtlAddRefActivationContext( handle
);
2462 case ActivationContextDetailedInformation
:
2464 ACTIVATION_CONTEXT_DETAILED_INFORMATION
*acdi
= buffer
;
2465 struct assembly
*assembly
= NULL
;
2466 SIZE_T len
, manifest_len
= 0, config_len
= 0, appdir_len
= 0;
2469 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2471 if (actctx
->num_assemblies
) assembly
= actctx
->assemblies
;
2473 if (assembly
&& assembly
->manifest
.info
)
2474 manifest_len
= strlenW(assembly
->manifest
.info
) + 1;
2475 if (actctx
->config
.info
) config_len
= strlenW(actctx
->config
.info
) + 1;
2476 if (actctx
->appdir
.info
) appdir_len
= strlenW(actctx
->appdir
.info
) + 1;
2477 len
= sizeof(*acdi
) + (manifest_len
+ config_len
+ appdir_len
) * sizeof(WCHAR
);
2479 if (retlen
) *retlen
= len
;
2480 if (!buffer
|| bufsize
< len
) return STATUS_BUFFER_TOO_SMALL
;
2483 acdi
->ulFormatVersion
= assembly
? 1 : 0; /* FIXME */
2484 acdi
->ulAssemblyCount
= actctx
->num_assemblies
;
2485 acdi
->ulRootManifestPathType
= assembly
? assembly
->manifest
.type
: 0 /* FIXME */;
2486 acdi
->ulRootManifestPathChars
= assembly
&& assembly
->manifest
.info
? manifest_len
- 1 : 0;
2487 acdi
->ulRootConfigurationPathType
= actctx
->config
.type
;
2488 acdi
->ulRootConfigurationPathChars
= actctx
->config
.info
? config_len
- 1 : 0;
2489 acdi
->ulAppDirPathType
= actctx
->appdir
.type
;
2490 acdi
->ulAppDirPathChars
= actctx
->appdir
.info
? appdir_len
- 1 : 0;
2491 ptr
= (LPWSTR
)(acdi
+ 1);
2494 acdi
->lpRootManifestPath
= ptr
;
2495 memcpy(ptr
, assembly
->manifest
.info
, manifest_len
* sizeof(WCHAR
));
2496 ptr
+= manifest_len
;
2498 else acdi
->lpRootManifestPath
= NULL
;
2501 acdi
->lpRootConfigurationPath
= ptr
;
2502 memcpy(ptr
, actctx
->config
.info
, config_len
* sizeof(WCHAR
));
2505 else acdi
->lpRootConfigurationPath
= NULL
;
2508 acdi
->lpAppDirPath
= ptr
;
2509 memcpy(ptr
, actctx
->appdir
.info
, appdir_len
* sizeof(WCHAR
));
2511 else acdi
->lpAppDirPath
= NULL
;
2515 case AssemblyDetailedInformationInActivationContext
:
2517 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION
*afdi
= buffer
;
2518 struct assembly
*assembly
;
2521 SIZE_T len
, id_len
= 0, ad_len
= 0, path_len
= 0;
2524 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2525 if (!subinst
) return STATUS_INVALID_PARAMETER
;
2527 index
= *(DWORD
*)subinst
;
2528 if (!index
|| index
> actctx
->num_assemblies
) return STATUS_INVALID_PARAMETER
;
2530 assembly
= &actctx
->assemblies
[index
- 1];
2532 if (!(assembly_id
= build_assembly_id( &assembly
->id
))) return STATUS_NO_MEMORY
;
2533 id_len
= strlenW(assembly_id
) + 1;
2534 if (assembly
->directory
) ad_len
= strlenW(assembly
->directory
) + 1;
2536 if (assembly
->manifest
.info
&&
2537 (assembly
->type
== ASSEMBLY_MANIFEST
|| assembly
->type
== ASSEMBLY_SHARED_MANIFEST
))
2538 path_len
= strlenW(assembly
->manifest
.info
) + 1;
2540 len
= sizeof(*afdi
) + (id_len
+ ad_len
+ path_len
) * sizeof(WCHAR
);
2542 if (retlen
) *retlen
= len
;
2543 if (!buffer
|| bufsize
< len
)
2545 RtlFreeHeap( GetProcessHeap(), 0, assembly_id
);
2546 return STATUS_BUFFER_TOO_SMALL
;
2549 afdi
->ulFlags
= 0; /* FIXME */
2550 afdi
->ulEncodedAssemblyIdentityLength
= (id_len
- 1) * sizeof(WCHAR
);
2551 afdi
->ulManifestPathType
= assembly
->manifest
.type
;
2552 afdi
->ulManifestPathLength
= assembly
->manifest
.info
? (path_len
- 1) * sizeof(WCHAR
) : 0;
2553 /* FIXME afdi->liManifestLastWriteTime = 0; */
2554 afdi
->ulPolicyPathType
= ACTIVATION_CONTEXT_PATH_TYPE_NONE
; /* FIXME */
2555 afdi
->ulPolicyPathLength
= 0;
2556 /* FIXME afdi->liPolicyLastWriteTime = 0; */
2557 afdi
->ulMetadataSatelliteRosterIndex
= 0; /* FIXME */
2558 afdi
->ulManifestVersionMajor
= 1;
2559 afdi
->ulManifestVersionMinor
= 0;
2560 afdi
->ulPolicyVersionMajor
= 0; /* FIXME */
2561 afdi
->ulPolicyVersionMinor
= 0; /* FIXME */
2562 afdi
->ulAssemblyDirectoryNameLength
= ad_len
? (ad_len
- 1) * sizeof(WCHAR
) : 0;
2563 ptr
= (LPWSTR
)(afdi
+ 1);
2564 afdi
->lpAssemblyEncodedAssemblyIdentity
= ptr
;
2565 memcpy( ptr
, assembly_id
, id_len
* sizeof(WCHAR
) );
2569 afdi
->lpAssemblyManifestPath
= ptr
;
2570 memcpy(ptr
, assembly
->manifest
.info
, path_len
* sizeof(WCHAR
));
2572 } else afdi
->lpAssemblyManifestPath
= NULL
;
2573 afdi
->lpAssemblyPolicyPath
= NULL
; /* FIXME */
2576 afdi
->lpAssemblyDirectoryName
= ptr
;
2577 memcpy(ptr
, assembly
->directory
, ad_len
* sizeof(WCHAR
));
2580 else afdi
->lpAssemblyDirectoryName
= NULL
;
2581 RtlFreeHeap( GetProcessHeap(), 0, assembly_id
);
2585 case FileInformationInAssemblyOfAssemblyInActivationContext
:
2587 const ACTIVATION_CONTEXT_QUERY_INDEX
*acqi
= subinst
;
2588 ASSEMBLY_FILE_DETAILED_INFORMATION
*afdi
= buffer
;
2589 struct assembly
*assembly
;
2590 struct dll_redirect
*dll
;
2591 SIZE_T len
, dll_len
= 0;
2594 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2595 if (!acqi
) return STATUS_INVALID_PARAMETER
;
2597 if (acqi
->ulAssemblyIndex
>= actctx
->num_assemblies
)
2598 return STATUS_INVALID_PARAMETER
;
2599 assembly
= &actctx
->assemblies
[acqi
->ulAssemblyIndex
];
2601 if (acqi
->ulFileIndexInAssembly
>= assembly
->num_dlls
)
2602 return STATUS_INVALID_PARAMETER
;
2603 dll
= &assembly
->dlls
[acqi
->ulFileIndexInAssembly
];
2605 if (dll
->name
) dll_len
= strlenW(dll
->name
) + 1;
2606 len
= sizeof(*afdi
) + dll_len
* sizeof(WCHAR
);
2608 if (!buffer
|| bufsize
< len
)
2610 if (retlen
) *retlen
= len
;
2611 return STATUS_BUFFER_TOO_SMALL
;
2613 if (retlen
) *retlen
= 0; /* yes that's what native does !! */
2614 afdi
->ulFlags
= ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
;
2615 afdi
->ulFilenameLength
= dll_len
? (dll_len
- 1) * sizeof(WCHAR
) : 0;
2616 afdi
->ulPathLength
= 0; /* FIXME */
2617 ptr
= (LPWSTR
)(afdi
+ 1);
2620 afdi
->lpFileName
= ptr
;
2621 memcpy( ptr
, dll
->name
, dll_len
* sizeof(WCHAR
) );
2622 } else afdi
->lpFileName
= NULL
;
2623 afdi
->lpFilePath
= NULL
; /* FIXME */
2628 FIXME( "class %u not implemented\n", class );
2629 return STATUS_NOT_IMPLEMENTED
;
2631 return STATUS_SUCCESS
;
2634 /***********************************************************************
2635 * RtlFindActivationContextSectionString (NTDLL.@)
2637 * Find information about a string in an activation context.
2638 * FIXME: function signature/prototype may be wrong
2640 NTSTATUS WINAPI
RtlFindActivationContextSectionString( ULONG flags
, const GUID
*guid
, ULONG section_kind
,
2641 const UNICODE_STRING
*section_name
, PVOID ptr
)
2643 PACTCTX_SECTION_KEYED_DATA data
= ptr
;
2644 NTSTATUS status
= STATUS_SXS_KEY_NOT_FOUND
;
2646 TRACE("%08x %s %u %s %p\n", flags
, debugstr_guid(guid
), section_kind
,
2647 debugstr_us(section_name
), data
);
2651 FIXME("expected guid == NULL\n");
2652 return STATUS_INVALID_PARAMETER
;
2654 if (flags
& ~FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
)
2656 FIXME("unknown flags %08x\n", flags
);
2657 return STATUS_INVALID_PARAMETER
;
2659 if (!data
|| data
->cbSize
< offsetof(ACTCTX_SECTION_KEYED_DATA
, ulAssemblyRosterIndex
) ||
2660 !section_name
|| !section_name
->Buffer
)
2662 WARN("invalid parameter\n");
2663 return STATUS_INVALID_PARAMETER
;
2666 if (NtCurrentTeb()->ActivationContextStack
.ActiveFrame
)
2668 ACTIVATION_CONTEXT
*actctx
= check_actctx(NtCurrentTeb()->ActivationContextStack
.ActiveFrame
->ActivationContext
);
2669 if (actctx
) status
= find_string( actctx
, section_kind
, section_name
, flags
, data
);
2672 if (status
!= STATUS_SUCCESS
)
2673 status
= find_string( process_actctx
, section_kind
, section_name
, flags
, data
);