2009-10-04 07:08:20 -06:00
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
https://github.com/peterix/dfhack
|
2012-09-29 20:03:37 -06:00
|
|
|
Copyright (c) 2009-2012 Petr Mrázek (peterix@gmail.com)
|
2009-10-04 07:08:20 -06:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2011-06-16 15:53:39 -06:00
|
|
|
|
2011-04-10 05:12:28 -06:00
|
|
|
#pragma once
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Pragma.h"
|
|
|
|
#include "Export.h"
|
2013-01-02 09:26:30 -07:00
|
|
|
/* #include "Types.h" */
|
2011-09-17 05:59:10 -06:00
|
|
|
#include <map>
|
2010-08-22 17:29:55 -06:00
|
|
|
#include <sys/types.h>
|
2011-08-23 02:48:28 -06:00
|
|
|
#include <vector>
|
2012-02-08 19:07:26 -07:00
|
|
|
#include <algorithm>
|
2010-06-10 09:53:25 -06:00
|
|
|
|
2009-11-13 20:46:56 -07:00
|
|
|
namespace DFHack
|
2009-10-04 07:08:20 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
/*
|
|
|
|
* Version Info
|
|
|
|
*/
|
2011-02-08 14:55:40 -07:00
|
|
|
enum OSType
|
|
|
|
{
|
|
|
|
OS_WINDOWS,
|
|
|
|
OS_LINUX,
|
|
|
|
OS_APPLE,
|
|
|
|
OS_BAD
|
|
|
|
};
|
2012-02-08 05:17:47 -07:00
|
|
|
struct DFHACK_EXPORT VersionInfo
|
2009-10-04 07:08:20 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
private:
|
2012-02-08 05:17:47 -07:00
|
|
|
std::vector <std::string> md5_list;
|
|
|
|
std::vector <uint32_t> PE_list;
|
2012-02-08 19:07:26 -07:00
|
|
|
std::map <std::string, uint32_t> Addresses;
|
2012-04-15 04:32:25 -06:00
|
|
|
std::map <std::string, uint32_t> VTables;
|
2012-02-08 05:17:47 -07:00
|
|
|
uint32_t base;
|
2012-04-15 04:32:25 -06:00
|
|
|
int rebase_delta;
|
2012-02-08 05:17:47 -07:00
|
|
|
std::string version;
|
|
|
|
OSType OS;
|
2009-11-13 20:46:56 -07:00
|
|
|
public:
|
2012-02-08 05:17:47 -07:00
|
|
|
VersionInfo()
|
|
|
|
{
|
2012-04-15 04:32:25 -06:00
|
|
|
base = 0; rebase_delta = 0;
|
2012-02-08 05:17:47 -07:00
|
|
|
version = "invalid";
|
|
|
|
OS = OS_BAD;
|
|
|
|
};
|
|
|
|
VersionInfo(const VersionInfo& rhs)
|
|
|
|
{
|
|
|
|
md5_list = rhs.md5_list;
|
|
|
|
PE_list = rhs.PE_list;
|
|
|
|
Addresses = rhs.Addresses;
|
2012-04-15 04:32:25 -06:00
|
|
|
VTables = rhs.VTables;
|
2012-02-08 05:17:47 -07:00
|
|
|
base = rhs.base;
|
2012-04-15 04:32:25 -06:00
|
|
|
rebase_delta = rhs.rebase_delta;
|
2012-02-08 05:17:47 -07:00
|
|
|
version = rhs.version;
|
|
|
|
OS = rhs.OS;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t getBase () const { return base; };
|
2012-04-15 04:32:25 -06:00
|
|
|
int getRebaseDelta() const { return rebase_delta; }
|
2012-02-08 05:17:47 -07:00
|
|
|
void setBase (const uint32_t _base) { base = _base; };
|
|
|
|
void rebaseTo(const uint32_t new_base)
|
|
|
|
{
|
|
|
|
int64_t old = base;
|
2012-02-08 19:07:26 -07:00
|
|
|
int64_t newx = new_base;
|
|
|
|
int64_t rebase = newx - old;
|
2012-02-08 05:17:47 -07:00
|
|
|
base = new_base;
|
2012-04-15 04:32:25 -06:00
|
|
|
rebase_delta += rebase;
|
|
|
|
for (auto iter = Addresses.begin(); iter != Addresses.end(); ++iter)
|
|
|
|
iter->second += rebase;
|
|
|
|
for (auto iter = VTables.begin(); iter != VTables.end(); ++iter)
|
|
|
|
iter->second += rebase;
|
2012-02-08 05:17:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void addMD5 (const std::string & _md5)
|
|
|
|
{
|
|
|
|
md5_list.push_back(_md5);
|
|
|
|
};
|
|
|
|
bool hasMD5 (const std::string & _md5) const
|
|
|
|
{
|
2012-02-08 19:07:26 -07:00
|
|
|
return std::find(md5_list.begin(), md5_list.end(), _md5) != md5_list.end();
|
2012-02-08 05:17:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void addPE (uint32_t PE_)
|
|
|
|
{
|
|
|
|
PE_list.push_back(PE_);
|
|
|
|
};
|
|
|
|
bool hasPE (uint32_t PE_) const
|
|
|
|
{
|
2012-02-08 19:07:26 -07:00
|
|
|
return std::find(PE_list.begin(), PE_list.end(), PE_) != PE_list.end();
|
2012-02-08 05:17:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void setVersion(const std::string& v)
|
|
|
|
{
|
|
|
|
version = v;
|
|
|
|
};
|
|
|
|
std::string getVersion() const { return version; };
|
|
|
|
|
|
|
|
void setAddress (const std::string& key, const uint32_t value)
|
|
|
|
{
|
|
|
|
Addresses[key] = value;
|
|
|
|
};
|
2012-02-08 19:07:26 -07:00
|
|
|
template <typename T>
|
|
|
|
bool getAddress (const std::string& key, T & value)
|
2012-02-08 05:17:47 -07:00
|
|
|
{
|
2012-02-08 19:07:26 -07:00
|
|
|
auto i = Addresses.find(key);
|
|
|
|
if(i == Addresses.end())
|
|
|
|
return false;
|
|
|
|
value = (T) (*i).second;
|
|
|
|
return true;
|
|
|
|
};
|
2012-04-15 04:32:25 -06:00
|
|
|
|
2012-02-08 19:07:26 -07:00
|
|
|
uint32_t getAddress (const std::string& key) const
|
|
|
|
{
|
|
|
|
auto i = Addresses.find(key);
|
2012-02-08 05:17:47 -07:00
|
|
|
if(i == Addresses.end())
|
|
|
|
return 0;
|
2012-02-08 19:07:26 -07:00
|
|
|
return (*i).second;
|
2012-02-08 05:17:47 -07:00
|
|
|
}
|
|
|
|
|
2012-04-15 04:32:25 -06:00
|
|
|
void setVTable (const std::string& key, const uint32_t value)
|
|
|
|
{
|
|
|
|
VTables[key] = value;
|
|
|
|
};
|
|
|
|
void *getVTable (const std::string& key) const
|
|
|
|
{
|
|
|
|
auto i = VTables.find(key);
|
|
|
|
if(i == VTables.end())
|
|
|
|
return 0;
|
|
|
|
return (void*)i->second;
|
|
|
|
}
|
|
|
|
|
2012-02-08 05:17:47 -07:00
|
|
|
void setOS(const OSType os)
|
|
|
|
{
|
|
|
|
OS = os;
|
|
|
|
};
|
|
|
|
OSType getOS() const
|
|
|
|
{
|
|
|
|
return OS;
|
|
|
|
};
|
2009-10-04 07:08:20 -06:00
|
|
|
};
|
2009-11-13 20:46:56 -07:00
|
|
|
}
|