cool
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Vendored
+2
-2
@@ -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
|
||||||
|
|||||||
Vendored
+6
-9
@@ -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,9 +17,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ template <>
|
|||||||
constexpr inline u64 ReadAccess(const u8 *data, const u32 index) {
|
constexpr inline u64 ReadAccess(const u8 *data, const u32 index) {
|
||||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
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;
|
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); }
|
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
|
||||||
|
|||||||
@@ -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 §ion : 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 §ion = 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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user