aboutsummaryrefslogblamecommitdiffstatshomepage
path: root/include/pdb/module.hpp
blob: db6722e6a067262bb55c38bfab874e3f93cb821f (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                            
                    
                    
 

                 
               
 


                                  
 

                                        
 

                                                        
 
                                                                
 
                                                           
 

                            
 

            
 



                                                       
 
                                                           
 

                                                             
 







                                                               
// Copyright (c) 2017 Egor Tensin <Egor.Tensin@gmail.com>
// This file is part of the "PDB repository" project.
// For details, see https://github.com/egor-tensin/pdb-repo.
// Distributed under the MIT License.

#pragma once

#include "address.hpp"

#include <DbgHelp.h>
#include <Windows.h>

#include <string>

namespace pdb {

class ModuleInfo {
public:
    typedef IMAGEHLP_MODULE64 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; }

    std::string get_name() const { return raw.ModuleName; }

private:
    static Raw create_raw();

    Raw raw;
};

class Module : public ModuleInfo {
public:
    Module(Address online_base, const ModuleInfo& info)
        : ModuleInfo{info}, online_base{online_base} {}

    Address get_online_base() const { return online_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::string invalid_online_address(Address online) const;

    const Address online_base;
};

} // namespace pdb