This commit is contained in:
2026-05-11 18:07:14 +02:00
parent f563827898
commit 2b0176790e
4 changed files with 75 additions and 79 deletions
+1
View File
@@ -8,6 +8,7 @@ option(BUILD_SHARED_LIBS OFF)
include_directories(external/ELFIO) include_directories(external/ELFIO)
include_directories(external/capstone/include) include_directories(external/capstone/include)
include_directories(external)
if(WIN32) if(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
+2 -2
View File
@@ -1,5 +1,5 @@
#pragma once #pragma once
#include <types.hpp> #include <ircolib/types.hpp>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <filesystem> #include <filesystem>
@@ -40,4 +40,4 @@ static inline size_t NextPow2(size_t num) {
num |= num >> 16; num |= num >> 16;
return num + 1; return num + 1;
} }
} // namespace Util } // namespace ircolib
+4 -7
View File
@@ -1,5 +1,5 @@
#pragma once #pragma once
#include <types.hpp> #include <ircolib/types.hpp>
#include <cstring> #include <cstring>
#include <functional> #include <functional>
#include <bit> #include <bit>
@@ -17,8 +17,7 @@ static inline std::vector<u8> IntegralToBuffer(const std::integral auto &val) {
return ret; return ret;
} }
static inline constexpr bool IsInsideRange(const std::integral auto& addr, static inline constexpr bool IsInsideRange(const std::integral auto &addr, const std::integral auto &start,
const std::integral auto& start,
const std::integral auto &end) { const std::integral auto &end) {
return addr >= start && addr <= end; return addr >= start && addr <= end;
} }
@@ -137,10 +136,8 @@ inline void *aligned_alloc(const size_t alignment, const size_t size) { return _
inline void aligned_free(void *ptr) { _aligned_free(ptr); } inline void aligned_free(void *ptr) { _aligned_free(ptr); }
#else #else
inline void *aligned_alloc(const size_t alignment, const size_t size) { inline void *aligned_alloc(const size_t alignment, const size_t size) { return std::aligned_alloc(alignment, size); }
return std::aligned_alloc(alignment, size);
}
inline void aligned_free(void *ptr) { std::free(ptr); } inline void aligned_free(void *ptr) { std::free(ptr); }
#endif #endif
} // namespace Util } // namespace ircolib
+7 -9
View File
@@ -1,22 +1,20 @@
#include <print> #include <print>
#include <elfio/elfio.hpp> #include <elfio/elfio.hpp>
#include <ircolib/mem_access.hpp>
int main() { int main() {
ELFIO::elfio reader; ELFIO::elfio reader;
if (!reader.load("tests/elf/application.elf")) if (!reader.load("tests/elf/application.elf"))
return 1; return 1;
for (ELFIO::Elf_Half i = 0; i < reader.segments.size(); i++) { for (const auto &section : reader.sections) {
const auto &segment = reader.segments[i]; for (const auto &segment : reader.segments) {
std::println(R"(Segment type {} @ 0x{:08X} -> 0x{:08X})", segment->get_type(), segment->get_virtual_address(), if (ircolib::IsInsideRange(section->get_address(), segment->get_virtual_address(),
segment->get_virtual_address() + segment->get_memory_size() - 1); segment->get_virtual_address() + segment->get_memory_size() - 1))
} std::println("Found section {} @ 0x{:08X} -> 0x{:08X}", section->get_index(), section->get_address(),
for (ELFIO::Elf_Half i = 1; i < reader.sections.size(); i++) {
const auto &section = reader.sections[i];
std::println(R"(Section n.{} "{}": 0x{:08X} -> 0x{:08X})", i, section->get_name(), section->get_address(),
section->get_address() + section->get_size() - 1); section->get_address() + section->get_size() - 1);
} }
}
return 0; return 0;
} }