OffsetGroup class (unfinished)

develop
Petr Mrázek 2010-08-23 19:28:53 +02:00
parent 143f30f64b
commit b33d56354f
2 changed files with 193 additions and 170 deletions

@ -82,50 +82,183 @@ namespace DFHack
}; };
} }
/*
* Private data
*/
namespace DFHack
{
class OffsetGroupPrivate
{
public:
map <string, uint32_t> addresses;
map <string, int32_t> offsets;
map <string, uint32_t> hexvals;
map <string, string> strings;
map <string, OffsetGroup> groups;
};
}
void OffsetGroup::setOffset (const string & key, const string & value)
{
int32_t offset = strtol(value.c_str(), NULL, 16);
d->offsets[key] = offset;
}
void OffsetGroup::setAddress (const string & key, const string & value)
{
uint32_t address = strtol(value.c_str(), NULL, 16);
d->addresses[key] = address;
}
void OffsetGroup::setHexValue (const string & key, const string & value)
{
uint32_t hexval = strtol(value.c_str(), NULL, 16);
d->hexvals[key] = hexval;
}
void OffsetGroup::setString (const string & key, const string & value)
{
d->strings[key] = value;
}
// Get named address
uint32_t OffsetGroup::getAddress (const char *key)
{
map <string, uint32_t>::iterator iter = d->addresses.find(key);
if(iter != d->addresses.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("address", key);
}
// Get named offset
int32_t OffsetGroup::getOffset (const char *key)
{
map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("offset", key);
}
// Get named numerical value
uint32_t OffsetGroup::getHexValue (const char *key)
{
map <string, uint32_t>::iterator iter = d->hexvals.find(key);
if(iter != d->hexvals.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("hexvalue", key);
}
// Get named address
uint32_t OffsetGroup::getAddress (const string &key)
{
map <string, uint32_t>::iterator iter = d->addresses.find(key);
if(iter != d->addresses.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("address", key.c_str());
}
// Get named offset
int32_t OffsetGroup::getOffset (const string &key)
{
map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("offset", key.c_str());
}
// Get named numerical value
uint32_t OffsetGroup::getHexValue (const string &key)
{
map <string, uint32_t>::iterator iter = d->hexvals.find(key);
if(iter != d->hexvals.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("hexvalue", key.c_str());
}
// Get named string
std::string OffsetGroup::getString (const string &key)
{
map <string, string>::iterator iter = d->strings.find(key);
if(iter != d->strings.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("string", key.c_str());
}
/* /*
* Private data * Private data
*/ */
class VersionInfo::Private namespace DFHack
{ {
public: class VersionInfoPrivate
map <string, uint32_t> addresses; {
map <string, int32_t> offsets; public:
map <string, uint32_t> hexvals; map <string, uint32_t> addresses;
map <string, string> strings; map <string, int32_t> offsets;
map <string, uint32_t> hexvals;
map <string, string> strings;
vector<string> professions; vector<string> professions;
vector<string> jobs; vector<string> jobs;
vector<string> skills; vector<string> skills;
vector<DFHack::t_level> levels; vector<DFHack::t_level> levels;
vector< vector<string> > traits; vector< vector<string> > traits;
vector<string> moods; vector<string> moods;
map <uint32_t, string> labors; map <uint32_t, string> labors;
// storage for class and multiclass // storage for class and multiclass
vector<t_class *> classes; vector<t_class *> classes;
// cache for faster name lookup, indexed by classID // cache for faster name lookup, indexed by classID
vector<string> classnames; vector<string> classnames;
// map between vptr and class id, needs further type id lookup for multi-classes, not inherited // map between vptr and class id, needs further type id lookup for multi-classes, not inherited
map<uint32_t, t_class *> classIDs; map<uint32_t, t_class *> classIDs;
// index for the next added class // index for the next added class
uint32_t classindex; uint32_t classindex;
int32_t base; int32_t base;
Process * p; // the process this belongs to Process * p; // the process this belongs to
string version; string version;
OSType OS; VersionInfo::OSType OS;
std::string md5; std::string md5;
uint32_t PE_timestamp; uint32_t PE_timestamp;
}; };
}
// normal constructor // normal constructor
VersionInfo::VersionInfo() VersionInfo::VersionInfo()
:d(new Private) :d(new VersionInfoPrivate)
{ {
d->base = 0; d->base = 0;
d->p = 0; d->p = 0;
@ -139,7 +272,7 @@ VersionInfo::VersionInfo()
// copy constructor // copy constructor
VersionInfo::VersionInfo(const VersionInfo &old) VersionInfo::VersionInfo(const VersionInfo &old)
:d(new Private) :d(new VersionInfoPrivate)
{ {
copy(&old); copy(&old);
} }
@ -289,33 +422,6 @@ void VersionInfo::setBase (const uint32_t b)
} }
void VersionInfo::setOffset (const string & key, const string & value)
{
int32_t offset = strtol(value.c_str(), NULL, 16);
d->offsets[key] = offset;
}
void VersionInfo::setAddress (const string & key, const string & value)
{
uint32_t address = strtol(value.c_str(), NULL, 16);
d->addresses[key] = address;
}
void VersionInfo::setHexValue (const string & key, const string & value)
{
uint32_t hexval = strtol(value.c_str(), NULL, 16);
d->hexvals[key] = hexval;
}
void VersionInfo::setString (const string & key, const string & value)
{
d->strings[key] = value;
}
void VersionInfo::setLabor(const string & key, const string & value) void VersionInfo::setLabor(const string & key, const string & value)
{ {
uint32_t keyInt = strtol(key.c_str(), NULL, 10); uint32_t keyInt = strtol(key.c_str(), NULL, 10);
@ -600,92 +706,6 @@ void VersionInfo::RebaseVTable(int32_t offset)
} }
// Get named address
uint32_t VersionInfo::getAddress (const char *key)
{
map <string, uint32_t>::iterator iter = d->addresses.find(key);
if(iter != d->addresses.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("address", key);
}
// Get named offset
int32_t VersionInfo::getOffset (const char *key)
{
map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("offset", key);
}
// Get named numerical value
uint32_t VersionInfo::getHexValue (const char *key)
{
map <string, uint32_t>::iterator iter = d->hexvals.find(key);
if(iter != d->hexvals.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("hexvalue", key);
}
// Get named address
uint32_t VersionInfo::getAddress (const string &key)
{
map <string, uint32_t>::iterator iter = d->addresses.find(key);
if(iter != d->addresses.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("address", key.c_str());
}
// Get named offset
int32_t VersionInfo::getOffset (const string &key)
{
map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("offset", key.c_str());
}
// Get named numerical value
uint32_t VersionInfo::getHexValue (const string &key)
{
map <string, uint32_t>::iterator iter = d->hexvals.find(key);
if(iter != d->hexvals.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("hexvalue", key.c_str());
}
// Get named string
std::string VersionInfo::getString (const string &key)
{
map <string, string>::iterator iter = d->strings.find(key);
if(iter != d->strings.end())
{
return (*iter).second;
}
throw Error::MissingMemoryDefinition("string", key.c_str());
}
// Get Profession // Get Profession
string VersionInfo::getProfession (const uint32_t key) const string VersionInfo::getProfession (const uint32_t key) const
{ {
@ -811,11 +831,11 @@ std::string VersionInfo::PrintOffsets()
switch (getOS()) switch (getOS())
{ {
case OS_LINUX: case OS_LINUX:
ss << "<MD5 value=\"" << getString("md5") << "\" />" << endl; ss << "<MD5 value=\"" << getMD5() << "\" />" << endl;
break; break;
case OS_WINDOWS: case OS_WINDOWS:
ss << "<PETimeStamp value=\"" << hex << "0x" << getHexValue("pe_timestamp") << "\" />" << endl; ss << "<PETimeStamp value=\"" << hex << "0x" << getPE() << "\" />" << endl;
ss << "<MD5 value=\"" << getString("md5") << "\" />" << endl; ss << "<MD5 value=\"" << getMD5() << "\" />" << endl;
break; break;
default: default:
ss << " UNKNOWN" << endl; ss << " UNKNOWN" << endl;

@ -41,13 +41,37 @@ namespace DFHack
class OffsetGroupPrivate; class OffsetGroupPrivate;
class DFHACK_EXPORT OffsetGroup class DFHACK_EXPORT OffsetGroup
{ {
private: protected:
OffsetGroupPrivate * d; OffsetGroupPrivate * d;
public: public:
int32_t getOffset (const std::string&);
uint32_t getAddress (const std::string&);
uint32_t getHexValue (const std::string&);
std::string getString (const std::string&);
int32_t getOffset (const char *);
uint32_t getAddress (const char *);
uint32_t getHexValue (const char *);
std::string getString (const char *);
void setOffset (const std::string &, const int32_t);
void setAddress (const std::string &, const uint32_t);
void setHexValue (const std::string &, const uint32_t);
void setOffset (const std::string &, const char *);
void setAddress (const std::string &, const char *);
void setHexValue (const std::string &, const char *);
void setString (const std::string &, const char *);
void setOffset (const std::string &, const std::string &);
void setAddress (const std::string &, const std::string &);
void setHexValue (const std::string &, const std::string &);
void setString (const std::string &, const std::string &);
OffsetGroup & getGroup (const std::string name);
}; };
class DFHACK_EXPORT VersionInfo class DFHACK_EXPORT VersionInfo : public OffsetGroup
{ {
private: private:
VersionInfoPrivate * d; VersionInfoPrivate * d;
@ -76,13 +100,6 @@ namespace DFHack
void setPE (uint32_t PE_); void setPE (uint32_t PE_);
uint getPE(); uint getPE();
int32_t getOffset (const std::string&);
uint32_t getAddress (const std::string&);
uint32_t getHexValue (const std::string&);
int32_t getOffset (const char *);
uint32_t getAddress (const char *);
uint32_t getHexValue (const char *);
std::string getMood(const uint32_t moodID); std::string getMood(const uint32_t moodID);
std::string getString (const std::string&); std::string getString (const std::string&);
std::string getProfession(const uint32_t) const; std::string getProfession(const uint32_t) const;
@ -105,20 +122,6 @@ namespace DFHack
void setOS(const OSType); void setOS(const OSType);
OSType getOS() const; OSType getOS() const;
void setOffset (const std::string &, const int32_t);
void setAddress (const std::string &, const uint32_t);
void setHexValue (const std::string &, const uint32_t);
void setOffset (const std::string &, const char *);
void setAddress (const std::string &, const char *);
void setHexValue (const std::string &, const char *);
void setString (const std::string &, const char *);
void setOffset (const std::string &, const std::string &);
void setAddress (const std::string &, const std::string &);
void setHexValue (const std::string &, const std::string &);
void setString (const std::string &, const std::string &);
void setProfession(const std::string & id, const std::string & name); void setProfession(const std::string & id, const std::string & name);
void setJob(const std::string &, const std::string &); void setJob(const std::string &, const std::string &);
void setSkill(const std::string &, const std::string &); void setSkill(const std::string &, const std::string &);