execformat/pe: test_headers.c support for arbitrary file, disable relocate

This commit is contained in:
Edgaru089 2021-10-11 20:48:02 +08:00
parent b0815a9638
commit c3d2cebaaa

View File

@ -83,14 +83,16 @@ void caseSectionFlags(uint32_t flags) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
execformat_pe_OptionalHeader_CheckPacking(); 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"); assert(f != -1 && "File open failed");
struct stat st; struct stat st;
fstat(f, &st); fstat(f, &st);
void *maddr = mmap(0, st.st_size, PROT_READ, MAP_SHARED, f, 0); void *addr = mmap(0, st.st_size, PROT_READ, MAP_SHARED, f, 0);
void *addr = malloc(st.st_size);
memcpy(addr, maddr, st.st_size);
execformat_pe_PortableExecutable pe; execformat_pe_PortableExecutable pe;
execformat_pe_LoadMemory(&pe, addr, st.st_size); 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; return 0;
} }