diff --git a/.gitignore b/.gitignore index 7a5d12f0..ab9c4d26 100644 --- a/.gitignore +++ b/.gitignore @@ -25,5 +25,6 @@ programs/longtwo/longtwo programs/longone/longone programs/pwd/pwd programs/which/which +programs/readelf/readelf programs/cd/cd programs/dist/ \ No newline at end of file diff --git a/kernel/src/scheduler.cpp b/kernel/src/scheduler.cpp index 66876fa1..07db7010 100644 --- a/kernel/src/scheduler.cpp +++ b/kernel/src/scheduler.cpp @@ -627,7 +627,9 @@ int64_t scheduler::exec(const std::string& file, const std::vector& return -std::ERROR_NOT_EXISTS; } - if(!elf::is_valid(content)){ + auto buffer = content.c_str(); + + if(!elf::is_valid(buffer)){ if(DEBUG_SCHEDULER){ k_print_line("Not a valid file"); } @@ -635,8 +637,6 @@ int64_t scheduler::exec(const std::string& file, const std::vector& return -std::ERROR_NOT_EXECUTABLE; } - auto buffer = content.c_str(); - auto& process = new_process(); if(!create_paging(buffer, process)){ diff --git a/programs/readelf/readelf b/programs/readelf/readelf deleted file mode 100755 index bd9e665f..00000000 Binary files a/programs/readelf/readelf and /dev/null differ diff --git a/programs/readelf/src/main.cpp b/programs/readelf/src/main.cpp index ebdb9f45..f768b803 100644 --- a/programs/readelf/src/main.cpp +++ b/programs/readelf/src/main.cpp @@ -13,16 +13,17 @@ namespace { -void readelf(std::string& content){ - if(!elf::is_valid(content)){ +void readelf(char* buffer){ + if(!elf::is_valid(buffer)){ print_line("readelf: This file is not an ELF file or not in ELF64 format"); return; } - auto buffer = content.c_str(); auto header = reinterpret_cast(buffer); + printf("%h\n", reinterpret_cast(buffer)); + printf("Number of Program Headers: %u\n", static_cast(header->e_phnum)); printf("Number of Section Headers: %u\n", static_cast(header->e_shnum)); @@ -100,9 +101,7 @@ int main(int argc, char* argv[]){ if(*content_result != size){ //TODO Read more } else { - std::string content(buffer); - - readelf(content); + readelf(buffer); } } else { printf("readelf: error: %s\n", std::error_message(content_result.error())); diff --git a/tlib/include/elf.hpp b/tlib/include/elf.hpp index 700f9e5f..26c69eea 100644 --- a/tlib/include/elf.hpp +++ b/tlib/include/elf.hpp @@ -54,8 +54,7 @@ struct section_header { uint64_t sh_entsize; }__attribute__((packed)); -inline bool is_valid(const std::string& content){ - auto buffer = content.c_str(); +inline bool is_valid(const char* buffer){ auto header = reinterpret_cast(buffer); //Test if ELF file