mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-10 21:14:38 -04:00
Finish readelf
This commit is contained in:
parent
cc25c7c640
commit
66c5e85557
1
.gitignore
vendored
1
.gitignore
vendored
@ -25,5 +25,6 @@ programs/longtwo/longtwo
|
|||||||
programs/longone/longone
|
programs/longone/longone
|
||||||
programs/pwd/pwd
|
programs/pwd/pwd
|
||||||
programs/which/which
|
programs/which/which
|
||||||
|
programs/readelf/readelf
|
||||||
programs/cd/cd
|
programs/cd/cd
|
||||||
programs/dist/
|
programs/dist/
|
@ -627,7 +627,9 @@ int64_t scheduler::exec(const std::string& file, const std::vector<std::string>&
|
|||||||
return -std::ERROR_NOT_EXISTS;
|
return -std::ERROR_NOT_EXISTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!elf::is_valid(content)){
|
auto buffer = content.c_str();
|
||||||
|
|
||||||
|
if(!elf::is_valid(buffer)){
|
||||||
if(DEBUG_SCHEDULER){
|
if(DEBUG_SCHEDULER){
|
||||||
k_print_line("Not a valid file");
|
k_print_line("Not a valid file");
|
||||||
}
|
}
|
||||||
@ -635,8 +637,6 @@ int64_t scheduler::exec(const std::string& file, const std::vector<std::string>&
|
|||||||
return -std::ERROR_NOT_EXECUTABLE;
|
return -std::ERROR_NOT_EXECUTABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto buffer = content.c_str();
|
|
||||||
|
|
||||||
auto& process = new_process();
|
auto& process = new_process();
|
||||||
|
|
||||||
if(!create_paging(buffer, process)){
|
if(!create_paging(buffer, process)){
|
||||||
|
Binary file not shown.
@ -13,16 +13,17 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void readelf(std::string& content){
|
void readelf(char* buffer){
|
||||||
if(!elf::is_valid(content)){
|
if(!elf::is_valid(buffer)){
|
||||||
print_line("readelf: This file is not an ELF file or not in ELF64 format");
|
print_line("readelf: This file is not an ELF file or not in ELF64 format");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto buffer = content.c_str();
|
|
||||||
auto header = reinterpret_cast<elf::elf_header*>(buffer);
|
auto header = reinterpret_cast<elf::elf_header*>(buffer);
|
||||||
|
|
||||||
|
printf("%h\n", reinterpret_cast<size_t>(buffer));
|
||||||
|
|
||||||
printf("Number of Program Headers: %u\n", static_cast<uint64_t>(header->e_phnum));
|
printf("Number of Program Headers: %u\n", static_cast<uint64_t>(header->e_phnum));
|
||||||
printf("Number of Section Headers: %u\n", static_cast<uint64_t>(header->e_shnum));
|
printf("Number of Section Headers: %u\n", static_cast<uint64_t>(header->e_shnum));
|
||||||
|
|
||||||
@ -100,9 +101,7 @@ int main(int argc, char* argv[]){
|
|||||||
if(*content_result != size){
|
if(*content_result != size){
|
||||||
//TODO Read more
|
//TODO Read more
|
||||||
} else {
|
} else {
|
||||||
std::string content(buffer);
|
readelf(buffer);
|
||||||
|
|
||||||
readelf(content);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("readelf: error: %s\n", std::error_message(content_result.error()));
|
printf("readelf: error: %s\n", std::error_message(content_result.error()));
|
||||||
|
@ -54,8 +54,7 @@ struct section_header {
|
|||||||
uint64_t sh_entsize;
|
uint64_t sh_entsize;
|
||||||
}__attribute__((packed));
|
}__attribute__((packed));
|
||||||
|
|
||||||
inline bool is_valid(const std::string& content){
|
inline bool is_valid(const char* buffer){
|
||||||
auto buffer = content.c_str();
|
|
||||||
auto header = reinterpret_cast<const elf::elf_header*>(buffer);
|
auto header = reinterpret_cast<const elf::elf_header*>(buffer);
|
||||||
|
|
||||||
//Test if ELF file
|
//Test if ELF file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user