aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/pdb/address.hpp10
-rw-r--r--include/pdb/module.hpp34
2 files changed, 44 insertions, 0 deletions
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 <Windows.h>
+#include <sstream>
+#include <string>
+
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 <cstring>
+#include <sstream>
+#include <stdexcept>
#include <string>
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;
};
}