From c3d2cebaaac27e563dc5eba8c37d609e56964469 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Mon, 11 Oct 2021 20:48:02 +0800 Subject: [PATCH] execformat/pe: test_headers.c support for arbitrary file, disable relocate --- execformat/pe/test_headers.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/execformat/pe/test_headers.c b/execformat/pe/test_headers.c index 2a43c79..054f7ce 100644 --- a/execformat/pe/test_headers.c +++ b/execformat/pe/test_headers.c @@ -83,14 +83,16 @@ void caseSectionFlags(uint32_t flags) { int main(int argc, char *argv[]) { execformat_pe_OptionalHeader_CheckPacking(); - int f = open("../../Main.efi", O_RDONLY); + int f; + if (argc > 1) + f = open(argv[1], O_RDONLY); + else + f = open("../../Main.efi", O_RDONLY); assert(f != -1 && "File open failed"); struct stat st; fstat(f, &st); - void *maddr = mmap(0, st.st_size, PROT_READ, MAP_SHARED, f, 0); - void *addr = malloc(st.st_size); - memcpy(addr, maddr, st.st_size); + void *addr = mmap(0, st.st_size, PROT_READ, MAP_SHARED, f, 0); execformat_pe_PortableExecutable pe; execformat_pe_LoadMemory(&pe, addr, st.st_size); @@ -112,7 +114,7 @@ int main(int argc, char *argv[]) { } - execformat_pe_BaseRelocate(&pe, 0, 0xFFFFFFFFC0000000ull); + //execformat_pe_BaseRelocate(&pe, 0, 0xFFFFFFFFC0000000ull); return 0; }