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/capstone/include)
include_directories(external)
if(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
+2 -2
View File
@@ -1,5 +1,5 @@
#pragma once
#include <types.hpp>
#include <ircolib/types.hpp>
#include <fstream>
#include <vector>
#include <filesystem>
@@ -40,4 +40,4 @@ static inline size_t NextPow2(size_t num) {
num |= num >> 16;
return num + 1;
}
} // namespace Util
} // namespace ircolib
+6 -9
View File
@@ -1,5 +1,5 @@
#pragma once
#include <types.hpp>
#include <ircolib/types.hpp>
#include <cstring>
#include <functional>
#include <bit>
@@ -17,9 +17,8 @@ static inline std::vector<u8> IntegralToBuffer(const std::integral auto &val) {
return ret;
}
static inline constexpr bool IsInsideRange(const std::integral auto& addr,
const std::integral auto& start,
const std::integral auto& end) {
static inline constexpr bool IsInsideRange(const std::integral auto &addr, const std::integral auto &start,
const std::integral auto &end) {
return addr >= start && addr <= end;
}
@@ -41,7 +40,7 @@ template <>
constexpr inline u64 ReadAccess(const u8 *data, const u32 index) {
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
const auto& result = static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
const auto &result = static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
return result;
}
@@ -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); }
#else
inline void *aligned_alloc(const size_t alignment, const size_t size) {
return std::aligned_alloc(alignment, size);
}
inline void *aligned_alloc(const size_t alignment, const size_t size) { return std::aligned_alloc(alignment, size); }
inline void aligned_free(void *ptr) { std::free(ptr); }
#endif
} // namespace Util
} // namespace ircolib
+7 -9
View File
@@ -1,22 +1,20 @@
#include <print>
#include <elfio/elfio.hpp>
#include <ircolib/mem_access.hpp>
int main() {
ELFIO::elfio reader;
if (!reader.load("tests/elf/application.elf"))
return 1;
for (ELFIO::Elf_Half i = 0; i < reader.segments.size(); i++) {
const auto &segment = reader.segments[i];
std::println(R"(Segment type {} @ 0x{:08X} -> 0x{:08X})", segment->get_type(), segment->get_virtual_address(),
segment->get_virtual_address() + segment->get_memory_size() - 1);
}
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(),
for (const auto &section : reader.sections) {
for (const auto &segment : reader.segments) {
if (ircolib::IsInsideRange(section->get_address(), segment->get_virtual_address(),
segment->get_virtual_address() + segment->get_memory_size() - 1))
std::println("Found section {} @ 0x{:08X} -> 0x{:08X}", section->get_index(), section->get_address(),
section->get_address() + section->get_size() - 1);
}
}
return 0;
}