From a8d767a99e4c09975503e092ee4674962b27c3ce Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 19 May 2017 05:31:58 +0300 Subject: refactoring --- include/pdb/address.hpp | 10 ++++++++++ include/pdb/module.hpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'include/pdb') diff --git a/include/pdb/address.hpp b/include/pdb/address.hpp index 53b25e8..33e0ac3 100644 --- a/include/pdb/address.hpp +++ b/include/pdb/address.hpp @@ -7,7 +7,17 @@ #include +#include +#include + namespace pdb { typedef DWORD64 Address; + + inline std::string format_address(Address address) + { + std::ostringstream oss; + oss << std::hex << std::showbase << address; + return oss.str(); + } } diff --git a/include/pdb/module.hpp b/include/pdb/module.hpp index 118a53b..3e785c4 100644 --- a/include/pdb/module.hpp +++ b/include/pdb/module.hpp @@ -12,6 +12,8 @@ #include +#include +#include #include namespace pdb @@ -59,7 +61,39 @@ namespace pdb Address get_online_base() const { return online_base; } + Address translate_offline_address(Address offline) const + { + if (offline < get_offline_base()) + throw std::range_error{invalid_offline_address(offline)}; + return offline - get_offline_base() + get_online_base(); + } + + Address translate_online_address(Address online) const + { + if (online < get_online_base()) + throw std::range_error{invalid_online_address(online)}; + return online - get_online_base() + get_offline_base(); + } + private: + std::string invalid_offline_address(Address offline) const + { + std::ostringstream oss; + oss << "offline address " << format_address(offline) + << " doesn't belong to module " << get_name() + << " (base offline address " << format_address(get_offline_base()) << ')'; + return oss.str(); + } + + std::string invalid_online_address(Address online) const + { + std::ostringstream oss; + oss << "online address " << format_address(online) + << " doesn't belong to module " << get_name() + << " (base online address " << format_address(get_online_base()) << ')'; + return oss.str(); + } + const Address online_base; }; } -- cgit v1.2.3