-
Notifications
You must be signed in to change notification settings - Fork 0
Michael elf parsing - LSDA parsing #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Mchan2003
commented
May 1, 2025
- Added ElfParser class
- Features
- able to parse out the headers
- open and close ELF files
- implemented LSDA parsing
…he elf header Completed Section and Program header parsing implement function to store lsda into a binary file and another to close the elf file fixed formatting fixed syntax errors
3f85911
to
e9790c5
Compare
CMakeLists.txt
Outdated
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
add_custom_target(copy_compile_commands ALL | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${CMAKE_BINARY_DIR}/compile_commands.json | ||
${CMAKE_SOURCE_DIR}/compile_commands.json | ||
DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json) | ||
|
||
# Find package dependancies | ||
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/build/Debug/generators") #TODO: Remove due to this being a temporary patch for libraries to work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try and keep code at 80 columns. Makes it easier to look at in most editors.
include/elf_parser.hpp
Outdated
#pragma once | ||
#include <bitset> | ||
#include <err.h> | ||
#include <fcntl.h> | ||
#include <gelf.h> | ||
#include <libelf.h> | ||
#include <print> | ||
#include <stdlib.h> | ||
#include <string> | ||
#include <sysexits.h> | ||
#include <unistd.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#pragma once | |
#include <bitset> | |
#include <err.h> | |
#include <fcntl.h> | |
#include <gelf.h> | |
#include <libelf.h> | |
#include <print> | |
#include <stdlib.h> | |
#include <string> | |
#include <sysexits.h> | |
#include <unistd.h> | |
#pragma once | |
#include <err.h> | |
#include <fcntl.h> | |
#include <stdlib.h> | |
#include <sysexits.h> | |
#include <unistd.h> | |
#include <gelf.h> | |
#include <libelf.h> | |
#include <bitset> | |
#include <string> | |
#include <print> |
Lets follow the libhal style guide for headers: https://libhal.github.io/4.1/contributor_guide/style/#s143-include-order
include/elf_parser.hpp
Outdated
ElfParser(char** t_file_ptr) | ||
: m_file(t_file_ptr){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ElfParser(char** t_file_ptr) | |
: m_file(t_file_ptr){}; | |
ElfParser(char** p_file_ptr) | |
: m_file(p_file_ptr){}; |
Input parameters should have prefix p_
include/elf_parser.hpp
Outdated
int m_fd, m_fbin; | ||
size_t m_n, m_shstrndx; | ||
|
||
char** m_file; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend replacing this with std::string so this object owns the string data.
include/elf_parser.hpp
Outdated
int m_elf_class{ 0 }; | ||
int m_fd, m_fbin; | ||
size_t m_n, m_shstrndx; | ||
|
||
char** m_file; | ||
|
||
char* m_name; | ||
Elf_Scn* m_scn; | ||
Elf_Data* m_data; | ||
|
||
Elf* m_e; | ||
GElf_Ehdr m_ehdr; | ||
GElf_Phdr m_phdr; | ||
GElf_Shdr m_shdr; | ||
//Gelf_Sym m_sym; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot, from visual inspection understand what of these are and why they need to be in the fields of the class.
include/elf_parser.hpp
Outdated
} | ||
} | ||
|
||
void ElfParser::getSection(std::string section) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the API name makes sense for what it does. Its more like it dumps the section to a bin file.
include/elf_parser.hpp
Outdated
void ElfParser::closeElf() | ||
{ | ||
close(m_fd); | ||
std::println("ELF file closed"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the destructor.
src/main.cpp
Outdated
#include "../include/elf_parser.hpp" | ||
#include <bitset> | ||
#include <print> | ||
#include <string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the order
src/main.cpp
Outdated
std::string lsda = ".gcc_except_table"; | ||
std::string symtab = ".symtab"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to not use std::string here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view
would work here instead.
src/main.cpp
Outdated
return 0; | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline to file for all files.
Also make everything |
…, move loading of the headers to the constructor, reformat to fit libhal formatting standard