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,11 +82,143 @@ 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
*/
class VersionInfo::Private
namespace DFHack
{
class VersionInfoPrivate
{
public:
map <string, uint32_t> addresses;
@ -117,15 +249,16 @@ class VersionInfo::Private
Process * p; // the process this belongs to
string version;
OSType OS;
VersionInfo::OSType OS;
std::string md5;
uint32_t PE_timestamp;
};
}
// normal constructor
VersionInfo::VersionInfo()
:d(new Private)
:d(new VersionInfoPrivate)
{
d->base = 0;
d->p = 0;
@ -139,7 +272,7 @@ VersionInfo::VersionInfo()
// copy constructor
VersionInfo::VersionInfo(const VersionInfo &old)
:d(new Private)
:d(new VersionInfoPrivate)
{
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)
{
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
string VersionInfo::getProfession (const uint32_t key) const
{
@ -811,11 +831,11 @@ std::string VersionInfo::PrintOffsets()
switch (getOS())
{
case OS_LINUX:
ss << "<MD5 value=\"" << getString("md5") << "\" />" << endl;
ss << "<MD5 value=\"" << getMD5() << "\" />" << endl;
break;
case OS_WINDOWS:
ss << "<PETimeStamp value=\"" << hex << "0x" << getHexValue("pe_timestamp") << "\" />" << endl;
ss << "<MD5 value=\"" << getString("md5") << "\" />" << endl;
ss << "<PETimeStamp value=\"" << hex << "0x" << getPE() << "\" />" << endl;
ss << "<MD5 value=\"" << getMD5() << "\" />" << endl;
break;
default:
ss << " UNKNOWN" << endl;

@ -41,13 +41,37 @@ namespace DFHack
class OffsetGroupPrivate;
class DFHACK_EXPORT OffsetGroup
{
private:
protected:
OffsetGroupPrivate * d;
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:
VersionInfoPrivate * d;
@ -76,13 +100,6 @@ namespace DFHack
void setPE (uint32_t PE_);
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 getString (const std::string&);
std::string getProfession(const uint32_t) const;
@ -105,20 +122,6 @@ namespace DFHack
void setOS(const OSType);
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 setJob(const std::string &, const std::string &);
void setSkill(const std::string &, const std::string &);