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 <piliu@xxxxxxxxxx> Cc: Simon Horman <horms@xxxxxxxxxx> To: kexec@xxxxxxxxxxxxxxxxxxx --- include/pe.h | 17 +++++++++++++++++ kexec/kexec-uki.c | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/pe.h b/include/pe.h index 2617074..1e1c59b 100644 --- a/include/pe.h +++ b/include/pe.h @@ -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 diff --git a/kexec/kexec-uki.c b/kexec/kexec-uki.c index 235f5a1..9888d7e 100644 --- a/kexec/kexec-uki.c +++ b/kexec/kexec-uki.c @@ -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; -- 2.41.0