mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-09 12:31:06 -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/pwd/pwd
|
||||
programs/which/which
|
||||
programs/readelf/readelf
|
||||
programs/cd/cd
|
||||
programs/dist/
|
@ -627,7 +627,9 @@ int64_t scheduler::exec(const std::string& file, const std::vector<std::string>&
|
||||
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<std::string>&
|
||||
return -std::ERROR_NOT_EXECUTABLE;
|
||||
}
|
||||
|
||||
auto buffer = content.c_str();
|
||||
|
||||
auto& process = new_process();
|
||||
|
||||
if(!create_paging(buffer, process)){
|
||||
|
Binary file not shown.
@ -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<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 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){
|
||||
//TODO Read more
|
||||
} else {
|
||||
std::string content(buffer);
|
||||
|
||||
readelf(content);
|
||||
readelf(buffer);
|
||||
}
|
||||
} else {
|
||||
printf("readelf: error: %s\n", std::error_message(content_result.error()));
|
||||
|
@ -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<const elf::elf_header*>(buffer);
|
||||
|
||||
//Test if ELF file
|
||||
|
Loading…
x
Reference in New Issue
Block a user