Skip to content

Commit

Permalink
PE: Extract get_pehdr_offset() for reuse
Browse files Browse the repository at this point in the history
The get_pehdr_offset() function helps skip the DOS stub in a PE file to
locate the start of the PE header. Since it can be used in multiple C
files, it is being moved to a header file.

Signed-off-by: Pingfan Liu <[email protected]>
Cc: Simon Horman <[email protected]>
To: [email protected]
Signed-off-by: Simon Horman <[email protected]>
  • Loading branch information
Pingfan Liu authored and horms committed Dec 13, 2024
1 parent 0475ec5 commit c8fd594
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 17 additions & 0 deletions include/pe.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,21 @@ struct section_header {
uint32_t flags;
};

/*
* Return -1 if not PE, else offset of the PE header
*/
static int get_pehdr_offset(const char *buf)
{
int pe_hdr_offset;

pe_hdr_offset = *((int *)(buf + 0x3c));
buf += pe_hdr_offset;
if (!!memcmp(buf, "PE\0\0", 4)) {
printf("Not a PE file\n");
return -1;
}

return pe_hdr_offset;
}

#endif
17 changes: 0 additions & 17 deletions kexec/kexec-uki.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@
static int embeded_linux_format_index = -1;
static int kernel_fd = -1;

/*
* Return -1 if not PE, else offset of the PE header
*/
static int get_pehdr_offset(const char *buf)
{
int pe_hdr_offset;

pe_hdr_offset = *((int *)(buf + 0x3c));
buf += pe_hdr_offset;
if (!!memcmp(buf, "PE\0\0", 4)) {
printf("Not a PE file\n");
return -1;
}

return pe_hdr_offset;
}

static int create_tmpfd(const char *template, char *buf, int buf_sz, int *tmpfd)
{
char *fname;
Expand Down

0 comments on commit c8fd594

Please sign in to comment.