Rename memory_info and its factory class.

develop
Petr Mrázek 2010-08-20 14:10:05 +02:00
parent 3b29fddf7b
commit 1bceac2343
45 changed files with 473 additions and 439 deletions

@ -27,11 +27,11 @@ include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/)
include_directories (${CMAKE_SOURCE_DIR}/library/private/) include_directories (${CMAKE_SOURCE_DIR}/library/private/)
SET(PROJECT_HDRS SET(PROJECT_HDRS
private/DFMemInfoManager.h private/VersionInfoFactory.h
private/ContextShared.h private/ContextShared.h
private/Internal.h private/Internal.h
include/dfhack/DFError.h include/dfhack/DFError.h
include/dfhack/DFMemInfo.h include/dfhack/VersionInfo.h
include/dfhack/DFProcessEnumerator.h include/dfhack/DFProcessEnumerator.h
include/dfhack/DFProcess.h include/dfhack/DFProcess.h
include/dfhack/DFTileTypes.h include/dfhack/DFTileTypes.h
@ -60,8 +60,8 @@ include/dfhack-c/DFContext_C.h
) )
SET(PROJECT_SRCS SET(PROJECT_SRCS
DFMemInfo.cpp VersionInfo.cpp
DFMemInfoManager.cpp VersionInfoFactory.cpp
DFContextManager.cpp DFContextManager.cpp
DFContext.cpp DFContext.cpp
DFProcessEnumerator.cpp DFProcessEnumerator.cpp
@ -147,7 +147,7 @@ SET( MEMXML_DATA_PATH . CACHE PATH "search path for Memory.xml")
# OPTION( VARIABLE "Description" Initial state) # OPTION( VARIABLE "Description" Initial state)
#OPTION( WITH_FOO "Enable FOO support" ON ) #OPTION( WITH_FOO "Enable FOO support" ON )
#OPTION( WITH_BAR "Enable BAR component" OFF ) #OPTION( WITH_BAR "Enable BAR component" OFF )
# Are we 64bit? (Damn you, ptrace()!) # Are we 64bit? (Damn you, ptrace()!)
IF( CMAKE_SIZEOF_VOID_P MATCHES 4 ) IF( CMAKE_SIZEOF_VOID_P MATCHES 4 )
SET( HAVE_64_BIT 0 ) SET( HAVE_64_BIT 0 )
@ -165,7 +165,7 @@ IF(UNIX)
find_library(X11_LIBRARY X11) find_library(X11_LIBRARY X11)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall") SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden") SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
SET(PROJECT_LIBS ${X11_LIBRARY} rt ) #dfhack-md5 dfhack-tixml SET(PROJECT_LIBS ${X11_LIBRARY} rt ) #dfhack-md5 dfhack-tixml
ELSE(UNIX) ELSE(UNIX)
SET(PROJECT_LIBS psapi) SET(PROJECT_LIBS psapi)

@ -4,7 +4,7 @@
#include <mod-maps.h> #include <mod-maps.h>
#include <mod-creature40d.h> #include <mod-creature40d.h>
#include "private/ContextShared.h" #include "private/ContextShared.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"

@ -199,7 +199,7 @@ void Context::WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *sou
d->p->write (offset, size, source); d->p->write (offset, size, source);
} }
memory_info *Context::getMemoryInfo() VersionInfo *Context::getMemoryInfo()
{ {
return d->offset_descriptor; return d->offset_descriptor;
} }

@ -23,7 +23,7 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "DFMemInfoManager.h" #include "VersionInfoFactory.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
@ -142,7 +142,7 @@ ContextManager::~ContextManager()
uint32_t ContextManager::Refresh( BadContexts* bad_contexts ) uint32_t ContextManager::Refresh( BadContexts* bad_contexts )
{ {
// handle expired processes, remove stale Contexts // handle expired processes, remove stale Contexts
{ {
BadProcesses expired; BadProcesses expired;
// get new list od living and expired Process objects // get new list od living and expired Process objects

@ -23,7 +23,7 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <errno.h> #include <errno.h>
@ -63,7 +63,7 @@ class SHMProcess::Private
self = self_; self = self_;
}; };
~Private(){}; ~Private(){};
memory_info * memdescriptor; VersionInfo * memdescriptor;
Process * self; Process * self;
pid_t process_ID; pid_t process_ID;
char *shm_addr; char *shm_addr;
@ -79,7 +79,7 @@ class SHMProcess::Private
bool identified; bool identified;
bool useYield; bool useYield;
bool validate(std::vector< memory_info* >& known_versions); bool validate(std::vector< VersionInfo* >& known_versions);
bool Aux_Core_Attach(bool & versionOK, pid_t & PID); bool Aux_Core_Attach(bool & versionOK, pid_t & PID);
//bool waitWhile (uint32_t state); //bool waitWhile (uint32_t state);
@ -159,7 +159,7 @@ uint32_t OS_getAffinity()
bool SHMProcess::Private::AreLocksOk() bool SHMProcess::Private::AreLocksOk()
{ {
// both locks are inited (we hold our lock) // both locks are inited (we hold our lock)
if(client_lock != -1 && server_lock != -1) if(client_lock != -1 && server_lock != -1)
{ {
if(lockf(server_lock,F_TEST,0) == -1) // and server holds its lock if(lockf(server_lock,F_TEST,0) == -1) // and server holds its lock
{ {
@ -204,7 +204,7 @@ bool SHMProcess::Private::GetLocks()
// cerr << "can't open sv lock" << endl; // cerr << "can't open sv lock" << endl;
return false; return false;
} }
if(lockf( server_lock, F_TEST, 0 ) != -1) if(lockf( server_lock, F_TEST, 0 ) != -1)
{ {
cerr << "sv lock not locked" << endl; cerr << "sv lock not locked" << endl;
@ -212,7 +212,7 @@ bool SHMProcess::Private::GetLocks()
server_lock = -1; server_lock = -1;
return false; return false;
} }
for(int i = 0; i < SHM_MAX_CLIENTS; i++) for(int i = 0; i < SHM_MAX_CLIENTS; i++)
{ {
// open the client suspend locked // open the client suspend locked
@ -258,7 +258,7 @@ bool SHMProcess::Private::GetLocks()
return false; return false;
} }
SHMProcess::SHMProcess(uint32_t PID, vector< memory_info* >& known_versions) SHMProcess::SHMProcess(uint32_t PID, vector< VersionInfo* >& known_versions)
: d(new Private(this)) : d(new Private(this))
{ {
d->process_ID = PID; d->process_ID = PID;
@ -282,7 +282,7 @@ SHMProcess::SHMProcess(uint32_t PID, vector< memory_info* >& known_versions)
detach(); detach();
throw Error::SHMVersionMismatch(); throw Error::SHMVersionMismatch();
} }
// try to identify the DF version (md5 the binary, compare with known versions) // try to identify the DF version (md5 the binary, compare with known versions)
d->validate(known_versions); d->validate(known_versions);
// detach // detach
@ -303,7 +303,7 @@ bool SHMProcess::isIdentified()
return d->identified; return d->identified;
} }
bool SHMProcess::Private::validate(vector <memory_info *> & known_versions) bool SHMProcess::Private::validate(vector <VersionInfo *> & known_versions)
{ {
char exe_link_name [256]; char exe_link_name [256];
char target_name[1024]; char target_name[1024];
@ -319,11 +319,11 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
// make sure we have a null terminated string... // make sure we have a null terminated string...
// see http://www.opengroup.org/onlinepubs/000095399/functions/readlink.html // see http://www.opengroup.org/onlinepubs/000095399/functions/readlink.html
target_name[target_result] = 0; target_name[target_result] = 0;
md5wrapper md5; md5wrapper md5;
// get hash of the running DF process // get hash of the running DF process
string hash = md5.getHashFromFile(target_name); string hash = md5.getHashFromFile(target_name);
vector<memory_info *>::iterator it; vector<VersionInfo *>::iterator it;
// cerr << exe_file << " " << hash << endl; // cerr << exe_file << " " << hash << endl;
// iterate over the list of memory locations // iterate over the list of memory locations
for ( it=known_versions.begin() ; it < known_versions.end(); it++ ) for ( it=known_versions.begin() ; it < known_versions.end(); it++ )
@ -331,7 +331,7 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
try{ try{
if(hash == (*it)->getString("md5")) // are the md5 hashes the same? if(hash == (*it)->getString("md5")) // are the md5 hashes the same?
{ {
memory_info *m = new memory_info(**it); VersionInfo *m = new VersionInfo(**it);
memdescriptor = m; memdescriptor = m;
m->setParentProcess(dynamic_cast<Process *>( self )); m->setParentProcess(dynamic_cast<Process *>( self ));
identified = true; identified = true;
@ -358,7 +358,7 @@ SHMProcess::~SHMProcess()
delete d; delete d;
} }
memory_info * SHMProcess::getDescriptor() VersionInfo * SHMProcess::getDescriptor()
{ {
return d->memdescriptor; return d->memdescriptor;
} }
@ -385,11 +385,11 @@ void SHMProcess::getMemRanges( vector<t_memrange> & ranges )
{ {
char buffer[1024]; char buffer[1024];
char permissions[5]; // r/-, w/-, x/-, p/s, 0 char permissions[5]; // r/-, w/-, x/-, p/s, 0
sprintf(buffer, "/proc/%lu/maps", d->process_ID); sprintf(buffer, "/proc/%lu/maps", d->process_ID);
FILE *mapFile = ::fopen(buffer, "r"); FILE *mapFile = ::fopen(buffer, "r");
uint64_t offset, device1, device2, node; uint64_t offset, device1, device2, node;
while (fgets(buffer, 1024, mapFile)) while (fgets(buffer, 1024, mapFile))
{ {
t_memrange temp; t_memrange temp;
@ -417,7 +417,7 @@ bool SHMProcess::suspend()
{ {
return true; return true;
} }
// FIXME: this should be controlled on the server side // FIXME: this should be controlled on the server side
// FIXME: IF server got CORE_RUN in this frame, interpret CORE_SUSPEND as CORE_STEP // FIXME: IF server got CORE_RUN in this frame, interpret CORE_SUSPEND as CORE_STEP
// did we just resume a moment ago? // did we just resume a moment ago?
@ -546,7 +546,7 @@ bool SHMProcess::attach()
cerr << "can't find segment" << endl; // FIXME: throw cerr << "can't find segment" << endl; // FIXME: throw
return false; return false;
} }
/* /*
* Attach the segment * Attach the segment
*/ */
@ -592,7 +592,7 @@ bool SHMProcess::detach()
void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buffer) void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buffer)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
// normal read under 1MB // normal read under 1MB
if(size <= SHM_BODY) if(size <= SHM_BODY)
{ {
@ -629,7 +629,7 @@ void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buff
uint8_t SHMProcess::readByte (const uint32_t offset) uint8_t SHMProcess::readByte (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_BYTE); d->SetAndWait(CORE_READ_BYTE);
@ -639,7 +639,7 @@ uint8_t SHMProcess::readByte (const uint32_t offset)
void SHMProcess::readByte (const uint32_t offset, uint8_t &val ) void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_BYTE); d->SetAndWait(CORE_READ_BYTE);
@ -649,7 +649,7 @@ void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
uint16_t SHMProcess::readWord (const uint32_t offset) uint16_t SHMProcess::readWord (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_WORD); d->SetAndWait(CORE_READ_WORD);
@ -659,7 +659,7 @@ uint16_t SHMProcess::readWord (const uint32_t offset)
void SHMProcess::readWord (const uint32_t offset, uint16_t &val) void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_WORD); d->SetAndWait(CORE_READ_WORD);
@ -669,7 +669,7 @@ void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
uint32_t SHMProcess::readDWord (const uint32_t offset) uint32_t SHMProcess::readDWord (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -678,7 +678,7 @@ uint32_t SHMProcess::readDWord (const uint32_t offset)
void SHMProcess::readDWord (const uint32_t offset, uint32_t &val) void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -688,7 +688,7 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
uint64_t SHMProcess::readQuad (const uint32_t offset) uint64_t SHMProcess::readQuad (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_QUAD); d->SetAndWait(CORE_READ_QUAD);
@ -697,7 +697,7 @@ uint64_t SHMProcess::readQuad (const uint32_t offset)
void SHMProcess::readQuad (const uint32_t offset, uint64_t &val) void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_QUAD); d->SetAndWait(CORE_READ_QUAD);
@ -707,7 +707,7 @@ void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
float SHMProcess::readFloat (const uint32_t offset) float SHMProcess::readFloat (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -716,7 +716,7 @@ float SHMProcess::readFloat (const uint32_t offset)
void SHMProcess::readFloat (const uint32_t offset, float &val) void SHMProcess::readFloat (const uint32_t offset, float &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
gcc_barrier gcc_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -730,7 +730,7 @@ void SHMProcess::readFloat (const uint32_t offset, float &val)
void SHMProcess::writeQuad (const uint32_t offset, const uint64_t data) void SHMProcess::writeQuad (const uint32_t offset, const uint64_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->Qvalue = data; D_SHMHDR->Qvalue = data;
gcc_barrier gcc_barrier
@ -740,7 +740,7 @@ void SHMProcess::writeQuad (const uint32_t offset, const uint64_t data)
void SHMProcess::writeDWord (uint32_t offset, uint32_t data) void SHMProcess::writeDWord (uint32_t offset, uint32_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->value = data; D_SHMHDR->value = data;
gcc_barrier gcc_barrier
@ -751,7 +751,7 @@ void SHMProcess::writeDWord (uint32_t offset, uint32_t data)
void SHMProcess::writeWord (uint32_t offset, uint16_t data) void SHMProcess::writeWord (uint32_t offset, uint16_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->value = data; D_SHMHDR->value = data;
gcc_barrier gcc_barrier
@ -761,7 +761,7 @@ void SHMProcess::writeWord (uint32_t offset, uint16_t data)
void SHMProcess::writeByte (uint32_t offset, uint8_t data) void SHMProcess::writeByte (uint32_t offset, uint8_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->value = data; D_SHMHDR->value = data;
gcc_barrier gcc_barrier
@ -771,7 +771,7 @@ void SHMProcess::writeByte (uint32_t offset, uint8_t data)
void SHMProcess::write (uint32_t dst_address, uint32_t size, uint8_t *source_buffer) void SHMProcess::write (uint32_t dst_address, uint32_t size, uint8_t *source_buffer)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
// normal write under 1MB // normal write under 1MB
if(size <= SHM_BODY) if(size <= SHM_BODY)
{ {
@ -809,7 +809,7 @@ void SHMProcess::write (uint32_t dst_address, uint32_t size, uint8_t *source_buf
const std::string SHMProcess::readCString (uint32_t offset) const std::string SHMProcess::readCString (uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
std::string temp; std::string temp;
char temp_c[256]; char temp_c[256];
int counter = 0; int counter = 0;
@ -828,7 +828,7 @@ const std::string SHMProcess::readCString (uint32_t offset)
const std::string SHMProcess::readSTLString(uint32_t offset) const std::string SHMProcess::readSTLString(uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_STL_STRING); d->SetAndWait(CORE_READ_STL_STRING);
@ -838,7 +838,7 @@ const std::string SHMProcess::readSTLString(uint32_t offset)
size_t SHMProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) size_t SHMProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_STL_STRING); d->SetAndWait(CORE_READ_STL_STRING);
@ -852,7 +852,7 @@ size_t SHMProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapa
void SHMProcess::writeSTLString(const uint32_t address, const std::string writeString) void SHMProcess::writeSTLString(const uint32_t address, const std::string writeString)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = address; D_SHMHDR->address = address;
strncpy(D_SHMDATA(char),writeString.c_str(),writeString.length()+1); // length + 1 for the null terminator strncpy(D_SHMDATA(char),writeString.c_str(),writeString.length()+1); // length + 1 for the null terminator
full_barrier full_barrier
@ -862,7 +862,7 @@ void SHMProcess::writeSTLString(const uint32_t address, const std::string writeS
string SHMProcess::readClassName (uint32_t vptr) string SHMProcess::readClassName (uint32_t vptr)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
int typeinfo = readDWord(vptr - 0x4); int typeinfo = readDWord(vptr - 0x4);
int typestring = readDWord(typeinfo + 0x4); int typestring = readDWord(typeinfo + 0x4);
string raw = readCString(typestring); string raw = readCString(typestring);
@ -875,13 +875,13 @@ string SHMProcess::readClassName (uint32_t vptr)
bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
modulelookup * payload = D_SHMDATA(modulelookup); modulelookup * payload = D_SHMDATA(modulelookup);
payload->version = version; payload->version = version;
strncpy(payload->name,name,255); strncpy(payload->name,name,255);
payload->name[255] = 0; payload->name[255] = 0;
if(!SetAndWait(CORE_ACQUIRE_MODULE)) if(!SetAndWait(CORE_ACQUIRE_MODULE))
{ {
return false; // FIXME: throw a fatal exception instead return false; // FIXME: throw a fatal exception instead
@ -898,14 +898,14 @@ bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint
char * SHMProcess::getSHMStart (void) char * SHMProcess::getSHMStart (void)
{ {
if(!d->locked) return 0; //THROW HERE! if(!d->locked) return 0; //THROW HERE!
return /*d->shm_addr_with_cl_idx*/ d->shm_addr; return /*d->shm_addr_with_cl_idx*/ d->shm_addr;
} }
bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, pid_t & PID) bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, pid_t & PID)
{ {
if(!locked) throw Error::MemoryAccessDenied(); if(!locked) throw Error::MemoryAccessDenied();
SHMDATA(coreattach)->cl_affinity = OS_getAffinity(); SHMDATA(coreattach)->cl_affinity = OS_getAffinity();
if(!SetAndWait(CORE_ATTACH)) return false; if(!SetAndWait(CORE_ATTACH)) return false;
/* /*

@ -23,7 +23,7 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <errno.h> #include <errno.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
@ -44,7 +44,7 @@ class WineProcess::Private
self = self_; self = self_;
}; };
~Private(){}; ~Private(){};
memory_info * my_descriptor; VersionInfo * my_descriptor;
Process * self; Process * self;
pid_t my_handle; pid_t my_handle;
uint32_t my_pid; uint32_t my_pid;
@ -53,10 +53,10 @@ class WineProcess::Private
bool attached; bool attached;
bool suspended; bool suspended;
bool identified; bool identified;
bool validate(char * exe_file, uint32_t pid, char * mem_file, vector <memory_info *> & known_versions); bool validate(char * exe_file, uint32_t pid, char * mem_file, vector <VersionInfo *> & known_versions);
}; };
WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions) WineProcess::WineProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
: d(new Private(this)) : d(new Private(this))
{ {
char dir_name [256]; char dir_name [256];
@ -66,16 +66,16 @@ WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions)
char cmdline_name [256]; char cmdline_name [256];
char target_name[1024]; char target_name[1024];
int target_result; int target_result;
d->identified = false; d->identified = false;
d->my_descriptor = 0; d->my_descriptor = 0;
sprintf(dir_name,"/proc/%d/", pid); sprintf(dir_name,"/proc/%d/", pid);
sprintf(exe_link_name,"/proc/%d/exe", pid); sprintf(exe_link_name,"/proc/%d/exe", pid);
sprintf(mem_name,"/proc/%d/mem", pid); sprintf(mem_name,"/proc/%d/mem", pid);
sprintf(cwd_name,"/proc/%d/cwd", pid); sprintf(cwd_name,"/proc/%d/cwd", pid);
sprintf(cmdline_name,"/proc/%d/cmdline", pid); sprintf(cmdline_name,"/proc/%d/cmdline", pid);
// resolve /proc/PID/exe link // resolve /proc/PID/exe link
target_result = readlink(exe_link_name, target_name, sizeof(target_name)-1); target_result = readlink(exe_link_name, target_name, sizeof(target_name)-1);
if (target_result == -1) if (target_result == -1)
@ -84,7 +84,7 @@ WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions)
} }
// make sure we have a null terminated string... // make sure we have a null terminated string...
target_name[target_result] = 0; target_name[target_result] = 0;
// FIXME: this fails when the wine process isn't started from the 'current working directory'. strip path data from cmdline // FIXME: this fails when the wine process isn't started from the 'current working directory'. strip path data from cmdline
// is this windows version of Df running in wine? // is this windows version of Df running in wine?
if(strstr(target_name, "wine-preloader")!= NULL) if(strstr(target_name, "wine-preloader")!= NULL)
@ -92,7 +92,7 @@ WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions)
// get working directory // get working directory
target_result = readlink(cwd_name, target_name, sizeof(target_name)-1); target_result = readlink(cwd_name, target_name, sizeof(target_name)-1);
target_name[target_result] = 0; target_name[target_result] = 0;
// got path to executable, do the same for its name // got path to executable, do the same for its name
ifstream ifs ( cmdline_name , ifstream::in ); ifstream ifs ( cmdline_name , ifstream::in );
string cmdline; string cmdline;
@ -102,7 +102,7 @@ WineProcess::WineProcess(uint32_t pid, vector <memory_info *> & known_versions)
char exe_link[1024]; char exe_link[1024];
// put executable name and path together // put executable name and path together
sprintf(exe_link,"%s/%s",target_name,cmdline.c_str()); sprintf(exe_link,"%s/%s",target_name,cmdline.c_str());
// create wine process, add it to the vector // create wine process, add it to the vector
d->identified = d->validate(exe_link,pid,mem_name,known_versions); d->identified = d->validate(exe_link,pid,mem_name,known_versions);
return; return;
@ -124,13 +124,13 @@ bool WineProcess::isIdentified()
return d->identified; return d->identified;
} }
bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file, std::vector< memory_info* >& known_versions) bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file, std::vector< VersionInfo* >& known_versions)
{ {
md5wrapper md5; md5wrapper md5;
// get hash of the running DF process // get hash of the running DF process
string hash = md5.getHashFromFile(exe_file); string hash = md5.getHashFromFile(exe_file);
vector<memory_info *>::iterator it; vector<VersionInfo *>::iterator it;
// iterate over the list of memory locations // iterate over the list of memory locations
for ( it=known_versions.begin() ; it < known_versions.end(); it++ ) for ( it=known_versions.begin() ; it < known_versions.end(); it++ )
{ {
@ -144,11 +144,11 @@ bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file
continue; continue;
} }
// are the md5 hashes the same? // are the md5 hashes the same?
if(memory_info::OS_WINDOWS == (*it)->getOS() && hash == thishash) if(VersionInfo::OS_WINDOWS == (*it)->getOS() && hash == thishash)
{ {
// keep track of created memory_info object so we can destroy it later // keep track of created memory_info object so we can destroy it later
memory_info *m = new memory_info(**it); VersionInfo *m = new VersionInfo(**it);
my_descriptor = m; my_descriptor = m;
m->setParentProcess(dynamic_cast<Process *>( self )); m->setParentProcess(dynamic_cast<Process *>( self ));
my_handle = my_pid = pid; my_handle = my_pid = pid;
@ -173,7 +173,7 @@ WineProcess::~WineProcess()
delete d; delete d;
} }
memory_info * WineProcess::getDescriptor() VersionInfo * WineProcess::getDescriptor()
{ {
return d->my_descriptor; return d->my_descriptor;
} }
@ -194,11 +194,11 @@ void WineProcess::getMemRanges( vector<t_memrange> & ranges )
{ {
char buffer[1024]; char buffer[1024];
char permissions[5]; // r/-, w/-, x/-, p/s, 0 char permissions[5]; // r/-, w/-, x/-, p/s, 0
sprintf(buffer, "/proc/%lu/maps", d->my_pid); sprintf(buffer, "/proc/%lu/maps", d->my_pid);
FILE *mapFile = ::fopen(buffer, "r"); FILE *mapFile = ::fopen(buffer, "r");
uint64_t offset, device1, device2, node; uint64_t offset, device1, device2, node;
while (fgets(buffer, 1024, mapFile)) while (fgets(buffer, 1024, mapFile))
{ {
t_memrange temp; t_memrange temp;
@ -310,7 +310,7 @@ bool WineProcess::attach()
} }
} }
d->suspended = true; d->suspended = true;
int proc_pid_mem = open(d->memFile.c_str(),O_RDONLY); int proc_pid_mem = open(d->memFile.c_str(),O_RDONLY);
if(proc_pid_mem == -1) if(proc_pid_mem == -1)
{ {
@ -323,7 +323,7 @@ bool WineProcess::attach()
else else
{ {
d->attached = true; d->attached = true;
d->memFileHandle = proc_pid_mem; d->memFileHandle = proc_pid_mem;
return true; // we are attached return true; // we are attached
} }
@ -365,7 +365,7 @@ bool WineProcess::detach()
void WineProcess::read (const uint32_t offset, const uint32_t size, uint8_t *target) void WineProcess::read (const uint32_t offset, const uint32_t size, uint8_t *target)
{ {
if(size == 0) return; if(size == 0) return;
ssize_t result; ssize_t result;
ssize_t total = 0; ssize_t total = 0;
ssize_t remaining = size; ssize_t remaining = size;
@ -576,10 +576,10 @@ size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcap
*/ */
uint32_t start_offset = offset + 4; uint32_t start_offset = offset + 4;
size_t length = readDWord(offset + 20); size_t length = readDWord(offset + 20);
size_t capacity = readDWord(offset + 24); size_t capacity = readDWord(offset + 24);
size_t read_real = min(length, bufcapacity-1);// keep space for null termination size_t read_real = min(length, bufcapacity-1);// keep space for null termination
// read data from inside the string structure // read data from inside the string structure
if(capacity < 16) if(capacity < 16)
{ {
@ -590,7 +590,7 @@ size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcap
start_offset = readDWord(start_offset);// dereference the start offset start_offset = readDWord(start_offset);// dereference the start offset
read(start_offset, read_real, (uint8_t *)buffer); read(start_offset, read_real, (uint8_t *)buffer);
} }
buffer[read_real] = 0; buffer[read_real] = 0;
return read_real; return read_real;
} }
@ -612,7 +612,7 @@ const string WineProcess::readSTLString (uint32_t offset)
uint32_t length = readDWord(offset + 20); uint32_t length = readDWord(offset + 20);
uint32_t capacity = readDWord(offset + 24); uint32_t capacity = readDWord(offset + 24);
char * temp = new char[capacity+1]; char * temp = new char[capacity+1];
// read data from inside the string structure // read data from inside the string structure
if(capacity < 16) if(capacity < 16)
{ {
@ -623,7 +623,7 @@ const string WineProcess::readSTLString (uint32_t offset)
start_offset = readDWord(start_offset);// dereference the start offset start_offset = readDWord(start_offset);// dereference the start offset
read(start_offset, capacity, (uint8_t *)temp); read(start_offset, capacity, (uint8_t *)temp);
} }
temp[length] = 0; temp[length] = 0;
string ret = temp; string ret = temp;
delete temp; delete temp;

@ -23,7 +23,7 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <errno.h> #include <errno.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
@ -44,7 +44,7 @@ class NormalProcess::Private
}; };
~Private(){}; ~Private(){};
Window* my_window; Window* my_window;
memory_info * my_descriptor; VersionInfo * my_descriptor;
pid_t my_handle; pid_t my_handle;
uint32_t my_pid; uint32_t my_pid;
string memFile; string memFile;
@ -53,10 +53,10 @@ class NormalProcess::Private
bool suspended; bool suspended;
bool identified; bool identified;
Process * self; Process * self;
bool validate(char * exe_file, uint32_t pid, char * mem_file, vector <memory_info *> & known_versions); bool validate(char * exe_file, uint32_t pid, char * mem_file, vector <VersionInfo *> & known_versions);
}; };
NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_versions) NormalProcess::NormalProcess(uint32_t pid, vector< VersionInfo* >& known_versions)
: d(new Private(this)) : d(new Private(this))
{ {
char dir_name [256]; char dir_name [256];
@ -66,16 +66,16 @@ NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_version
char cmdline_name [256]; char cmdline_name [256];
char target_name[1024]; char target_name[1024];
int target_result; int target_result;
d->identified = false; d->identified = false;
d->my_descriptor = 0; d->my_descriptor = 0;
sprintf(dir_name,"/proc/%d/", pid); sprintf(dir_name,"/proc/%d/", pid);
sprintf(exe_link_name,"/proc/%d/exe", pid); sprintf(exe_link_name,"/proc/%d/exe", pid);
sprintf(mem_name,"/proc/%d/mem", pid); sprintf(mem_name,"/proc/%d/mem", pid);
sprintf(cwd_name,"/proc/%d/cwd", pid); sprintf(cwd_name,"/proc/%d/cwd", pid);
sprintf(cmdline_name,"/proc/%d/cmdline", pid); sprintf(cmdline_name,"/proc/%d/cmdline", pid);
// resolve /proc/PID/exe link // resolve /proc/PID/exe link
target_result = readlink(exe_link_name, target_name, sizeof(target_name)-1); target_result = readlink(exe_link_name, target_name, sizeof(target_name)-1);
if (target_result == -1) if (target_result == -1)
@ -84,7 +84,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_version
} }
// make sure we have a null terminated string... // make sure we have a null terminated string...
target_name[target_result] = 0; target_name[target_result] = 0;
// is this the regular linux DF? // is this the regular linux DF?
if (strstr(target_name, "dwarfort.exe") != 0 || strstr(target_name,"Dwarf_Fortress") != 0) if (strstr(target_name, "dwarfort.exe") != 0 || strstr(target_name,"Dwarf_Fortress") != 0)
{ {
@ -108,13 +108,13 @@ bool NormalProcess::isIdentified()
return d->identified; return d->identified;
} }
bool NormalProcess::Private::validate(char * exe_file,uint32_t pid, char * memFile, vector <memory_info *> & known_versions) bool NormalProcess::Private::validate(char * exe_file,uint32_t pid, char * memFile, vector <VersionInfo *> & known_versions)
{ {
md5wrapper md5; md5wrapper md5;
// get hash of the running DF process // get hash of the running DF process
string hash = md5.getHashFromFile(exe_file); string hash = md5.getHashFromFile(exe_file);
vector<memory_info *>::iterator it; vector<VersionInfo *>::iterator it;
// iterate over the list of memory locations // iterate over the list of memory locations
for ( it=known_versions.begin() ; it < known_versions.end(); it++ ) for ( it=known_versions.begin() ; it < known_versions.end(); it++ )
{ {
@ -122,10 +122,10 @@ bool NormalProcess::Private::validate(char * exe_file,uint32_t pid, char * memFi
{ {
if(hash == (*it)->getString("md5")) // are the md5 hashes the same? if(hash == (*it)->getString("md5")) // are the md5 hashes the same?
{ {
memory_info * m = *it; VersionInfo * m = *it;
if (memory_info::OS_LINUX == m->getOS()) if (VersionInfo::OS_LINUX == m->getOS())
{ {
memory_info *m2 = new memory_info(*m); VersionInfo *m2 = new VersionInfo(*m);
my_descriptor = m2; my_descriptor = m2;
m2->setParentProcess(dynamic_cast<Process *>( self )); m2->setParentProcess(dynamic_cast<Process *>( self ));
my_handle = my_pid = pid; my_handle = my_pid = pid;
@ -161,7 +161,7 @@ NormalProcess::~NormalProcess()
delete d; delete d;
} }
memory_info * NormalProcess::getDescriptor() VersionInfo * NormalProcess::getDescriptor()
{ {
return d->my_descriptor; return d->my_descriptor;
} }
@ -182,11 +182,11 @@ void NormalProcess::getMemRanges( vector<t_memrange> & ranges )
{ {
char buffer[1024]; char buffer[1024];
char permissions[5]; // r/-, w/-, x/-, p/s, 0 char permissions[5]; // r/-, w/-, x/-, p/s, 0
sprintf(buffer, "/proc/%lu/maps", d->my_pid); sprintf(buffer, "/proc/%lu/maps", d->my_pid);
FILE *mapFile = ::fopen(buffer, "r"); FILE *mapFile = ::fopen(buffer, "r");
uint64_t offset, device1, device2, node; uint64_t offset, device1, device2, node;
while (fgets(buffer, 1024, mapFile)) while (fgets(buffer, 1024, mapFile))
{ {
t_memrange temp; t_memrange temp;
@ -298,7 +298,7 @@ bool NormalProcess::attach()
} }
} }
d->suspended = true; d->suspended = true;
int proc_pid_mem = open(d->memFile.c_str(),O_RDONLY); int proc_pid_mem = open(d->memFile.c_str(),O_RDONLY);
if(proc_pid_mem == -1) if(proc_pid_mem == -1)
{ {
@ -310,7 +310,7 @@ bool NormalProcess::attach()
else else
{ {
d->attached = true; d->attached = true;
d->memFileHandle = proc_pid_mem; d->memFileHandle = proc_pid_mem;
return true; // we are attached return true; // we are attached
} }
@ -352,7 +352,7 @@ bool NormalProcess::detach()
void NormalProcess::read (const uint32_t offset, const uint32_t size, uint8_t *target) void NormalProcess::read (const uint32_t offset, const uint32_t size, uint8_t *target)
{ {
if(size == 0) return; if(size == 0) return;
ssize_t result; ssize_t result;
result = pread(d->memFileHandle, target,size,offset); result = pread(d->memFileHandle, target,size,offset);
if(result != size) if(result != size)
@ -564,10 +564,10 @@ size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufc
const string NormalProcess::readSTLString (uint32_t offset) const string NormalProcess::readSTLString (uint32_t offset)
{ {
_Rep_base header; _Rep_base header;
offset = readDWord(offset); offset = readDWord(offset);
read(offset - sizeof(_Rep_base),sizeof(_Rep_base),(uint8_t *)&header); read(offset - sizeof(_Rep_base),sizeof(_Rep_base),(uint8_t *)&header);
// FIXME: use char* everywhere, avoid string // FIXME: use char* everywhere, avoid string
char * temp = new char[header._M_length+1]; char * temp = new char[header._M_length+1];
read(offset,header._M_length+1,(uint8_t * )temp); read(offset,header._M_length+1,(uint8_t * )temp);

@ -23,7 +23,7 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "shms.h" #include "shms.h"
#include "mod-core.h" #include "mod-core.h"
@ -48,7 +48,7 @@ class SHMProcess::Private
attachmentIdx = -1; attachmentIdx = -1;
}; };
~Private(){}; ~Private(){};
memory_info * memdescriptor; VersionInfo * memdescriptor;
SHMProcess * self; SHMProcess * self;
uint32_t process_ID; uint32_t process_ID;
char *shm_addr; char *shm_addr;
@ -56,14 +56,14 @@ class SHMProcess::Private
HANDLE DFCLMutex; HANDLE DFCLMutex;
HANDLE DFCLSuspendMutex; HANDLE DFCLSuspendMutex;
int attachmentIdx; int attachmentIdx;
bool attached; bool attached;
bool locked; bool locked;
bool identified; bool identified;
bool useYield; bool useYield;
bool validate(std::vector< memory_info* >& known_versions); bool validate(std::vector< VersionInfo* >& known_versions);
bool Aux_Core_Attach(bool & versionOK, uint32_t & PID); bool Aux_Core_Attach(bool & versionOK, uint32_t & PID);
bool SetAndWait (uint32_t state); bool SetAndWait (uint32_t state);
bool GetLocks(); bool GetLocks();
@ -91,7 +91,7 @@ bool SHMProcess::Private::SetAndWait (uint32_t state)
uint32_t cnt = 0; uint32_t cnt = 0;
if(!attached) return false; if(!attached) return false;
SHMCMD = state; SHMCMD = state;
while (SHMCMD == state) while (SHMCMD == state)
{ {
// yield the CPU, only on single-core CPUs // yield the CPU, only on single-core CPUs
@ -176,7 +176,7 @@ bool SHMProcess::Private::GetLocks()
DFSVMutex = 0; DFSVMutex = 0;
return false; return false;
} }
for(int i = 0; i < SHM_MAX_CLIENTS; i++) for(int i = 0; i < SHM_MAX_CLIENTS; i++)
{ {
// open the client suspend locked // open the client suspend locked
@ -190,7 +190,7 @@ bool SHMProcess::Private::GetLocks()
} }
// open the client lock, try to lock it // open the client lock, try to lock it
sprintf(name,"DFCLMutex-%d-%d",process_ID,i); sprintf(name,"DFCLMutex-%d-%d",process_ID,i);
DFCLMutex = OpenMutex(SYNCHRONIZE,0,name); DFCLMutex = OpenMutex(SYNCHRONIZE,0,name);
if(DFCLMutex == 0) if(DFCLMutex == 0)
@ -226,7 +226,7 @@ bool SHMProcess::Private::GetLocks()
bool SHMProcess::Private::AreLocksOk() bool SHMProcess::Private::AreLocksOk()
{ {
// both locks are inited (we hold our lock) // both locks are inited (we hold our lock)
if(DFCLMutex != 0 && DFSVMutex != 0) if(DFCLMutex != 0 && DFSVMutex != 0)
{ {
// try if CL mutex is free // try if CL mutex is free
switch (WaitForSingleObject(DFSVMutex,0)) switch (WaitForSingleObject(DFSVMutex,0))
@ -241,7 +241,7 @@ bool SHMProcess::Private::AreLocksOk()
{ {
// mutex is held by DF // mutex is held by DF
return true; return true;
} }
default: default:
case WAIT_FAILED: case WAIT_FAILED:
{ {
@ -257,10 +257,10 @@ bool SHMProcess::Private::AreLocksOk()
/* /*
char svmutexname [256]; char svmutexname [256];
char clmutexname [256]; char clmutexname [256];
sprintf(clmutexname,"DFCLMutex-%d",PID); sprintf(clmutexname,"DFCLMutex-%d",PID);
// get server and client mutex // get server and client mutex
d->DFSVMutex = OpenMutex(SYNCHRONIZE,false, svmutexname); d->DFSVMutex = OpenMutex(SYNCHRONIZE,false, svmutexname);
if(d->DFSVMutex == 0) if(d->DFSVMutex == 0)
@ -274,7 +274,7 @@ bool SHMProcess::Private::AreLocksOk()
} }
*/ */
SHMProcess::SHMProcess(uint32_t PID, vector <memory_info *> & known_versions) SHMProcess::SHMProcess(uint32_t PID, vector <VersionInfo *> & known_versions)
: d(new Private()) : d(new Private())
{ {
d->process_ID = PID; d->process_ID = PID;
@ -314,7 +314,7 @@ bool SHMProcess::isIdentified()
{ {
return d->identified; return d->identified;
} }
bool SHMProcess::Private::validate(vector <memory_info *> & known_versions) bool SHMProcess::Private::validate(vector <VersionInfo *> & known_versions)
{ {
// try to identify the DF version // try to identify the DF version
IMAGE_NT_HEADERS32 pe_header; IMAGE_NT_HEADERS32 pe_header;
@ -324,11 +324,11 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
HANDLE hProcess; HANDLE hProcess;
bool found = false; bool found = false;
identified = false; identified = false;
// open process, we only need the process open // open process, we only need the process open
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, process_ID ); hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, process_ID );
if (NULL == hProcess) if (NULL == hProcess)
return false; return false;
// try getting the first module of the process // try getting the first module of the process
if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0) if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0)
{ {
@ -338,14 +338,14 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
} }
// got base ;) // got base ;)
uint32_t base = (uint32_t)hmod; uint32_t base = (uint32_t)hmod;
// read from this process // read from this process
uint32_t pe_offset = self->readDWord(base+0x3C); uint32_t pe_offset = self->readDWord(base+0x3C);
self->read(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header); self->read(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header);
self->read(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)&sections ); self->read(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)&sections );
// iterate over the list of memory locations // iterate over the list of memory locations
vector<memory_info *>::iterator it; vector<VersionInfo *>::iterator it;
for ( it=known_versions.begin() ; it < known_versions.end(); it++ ) for ( it=known_versions.begin() ; it < known_versions.end(); it++ )
{ {
uint32_t pe_timestamp; uint32_t pe_timestamp;
@ -359,7 +359,7 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
} }
if (pe_timestamp == pe_header.FileHeader.TimeDateStamp) if (pe_timestamp == pe_header.FileHeader.TimeDateStamp)
{ {
memory_info *m = new memory_info(**it); VersionInfo *m = new VersionInfo(**it);
m->RebaseAll(base); m->RebaseAll(base);
memdescriptor = m; memdescriptor = m;
m->setParentProcess(self); m->setParentProcess(self);
@ -385,7 +385,7 @@ SHMProcess::~SHMProcess()
delete d; delete d;
} }
memory_info * SHMProcess::getDescriptor() VersionInfo * SHMProcess::getDescriptor()
{ {
return d->memdescriptor; return d->memdescriptor;
} }
@ -397,30 +397,30 @@ int SHMProcess::getPID()
bool SHMProcess::getThreadIDs(vector<uint32_t> & threads ) bool SHMProcess::getThreadIDs(vector<uint32_t> & threads )
{ {
HANDLE AllThreads = INVALID_HANDLE_VALUE; HANDLE AllThreads = INVALID_HANDLE_VALUE;
THREADENTRY32 te32; THREADENTRY32 te32;
AllThreads = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); AllThreads = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
if( AllThreads == INVALID_HANDLE_VALUE ) if( AllThreads == INVALID_HANDLE_VALUE )
{ {
return false; return false;
} }
te32.dwSize = sizeof(THREADENTRY32 ); te32.dwSize = sizeof(THREADENTRY32 );
if( !Thread32First( AllThreads, &te32 ) ) if( !Thread32First( AllThreads, &te32 ) )
{ {
CloseHandle( AllThreads ); CloseHandle( AllThreads );
return false; return false;
} }
do do
{ {
if( te32.th32OwnerProcessID == d->process_ID ) if( te32.th32OwnerProcessID == d->process_ID )
{ {
threads.push_back(te32.th32ThreadID); threads.push_back(te32.th32ThreadID);
} }
} while( Thread32Next(AllThreads, &te32 ) ); } while( Thread32Next(AllThreads, &te32 ) );
CloseHandle( AllThreads ); CloseHandle( AllThreads );
return true; return true;
} }
@ -430,9 +430,9 @@ void SHMProcess::getMemRanges( vector<t_memrange> & ranges )
{ {
// code here is taken from hexsearch by Silas Dunmore. // code here is taken from hexsearch by Silas Dunmore.
// As this IMHO isn't a 'sunstantial portion' of anything, I'm not including the MIT license here // As this IMHO isn't a 'sunstantial portion' of anything, I'm not including the MIT license here
// I'm faking this, because there's no way I'm using VirtualQuery // I'm faking this, because there's no way I'm using VirtualQuery
t_memrange temp; t_memrange temp;
uint32_t base = d->memdescriptor->getBase(); uint32_t base = d->memdescriptor->getBase();
temp.start = base + 0x1000; // more fakery. temp.start = base + 0x1000; // more fakery.
@ -591,7 +591,7 @@ bool SHMProcess::attach()
return false; // we couldn't lock it return false; // we couldn't lock it
} }
*/ */
/* /*
* Locate the segment. * Locate the segment.
*/ */
@ -613,12 +613,12 @@ bool SHMProcess::attach()
{ {
CloseHandle(shmHandle); CloseHandle(shmHandle);
//ReleaseMutex(d->DFCLMutex); //ReleaseMutex(d->DFCLMutex);
d->FreeLocks(); d->FreeLocks();
return false; // we couldn't attach the mapping // FIXME: throw return false; // we couldn't attach the mapping // FIXME: throw
} }
// we close the handle right here - it's not needed anymore // we close the handle right here - it's not needed anymore
CloseHandle(shmHandle); CloseHandle(shmHandle);
d->attached = true; d->attached = true;
if(!suspend()) if(!suspend())
{ {
@ -653,7 +653,7 @@ bool SHMProcess::detach()
void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buffer) void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buffer)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
// normal read under 1MB // normal read under 1MB
if(size <= SHM_BODY) if(size <= SHM_BODY)
{ {
@ -690,7 +690,7 @@ void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buff
uint8_t SHMProcess::readByte (const uint32_t offset) uint8_t SHMProcess::readByte (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_BYTE); d->SetAndWait(CORE_READ_BYTE);
@ -700,7 +700,7 @@ uint8_t SHMProcess::readByte (const uint32_t offset)
void SHMProcess::readByte (const uint32_t offset, uint8_t &val ) void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_BYTE); d->SetAndWait(CORE_READ_BYTE);
@ -710,7 +710,7 @@ void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
uint16_t SHMProcess::readWord (const uint32_t offset) uint16_t SHMProcess::readWord (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_WORD); d->SetAndWait(CORE_READ_WORD);
@ -720,7 +720,7 @@ uint16_t SHMProcess::readWord (const uint32_t offset)
void SHMProcess::readWord (const uint32_t offset, uint16_t &val) void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_WORD); d->SetAndWait(CORE_READ_WORD);
@ -730,7 +730,7 @@ void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
uint32_t SHMProcess::readDWord (const uint32_t offset) uint32_t SHMProcess::readDWord (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -739,7 +739,7 @@ uint32_t SHMProcess::readDWord (const uint32_t offset)
void SHMProcess::readDWord (const uint32_t offset, uint32_t &val) void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -749,7 +749,7 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
float SHMProcess::readFloat (const uint32_t offset) float SHMProcess::readFloat (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -758,7 +758,7 @@ float SHMProcess::readFloat (const uint32_t offset)
void SHMProcess::readFloat (const uint32_t offset, float &val) void SHMProcess::readFloat (const uint32_t offset, float &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_DWORD); d->SetAndWait(CORE_READ_DWORD);
@ -767,7 +767,7 @@ void SHMProcess::readFloat (const uint32_t offset, float &val)
uint64_t SHMProcess::readQuad (const uint32_t offset) uint64_t SHMProcess::readQuad (const uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_QUAD); d->SetAndWait(CORE_READ_QUAD);
@ -776,7 +776,7 @@ uint64_t SHMProcess::readQuad (const uint32_t offset)
void SHMProcess::readQuad (const uint32_t offset, uint64_t &val) void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_QUAD); d->SetAndWait(CORE_READ_QUAD);
@ -790,7 +790,7 @@ void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
void SHMProcess::writeQuad (uint32_t offset, uint64_t data) void SHMProcess::writeQuad (uint32_t offset, uint64_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->Qvalue = data; D_SHMHDR->Qvalue = data;
full_barrier full_barrier
@ -801,7 +801,7 @@ void SHMProcess::writeQuad (uint32_t offset, uint64_t data)
void SHMProcess::writeDWord (uint32_t offset, uint32_t data) void SHMProcess::writeDWord (uint32_t offset, uint32_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->value = data; D_SHMHDR->value = data;
full_barrier full_barrier
@ -812,7 +812,7 @@ void SHMProcess::writeDWord (uint32_t offset, uint32_t data)
void SHMProcess::writeWord (uint32_t offset, uint16_t data) void SHMProcess::writeWord (uint32_t offset, uint16_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->value = data; D_SHMHDR->value = data;
full_barrier full_barrier
@ -822,7 +822,7 @@ void SHMProcess::writeWord (uint32_t offset, uint16_t data)
void SHMProcess::writeByte (uint32_t offset, uint8_t data) void SHMProcess::writeByte (uint32_t offset, uint8_t data)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
D_SHMHDR->value = data; D_SHMHDR->value = data;
full_barrier full_barrier
@ -832,7 +832,7 @@ void SHMProcess::writeByte (uint32_t offset, uint8_t data)
void SHMProcess::write (uint32_t dst_address, uint32_t size, uint8_t *source_buffer) void SHMProcess::write (uint32_t dst_address, uint32_t size, uint8_t *source_buffer)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
// normal write under 1MB // normal write under 1MB
if(size <= SHM_BODY) if(size <= SHM_BODY)
{ {
@ -870,7 +870,7 @@ void SHMProcess::write (uint32_t dst_address, uint32_t size, uint8_t *source_buf
const std::string SHMProcess::readCString (uint32_t offset) const std::string SHMProcess::readCString (uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
std::string temp; std::string temp;
char temp_c[256]; char temp_c[256];
int counter = 0; int counter = 0;
@ -889,7 +889,7 @@ const std::string SHMProcess::readCString (uint32_t offset)
const std::string SHMProcess::readSTLString(uint32_t offset) const std::string SHMProcess::readSTLString(uint32_t offset)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_STL_STRING); d->SetAndWait(CORE_READ_STL_STRING);
@ -899,7 +899,7 @@ const std::string SHMProcess::readSTLString(uint32_t offset)
size_t SHMProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) size_t SHMProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset; D_SHMHDR->address = offset;
full_barrier full_barrier
d->SetAndWait(CORE_READ_STL_STRING); d->SetAndWait(CORE_READ_STL_STRING);
@ -913,7 +913,7 @@ size_t SHMProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapa
void SHMProcess::writeSTLString(const uint32_t address, const std::string writeString) void SHMProcess::writeSTLString(const uint32_t address, const std::string writeString)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = address; D_SHMHDR->address = address;
strncpy(D_SHMDATA(char),writeString.c_str(),writeString.length()+1); // length + 1 for the null terminator strncpy(D_SHMDATA(char),writeString.c_str(),writeString.length()+1); // length + 1 for the null terminator
full_barrier full_barrier
@ -933,13 +933,13 @@ string SHMProcess::readClassName (uint32_t vptr)
bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT)
{ {
if(!d->locked) throw Error::MemoryAccessDenied(); if(!d->locked) throw Error::MemoryAccessDenied();
modulelookup * payload = D_SHMDATA(modulelookup); modulelookup * payload = D_SHMDATA(modulelookup);
payload->version = version; payload->version = version;
strncpy(payload->name,name,255); strncpy(payload->name,name,255);
payload->name[255] = 0; payload->name[255] = 0;
if(!SetAndWait(CORE_ACQUIRE_MODULE)) if(!SetAndWait(CORE_ACQUIRE_MODULE))
{ {
return false; // FIXME: throw a fatal exception instead return false; // FIXME: throw a fatal exception instead
@ -962,7 +962,7 @@ char * SHMProcess::getSHMStart (void)
bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, uint32_t & PID) bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, uint32_t & PID)
{ {
if(!locked) throw Error::MemoryAccessDenied(); if(!locked) throw Error::MemoryAccessDenied();
SHMDATA(coreattach)->cl_affinity = OS_getAffinity(); SHMDATA(coreattach)->cl_affinity = OS_getAffinity();
if(!SetAndWait(CORE_ATTACH)) return false; if(!SetAndWait(CORE_ATTACH)) return false;
/* /*

@ -23,7 +23,7 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
using namespace DFHack; using namespace DFHack;
@ -40,7 +40,7 @@ class NormalProcess::Private
suspended = false; suspended = false;
}; };
~Private(){}; ~Private(){};
memory_info * my_descriptor; VersionInfo * my_descriptor;
HANDLE my_handle; HANDLE my_handle;
HANDLE my_main_thread; HANDLE my_main_thread;
uint32_t my_pid; uint32_t my_pid;
@ -50,14 +50,14 @@ class NormalProcess::Private
bool identified; bool identified;
}; };
NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versions) NormalProcess::NormalProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
: d(new Private()) : d(new Private())
{ {
HMODULE hmod = NULL; HMODULE hmod = NULL;
DWORD junk; DWORD junk;
HANDLE hProcess; HANDLE hProcess;
bool found = false; bool found = false;
IMAGE_NT_HEADERS32 pe_header; IMAGE_NT_HEADERS32 pe_header;
IMAGE_SECTION_HEADER sections[16]; IMAGE_SECTION_HEADER sections[16];
d->identified = false; d->identified = false;
@ -65,7 +65,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid ); hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
if (NULL == hProcess) if (NULL == hProcess)
return; return;
// try getting the first module of the process // try getting the first module of the process
if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0) if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0)
{ {
@ -73,10 +73,10 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
// cout << "EnumProcessModules fail'd" << endl; // cout << "EnumProcessModules fail'd" << endl;
return; //if enumprocessModules fails, give up return; //if enumprocessModules fails, give up
} }
// got base ;) // got base ;)
uint32_t base = (uint32_t)hmod; uint32_t base = (uint32_t)hmod;
// temporarily assign this to allow some checks // temporarily assign this to allow some checks
d->my_handle = hProcess; d->my_handle = hProcess;
d->my_main_thread = 0; d->my_main_thread = 0;
@ -94,13 +94,13 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
d->my_handle = 0; d->my_handle = 0;
return; return;
} }
// see if there's a version entry that matches this process // see if there's a version entry that matches this process
vector<memory_info*>::iterator it; vector<VersionInfo*>::iterator it;
for ( it=known_versions.begin() ; it < known_versions.end(); it++ ) for ( it=known_versions.begin() ; it < known_versions.end(); it++ )
{ {
// filter by OS // filter by OS
if(memory_info::OS_WINDOWS != (*it)->getOS()) if(VersionInfo::OS_WINDOWS != (*it)->getOS())
continue; continue;
uint32_t pe_timestamp; uint32_t pe_timestamp;
// filter by timestamp, skip entries without a timestamp // filter by timestamp, skip entries without a timestamp
@ -114,13 +114,13 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
} }
if (pe_timestamp != pe_header.FileHeader.TimeDateStamp) if (pe_timestamp != pe_header.FileHeader.TimeDateStamp)
continue; continue;
// all went well // all went well
{ {
printf("Match found! Using version %s.\n", (*it)->getVersion().c_str()); printf("Match found! Using version %s.\n", (*it)->getVersion().c_str());
d->identified = true; d->identified = true;
// give the process a data model and memory layout fixed for the base of first module // give the process a data model and memory layout fixed for the base of first module
memory_info *m = new memory_info(**it); VersionInfo *m = new VersionInfo(**it);
m->RebaseAll(base); m->RebaseAll(base);
// keep track of created memory_info object so we can destroy it later // keep track of created memory_info object so we can destroy it later
d->my_descriptor = m; d->my_descriptor = m;
@ -129,12 +129,12 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & known_versio
d->my_pid = pid; d->my_pid = pid;
d->my_handle = hProcess; d->my_handle = hProcess;
d->identified = true; d->identified = true;
// TODO: detect errors in thread enumeration // TODO: detect errors in thread enumeration
vector<uint32_t> threads; vector<uint32_t> threads;
getThreadIDs( threads ); getThreadIDs( threads );
d->my_main_thread = OpenThread(THREAD_ALL_ACCESS, FALSE, (DWORD) threads[0]); d->my_main_thread = OpenThread(THREAD_ALL_ACCESS, FALSE, (DWORD) threads[0]);
found = true; found = true;
break; // break the iterator loop break; // break the iterator loop
} }
@ -167,7 +167,7 @@ NormalProcess::~NormalProcess()
delete d; delete d;
} }
memory_info * NormalProcess::getDescriptor() VersionInfo * NormalProcess::getDescriptor()
{ {
return d->my_descriptor; return d->my_descriptor;
} }
@ -257,30 +257,30 @@ bool NormalProcess::detach()
bool NormalProcess::getThreadIDs(vector<uint32_t> & threads ) bool NormalProcess::getThreadIDs(vector<uint32_t> & threads )
{ {
HANDLE AllThreads = INVALID_HANDLE_VALUE; HANDLE AllThreads = INVALID_HANDLE_VALUE;
THREADENTRY32 te32; THREADENTRY32 te32;
AllThreads = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); AllThreads = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
if( AllThreads == INVALID_HANDLE_VALUE ) if( AllThreads == INVALID_HANDLE_VALUE )
{ {
return false; return false;
} }
te32.dwSize = sizeof(THREADENTRY32 ); te32.dwSize = sizeof(THREADENTRY32 );
if( !Thread32First( AllThreads, &te32 ) ) if( !Thread32First( AllThreads, &te32 ) )
{ {
CloseHandle( AllThreads ); CloseHandle( AllThreads );
return false; return false;
} }
do do
{ {
if( te32.th32OwnerProcessID == d->my_pid ) if( te32.th32OwnerProcessID == d->my_pid )
{ {
threads.push_back(te32.th32ThreadID); threads.push_back(te32.th32ThreadID);
} }
} while( Thread32Next(AllThreads, &te32 ) ); } while( Thread32Next(AllThreads, &te32 ) );
CloseHandle( AllThreads ); CloseHandle( AllThreads );
return true; return true;
} }
@ -290,9 +290,9 @@ void NormalProcess::getMemRanges( vector<t_memrange> & ranges )
{ {
// code here is taken from hexsearch by Silas Dunmore. // code here is taken from hexsearch by Silas Dunmore.
// As this IMHO isn't a 'sunstantial portion' of anything, I'm not including the MIT license here // As this IMHO isn't a 'sunstantial portion' of anything, I'm not including the MIT license here
// I'm faking this, because there's no way I'm using VirtualQuery // I'm faking this, because there's no way I'm using VirtualQuery
t_memrange temp; t_memrange temp;
uint32_t base = d->my_descriptor->getBase(); uint32_t base = d->my_descriptor->getBase();
temp.start = base + 0x1000; // more fakery. temp.start = base + 0x1000; // more fakery.
@ -443,10 +443,10 @@ Uint32 capacity
*/ */
uint32_t start_offset = offset + 4; uint32_t start_offset = offset + 4;
size_t length = readDWord(offset + 20); size_t length = readDWord(offset + 20);
size_t capacity = readDWord(offset + 24); size_t capacity = readDWord(offset + 24);
size_t read_real = min(length, bufcapacity-1);// keep space for null termination size_t read_real = min(length, bufcapacity-1);// keep space for null termination
// read data from inside the string structure // read data from inside the string structure
if(capacity < 16) if(capacity < 16)
{ {
@ -457,7 +457,7 @@ Uint32 capacity
start_offset = readDWord(start_offset);// dereference the start offset start_offset = readDWord(start_offset);// dereference the start offset
read(start_offset, read_real, (uint8_t *)buffer); read(start_offset, read_real, (uint8_t *)buffer);
} }
buffer[read_real] = 0; buffer[read_real] = 0;
return read_real; return read_real;
} }
@ -479,7 +479,7 @@ const string NormalProcess::readSTLString (uint32_t offset)
uint32_t length = readDWord(offset + 20); uint32_t length = readDWord(offset + 20);
uint32_t capacity = readDWord(offset + 24); uint32_t capacity = readDWord(offset + 24);
char * temp = new char[capacity+1]; char * temp = new char[capacity+1];
// read data from inside the string structure // read data from inside the string structure
if(capacity < 16) if(capacity < 16)
{ {
@ -490,7 +490,7 @@ const string NormalProcess::readSTLString (uint32_t offset)
start_offset = readDWord(start_offset);// dereference the start offset start_offset = readDWord(start_offset);// dereference the start offset
read(start_offset, capacity, (uint8_t *)temp); read(start_offset, capacity, (uint8_t *)temp);
} }
temp[length] = 0; temp[length] = 0;
string ret = temp; string ret = temp;
delete temp; delete temp;

@ -23,11 +23,11 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "DFMemInfoManager.h" #include "VersionInfoFactory.h"
#include "dfhack/DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
using namespace DFHack; using namespace DFHack;
@ -39,7 +39,7 @@ class DFHack::ProcessEnumerator::Private
{ {
public: public:
Private(){}; Private(){};
MemInfoManager *meminfo; VersionInfoFactory *meminfo;
PROC_V Processes; PROC_V Processes;
PID2PROC ProcMap; PID2PROC ProcMap;
Process *GetProcessObject(ProcessID ID); Process *GetProcessObject(ProcessID ID);
@ -119,13 +119,13 @@ Process * BadProcesses::operator[](uint32_t index)
//FIXME: wasteful //FIXME: wasteful
Process *ProcessEnumerator::Private::GetProcessObject(ProcessID ID) Process *ProcessEnumerator::Private::GetProcessObject(ProcessID ID)
{ {
Process *p1 = new SHMProcess(ID.pid,meminfo->meminfo); Process *p1 = new SHMProcess(ID.pid,meminfo->meminfo);
if(p1->isIdentified()) if(p1->isIdentified())
return p1; return p1;
else else
delete p1; delete p1;
Process *p2 = new NormalProcess(ID.pid,meminfo->meminfo); Process *p2 = new NormalProcess(ID.pid,meminfo->meminfo);
if(p2->isIdentified()) if(p2->isIdentified())
return p2; return p2;
@ -358,7 +358,7 @@ Process * ProcessEnumerator::operator[](uint32_t index)
ProcessEnumerator::ProcessEnumerator( string path_to_xml ) ProcessEnumerator::ProcessEnumerator( string path_to_xml )
: d(new Private()) : d(new Private())
{ {
d->meminfo = new MemInfoManager(path_to_xml); d->meminfo = new VersionInfoFactory(path_to_xml);
} }
void ProcessEnumerator::purge() void ProcessEnumerator::purge()

@ -23,11 +23,11 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
//Inital amount of space in levels vector (since we usually know the number, efficent!) //Inital amount of space in levels vector (since we usually know the number, efficient!)
#define NUM_RESERVE_LVLS 20 #define NUM_RESERVE_LVLS 20
#define NUM_RESERVE_MOODS 6 #define NUM_RESERVE_MOODS 6
using namespace DFHack; using namespace DFHack;
@ -81,56 +81,60 @@ namespace DFHack
std::vector<t_type *> subs; std::vector<t_type *> subs;
}; };
} }
/* /*
* Private data * Private data
*/ */
class memory_info::Private class VersionInfo::Private
{ {
public: public:
map <string, uint32_t> addresses; map <string, uint32_t> addresses;
map <string, int32_t> offsets; map <string, int32_t> offsets;
map <string, uint32_t> hexvals; map <string, uint32_t> hexvals;
map <string, string> strings; 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; OSType OS;
}; };
// normal constructor // normal constructor
memory_info::memory_info() VersionInfo::VersionInfo()
:d(new Private) :d(new Private)
{ {
d->base = 0; d->base = 0;
d->p = 0; d->p = 0;
d->classindex = 0; d->classindex = 0;
d->levels.reserve(NUM_RESERVE_LVLS); d->levels.reserve(NUM_RESERVE_LVLS);
d->moods.reserve(NUM_RESERVE_MOODS); d->moods.reserve(NUM_RESERVE_MOODS);
} }
// copy constructor // copy constructor
memory_info::memory_info(const memory_info &old) VersionInfo::VersionInfo(const VersionInfo &old)
:d(new Private) :d(new Private)
{ {
d->version = old.d->version; d->version = old.d->version;
@ -153,16 +157,19 @@ memory_info::memory_info(const memory_info &old)
d->skills = old.d->skills; d->skills = old.d->skills;
d->traits = old.d->traits; d->traits = old.d->traits;
d->labors = old.d->labors; d->labors = old.d->labors;
d->levels = old.d->levels; d->levels = old.d->levels;
d->moods = old.d->moods; d->moods = old.d->moods;
} }
void memory_info::setParentProcess(Process * _p)
void VersionInfo::setParentProcess(Process * _p)
{ {
d->p = _p; d->p = _p;
} }
// destructor // destructor
memory_info::~memory_info() VersionInfo::~VersionInfo()
{ {
// delete the vtables // delete the vtables
for(uint32_t i = 0; i < d->classes.size();i++) for(uint32_t i = 0; i < d->classes.size();i++)
@ -173,25 +180,26 @@ memory_info::~memory_info()
delete d; delete d;
} }
void memory_info::setVersion(const char * v)
void VersionInfo::setVersion(const char * v)
{ {
d->version = v; d->version = v;
} }
void memory_info::setVersion(const string &v) void VersionInfo::setVersion(const string &v)
{ {
d->version = v; d->version = v;
} }
string memory_info::getVersion() string VersionInfo::getVersion()
{ {
return d->version; return d->version;
} }
void memory_info::setOS(const char *os) void VersionInfo::setOS(const char *os)
{ {
string oss = os; string oss = os;
if(oss == "windows") if(oss == "windows")
@ -203,7 +211,7 @@ void memory_info::setOS(const char *os)
} }
void memory_info::setOS(const string &os) void VersionInfo::setOS(const string &os)
{ {
if(os == "windows") if(os == "windows")
d->OS = OS_WINDOWS; d->OS = OS_WINDOWS;
@ -214,7 +222,7 @@ void memory_info::setOS(const string &os)
} }
void memory_info::setOS(OSType os) void VersionInfo::setOS(OSType os)
{ {
if(os >= OS_WINDOWS && os < OS_BAD) if(os >= OS_WINDOWS && os < OS_BAD)
{ {
@ -225,62 +233,64 @@ void memory_info::setOS(OSType os)
} }
memory_info::OSType memory_info::getOS() const VersionInfo::OSType VersionInfo::getOS() const
{ {
return d->OS; return d->OS;
} }
uint32_t memory_info::getBase () const uint32_t VersionInfo::getBase () const
{ {
return d->base; return d->base;
} }
void memory_info::setBase (const string &s) void VersionInfo::setBase (const string &s)
{ {
d->base = strtol(s.c_str(), NULL, 16); d->base = strtol(s.c_str(), NULL, 16);
} }
void memory_info::setBase (const uint32_t b) void VersionInfo::setBase (const uint32_t b)
{ {
d->base = b; d->base = b;
} }
void memory_info::setOffset (const string & key, const string & value) void VersionInfo::setOffset (const string & key, const string & value)
{ {
int32_t offset = strtol(value.c_str(), NULL, 16); int32_t offset = strtol(value.c_str(), NULL, 16);
d->offsets[key] = offset; d->offsets[key] = offset;
} }
void memory_info::setAddress (const string & key, const string & value) void VersionInfo::setAddress (const string & key, const string & value)
{ {
uint32_t address = strtol(value.c_str(), NULL, 16); uint32_t address = strtol(value.c_str(), NULL, 16);
d->addresses[key] = address; d->addresses[key] = address;
} }
void memory_info::setHexValue (const string & key, const string & value) void VersionInfo::setHexValue (const string & key, const string & value)
{ {
uint32_t hexval = strtol(value.c_str(), NULL, 16); uint32_t hexval = strtol(value.c_str(), NULL, 16);
d->hexvals[key] = hexval; d->hexvals[key] = hexval;
} }
void memory_info::setString (const string & key, const string & value) void VersionInfo::setString (const string & key, const string & value)
{ {
d->strings[key] = value; d->strings[key] = value;
} }
void memory_info::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);
d->labors[keyInt] = value; d->labors[keyInt] = value;
} }
void memory_info::setProfession (const string & key, const string & value)
void VersionInfo::setProfession (const string & key, const string & value)
{ {
uint32_t keyInt = strtol(key.c_str(), NULL, 10); uint32_t keyInt = strtol(key.c_str(), NULL, 10);
if(d->professions.size() <= keyInt) if(d->professions.size() <= keyInt)
@ -290,7 +300,8 @@ void memory_info::setProfession (const string & key, const string & value)
d->professions[keyInt] = value; d->professions[keyInt] = value;
} }
void memory_info::setJob (const string & key, const string & value)
void VersionInfo::setJob (const string & key, const string & value)
{ {
uint32_t keyInt = strtol(key.c_str(), NULL, 10); uint32_t keyInt = strtol(key.c_str(), NULL, 10);
if(d->jobs.size() <= keyInt) if(d->jobs.size() <= keyInt)
@ -300,7 +311,8 @@ void memory_info::setJob (const string & key, const string & value)
d->jobs[keyInt] = value; d->jobs[keyInt] = value;
} }
void memory_info::setSkill (const string & key, const string & value)
void VersionInfo::setSkill (const string & key, const string & value)
{ {
uint32_t keyInt = strtol(key.c_str(), NULL, 10); uint32_t keyInt = strtol(key.c_str(), NULL, 10);
if(d->skills.size() <= keyInt){ if(d->skills.size() <= keyInt){
@ -309,31 +321,34 @@ void memory_info::setSkill (const string & key, const string & value)
d->skills[keyInt] = value; d->skills[keyInt] = value;
} }
void memory_info::setLevel(const std::string &nLevel,
const std::string &nName, void VersionInfo::setLevel(const std::string &nLevel,
const std::string &nXp) const std::string &nName,
const std::string &nXp)
{ {
uint32_t keyInt = strtol(nLevel.c_str(), NULL, 10); uint32_t keyInt = strtol(nLevel.c_str(), NULL, 10);
if(d->levels.size() <= keyInt) if(d->levels.size() <= keyInt)
d->levels.resize(keyInt+1); d->levels.resize(keyInt+1);
d->levels[keyInt].level = keyInt; d->levels[keyInt].level = keyInt;
d->levels[keyInt].name = nName; d->levels[keyInt].name = nName;
d->levels[keyInt].xpNxtLvl = strtol(nXp.c_str(), NULL, 10); d->levels[keyInt].xpNxtLvl = strtol(nXp.c_str(), NULL, 10);
} }
void memory_info::setMood(const std::string &id, const std::string &mood)
void VersionInfo::setMood(const std::string &id, const std::string &mood)
{ {
uint32_t keyInt = strtol(id.c_str(), NULL, 10); uint32_t keyInt = strtol(id.c_str(), NULL, 10);
if(d->moods.size() <= keyInt) if(d->moods.size() <= keyInt)
d->moods.resize(keyInt+1); d->moods.resize(keyInt+1);
d->moods[keyInt] = mood; d->moods[keyInt] = mood;
} }
void memory_info::setTrait(const string & key,
void VersionInfo::setTrait(const string & key,
const string & value, const string & value,
const string & zero, const string & zero,
const string & one, const string & one,
@ -356,8 +371,9 @@ void memory_info::setTrait(const string & key,
d->traits[keyInt].push_back(value); d->traits[keyInt].push_back(value);
} }
// FIXME: next three methods should use some kind of custom container so it doesn't have to search so much. // FIXME: next three methods should use some kind of custom container so it doesn't have to search so much.
t_class * memory_info::setClass (const char * name, uint32_t vtable, uint32_t typeoffset) t_class * VersionInfo::setClass (const char * name, uint32_t vtable, uint32_t typeoffset)
{ {
if(name == 0) if(name == 0)
return 0; return 0;
@ -372,27 +388,27 @@ t_class * memory_info::setClass (const char * name, uint32_t vtable, uint32_t ty
return d->classes[i]; return d->classes[i];
} }
} }
t_class *cls = new t_class(); t_class *cls = new t_class();
// get an unique ID and add ourselves to the index // get an unique ID and add ourselves to the index
cls->assign = d->classindex; cls->assign = d->classindex;
cls->classname = name; cls->classname = name;
d->classnames.push_back(name); d->classnames.push_back(name);
// vtables no longer a requirement // vtables no longer a requirement
cls->vtable = vtable; cls->vtable = vtable;
// multi class yes/no // multi class yes/no
cls->type_offset = typeoffset; cls->type_offset = typeoffset;
d->classes.push_back(cls); d->classes.push_back(cls);
d->classindex++; d->classindex++;
return cls; return cls;
} }
void memory_info::setClassChild (t_class * parent, const char * name, const char * type) void VersionInfo::setClassChild (t_class * parent, const char * name, const char * type)
{ {
vector <t_type *>& vec = parent->subs; vector <t_type *>& vec = parent->subs;
for (uint32_t i=0; i<vec.size(); i++) for (uint32_t i=0; i<vec.size(); i++)
@ -408,19 +424,20 @@ void memory_info::setClassChild (t_class * parent, const char * name, const char
d->classnames.push_back(name); d->classnames.push_back(name);
vec.push_back(mcc); vec.push_back(mcc);
d->classindex++; d->classindex++;
//cout << " classtype " << name << ", assign " << mcc->assign << ", vtable " << mcc->type << endl; //cout << " classtype " << name << ", assign " << mcc->assign << ", vtable " << mcc->type << endl;
} }
// FIXME: stupid. we need a better container // FIXME: stupid. we need a better container
bool memory_info::resolveObjectToClassID(const uint32_t address, int32_t & classid) bool VersionInfo::resolveObjectToClassID(const uint32_t address, int32_t & classid)
{ {
uint32_t vtable = d->p->readDWord(address); uint32_t vtable = d->p->readDWord(address);
// try to find the vtable in our cache // try to find the vtable in our cache
map<uint32_t, t_class *>::iterator it; map<uint32_t, t_class *>::iterator it;
it = d->classIDs.find(vtable); it = d->classIDs.find(vtable);
t_class * cl; t_class * cl;
// class found in cache? // class found in cache?
if(it != d->classIDs.end()) if(it != d->classIDs.end())
{ {
@ -464,8 +481,9 @@ bool memory_info::resolveObjectToClassID(const uint32_t address, int32_t & class
} }
} }
//ALERT: doesn't care about multiclasses //ALERT: doesn't care about multiclasses
bool memory_info::resolveClassnameToVPtr(const string classname, uint32_t & vptr) bool VersionInfo::resolveClassnameToVPtr(const string classname, uint32_t & vptr)
{ {
// FIXME: another stupid search. // FIXME: another stupid search.
for(uint32_t i = 0;i< d->classes.size();i++) for(uint32_t i = 0;i< d->classes.size();i++)
@ -481,7 +499,8 @@ bool memory_info::resolveClassnameToVPtr(const string classname, uint32_t & vptr
return false; return false;
} }
bool memory_info::resolveClassnameToClassID (const string classname, int32_t & classID)
bool VersionInfo::resolveClassnameToClassID (const string classname, int32_t & classID)
{ {
// FIXME: another stupid search. // FIXME: another stupid search.
classID = -1; classID = -1;
@ -497,7 +516,8 @@ bool memory_info::resolveClassnameToClassID (const string classname, int32_t & c
return false; return false;
} }
bool memory_info::resolveClassIDToClassname (const int32_t classID, string & classname)
bool VersionInfo::resolveClassIDToClassname (const int32_t classID, string & classname)
{ {
if (classID >=0 && (uint32_t)classID < d->classnames.size()) if (classID >=0 && (uint32_t)classID < d->classnames.size())
{ {
@ -509,14 +529,14 @@ bool memory_info::resolveClassIDToClassname (const int32_t classID, string & cla
// return pointer to our internal classID -> className mapping // return pointer to our internal classID -> className mapping
const vector<string> * memory_info::getClassIDMapping() const vector<string> * VersionInfo::getClassIDMapping()
{ {
return &d->classnames; return &d->classnames;
} }
// change base of all addresses // change base of all addresses
void memory_info::RebaseAddresses(const int32_t new_base) void VersionInfo::RebaseAddresses(const int32_t new_base)
{ {
map<string, uint32_t>::iterator iter; map<string, uint32_t>::iterator iter;
int32_t rebase = - (int32_t)d->base + new_base; int32_t rebase = - (int32_t)d->base + new_base;
@ -528,7 +548,7 @@ void memory_info::RebaseAddresses(const int32_t new_base)
// change base of all addresses *and* vtable entries // change base of all addresses *and* vtable entries
void memory_info::RebaseAll(int32_t new_base) void VersionInfo::RebaseAll(int32_t new_base)
{ {
map<string, uint32_t>::iterator iter; map<string, uint32_t>::iterator iter;
int32_t rebase = - (int32_t)d->base + new_base; int32_t rebase = - (int32_t)d->base + new_base;
@ -541,7 +561,7 @@ void memory_info::RebaseAll(int32_t new_base)
// change all vtable entries by offset // change all vtable entries by offset
void memory_info::RebaseVTable(int32_t offset) void VersionInfo::RebaseVTable(int32_t offset)
{ {
vector<t_class *>::iterator iter; vector<t_class *>::iterator iter;
for(iter = d->classes.begin(); iter != d->classes.end(); iter++) for(iter = d->classes.begin(); iter != d->classes.end(); iter++)
@ -550,11 +570,12 @@ void memory_info::RebaseVTable(int32_t offset)
} }
} }
// Get named address // Get named address
uint32_t memory_info::getAddress (const char *key) uint32_t VersionInfo::getAddress (const char *key)
{ {
map <string, uint32_t>::iterator iter = d->addresses.find(key); map <string, uint32_t>::iterator iter = d->addresses.find(key);
if(iter != d->addresses.end()) if(iter != d->addresses.end())
{ {
return (*iter).second; return (*iter).second;
@ -564,7 +585,7 @@ uint32_t memory_info::getAddress (const char *key)
// Get named offset // Get named offset
int32_t memory_info::getOffset (const char *key) int32_t VersionInfo::getOffset (const char *key)
{ {
map <string, int32_t>::iterator iter = d->offsets.find(key); map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end()) if(iter != d->offsets.end())
@ -574,8 +595,9 @@ int32_t memory_info::getOffset (const char *key)
throw Error::MissingMemoryDefinition("offset", key); throw Error::MissingMemoryDefinition("offset", key);
} }
// Get named numerical value // Get named numerical value
uint32_t memory_info::getHexValue (const char *key) uint32_t VersionInfo::getHexValue (const char *key)
{ {
map <string, uint32_t>::iterator iter = d->hexvals.find(key); map <string, uint32_t>::iterator iter = d->hexvals.find(key);
if(iter != d->hexvals.end()) if(iter != d->hexvals.end())
@ -587,10 +609,10 @@ uint32_t memory_info::getHexValue (const char *key)
// Get named address // Get named address
uint32_t memory_info::getAddress (const string &key) uint32_t VersionInfo::getAddress (const string &key)
{ {
map <string, uint32_t>::iterator iter = d->addresses.find(key); map <string, uint32_t>::iterator iter = d->addresses.find(key);
if(iter != d->addresses.end()) if(iter != d->addresses.end())
{ {
return (*iter).second; return (*iter).second;
@ -600,7 +622,7 @@ uint32_t memory_info::getAddress (const string &key)
// Get named offset // Get named offset
int32_t memory_info::getOffset (const string &key) int32_t VersionInfo::getOffset (const string &key)
{ {
map <string, int32_t>::iterator iter = d->offsets.find(key); map <string, int32_t>::iterator iter = d->offsets.find(key);
if(iter != d->offsets.end()) if(iter != d->offsets.end())
@ -610,8 +632,9 @@ int32_t memory_info::getOffset (const string &key)
throw Error::MissingMemoryDefinition("offset", key.c_str()); throw Error::MissingMemoryDefinition("offset", key.c_str());
} }
// Get named numerical value // Get named numerical value
uint32_t memory_info::getHexValue (const string &key) uint32_t VersionInfo::getHexValue (const string &key)
{ {
map <string, uint32_t>::iterator iter = d->hexvals.find(key); map <string, uint32_t>::iterator iter = d->hexvals.find(key);
if(iter != d->hexvals.end()) if(iter != d->hexvals.end())
@ -621,8 +644,9 @@ uint32_t memory_info::getHexValue (const string &key)
throw Error::MissingMemoryDefinition("hexvalue", key.c_str()); throw Error::MissingMemoryDefinition("hexvalue", key.c_str());
} }
// Get named string // Get named string
std::string memory_info::getString (const string &key) std::string VersionInfo::getString (const string &key)
{ {
map <string, string>::iterator iter = d->strings.find(key); map <string, string>::iterator iter = d->strings.find(key);
if(iter != d->strings.end()) if(iter != d->strings.end())
@ -632,8 +656,9 @@ std::string memory_info::getString (const string &key)
throw Error::MissingMemoryDefinition("string", key.c_str()); throw Error::MissingMemoryDefinition("string", key.c_str());
} }
// Get Profession // Get Profession
string memory_info::getProfession (const uint32_t key) const string VersionInfo::getProfession (const uint32_t key) const
{ {
if(d->professions.size() > key) if(d->professions.size() > key)
{ {
@ -642,8 +667,9 @@ string memory_info::getProfession (const uint32_t key) const
throw Error::MissingMemoryDefinition("profession", key); throw Error::MissingMemoryDefinition("profession", key);
} }
// Get Job // Get Job
string memory_info::getJob (const uint32_t key) const string VersionInfo::getJob (const uint32_t key) const
{ {
if(d->jobs.size() > key) if(d->jobs.size() > key)
@ -653,7 +679,8 @@ string memory_info::getJob (const uint32_t key) const
throw Error::MissingMemoryDefinition("job", key); throw Error::MissingMemoryDefinition("job", key);
} }
string memory_info::getSkill (const uint32_t key) const
string VersionInfo::getSkill (const uint32_t key) const
{ {
if(d->skills.size() > key) if(d->skills.size() > key)
{ {
@ -662,15 +689,17 @@ string memory_info::getSkill (const uint32_t key) const
throw Error::MissingMemoryDefinition("skill", key); throw Error::MissingMemoryDefinition("skill", key);
} }
DFHack::t_level memory_info::getLevelInfo(const uint32_t level) const
DFHack::t_level VersionInfo::getLevelInfo(const uint32_t level) const
{ {
if(d->levels.size() > level) if(d->levels.size() > level)
{ {
return d->levels[level]; return d->levels[level];
} }
throw Error::MissingMemoryDefinition("Level", level); throw Error::MissingMemoryDefinition("Level", level);
} }
// FIXME: ugly hack that needs to die // FIXME: ugly hack that needs to die
int absolute (int number) int absolute (int number)
{ {
@ -679,7 +708,8 @@ int absolute (int number)
return number; return number;
} }
string memory_info::getTrait (const uint32_t traitIdx, const uint32_t traitValue) const
string VersionInfo::getTrait (const uint32_t traitIdx, const uint32_t traitValue) const
{ {
if(d->traits.size() > traitIdx) if(d->traits.size() > traitIdx)
{ {
@ -704,7 +734,8 @@ string memory_info::getTrait (const uint32_t traitIdx, const uint32_t traitValue
throw Error::MissingMemoryDefinition("trait", traitIdx); throw Error::MissingMemoryDefinition("trait", traitIdx);
} }
string memory_info::getTraitName(const uint32_t traitIdx) const
string VersionInfo::getTraitName(const uint32_t traitIdx) const
{ {
if(d->traits.size() > traitIdx) if(d->traits.size() > traitIdx)
{ {
@ -713,12 +744,14 @@ string memory_info::getTraitName(const uint32_t traitIdx) const
throw Error::MissingMemoryDefinition("traitname", traitIdx); throw Error::MissingMemoryDefinition("traitname", traitIdx);
} }
std::vector< std::vector<std::string> > const& memory_info::getAllTraits()
std::vector< std::vector<std::string> > const& VersionInfo::getAllTraits()
{ {
return d->traits; return d->traits;
} }
string memory_info::getLabor (const uint32_t laborIdx)
string VersionInfo::getLabor (const uint32_t laborIdx)
{ {
if(d->labors.count(laborIdx)) if(d->labors.count(laborIdx))
{ {
@ -727,16 +760,18 @@ string memory_info::getLabor (const uint32_t laborIdx)
throw Error::MissingMemoryDefinition("labor", laborIdx); throw Error::MissingMemoryDefinition("labor", laborIdx);
} }
std::string memory_info::getMood(const uint32_t moodID)
std::string VersionInfo::getMood(const uint32_t moodID)
{ {
if(d->moods.size() > moodID) if(d->moods.size() > moodID)
{ {
return d->moods[moodID]; return d->moods[moodID];
} }
throw Error::MissingMemoryDefinition("Mood", moodID); throw Error::MissingMemoryDefinition("Mood", moodID);
} }
std::string memory_info::PrintOffsets()
std::string VersionInfo::PrintOffsets()
{ {
ostringstream ss; ostringstream ss;
ss << "<Version name=\"" << getVersion() << "\">" << endl; ss << "<Version name=\"" << getVersion() << "\">" << endl;

@ -23,14 +23,14 @@ distribution.
*/ */
#include "Internal.h" #include "Internal.h"
#include "DFMemInfoManager.h" #include "VersionInfoFactory.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
using namespace DFHack; using namespace DFHack;
MemInfoManager::~MemInfoManager() VersionInfoFactory::~VersionInfoFactory()
{ {
// for each in std::vector<memory_info*> meminfo;, delete // for each in std::vector<memory_info*> meminfo;, delete
for(uint32_t i = 0; i < meminfo.size();i++) for(uint32_t i = 0; i < meminfo.size();i++)
@ -40,7 +40,7 @@ MemInfoManager::~MemInfoManager()
meminfo.clear(); meminfo.clear();
} }
void MemInfoManager::ParseVTable(TiXmlElement* vtable, memory_info* mem) void VersionInfoFactory::ParseVTable(TiXmlElement* vtable, VersionInfo* mem)
{ {
TiXmlElement* pClassEntry; TiXmlElement* pClassEntry;
TiXmlElement* pClassSubEntry; TiXmlElement* pClassSubEntry;
@ -92,9 +92,7 @@ void MemInfoManager::ParseVTable(TiXmlElement* vtable, memory_info* mem)
} }
} }
void VersionInfoFactory::ParseEntry (TiXmlElement* entry, VersionInfo* mem, map <string ,TiXmlElement *>& knownEntries)
void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <string ,TiXmlElement *>& knownEntries)
{ {
TiXmlElement* pMemEntry; TiXmlElement* pMemEntry;
const char *cstr_version = entry->Attribute("version"); const char *cstr_version = entry->Attribute("version");
@ -111,11 +109,11 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
throw Error::MemoryXmlBadAttribute("version"); throw Error::MemoryXmlBadAttribute("version");
if (!cstr_os) if (!cstr_os)
throw Error::MemoryXmlBadAttribute("os"); throw Error::MemoryXmlBadAttribute("os");
string os = cstr_os; string os = cstr_os;
mem->setVersion(cstr_version); mem->setVersion(cstr_version);
mem->setOS(cstr_os); mem->setOS(cstr_os);
// offset inherited addresses by 'rebase'. // offset inherited addresses by 'rebase'.
int32_t rebase = 0; int32_t rebase = 0;
if(cstr_rebase) if(cstr_rebase)
@ -123,7 +121,7 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
rebase = mem->getBase() + strtol(cstr_rebase, NULL, 16); rebase = mem->getBase() + strtol(cstr_rebase, NULL, 16);
mem->RebaseAddresses(rebase); mem->RebaseAddresses(rebase);
} }
//set base to default, we're overwriting this because the previous rebase could cause havoc on Vista/7 //set base to default, we're overwriting this because the previous rebase could cause havoc on Vista/7
if(os == "windows") if(os == "windows")
{ {
@ -144,7 +142,7 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
{ {
throw Error::MemoryXmlBadAttribute("os"); throw Error::MemoryXmlBadAttribute("os");
} }
// process additional entries // process additional entries
//cout << "Entry " << cstr_version << " " << cstr_os << endl; //cout << "Entry " << cstr_version << " " << cstr_os << endl;
pMemEntry = entry->FirstChildElement()->ToElement(); pMemEntry = entry->FirstChildElement()->ToElement();
@ -152,7 +150,7 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
{ {
// only elements get processed // only elements get processed
const char *cstr_type = pMemEntry->Value(); const char *cstr_type = pMemEntry->Value();
const char *cstr_name = pMemEntry->Attribute("name"); const char *cstr_name = pMemEntry->Attribute("name");
const char *cstr_value = pMemEntry->GetText(); const char *cstr_value = pMemEntry->GetText();
if(!cstr_value) if(!cstr_value)
@ -208,14 +206,14 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
{ {
mem->setLabor(value,name); mem->setLabor(value,name);
} }
else if (type == "Level") else if (type == "Level")
{
mem->setLevel(value, name, pMemEntry->Attribute("xpNxtLvl"));
}
else if (type == "Mood")
{ {
mem->setLevel(value, name, pMemEntry->Attribute("xpNxtLvl")); mem->setMood(value, name);
} }
else if (type == "Mood")
{
mem->setMood(value, name);
}
else else
{ {
throw Error::MemoryXmlUnknownType(type.c_str()); throw Error::MemoryXmlUnknownType(type.c_str());
@ -223,14 +221,14 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
} // for } // for
} // method } // method
MemInfoManager::MemInfoManager(string path_to_xml) VersionInfoFactory::VersionInfoFactory(string path_to_xml)
{ {
error = false; error = false;
loadFile(path_to_xml); loadFile(path_to_xml);
} }
// load the XML file with offsets // load the XML file with offsets
bool MemInfoManager::loadFile(string path_to_xml) bool VersionInfoFactory::loadFile(string path_to_xml)
{ {
TiXmlDocument doc( path_to_xml.c_str() ); TiXmlDocument doc( path_to_xml.c_str() );
//bool loadOkay = doc.LoadFile(); //bool loadOkay = doc.LoadFile();
@ -242,7 +240,7 @@ bool MemInfoManager::loadFile(string path_to_xml)
TiXmlHandle hDoc(&doc); TiXmlHandle hDoc(&doc);
TiXmlElement* pElem; TiXmlElement* pElem;
TiXmlHandle hRoot(0); TiXmlHandle hRoot(0);
memory_info mem; VersionInfo mem;
// block: name // block: name
{ {
@ -285,7 +283,7 @@ bool MemInfoManager::loadFile(string path_to_xml)
} }
for(uint32_t i = 0; i< v_pEntries.size();i++) for(uint32_t i = 0; i< v_pEntries.size();i++)
{ {
memory_info *mem = new memory_info(); VersionInfo *mem = new VersionInfo();
//FIXME: add a set of entries processed in a step of this cycle, use it to check for infinite loops //FIXME: add a set of entries processed in a step of this cycle, use it to check for infinite loops
/* recursive */ParseEntry( v_pEntries[i] , mem , map_pNamedEntries); /* recursive */ParseEntry( v_pEntries[i] , mem , map_pNamedEntries);
meminfo.push_back(mem); meminfo.push_back(mem);

@ -17,7 +17,7 @@
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "dfhack/DFContextManager.h" #include "dfhack/DFContextManager.h"
#include "dfhack/DFContext.h" #include "dfhack/DFContext.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"

@ -40,7 +40,7 @@ namespace DFHack
class Vegetation; class Vegetation;
class Buildings; class Buildings;
class Constructions; class Constructions;
class memory_info; class VersionInfo;
class DFContextShared; class DFContextShared;
class WindowIO; class WindowIO;
class Process; class Process;
@ -71,7 +71,7 @@ namespace DFHack
/// forces resume on Windows. This can be a bad thing with multiple tools running! /// forces resume on Windows. This can be a bad thing with multiple tools running!
bool ForceResume(); bool ForceResume();
memory_info *getMemoryInfo(); VersionInfo *getMemoryInfo();
Process* getProcess(); Process* getProcess();
void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target); void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target);

@ -12,7 +12,7 @@
using namespace std; using namespace std;
#include <dfhack/DFProcess.h> #include <dfhack/DFProcess.h>
#include <dfhack/DFMemInfo.h> #include <dfhack/VersionInfo.h>
#include <dfhack/DFVector.h> #include <dfhack/DFVector.h>
void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr) void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
@ -81,7 +81,7 @@ void hexdump (DFHack::Context *DF, uint32_t address, uint32_t length)
void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint32_t length) void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint32_t length)
{ {
vector <char * > bufs; vector <char * > bufs;
for(uint32_t counter = 0; counter < addresses.size(); counter ++) for(uint32_t counter = 0; counter < addresses.size(); counter ++)
{ {
char * buf = new char[length * 16]; char * buf = new char[length * 16];
@ -97,7 +97,7 @@ void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint3
cout << "0x" << hex << setw(9) << addresses[obj] << " "; cout << "0x" << hex << setw(9) << addresses[obj] << " ";
} }
cout << endl; cout << endl;
for(uint32_t offs = 0 ; offs < length * 16; offs += 4) for(uint32_t offs = 0 ; offs < length * 16; offs += 4)
{ {
if((!(offs % 16)) && offs != 0) if((!(offs % 16)) && offs != 0)
@ -130,7 +130,7 @@ template <typename T>
void print_bits ( T val, std::ostream& out ) void print_bits ( T val, std::ostream& out )
{ {
T n_bits = sizeof ( val ) * CHAR_BIT; T n_bits = sizeof ( val ) * CHAR_BIT;
for ( unsigned i = 0; i < n_bits; ++i ) { for ( unsigned i = 0; i < n_bits; ++i ) {
out<< !!( val & 1 ) << " "; out<< !!( val & 1 ) << " ";
val >>= 1; val >>= 1;

@ -31,7 +31,7 @@ distribution.
namespace DFHack namespace DFHack
{ {
class memory_info; class VersionInfo;
class Process; class Process;
class Window; class Window;
@ -160,7 +160,7 @@ namespace DFHack
virtual void getMemRanges(std::vector<t_memrange> & ranges ) = 0; virtual void getMemRanges(std::vector<t_memrange> & ranges ) = 0;
/// get the flattened Memory.xml entry of this process /// get the flattened Memory.xml entry of this process
virtual memory_info *getDescriptor() = 0; virtual VersionInfo *getDescriptor() = 0;
/// get the DF Process ID /// get the DF Process ID
virtual int getPID() = 0; virtual int getPID() = 0;
/// get module index by name and version. bool 1 = error /// get module index by name and version. bool 1 = error
@ -182,7 +182,7 @@ namespace DFHack
private: private:
Private * const d; Private * const d;
public: public:
NormalProcess(uint32_t pid, std::vector <memory_info *> & known_versions); NormalProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
~NormalProcess(); ~NormalProcess();
bool attach(); bool attach();
bool detach(); bool detach();
@ -228,7 +228,7 @@ namespace DFHack
bool getThreadIDs(std::vector<uint32_t> & threads ); bool getThreadIDs(std::vector<uint32_t> & threads );
void getMemRanges(std::vector<t_memrange> & ranges ); void getMemRanges(std::vector<t_memrange> & ranges );
memory_info *getDescriptor(); VersionInfo *getDescriptor();
int getPID(); int getPID();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;}; bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;};
@ -246,7 +246,7 @@ namespace DFHack
Private * const d; Private * const d;
public: public:
SHMProcess(uint32_t PID, std::vector <memory_info *> & known_versions); SHMProcess(uint32_t PID, std::vector <VersionInfo *> & known_versions);
~SHMProcess(); ~SHMProcess();
// Set up stuff so we can read memory // Set up stuff so we can read memory
bool attach(); bool attach();
@ -293,7 +293,7 @@ namespace DFHack
bool getThreadIDs(std::vector<uint32_t> & threads ); bool getThreadIDs(std::vector<uint32_t> & threads );
void getMemRanges(std::vector<t_memrange> & ranges ); void getMemRanges(std::vector<t_memrange> & ranges );
memory_info *getDescriptor(); VersionInfo *getDescriptor();
int getPID(); int getPID();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT); bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT);
@ -311,7 +311,7 @@ namespace DFHack
Private * const d; Private * const d;
public: public:
WineProcess(uint32_t pid, std::vector <memory_info *> & known_versions); WineProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
~WineProcess(); ~WineProcess();
bool attach(); bool attach();
bool detach(); bool detach();
@ -357,7 +357,7 @@ namespace DFHack
bool getThreadIDs(std::vector<uint32_t> & threads ); bool getThreadIDs(std::vector<uint32_t> & threads );
void getMemRanges(std::vector<t_memrange> & ranges ); void getMemRanges(std::vector<t_memrange> & ranges );
memory_info *getDescriptor(); VersionInfo *getDescriptor();
int getPID(); int getPID();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) {OUTPUT=0; return false;}; bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) {OUTPUT=0; return false;};

@ -30,7 +30,7 @@ distribution.
namespace DFHack namespace DFHack
{ {
class memory_info; class VersionInfo;
class Process; class Process;
class BadProcesses; class BadProcesses;
/** /**

@ -29,6 +29,7 @@ distribution.
#include "DFExport.h" #include "DFExport.h"
namespace DFHack namespace DFHack
{ {
class VersionInfo;
class Process; class Process;
template <class T> template <class T>
class DFHACK_EXPORT DfVector class DFHACK_EXPORT DfVector
@ -41,9 +42,9 @@ namespace DFHack
DfVector(Process * p, uint32_t address) DfVector(Process * p, uint32_t address)
{ {
uint32_t triplet[3]; uint32_t triplet[3];
memory_info * mem = p->getDescriptor(); VersionInfo * mem = p->getDescriptor();
uint32_t offs = mem->getOffset("vector_triplet"); uint32_t offs = mem->getOffset("vector_triplet");
p->read(address + offs, sizeof(triplet), (uint8_t *) &triplet); p->read(address + offs, sizeof(triplet), (uint8_t *) &triplet);
_start = triplet[0]; _start = triplet[0];
uint32_t byte_size = triplet[1] - triplet[0]; uint32_t byte_size = triplet[1] - triplet[0];
@ -74,12 +75,12 @@ namespace DFHack
return data[index]; return data[index];
}; };
// get vector size // get vector size
inline uint32_t size () inline uint32_t size ()
{ {
return _size; return _size;
}; };
// get vector start // get vector start
inline uint32_t start () inline uint32_t start ()
{ {
return _start; return _start;
}; };

@ -37,7 +37,7 @@ namespace DFHack
class Process; class Process;
struct t_class; struct t_class;
class DFHACK_EXPORT memory_info class DFHACK_EXPORT VersionInfo
{ {
private: private:
class Private; class Private;
@ -49,9 +49,9 @@ namespace DFHack
OS_LINUX, OS_LINUX,
OS_BAD OS_BAD
}; };
memory_info(); VersionInfo();
memory_info(const memory_info&); VersionInfo(const VersionInfo&);
~memory_info(); ~VersionInfo();
void RebaseAddresses(const int32_t new_base); void RebaseAddresses(const int32_t new_base);
void RebaseAll(const int32_t new_base); void RebaseAll(const int32_t new_base);
@ -145,7 +145,7 @@ namespace DFHack
* Get the internal classID->classname mapping (for speed). DO NOT MANIPULATE THE VECTOR! * Get the internal classID->classname mapping (for speed). DO NOT MANIPULATE THE VECTOR!
*/ */
const std::vector<std::string> * getClassIDMapping(); const std::vector<std::string> * getClassIDMapping();
/** /**
* Get a string with all addresses and offsets * Get a string with all addresses and offsets
*/ */

@ -25,7 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
@ -71,7 +71,7 @@ Buildings::Buildings(DFContextShared * d_)
d->d = d_; d->d = d_;
d->owner = d_->p; d->owner = d_->p;
d->Inited = d->Started = false; d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor; VersionInfo * mem = d->d->offset_descriptor;
d->custom_workshop_vector = mem->getAddress("custom_workshop_vector"); d->custom_workshop_vector = mem->getAddress("custom_workshop_vector");
d->building_custom_workshop_type = mem->getOffset("building_custom_workshop_type"); d->building_custom_workshop_type = mem->getOffset("building_custom_workshop_type");
d->custom_workshop_type = mem->getOffset("custom_workshop_type"); d->custom_workshop_type = mem->getOffset("custom_workshop_type");
@ -139,12 +139,12 @@ bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes)
{ {
if(!d->Started) if(!d->Started)
return false; return false;
Process * p = d->owner; Process * p = d->owner;
DfVector <uint32_t> p_matgloss (p, d->custom_workshop_vector); DfVector <uint32_t> p_matgloss (p, d->custom_workshop_vector);
uint32_t size = p_matgloss.size(); uint32_t size = p_matgloss.size();
btypes.clear(); btypes.clear();
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
string out = p->readSTLString (p_matgloss[i] + d->custom_workshop_name); string out = p->readSTLString (p_matgloss[i] + d->custom_workshop_name);

@ -25,7 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
@ -38,7 +38,7 @@ struct Constructions::Private
uint32_t construction_vector; uint32_t construction_vector;
// translation // translation
DfVector <uint32_t> * p_cons; DfVector <uint32_t> * p_cons;
DFContextShared *d; DFContextShared *d;
Process * owner; Process * owner;
bool Inited; bool Inited;
@ -52,7 +52,7 @@ Constructions::Constructions(DFContextShared * d_)
d->owner = d_->p; d->owner = d_->p;
d->p_cons = 0; d->p_cons = 0;
d->Inited = d->Started = false; d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor; VersionInfo * mem = d->d->offset_descriptor;
d->construction_vector = mem->getAddress ("construction_vector"); d->construction_vector = mem->getAddress ("construction_vector");
d->Inited = true; d->Inited = true;
} }

@ -25,7 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
@ -69,7 +69,7 @@ Creatures::Creatures(DFContextShared* _d)
d->d->InitReadNames(); // throws on error d->d->InitReadNames(); // throws on error
try try
{ {
memory_info * minfo = d->d->offset_descriptor; VersionInfo * minfo = d->d->offset_descriptor;
Creatures2010::creature_offsets &creatures = d->creatures; Creatures2010::creature_offsets &creatures = d->creatures;
creatures.vector = minfo->getAddress ("creature_vector"); creatures.vector = minfo->getAddress ("creature_vector");
creatures.pos_offset = minfo->getOffset ("creature_position"); creatures.pos_offset = minfo->getOffset ("creature_position");
@ -171,7 +171,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
} }
*/ */
// non-SHM slow path // non-SHM slow path
memory_info * minfo = d->d->offset_descriptor; VersionInfo * minfo = d->d->offset_descriptor;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = d->p_cre->at (index); uint32_t temp = d->p_cre->at (index);
@ -269,7 +269,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
furball.defaultSoul.skills[i].id = p->readByte (temp2); furball.defaultSoul.skills[i].id = p->readByte (temp2);
furball.defaultSoul.skills[i].rating = furball.defaultSoul.skills[i].rating =
p->readByte (temp2 + offsetof(t_skill, rating)); p->readByte (temp2 + offsetof(t_skill, rating));
furball.defaultSoul.skills[i].experience = furball.defaultSoul.skills[i].experience =
p->readWord (temp2 + offsetof(t_skill, experience)); p->readWord (temp2 + offsetof(t_skill, experience));
} }
@ -525,7 +525,7 @@ bool Creatures::WriteJob(const t_creature * furball, std::vector<t_material> con
if(!d->Inited) return false; if(!d->Inited) return false;
if(!furball->current_job.active) return false; if(!furball->current_job.active) return false;
Process * p = d->owner; Process * p = d->owner;
memory_info * minfo = d->d->offset_descriptor; VersionInfo * minfo = d->d->offset_descriptor;
DfVector <uint32_t> cmats(p, furball->current_job.occupationPtr + minfo->getOffset("job_materials_vector")); DfVector <uint32_t> cmats(p, furball->current_job.occupationPtr + minfo->getOffset("job_materials_vector"));
@ -595,7 +595,7 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
if(!d->Inited) return false; if(!d->Inited) return false;
if(!furball->current_job.active) return false; if(!furball->current_job.active) return false;
Process * p = d->owner; Process * p = d->owner;
memory_info * minfo = d->d->offset_descriptor; VersionInfo * minfo = d->d->offset_descriptor;
DfVector <uint32_t> cmats(p, furball->current_job.occupationPtr + minfo->getOffset("job_materials_vector")); DfVector <uint32_t> cmats(p, furball->current_job.occupationPtr + minfo->getOffset("job_materials_vector"));
mat.resize(cmats.size()); mat.resize(cmats.size());

@ -26,7 +26,7 @@ distribution.
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/Gui.h" #include "dfhack/modules/Gui.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
using namespace DFHack; using namespace DFHack;
@ -45,13 +45,13 @@ struct Gui::Private
Gui::Gui(DFContextShared * _d) Gui::Gui(DFContextShared * _d)
{ {
d = new Private; d = new Private;
d->d = _d; d->d = _d;
d->owner = _d->p; d->owner = _d->p;
d->Inited = d->Started = true; d->Inited = d->Started = true;
memory_info * mem = d->d->offset_descriptor; VersionInfo * mem = d->d->offset_descriptor;
d->current_menu_state_offset = mem->getAddress("current_menu_state"); d->current_menu_state_offset = mem->getAddress("current_menu_state");
d->pause_state_offset = mem->getAddress ("pause_state"); d->pause_state_offset = mem->getAddress ("pause_state");
d->view_screen_offset = mem->getAddress ("view_screen"); d->view_screen_offset = mem->getAddress ("view_screen");
@ -93,7 +93,7 @@ bool Gui::ReadViewScreen (t_viewscreen &screen)
{ {
if (!d->Inited) return false; if (!d->Inited) return false;
Process * p = d->owner; Process * p = d->owner;
uint32_t last = p->readDWord (d->view_screen_offset); uint32_t last = p->readDWord (d->view_screen_offset);
uint32_t screenAddr = p->readDWord (last); uint32_t screenAddr = p->readDWord (last);
uint32_t nextScreenPtr = p->readDWord (last + 4); uint32_t nextScreenPtr = p->readDWord (last + 4);

@ -25,7 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"

@ -29,7 +29,7 @@ distribution.
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/Maps.h" #include "dfhack/modules/Maps.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
@ -68,7 +68,7 @@ Maps::Maps(DFContextShared* _d)
Process *p = d->owner = _d->p; Process *p = d->owner = _d->p;
d->Inited = d->Started = false; d->Inited = d->Started = false;
DFHack::memory_info * mem = p->getDescriptor(); DFHack::VersionInfo * mem = p->getDescriptor();
Server::Maps::maps_offsets &off = d->offsets; Server::Maps::maps_offsets &off = d->offsets;
// get the offsets once here // get the offsets once here
@ -446,7 +446,7 @@ bool Maps::WriteTemperatures (uint32_t x, uint32_t y, uint32_t z, t_temperatures
/* /*
* Region Offsets - used for layer geology * Region Offsets - used for layer geology
*/ */
bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer) bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer)
{ {
MAPS_GUARD MAPS_GUARD
@ -501,7 +501,7 @@ bool Maps::WriteGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global
/* /*
* Block events * Block events
*/ */
bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein>* veins, vector <t_frozenliquidvein>* ices, vector <t_spattervein> *splatter) bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein>* veins, vector <t_frozenliquidvein>* ices, vector <t_spattervein> *splatter)
{ {
MAPS_GUARD MAPS_GUARD
@ -509,12 +509,12 @@ bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein>* veins,
t_frozenliquidvein fv; t_frozenliquidvein fv;
t_spattervein sv; t_spattervein sv;
Process* p = d->owner; Process* p = d->owner;
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if(veins) veins->clear(); if(veins) veins->clear();
if(ices) ices->clear(); if(ices) ices->clear();
if(splatter) splatter->clear(); if(splatter) splatter->clear();
Server::Maps::maps_offsets &off = d->offsets; Server::Maps::maps_offsets &off = d->offsets;
if (addr) if (addr)
{ {
@ -646,7 +646,7 @@ __int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __i
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign) bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
{ {
MAPS_GUARD MAPS_GUARD
memory_info * minfo = d->d->offset_descriptor; VersionInfo * minfo = d->d->offset_descriptor;
Process *p = d->owner; Process *p = d->owner;
// get needed addresses and offsets. Now this is what I call crazy. // get needed addresses and offsets. Now this is what I call crazy.
uint16_t worldSizeX, worldSizeY; uint16_t worldSizeX, worldSizeY;
@ -721,7 +721,7 @@ bool Maps::ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > &
return false; return false;
Process * p = d->owner; Process * p = d->owner;
memory_info * mem = p->getDescriptor(); VersionInfo * mem = p->getDescriptor();
// deref pointer to the humongo-structure // deref pointer to the humongo-structure
uint32_t base = p->readDWord(mem->getAddress("local_feature_start_ptr")); uint32_t base = p->readDWord(mem->getAddress("local_feature_start_ptr"));
if(!base) if(!base)
@ -746,7 +746,7 @@ bool Maps::ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > &
uint32_t array_elem = p->readDWord(base + (region_x_local / 16) * 4); uint32_t array_elem = p->readDWord(base + (region_x_local / 16) * 4);
// 16B structs, second DWORD of the struct is a pointer // 16B structs, second DWORD of the struct is a pointer
uint32_t wtf = p->readDWord(array_elem + ( sizeof_elem * ( (uint32_t)region_y_local/16)) + offset_elem); uint32_t wtf = p->readDWord(array_elem + ( sizeof_elem * ( (uint32_t)region_y_local/16)) + offset_elem);
if(wtf) if(wtf)
{ {
// wtf + sizeof(vector<ptr>) * crap; // wtf + sizeof(vector<ptr>) * crap;
@ -814,7 +814,7 @@ bool Maps::ReadGlobalFeatures( std::vector <t_feature> & features)
return false; return false;
Process * p = d->owner; Process * p = d->owner;
memory_info * mem = p->getDescriptor(); VersionInfo * mem = p->getDescriptor();
uint32_t global_feature_vector = mem->getAddress("global_feature_vector"); uint32_t global_feature_vector = mem->getAddress("global_feature_vector");
uint32_t global_feature_funcptr = mem->getOffset("global_feature_funcptr_"); uint32_t global_feature_funcptr = mem->getOffset("global_feature_funcptr_");

@ -26,7 +26,7 @@ distribution.
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
@ -183,12 +183,12 @@ bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
//cout << temp << endl; //cout << temp << endl;
//fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address //fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address
p->readSTLString (temp, mat.id, 128); p->readSTLString (temp, mat.id, 128);
p->readSTLString (temp+matgloss_stone_name_offset, mat.name, 128); p->readSTLString (temp+matgloss_stone_name_offset, mat.name, 128);
mat.fore = (uint8_t) p->readWord (temp + matgloss_colors); mat.fore = (uint8_t) p->readWord (temp + matgloss_colors);
mat.back = (uint8_t) p->readWord (temp + matgloss_colors + 2); mat.back = (uint8_t) p->readWord (temp + matgloss_colors + 2);
mat.bright = (uint8_t) p->readWord (temp + matgloss_colors + 4); mat.bright = (uint8_t) p->readWord (temp + matgloss_colors + 4);
inorganic.push_back (mat); inorganic.push_back (mat);
} }
return true; return true;
@ -223,7 +223,7 @@ bool Materials::ReadInorganicMaterials (void)
for (uint32_t i = 0; i < size;i++) for (uint32_t i = 0; i < size;i++)
{ {
t_matgloss mat; t_matgloss mat;
p->readSTLString (p_matgloss[i], mat.id, 128); p->readSTLString (p_matgloss[i], mat.id, 128);
//p->readSTLString (p_matgloss[i] + mat_name, mat.name, 128); //p->readSTLString (p_matgloss[i] + mat_name, mat.name, 128);
mat.name[0] = 0; mat.name[0] = 0;
@ -305,7 +305,7 @@ bool Materials::ReadDescriptorColors (void)
bool Materials::ReadCreatureTypesEx (void) bool Materials::ReadCreatureTypesEx (void)
{ {
Process *p = d->owner; Process *p = d->owner;
memory_info *mem = d->owner->getDescriptor(); VersionInfo *mem = d->owner->getDescriptor();
DfVector <uint32_t> p_races (p, mem->getAddress ("creature_type_vector")); DfVector <uint32_t> p_races (p, mem->getAddress ("creature_type_vector"));
uint32_t castes_vector_offset = mem->getOffset ("creature_type_caste_vector"); uint32_t castes_vector_offset = mem->getOffset ("creature_type_caste_vector");
uint32_t extract_vector_offset = mem->getOffset ("creature_type_extract_vector"); uint32_t extract_vector_offset = mem->getOffset ("creature_type_extract_vector");
@ -338,13 +338,13 @@ bool Materials::ReadCreatureTypesEx (void)
// char tile_character AT tile_offset, // char tile_character AT tile_offset,
// word tilecolor.fore : tile_color_offset, // word tilecolor.fore : tile_color_offset,
// word tilecolor.back : tile_color_offset + 2, // word tilecolor.back : tile_color_offset + 2,
// word tilecolor.bright : tile_color_offset + 4 // word tilecolor.bright : tile_color_offset + 4
p->readSTLString (p_races[i], mat.rawname, sizeof(mat.rawname)); p->readSTLString (p_races[i], mat.rawname, sizeof(mat.rawname));
mat.tile_character = p->readByte( p_races[i] + tile_offset ); mat.tile_character = p->readByte( p_races[i] + tile_offset );
mat.tilecolor.fore = p->readWord( p_races[i] + tile_color_offset ); mat.tilecolor.fore = p->readWord( p_races[i] + tile_color_offset );
mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 ); mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 );
mat.tilecolor.bright = p->readWord( p_races[i] + tile_color_offset + 4 ); mat.tilecolor.bright = p->readWord( p_races[i] + tile_color_offset + 4 );
DfVector <uint32_t> p_castes(p, p_races[i] + castes_vector_offset); DfVector <uint32_t> p_castes(p, p_races[i] + castes_vector_offset);
sizecas = p_castes.size(); sizecas = p_castes.size();
for (uint32_t j = 0; j < sizecas;j++) for (uint32_t j = 0; j < sizecas;j++)
@ -504,7 +504,7 @@ std::string Materials::getType(t_material & mat)
} }
} }
} }
else else
return "inorganic"; return "inorganic";
} }
else else

@ -25,7 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/Position.h" #include "dfhack/modules/Position.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
using namespace DFHack; using namespace DFHack;
@ -41,7 +41,7 @@ struct Position::Private
uint32_t hotkey_mode_offset; uint32_t hotkey_mode_offset;
uint32_t hotkey_xyz_offset; uint32_t hotkey_xyz_offset;
uint32_t hotkey_size; uint32_t hotkey_size;
uint32_t screen_tiles_ptr_offset; uint32_t screen_tiles_ptr_offset;
DFContextShared *d; DFContextShared *d;
@ -59,7 +59,7 @@ Position::Position(DFContextShared * d_)
d->owner = d_->p; d->owner = d_->p;
d->Inited = true; d->Inited = true;
d->StartedHotkeys = d->Started = d->StartedScreen = false; d->StartedHotkeys = d->Started = d->StartedScreen = false;
memory_info * mem; VersionInfo * mem;
try try
{ {
mem = d->d->offset_descriptor; mem = d->d->offset_descriptor;

@ -25,7 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/Translation.h" #include "dfhack/modules/Translation.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
@ -38,10 +38,10 @@ struct Translation::Private
uint32_t transAddress; uint32_t transAddress;
uint32_t word_table_offset; uint32_t word_table_offset;
uint32_t sizeof_string; uint32_t sizeof_string;
// translation // translation
Dicts dicts; Dicts dicts;
DFContextShared *d; DFContextShared *d;
bool Inited; bool Inited;
bool Started; bool Started;
@ -52,7 +52,7 @@ Translation::Translation(DFContextShared * d_)
d = new Private; d = new Private;
d->d = d_; d->d = d_;
d->Inited = d->Started = false; d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor; VersionInfo * mem = d->d->offset_descriptor;
d->genericAddress = mem->getAddress ("language_vector"); d->genericAddress = mem->getAddress ("language_vector");
d->transAddress = mem->getAddress ("translation_vector"); d->transAddress = mem->getAddress ("translation_vector");
d->word_table_offset = mem->getOffset ("word_table"); d->word_table_offset = mem->getOffset ("word_table");
@ -116,7 +116,7 @@ bool Translation::Finish()
Dicts * Translation::getDicts() Dicts * Translation::getDicts()
{ {
assert(d->Started); assert(d->Started);
if(d->Started) if(d->Started)
return &d->dicts; return &d->dicts;
return 0; return 0;
@ -126,10 +126,10 @@ string Translation::TranslateName(const t_name &name, bool inEnglish)
{ {
string out; string out;
assert (d->Started); assert (d->Started);
map<string, vector<string> >::const_iterator it; map<string, vector<string> >::const_iterator it;
if(!inEnglish) if(!inEnglish)
{ {
if(name.words[0] >=0 || name.words[1] >=0) if(name.words[0] >=0 || name.words[1] >=0)
{ {
@ -137,7 +137,7 @@ string Translation::TranslateName(const t_name &name, bool inEnglish)
if(name.words[1]>=0) out.append(d->dicts.foreign_languages[name.language][name.words[1]]); if(name.words[1]>=0) out.append(d->dicts.foreign_languages[name.language][name.words[1]]);
out[0] = toupper(out[0]); out[0] = toupper(out[0]);
} }
if(name.words[5] >=0) if(name.words[5] >=0)
{ {
string word; string word;
for(int i=2;i<=5;i++) for(int i=2;i<=5;i++)
@ -146,7 +146,7 @@ string Translation::TranslateName(const t_name &name, bool inEnglish)
if(out.length() > 0) out.append(" "); if(out.length() > 0) out.append(" ");
out.append(word); out.append(word);
} }
if(name.words[6] >=0) if(name.words[6] >=0)
{ {
string word; string word;
word.append(d->dicts.foreign_languages[name.language][name.words[6]]); word.append(d->dicts.foreign_languages[name.language][name.words[6]]);
@ -154,7 +154,7 @@ string Translation::TranslateName(const t_name &name, bool inEnglish)
if(out.length() > 0) out.append(" "); if(out.length() > 0) out.append(" ");
out.append(word); out.append(word);
} }
} }
else else
{ {
if(name.words[0] >=0 || name.words[1] >=0) if(name.words[0] >=0 || name.words[1] >=0)
@ -163,7 +163,7 @@ string Translation::TranslateName(const t_name &name, bool inEnglish)
if(name.words[1]>=0) out.append(d->dicts.translations[name.parts_of_speech[1]+1][name.words[1]]); if(name.words[1]>=0) out.append(d->dicts.translations[name.parts_of_speech[1]+1][name.words[1]]);
out[0] = toupper(out[0]); out[0] = toupper(out[0]);
} }
if(name.words[5] >=0) if(name.words[5] >=0)
{ {
if(out.length() > 0) if(out.length() > 0)
out.append(" the"); out.append(" the");
@ -180,7 +180,7 @@ string Translation::TranslateName(const t_name &name, bool inEnglish)
} }
} }
} }
if(name.words[6] >=0) if(name.words[6] >=0)
{ {
if(out.length() > 0) if(out.length() > 0)
out.append(" of"); out.append(" of");

@ -25,7 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h" #include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
@ -40,7 +40,7 @@ struct Vegetation::Private
uint32_t tree_desc_offset; uint32_t tree_desc_offset;
// translation // translation
DfVector <uint32_t> * p_veg; DfVector <uint32_t> * p_veg;
DFContextShared *d; DFContextShared *d;
Process * owner; Process * owner;
bool Inited; bool Inited;
@ -53,7 +53,7 @@ Vegetation::Vegetation(DFContextShared * d_)
d->owner = d_->p; d->owner = d_->p;
d->d = d_; d->d = d_;
d->Inited = d->Started = false; d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor; VersionInfo * mem = d->d->offset_descriptor;
d->vegetation_vector = mem->getAddress ("vegetation_vector"); d->vegetation_vector = mem->getAddress ("vegetation_vector");
d->tree_desc_offset = mem->getOffset ("tree_desc_offset"); d->tree_desc_offset = mem->getOffset ("tree_desc_offset");
d->Inited = true; d->Inited = true;

@ -38,7 +38,7 @@ FIXME: Japa said that he had to do this with the time stuff he got from here
#include "ContextShared.h" #include "ContextShared.h"
#include "dfhack/modules/World.h" #include "dfhack/modules/World.h"
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h" #include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h" #include "dfhack/DFTypes.h"
using namespace DFHack; using namespace DFHack;
@ -55,12 +55,12 @@ struct World::Private
World::World(DFContextShared * _d) World::World(DFContextShared * _d)
{ {
d = new Private; d = new Private;
d->d = _d; d->d = _d;
d->owner = _d->p; d->owner = _d->p;
memory_info * mem = d->d->offset_descriptor; VersionInfo * mem = d->d->offset_descriptor;
d->year_offset = mem->getAddress( "current_year" ); d->year_offset = mem->getAddress( "current_year" );
d->tick_offset = mem->getAddress( "current_tick" ); d->tick_offset = mem->getAddress( "current_tick" );
d->Inited = d->Started = true; d->Inited = d->Started = true;
@ -95,7 +95,7 @@ uint32_t World::ReadCurrentTick()
return 0; return 0;
} }
// FIX'D according to this: // FIX'D according to this:
/* /*
World::ReadCurrentMonth and World::ReadCurrentDay World::ReadCurrentMonth and World::ReadCurrentDay
« Sent to: peterix on: June 04, 2010, 04:44:30 » « Sent to: peterix on: June 04, 2010, 04:44:30 »

@ -48,7 +48,7 @@ namespace DFHack
class ProcessEnumerator; class ProcessEnumerator;
class Process; class Process;
class memory_info; class VersionInfo;
struct t_name; struct t_name;
class DFContextShared class DFContextShared
{ {
@ -68,7 +68,7 @@ namespace DFHack
ProcessEnumerator* pm; ProcessEnumerator* pm;
Process* p; Process* p;
char * shm_start; char * shm_start;
memory_info* offset_descriptor; VersionInfo* offset_descriptor;
string xml; string xml;
// Modules // Modules

@ -30,20 +30,20 @@ distribution.
class TiXmlElement; class TiXmlElement;
namespace DFHack namespace DFHack
{ {
class memory_info; class VersionInfo;
class MemInfoManager class VersionInfoFactory
{ {
friend class ProcessEnumerator; friend class ProcessEnumerator;
public: public:
MemInfoManager(string path_to_xml); VersionInfoFactory(string path_to_xml);
~MemInfoManager(); ~VersionInfoFactory();
// memory info entries loaded from a file // memory info entries loaded from a file
bool loadFile( string path_to_xml); bool loadFile( string path_to_xml);
bool isInErrorState() const {return error;}; bool isInErrorState() const {return error;};
std::vector<memory_info*> meminfo; std::vector<VersionInfo*> meminfo;
private: private:
void ParseVTable(TiXmlElement* vtable, memory_info* mem); void ParseVTable(TiXmlElement* vtable, VersionInfo* mem);
void ParseEntry (TiXmlElement* entry, memory_info* mem, map <string ,TiXmlElement *>& knownEntries); void ParseEntry (TiXmlElement* entry, VersionInfo* mem, map <string ,TiXmlElement *>& knownEntries);
bool error; bool error;
}; };
} }

@ -54,7 +54,7 @@ int main (int argc,const char* argv[])
return 1; return 1;
} }
DFHack::memory_info * mem = DF->getMemoryInfo(); DFHack::VersionInfo * mem = DF->getMemoryInfo();
DFHack::Buildings * Bld = DF->getBuildings(); DFHack::Buildings * Bld = DF->getBuildings();
DFHack::Position * Pos = DF->getPosition(); DFHack::Position * Pos = DF->getPosition();

@ -19,7 +19,7 @@ enum likeType
}; };
DFHack::Materials * Materials; DFHack::Materials * Materials;
DFHack::memory_info *mem; DFHack::VersionInfo *mem;
vector< vector<string> > englishWords; vector< vector<string> > englishWords;
vector< vector<string> > foreignWords; vector< vector<string> > foreignWords;
DFHack::Creatures * Creatures = NULL; DFHack::Creatures * Creatures = NULL;
@ -154,7 +154,7 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature)
} }
DFHack::Translation *Tran = DF->getTranslation(); DFHack::Translation *Tran = DF->getTranslation();
DFHack::memory_info *mem = DF->getMemoryInfo(); DFHack::VersionInfo *mem = DF->getMemoryInfo();
string transName = Tran->TranslateName(creature.name,false); string transName = Tran->TranslateName(creature.name,false);
if(!transName.empty()) if(!transName.empty())

@ -37,7 +37,7 @@ int main ()
return 1; return 1;
} }
DFHack::memory_info * mem = DF->getMemoryInfo(); DFHack::VersionInfo * mem = DF->getMemoryInfo();
Materials = DF->getMaterials(); Materials = DF->getMaterials();
Materials->ReadAllMaterials(); Materials->ReadAllMaterials();
p = DF->getProcess(); p = DF->getProcess();

@ -25,7 +25,7 @@ int main (void)
return 1; return 1;
} }
DFHack::memory_info * mem = DF->getMemoryInfo(); DFHack::VersionInfo * mem = DF->getMemoryInfo();
DFHack::Position * Pos = DF->getPosition(); DFHack::Position * Pos = DF->getPosition();
// get stone matgloss mapping // get stone matgloss mapping
/* /*

@ -35,7 +35,7 @@ int main (int numargs, const char ** args)
} }
DFHack::Process* p = DF->getProcess(); DFHack::Process* p = DF->getProcess();
DFHack::memory_info* mem = DF->getMemoryInfo(); DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Materials *Materials = DF->getMaterials(); DFHack::Materials *Materials = DF->getMaterials();
cout << "----==== Inorganic ====----" << endl; cout << "----==== Inorganic ====----" << endl;

@ -56,7 +56,7 @@ int main (void)
{ {
cout << "Testing ProcessEnumerator" << endl; cout << "Testing ProcessEnumerator" << endl;
ProcessEnumerator Penum("Memory.xml"); ProcessEnumerator Penum("Memory.xml");
memory_info * mem; VersionInfo * mem;
do do
{ {
// make the ProcessEnumerator update its list of Processes // make the ProcessEnumerator update its list of Processes
@ -90,7 +90,7 @@ int main (void)
{ {
cout << "Testing ContextManager" << endl; cout << "Testing ContextManager" << endl;
ContextManager Cman("Memory.xml"); ContextManager Cman("Memory.xml");
memory_info * mem; VersionInfo * mem;
do do
{ {
// make the ContextManager update its list of Contexts // make the ContextManager update its list of Contexts

@ -37,7 +37,7 @@ int main (int numargs, const char ** args)
} }
DFHack::Process* p = DF->getProcess(); DFHack::Process* p = DF->getProcess();
DFHack::memory_info* mem = DF->getMemoryInfo(); DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Position * pos = DF->getPosition(); DFHack::Position * pos = DF->getPosition();
DFHack::Vegetation * v = DF->getVegetation(); DFHack::Vegetation * v = DF->getVegetation();
DFHack::Materials * mat = DF->getMaterials(); DFHack::Materials * mat = DF->getMaterials();

@ -21,7 +21,7 @@ using namespace DFHack;
int main ( int argc, char** argv ) int main ( int argc, char** argv )
{ {
DFHack::memory_info *mem; DFHack::VersionInfo *mem;
DFHack::Process *proc; DFHack::Process *proc;
uint32_t creature_pregnancy_offset; uint32_t creature_pregnancy_offset;

@ -181,12 +181,12 @@ bool getRanges(DFHack::Process * p, vector <DFHack::t_memrange>& selected_ranges
{ {
// empty input, assume default. observe the length of the memory range vector // empty input, assume default. observe the length of the memory range vector
// these are hardcoded values, intended for my convenience only // these are hardcoded values, intended for my convenience only
if(p->getDescriptor()->getOS() == DFHack::memory_info::OS_WINDOWS) if(p->getDescriptor()->getOS() == DFHack::VersionInfo::OS_WINDOWS)
{ {
start = min(11, (int)ranges.size()); start = min(11, (int)ranges.size());
end = min(14, (int)ranges.size()); end = min(14, (int)ranges.size());
} }
else if(p->getDescriptor()->getOS() == DFHack::memory_info::OS_LINUX) else if(p->getDescriptor()->getOS() == DFHack::VersionInfo::OS_LINUX)
{ {
start = min(2, (int)ranges.size()); start = min(2, (int)ranges.size());
end = min(4, (int)ranges.size()); end = min(4, (int)ranges.size());
@ -793,8 +793,8 @@ int main (void)
vector <DFHack::t_memrange> selected_ranges; vector <DFHack::t_memrange> selected_ranges;
getRanges(p,selected_ranges); getRanges(p,selected_ranges);
DFHack::memory_info *minfo = DF->getMemoryInfo(); DFHack::VersionInfo *minfo = DF->getMemoryInfo();
DFHack::memory_info::OSType os = minfo->getOS(); DFHack::VersionInfo::OSType os = minfo->getOS();
string prompt = string prompt =
"Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n" "Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n"

@ -6,7 +6,7 @@ using namespace std;
#include <DFHack.h> #include <DFHack.h>
DFHack::Materials * Materials; DFHack::Materials * Materials;
DFHack::memory_info *mem; DFHack::VersionInfo *mem;
vector< vector<string> > englishWords; vector< vector<string> > englishWords;
vector< vector<string> > foreignWords; vector< vector<string> > foreignWords;

@ -32,7 +32,7 @@ int main ()
return 1; return 1;
} }
DFHack::memory_info * mem = DF->getMemoryInfo(); DFHack::VersionInfo * mem = DF->getMemoryInfo();
p = DF->getProcess(); p = DF->getProcess();
uint32_t item_vec_offset = 0; uint32_t item_vec_offset = 0;
try try

@ -27,7 +27,7 @@ int main (int numargs, const char ** args)
#endif #endif
return 1; return 1;
} }
memory_info * minfo = DF->getMemoryInfo(); VersionInfo * minfo = DF->getMemoryInfo();
if(minfo) if(minfo)
cout << minfo->PrintOffsets(); cout << minfo->PrintOffsets();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD

@ -32,7 +32,7 @@ int main (int numargs, const char ** args)
} }
DFHack::Position *Pos = DF->getPosition(); DFHack::Position *Pos = DF->getPosition();
DFHack::memory_info* mem = DF->getMemoryInfo(); DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Maps *Maps = DF->getMaps(); DFHack::Maps *Maps = DF->getMaps();
DFHack::Process * p = DF->getProcess(); DFHack::Process * p = DF->getProcess();
uint32_t designatus = mem->getOffset("map_data_designation"); uint32_t designatus = mem->getOffset("map_data_designation");