diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-19 06:48:22 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-05-19 06:48:22 +0300 |
commit | d48f6281af49b17d1f6d6802b8921c1aed38a713 (patch) | |
tree | eb57744f1eb8a1e414b9b3ea9237156430acd83c /include | |
parent | refactoring (diff) | |
download | winapi-debug-d48f6281af49b17d1f6d6802b8921c1aed38a713.tar.gz winapi-debug-d48f6281af49b17d1f6d6802b8921c1aed38a713.zip |
hardening & refactoring
My latest obsession is integer overflows.
Diffstat (limited to '')
-rw-r--r-- | include/pdb/module.hpp | 56 |
1 files changed, 7 insertions, 49 deletions
diff --git a/include/pdb/module.hpp b/include/pdb/module.hpp index 3e785c4..e539fde 100644 --- a/include/pdb/module.hpp +++ b/include/pdb/module.hpp @@ -10,10 +10,6 @@ #include <Windows.h> #include <DbgHelp.h> -#include <cstring> - -#include <sstream> -#include <stdexcept> #include <string> namespace pdb @@ -23,16 +19,10 @@ namespace pdb public: typedef IMAGEHLP_MODULE64 Raw; - ModuleInfo() - : raw{prepare_buffer()} - { } - - explicit ModuleInfo(const Raw& raw) - : raw{raw} - { } + ModuleInfo(); + explicit ModuleInfo(const Raw& raw); explicit operator Raw&() { return raw; } - explicit operator const Raw&() const { return raw; } Address get_offline_base() const { return raw.BaseOfImage; } @@ -40,13 +30,7 @@ namespace pdb std::string get_name() const { return raw.ModuleName; } private: - static Raw prepare_buffer() - { - Raw raw; - std::memset(&raw, 0, sizeof(raw)); - raw.SizeOfStruct = sizeof(raw); - return raw; - } + static Raw create_raw(); Raw raw; }; @@ -61,38 +45,12 @@ 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(); - } + Address translate_offline_address(Address offline) const; + Address translate_online_address(Address online) const; 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(); - } + std::string invalid_offline_address(Address offline) const; + std::string invalid_online_address(Address online) const; const Address online_base; }; |