style(kernel/elf): change code style
Some checks failed
Build OS / Build Cross-Compiler & Toolchain (push) Has been cancelled
Deploy Website / Deploy Website to GitHub Pages (push) Has been cancelled
Build OS / Analyze (c-cpp) (push) Has been cancelled
Build OS / Build OS (push) Has been cancelled

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
2025-04-03 12:06:23 +00:00
parent fe6d7f4b08
commit 0041300a00
9 changed files with 238 additions and 304 deletions

View File

@ -21,33 +21,28 @@
namespace Execute
{
std::vector<Elf64_Shdr> ELFGetSections_x86_64(FileNode *fd,
const char *SectionName)
std::vector<Elf_Shdr> ELFGetSections(FileNode *fd, const char *SectionName)
{
#if defined(__amd64__) || defined(__aarch64__)
std::vector<Elf64_Shdr> Ret;
std::vector<Elf_Shdr> ret;
Elf64_Ehdr ELFHeader{};
fd->Read(&ELFHeader, sizeof(Elf64_Ehdr), 0);
Elf_Ehdr ehdr{};
fd->Read(&ehdr, sizeof(Elf_Ehdr), 0);
Elf64_Shdr *SectionHeaders = new Elf64_Shdr[ELFHeader.e_shnum];
fd->Read(SectionHeaders, sizeof(Elf64_Shdr) * ELFHeader.e_shnum, ELFHeader.e_shoff);
Elf_Shdr *sections = new Elf_Shdr[ehdr.e_shnum];
fd->Read(sections, sizeof(Elf_Shdr) * ehdr.e_shnum, ehdr.e_shoff);
char *SectionNames = new char[SectionHeaders[ELFHeader.e_shstrndx].sh_size];
fd->Read(SectionNames, SectionHeaders[ELFHeader.e_shstrndx].sh_size, SectionHeaders[ELFHeader.e_shstrndx].sh_offset);
char *sectionNames = new char[sections[ehdr.e_shstrndx].sh_size];
fd->Read(sectionNames, sections[ehdr.e_shstrndx].sh_size, sections[ehdr.e_shstrndx].sh_offset);
for (Elf64_Half i = 0; i < ELFHeader.e_shnum; ++i)
for (Elf_Half i = 0; i < ehdr.e_shnum; ++i)
{
const char *Name = SectionNames + SectionHeaders[i].sh_name;
const char *Name = sectionNames + sections[i].sh_name;
if (strcmp(Name, SectionName) == 0)
Ret.push_back(SectionHeaders[i]);
ret.push_back(sections[i]);
}
delete[] SectionHeaders;
delete[] SectionNames;
return Ret;
#elif defined(__i386__)
return {};
#endif
delete[] sections;
delete[] sectionNames;
return ret;
}
}