Hans Leidekker <hans(a)codeweavers.com> writes:
> ---
> dlls/user32/exticon.c | 202 ++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 133 insertions(+), 69 deletions(-)
>
> diff --git a/dlls/user32/exticon.c b/dlls/user32/exticon.c
> index 5b9d681..e6e97d5 100644
> --- a/dlls/user32/exticon.c
> +++ b/dlls/user32/exticon.c
> @@ -251,6 +251,127 @@ static BYTE * ICO_GetIconDirectory( LPBYTE peimage, LPicoICONDIR* lplpiID, ULONG
> return 0;
> }
>
> +/* caller must make sure we have a PE image */
> +static BOOL get_nt_header( const BYTE *image, const IMAGE_NT_HEADERS32 **nt32, const IMAGE_NT_HEADERS64 **nt64 )
> +{
> + const IMAGE_DOS_HEADER *dos = (const IMAGE_DOS_HEADER *)image;
> + const IMAGE_NT_HEADERS *nt = (const IMAGE_NT_HEADERS *)(image + dos->e_lfanew);
> +
> + if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
> + {
> + *nt32 = (const IMAGE_NT_HEADERS32 *)nt;
> + *nt64 = NULL;
> + return TRUE;
> + }
> + else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
> + {
> + *nt64 = (const IMAGE_NT_HEADERS64 *)nt;
> + *nt32 = NULL;
> + return TRUE;
> + }
> + return FALSE;
> +}
> +
> +static const IMAGE_SECTION_HEADER *get_next_section_header( const BYTE *image, WORD *index )
> +{
> + const IMAGE_NT_HEADERS32 *hdr32;
> + const IMAGE_NT_HEADERS64 *hdr64;
> + const IMAGE_SECTION_HEADER *section = NULL;
> +
> + if (!get_nt_header( image, &hdr32, &hdr64 )) return NULL;
> + if (hdr32)
> + {
> + if (*index >= hdr32->FileHeader.NumberOfSections) return NULL;
> + section = (const IMAGE_SECTION_HEADER *)((char *)hdr32 + sizeof(DWORD) +
> + sizeof(IMAGE_FILE_HEADER) + hdr32->FileHeader.SizeOfOptionalHeader +
> + *index * sizeof(IMAGE_SECTION_HEADER));
> + }
> + else
> + {
> + if (*index >= hdr64->FileHeader.NumberOfSections) return NULL;
> + section = (const IMAGE_SECTION_HEADER *)((char *)hdr64 + sizeof(DWORD) +
> + sizeof(IMAGE_FILE_HEADER) + hdr64->FileHeader.SizeOfOptionalHeader +
> + *index * sizeof(IMAGE_SECTION_HEADER));
> + }
> + if (section) (*index)++;
> + return section;
> +}
You probably want to use RtlImageDirectoryEntryToData and friends instead.
--
Alexandre Julliard
julliard(a)winehq.org