On 26.08.2024 21:44, rtrk wrote:
> @@ -105,33 +55,29 @@ static bool __init pe_name_compare(const struct 
> PeSectionHeader *sect,
>  const void *__init pe_find_section(const void *image, const UINTN image_size,
>                                     const CHAR16 *section_name, UINTN 
> *size_out)
>  {
> -    const struct DosFileHeader *dos = image;
> -    const struct PeHeader *pe;
> -    const struct PeSectionHeader *sect;
> +    const struct mz_hdr *mz = image;
> +    const struct pe_hdr *pe;
> +    const struct section_header *sect;
>      UINTN offset, i;
>  
> -    if ( image_size < sizeof(*dos) ||
> -         dos->Magic[0] != 'M' ||
> -         dos->Magic[1] != 'Z' )
> +    if ( image_size < sizeof(*mz) ||
> +         mz->magic != 0x4D5A ) /* 0x4D5A is the hexadecimal value for "MZ" */

I think this is byte-order-reversed. The question is anyway why you don't
use MZ_MAGIC here.

>          return NULL;
>  
> -    offset = dos->ExeHeader;
> +    offset = mz->peaddr;
>      pe = image + offset;
>  
>      offset += sizeof(*pe);
>      if ( image_size < offset ||
> -         pe->Magic[0] != 'P' ||
> -         pe->Magic[1] != 'E' ||
> -         pe->Magic[2] != '\0' ||
> -         pe->Magic[3] != '\0' )
> +         pe->magic != 0x50450000 ) /* 0x50450000 is the hexadecimal value 
> for "PE\0\0" */

Same here, with PE_MAGIC wanting using.

Jan

Reply via email to