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

@ -4,7 +4,7 @@
#include <mod-maps.h>
#include <mod-creature40d.h>
#include "private/ContextShared.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.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);
}
memory_info *Context::getMemoryInfo()
VersionInfo *Context::getMemoryInfo()
{
return d->offset_descriptor;
}

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

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

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

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

@ -23,7 +23,7 @@ distribution.
*/
#include "Internal.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h"
#include "shms.h"
#include "mod-core.h"
@ -48,7 +48,7 @@ class SHMProcess::Private
attachmentIdx = -1;
};
~Private(){};
memory_info * memdescriptor;
VersionInfo * memdescriptor;
SHMProcess * self;
uint32_t process_ID;
char *shm_addr;
@ -56,14 +56,14 @@ class SHMProcess::Private
HANDLE DFCLMutex;
HANDLE DFCLSuspendMutex;
int attachmentIdx;
bool attached;
bool locked;
bool identified;
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 SetAndWait (uint32_t state);
bool GetLocks();
@ -91,7 +91,7 @@ bool SHMProcess::Private::SetAndWait (uint32_t state)
uint32_t cnt = 0;
if(!attached) return false;
SHMCMD = state;
while (SHMCMD == state)
{
// yield the CPU, only on single-core CPUs
@ -176,7 +176,7 @@ bool SHMProcess::Private::GetLocks()
DFSVMutex = 0;
return false;
}
for(int i = 0; i < SHM_MAX_CLIENTS; i++)
{
// open the client suspend locked
@ -190,7 +190,7 @@ bool SHMProcess::Private::GetLocks()
}
// open the client lock, try to lock it
sprintf(name,"DFCLMutex-%d-%d",process_ID,i);
DFCLMutex = OpenMutex(SYNCHRONIZE,0,name);
if(DFCLMutex == 0)
@ -226,7 +226,7 @@ bool SHMProcess::Private::GetLocks()
bool SHMProcess::Private::AreLocksOk()
{
// both locks are inited (we hold our lock)
if(DFCLMutex != 0 && DFSVMutex != 0)
if(DFCLMutex != 0 && DFSVMutex != 0)
{
// try if CL mutex is free
switch (WaitForSingleObject(DFSVMutex,0))
@ -241,7 +241,7 @@ bool SHMProcess::Private::AreLocksOk()
{
// mutex is held by DF
return true;
}
}
default:
case WAIT_FAILED:
{
@ -257,10 +257,10 @@ bool SHMProcess::Private::AreLocksOk()
/*
char svmutexname [256];
char clmutexname [256];
sprintf(clmutexname,"DFCLMutex-%d",PID);
// get server and client mutex
d->DFSVMutex = OpenMutex(SYNCHRONIZE,false, svmutexname);
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->process_ID = PID;
@ -314,7 +314,7 @@ bool SHMProcess::isIdentified()
{
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
IMAGE_NT_HEADERS32 pe_header;
@ -324,11 +324,11 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
HANDLE hProcess;
bool found = 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 );
if (NULL == hProcess)
return false;
// try getting the first module of the process
if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0)
{
@ -338,14 +338,14 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
}
// got base ;)
uint32_t base = (uint32_t)hmod;
// read from this process
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), sizeof(sections) , (uint8_t *)&sections );
// 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++ )
{
uint32_t pe_timestamp;
@ -359,7 +359,7 @@ bool SHMProcess::Private::validate(vector <memory_info *> & known_versions)
}
if (pe_timestamp == pe_header.FileHeader.TimeDateStamp)
{
memory_info *m = new memory_info(**it);
VersionInfo *m = new VersionInfo(**it);
m->RebaseAll(base);
memdescriptor = m;
m->setParentProcess(self);
@ -385,7 +385,7 @@ SHMProcess::~SHMProcess()
delete d;
}
memory_info * SHMProcess::getDescriptor()
VersionInfo * SHMProcess::getDescriptor()
{
return d->memdescriptor;
}
@ -397,30 +397,30 @@ int SHMProcess::getPID()
bool SHMProcess::getThreadIDs(vector<uint32_t> & threads )
{
HANDLE AllThreads = INVALID_HANDLE_VALUE;
HANDLE AllThreads = INVALID_HANDLE_VALUE;
THREADENTRY32 te32;
AllThreads = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
if( AllThreads == INVALID_HANDLE_VALUE )
AllThreads = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
if( AllThreads == INVALID_HANDLE_VALUE )
{
return false;
return false;
}
te32.dwSize = sizeof(THREADENTRY32 );
if( !Thread32First( AllThreads, &te32 ) )
te32.dwSize = sizeof(THREADENTRY32 );
if( !Thread32First( AllThreads, &te32 ) )
{
CloseHandle( AllThreads );
return false;
}
do
{
do
{
if( te32.th32OwnerProcessID == d->process_ID )
{
threads.push_back(te32.th32ThreadID);
}
} while( Thread32Next(AllThreads, &te32 ) );
} while( Thread32Next(AllThreads, &te32 ) );
CloseHandle( AllThreads );
return true;
}
@ -430,9 +430,9 @@ void SHMProcess::getMemRanges( vector<t_memrange> & ranges )
{
// 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
// I'm faking this, because there's no way I'm using VirtualQuery
t_memrange temp;
uint32_t base = d->memdescriptor->getBase();
temp.start = base + 0x1000; // more fakery.
@ -591,7 +591,7 @@ bool SHMProcess::attach()
return false; // we couldn't lock it
}
*/
/*
* Locate the segment.
*/
@ -613,12 +613,12 @@ bool SHMProcess::attach()
{
CloseHandle(shmHandle);
//ReleaseMutex(d->DFCLMutex);
d->FreeLocks();
d->FreeLocks();
return false; // we couldn't attach the mapping // FIXME: throw
}
// we close the handle right here - it's not needed anymore
CloseHandle(shmHandle);
d->attached = true;
if(!suspend())
{
@ -653,7 +653,7 @@ bool SHMProcess::detach()
void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buffer)
{
if(!d->locked) throw Error::MemoryAccessDenied();
// normal read under 1MB
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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 )
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
D_SHMHDR->Qvalue = data;
full_barrier
@ -801,7 +801,7 @@ void SHMProcess::writeQuad (uint32_t offset, uint64_t data)
void SHMProcess::writeDWord (uint32_t offset, uint32_t data)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
D_SHMHDR->value = data;
full_barrier
@ -812,7 +812,7 @@ void SHMProcess::writeDWord (uint32_t offset, uint32_t data)
void SHMProcess::writeWord (uint32_t offset, uint16_t data)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
D_SHMHDR->value = data;
full_barrier
@ -822,7 +822,7 @@ void SHMProcess::writeWord (uint32_t offset, uint16_t data)
void SHMProcess::writeByte (uint32_t offset, uint8_t data)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
D_SHMHDR->value = data;
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
// normal write under 1MB
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
std::string temp;
char temp_c[256];
int counter = 0;
@ -889,7 +889,7 @@ const std::string SHMProcess::readCString (uint32_t offset)
const std::string SHMProcess::readSTLString(uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = address;
strncpy(D_SHMDATA(char),writeString.c_str(),writeString.length()+1); // length + 1 for the null terminator
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)
{
if(!d->locked) throw Error::MemoryAccessDenied();
modulelookup * payload = D_SHMDATA(modulelookup);
payload->version = version;
strncpy(payload->name,name,255);
payload->name[255] = 0;
if(!SetAndWait(CORE_ACQUIRE_MODULE))
{
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)
{
if(!locked) throw Error::MemoryAccessDenied();
SHMDATA(coreattach)->cl_affinity = OS_getAffinity();
if(!SetAndWait(CORE_ATTACH)) return false;
/*

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

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

@ -23,11 +23,11 @@ distribution.
*/
#include "Internal.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFError.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_MOODS 6
using namespace DFHack;
@ -81,56 +81,60 @@ namespace DFHack
std::vector<t_type *> subs;
};
}
/*
* Private data
*/
class memory_info::Private
class VersionInfo::Private
{
public:
map <string, uint32_t> addresses;
map <string, int32_t> offsets;
map <string, uint32_t> hexvals;
map <string, string> strings;
vector<string> professions;
vector<string> jobs;
vector<string> skills;
vector<DFHack::t_level> levels;
vector<DFHack::t_level> levels;
vector< vector<string> > traits;
vector<string> moods;
vector<string> moods;
map <uint32_t, string> labors;
// storage for class and multiclass
vector<t_class *> classes;
// cache for faster name lookup, indexed by classID
vector<string> classnames;
// map between vptr and class id, needs further type id lookup for multi-classes, not inherited
map<uint32_t, t_class *> classIDs;
// index for the next added class
uint32_t classindex;
int32_t base;
Process * p; // the process this belongs to
string version;
OSType OS;
};
// normal constructor
memory_info::memory_info()
VersionInfo::VersionInfo()
:d(new Private)
{
d->base = 0;
d->p = 0;
d->classindex = 0;
d->levels.reserve(NUM_RESERVE_LVLS);
d->moods.reserve(NUM_RESERVE_MOODS);
d->levels.reserve(NUM_RESERVE_LVLS);
d->moods.reserve(NUM_RESERVE_MOODS);
}
// copy constructor
memory_info::memory_info(const memory_info &old)
VersionInfo::VersionInfo(const VersionInfo &old)
:d(new Private)
{
d->version = old.d->version;
@ -153,16 +157,19 @@ memory_info::memory_info(const memory_info &old)
d->skills = old.d->skills;
d->traits = old.d->traits;
d->labors = old.d->labors;
d->levels = old.d->levels;
d->moods = old.d->moods;
d->levels = old.d->levels;
d->moods = old.d->moods;
}
void memory_info::setParentProcess(Process * _p)
void VersionInfo::setParentProcess(Process * _p)
{
d->p = _p;
}
// destructor
memory_info::~memory_info()
VersionInfo::~VersionInfo()
{
// delete the vtables
for(uint32_t i = 0; i < d->classes.size();i++)
@ -173,25 +180,26 @@ memory_info::~memory_info()
delete d;
}
void memory_info::setVersion(const char * v)
void VersionInfo::setVersion(const char * v)
{
d->version = v;
}
void memory_info::setVersion(const string &v)
void VersionInfo::setVersion(const string &v)
{
d->version = v;
}
string memory_info::getVersion()
string VersionInfo::getVersion()
{
return d->version;
}
void memory_info::setOS(const char *os)
void VersionInfo::setOS(const char *os)
{
string oss = os;
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")
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)
{
@ -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;
}
uint32_t memory_info::getBase () const
uint32_t VersionInfo::getBase () const
{
return d->base;
}
void memory_info::setBase (const string &s)
void VersionInfo::setBase (const string &s)
{
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;
}
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);
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);
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);
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;
}
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);
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);
if(d->professions.size() <= keyInt)
@ -290,7 +300,8 @@ void memory_info::setProfession (const string & key, const string & 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);
if(d->jobs.size() <= keyInt)
@ -300,7 +311,8 @@ void memory_info::setJob (const string & key, const string & 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);
if(d->skills.size() <= keyInt){
@ -309,31 +321,34 @@ void memory_info::setSkill (const string & key, const string & value)
d->skills[keyInt] = value;
}
void memory_info::setLevel(const std::string &nLevel,
const std::string &nName,
const std::string &nXp)
void VersionInfo::setLevel(const std::string &nLevel,
const std::string &nName,
const std::string &nXp)
{
uint32_t keyInt = strtol(nLevel.c_str(), NULL, 10);
if(d->levels.size() <= keyInt)
d->levels.resize(keyInt+1);
d->levels[keyInt].level = keyInt;
d->levels[keyInt].name = nName;
d->levels[keyInt].xpNxtLvl = strtol(nXp.c_str(), NULL, 10);
uint32_t keyInt = strtol(nLevel.c_str(), NULL, 10);
if(d->levels.size() <= keyInt)
d->levels.resize(keyInt+1);
d->levels[keyInt].level = keyInt;
d->levels[keyInt].name = nName;
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);
if(d->moods.size() <= keyInt)
d->moods.resize(keyInt+1);
uint32_t keyInt = strtol(id.c_str(), NULL, 10);
if(d->moods.size() <= keyInt)
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 & zero,
const string & one,
@ -356,8 +371,9 @@ void memory_info::setTrait(const string & key,
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.
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)
return 0;
@ -372,27 +388,27 @@ t_class * memory_info::setClass (const char * name, uint32_t vtable, uint32_t ty
return d->classes[i];
}
}
t_class *cls = new t_class();
// get an unique ID and add ourselves to the index
cls->assign = d->classindex;
cls->classname = name;
d->classnames.push_back(name);
// vtables no longer a requirement
cls->vtable = vtable;
// multi class yes/no
cls->type_offset = typeoffset;
d->classes.push_back(cls);
d->classindex++;
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;
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);
vec.push_back(mcc);
d->classindex++;
//cout << " classtype " << name << ", assign " << mcc->assign << ", vtable " << mcc->type << endl;
}
// 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);
// try to find the vtable in our cache
map<uint32_t, t_class *>::iterator it;
it = d->classIDs.find(vtable);
t_class * cl;
// class found in cache?
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
bool memory_info::resolveClassnameToVPtr(const string classname, uint32_t & vptr)
bool VersionInfo::resolveClassnameToVPtr(const string classname, uint32_t & vptr)
{
// FIXME: another stupid search.
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;
}
bool memory_info::resolveClassnameToClassID (const string classname, int32_t & classID)
bool VersionInfo::resolveClassnameToClassID (const string classname, int32_t & classID)
{
// FIXME: another stupid search.
classID = -1;
@ -497,7 +516,8 @@ bool memory_info::resolveClassnameToClassID (const string classname, int32_t & c
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())
{
@ -509,14 +529,14 @@ bool memory_info::resolveClassIDToClassname (const int32_t classID, string & cla
// return pointer to our internal classID -> className mapping
const vector<string> * memory_info::getClassIDMapping()
const vector<string> * VersionInfo::getClassIDMapping()
{
return &d->classnames;
}
// 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;
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
void memory_info::RebaseAll(int32_t new_base)
void VersionInfo::RebaseAll(int32_t new_base)
{
map<string, uint32_t>::iterator iter;
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
void memory_info::RebaseVTable(int32_t offset)
void VersionInfo::RebaseVTable(int32_t offset)
{
vector<t_class *>::iterator 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
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);
if(iter != d->addresses.end())
{
return (*iter).second;
@ -564,7 +585,7 @@ uint32_t memory_info::getAddress (const char *key)
// 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);
if(iter != d->offsets.end())
@ -574,8 +595,9 @@ int32_t memory_info::getOffset (const char *key)
throw Error::MissingMemoryDefinition("offset", key);
}
// 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);
if(iter != d->hexvals.end())
@ -587,10 +609,10 @@ uint32_t memory_info::getHexValue (const char *key)
// 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);
if(iter != d->addresses.end())
{
return (*iter).second;
@ -600,7 +622,7 @@ uint32_t memory_info::getAddress (const string &key)
// 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);
if(iter != d->offsets.end())
@ -610,8 +632,9 @@ int32_t memory_info::getOffset (const string &key)
throw Error::MissingMemoryDefinition("offset", key.c_str());
}
// 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);
if(iter != d->hexvals.end())
@ -621,8 +644,9 @@ uint32_t memory_info::getHexValue (const string &key)
throw Error::MissingMemoryDefinition("hexvalue", key.c_str());
}
// 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);
if(iter != d->strings.end())
@ -632,8 +656,9 @@ std::string memory_info::getString (const string &key)
throw Error::MissingMemoryDefinition("string", key.c_str());
}
// Get Profession
string memory_info::getProfession (const uint32_t key) const
string VersionInfo::getProfession (const uint32_t key) const
{
if(d->professions.size() > key)
{
@ -642,8 +667,9 @@ string memory_info::getProfession (const uint32_t key) const
throw Error::MissingMemoryDefinition("profession", key);
}
// Get Job
string memory_info::getJob (const uint32_t key) const
string VersionInfo::getJob (const uint32_t key) const
{
if(d->jobs.size() > key)
@ -653,7 +679,8 @@ string memory_info::getJob (const uint32_t key) const
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)
{
@ -662,15 +689,17 @@ string memory_info::getSkill (const uint32_t key) const
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];
}
throw Error::MissingMemoryDefinition("Level", level);
}
// FIXME: ugly hack that needs to die
int absolute (int number)
{
@ -679,7 +708,8 @@ int absolute (int 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)
{
@ -704,7 +734,8 @@ string memory_info::getTrait (const uint32_t traitIdx, const uint32_t traitValue
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)
{
@ -713,12 +744,14 @@ string memory_info::getTraitName(const uint32_t traitIdx) const
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))
{
@ -727,16 +760,18 @@ string memory_info::getLabor (const uint32_t 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)
{
return d->moods[moodID];
}
throw Error::MissingMemoryDefinition("Mood", moodID);
if(d->moods.size() > moodID)
{
return d->moods[moodID];
}
throw Error::MissingMemoryDefinition("Mood", moodID);
}
std::string memory_info::PrintOffsets()
std::string VersionInfo::PrintOffsets()
{
ostringstream ss;
ss << "<Version name=\"" << getVersion() << "\">" << endl;

@ -23,14 +23,14 @@ distribution.
*/
#include "Internal.h"
#include "DFMemInfoManager.h"
#include "VersionInfoFactory.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFError.h"
using namespace DFHack;
MemInfoManager::~MemInfoManager()
VersionInfoFactory::~VersionInfoFactory()
{
// for each in std::vector<memory_info*> meminfo;, delete
for(uint32_t i = 0; i < meminfo.size();i++)
@ -40,7 +40,7 @@ MemInfoManager::~MemInfoManager()
meminfo.clear();
}
void MemInfoManager::ParseVTable(TiXmlElement* vtable, memory_info* mem)
void VersionInfoFactory::ParseVTable(TiXmlElement* vtable, VersionInfo* mem)
{
TiXmlElement* pClassEntry;
TiXmlElement* pClassSubEntry;
@ -92,9 +92,7 @@ void MemInfoManager::ParseVTable(TiXmlElement* vtable, memory_info* mem)
}
}
void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <string ,TiXmlElement *>& knownEntries)
void VersionInfoFactory::ParseEntry (TiXmlElement* entry, VersionInfo* mem, map <string ,TiXmlElement *>& knownEntries)
{
TiXmlElement* pMemEntry;
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");
if (!cstr_os)
throw Error::MemoryXmlBadAttribute("os");
string os = cstr_os;
mem->setVersion(cstr_version);
mem->setOS(cstr_os);
// offset inherited addresses by 'rebase'.
int32_t rebase = 0;
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);
mem->RebaseAddresses(rebase);
}
//set base to default, we're overwriting this because the previous rebase could cause havoc on Vista/7
if(os == "windows")
{
@ -144,7 +142,7 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
{
throw Error::MemoryXmlBadAttribute("os");
}
// process additional entries
//cout << "Entry " << cstr_version << " " << cstr_os << endl;
pMemEntry = entry->FirstChildElement()->ToElement();
@ -152,7 +150,7 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
{
// only elements get processed
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();
if(!cstr_value)
@ -208,14 +206,14 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
{
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
{
throw Error::MemoryXmlUnknownType(type.c_str());
@ -223,14 +221,14 @@ void MemInfoManager::ParseEntry (TiXmlElement* entry, memory_info* mem, map <str
} // for
} // method
MemInfoManager::MemInfoManager(string path_to_xml)
VersionInfoFactory::VersionInfoFactory(string path_to_xml)
{
error = false;
loadFile(path_to_xml);
}
// 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() );
//bool loadOkay = doc.LoadFile();
@ -242,7 +240,7 @@ bool MemInfoManager::loadFile(string path_to_xml)
TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
TiXmlHandle hRoot(0);
memory_info mem;
VersionInfo mem;
// block: name
{
@ -285,7 +283,7 @@ bool MemInfoManager::loadFile(string path_to_xml)
}
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
/* recursive */ParseEntry( v_pEntries[i] , mem , map_pNamedEntries);
meminfo.push_back(mem);

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

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

@ -12,7 +12,7 @@
using namespace std;
#include <dfhack/DFProcess.h>
#include <dfhack/DFMemInfo.h>
#include <dfhack/VersionInfo.h>
#include <dfhack/DFVector.h>
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)
{
vector <char * > bufs;
for(uint32_t counter = 0; counter < addresses.size(); counter ++)
{
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 << endl;
for(uint32_t offs = 0 ; offs < length * 16; offs += 4)
{
if((!(offs % 16)) && offs != 0)
@ -130,7 +130,7 @@ template <typename T>
void print_bits ( T val, std::ostream& out )
{
T n_bits = sizeof ( val ) * CHAR_BIT;
for ( unsigned i = 0; i < n_bits; ++i ) {
out<< !!( val & 1 ) << " ";
val >>= 1;

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

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

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

@ -37,7 +37,7 @@ namespace DFHack
class Process;
struct t_class;
class DFHACK_EXPORT memory_info
class DFHACK_EXPORT VersionInfo
{
private:
class Private;
@ -49,9 +49,9 @@ namespace DFHack
OS_LINUX,
OS_BAD
};
memory_info();
memory_info(const memory_info&);
~memory_info();
VersionInfo();
VersionInfo(const VersionInfo&);
~VersionInfo();
void RebaseAddresses(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!
*/
const std::vector<std::string> * getClassIDMapping();
/**
* Get a string with all addresses and offsets
*/

@ -25,7 +25,7 @@ distribution.
#include "Internal.h"
#include "ContextShared.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h"
@ -71,7 +71,7 @@ Buildings::Buildings(DFContextShared * d_)
d->d = d_;
d->owner = d_->p;
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->building_custom_workshop_type = mem->getOffset("building_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)
return false;
Process * p = d->owner;
DfVector <uint32_t> p_matgloss (p, d->custom_workshop_vector);
uint32_t size = p_matgloss.size();
btypes.clear();
for (uint32_t i = 0; i < size;i++)
{
string out = p->readSTLString (p_matgloss[i] + d->custom_workshop_name);

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

@ -25,7 +25,7 @@ distribution.
#include "Internal.h"
#include "ContextShared.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
#include "dfhack/DFError.h"
@ -69,7 +69,7 @@ Creatures::Creatures(DFContextShared* _d)
d->d->InitReadNames(); // throws on error
try
{
memory_info * minfo = d->d->offset_descriptor;
VersionInfo * minfo = d->d->offset_descriptor;
Creatures2010::creature_offsets &creatures = d->creatures;
creatures.vector = minfo->getAddress ("creature_vector");
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
memory_info * minfo = d->d->offset_descriptor;
VersionInfo * minfo = d->d->offset_descriptor;
// read pointer from vector at position
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].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));
}
@ -525,7 +525,7 @@ bool Creatures::WriteJob(const t_creature * furball, std::vector<t_material> con
if(!d->Inited) return false;
if(!furball->current_job.active) return false;
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"));
@ -595,7 +595,7 @@ bool Creatures::ReadJob(const t_creature * furball, vector<t_material> & mat)
if(!d->Inited) return false;
if(!furball->current_job.active) return false;
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"));
mat.resize(cmats.size());

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

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

@ -29,7 +29,7 @@ distribution.
#include "ContextShared.h"
#include "dfhack/modules/Maps.h"
#include "dfhack/DFError.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
@ -68,7 +68,7 @@ Maps::Maps(DFContextShared* _d)
Process *p = d->owner = _d->p;
d->Inited = d->Started = false;
DFHack::memory_info * mem = p->getDescriptor();
DFHack::VersionInfo * mem = p->getDescriptor();
Server::Maps::maps_offsets &off = d->offsets;
// 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
*/
*/
bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer)
{
MAPS_GUARD
@ -501,7 +501,7 @@ bool Maps::WriteGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global
/*
* 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)
{
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_spattervein sv;
Process* p = d->owner;
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(ices) ices->clear();
if(splatter) splatter->clear();
Server::Maps::maps_offsets &off = d->offsets;
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)
{
MAPS_GUARD
memory_info * minfo = d->d->offset_descriptor;
VersionInfo * minfo = d->d->offset_descriptor;
Process *p = d->owner;
// get needed addresses and offsets. Now this is what I call crazy.
uint16_t worldSizeX, worldSizeY;
@ -721,7 +721,7 @@ bool Maps::ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > &
return false;
Process * p = d->owner;
memory_info * mem = p->getDescriptor();
VersionInfo * mem = p->getDescriptor();
// deref pointer to the humongo-structure
uint32_t base = p->readDWord(mem->getAddress("local_feature_start_ptr"));
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);
// 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)
{
// wtf + sizeof(vector<ptr>) * crap;
@ -814,7 +814,7 @@ bool Maps::ReadGlobalFeatures( std::vector <t_feature> & features)
return false;
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_funcptr = mem->getOffset("global_feature_funcptr_");

@ -26,7 +26,7 @@ distribution.
#include "ContextShared.h"
#include "dfhack/DFTypes.h"
#include "dfhack/modules/Materials.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
@ -183,12 +183,12 @@ bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic)
//cout << temp << endl;
//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+matgloss_stone_name_offset, mat.name, 128);
mat.fore = (uint8_t) p->readWord (temp + matgloss_colors);
mat.back = (uint8_t) p->readWord (temp + matgloss_colors + 2);
mat.bright = (uint8_t) p->readWord (temp + matgloss_colors + 4);
inorganic.push_back (mat);
}
return true;
@ -223,7 +223,7 @@ bool Materials::ReadInorganicMaterials (void)
for (uint32_t i = 0; i < size;i++)
{
t_matgloss mat;
p->readSTLString (p_matgloss[i], mat.id, 128);
//p->readSTLString (p_matgloss[i] + mat_name, mat.name, 128);
mat.name[0] = 0;
@ -305,7 +305,7 @@ bool Materials::ReadDescriptorColors (void)
bool Materials::ReadCreatureTypesEx (void)
{
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"));
uint32_t castes_vector_offset = mem->getOffset ("creature_type_caste_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,
// word tilecolor.fore : tile_color_offset,
// 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));
mat.tile_character = p->readByte( p_races[i] + tile_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.bright = p->readWord( p_races[i] + tile_color_offset + 4 );
DfVector <uint32_t> p_castes(p, p_races[i] + castes_vector_offset);
sizecas = p_castes.size();
for (uint32_t j = 0; j < sizecas;j++)
@ -504,7 +504,7 @@ std::string Materials::getType(t_material & mat)
}
}
}
else
else
return "inorganic";
}
else

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

@ -25,7 +25,7 @@ distribution.
#include "Internal.h"
#include "ContextShared.h"
#include "dfhack/modules/Translation.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h"
@ -38,10 +38,10 @@ struct Translation::Private
uint32_t transAddress;
uint32_t word_table_offset;
uint32_t sizeof_string;
// translation
Dicts dicts;
DFContextShared *d;
bool Inited;
bool Started;
@ -52,7 +52,7 @@ Translation::Translation(DFContextShared * d_)
d = new Private;
d->d = d_;
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->transAddress = mem->getAddress ("translation_vector");
d->word_table_offset = mem->getOffset ("word_table");
@ -116,7 +116,7 @@ bool Translation::Finish()
Dicts * Translation::getDicts()
{
assert(d->Started);
if(d->Started)
return &d->dicts;
return 0;
@ -126,10 +126,10 @@ string Translation::TranslateName(const t_name &name, bool inEnglish)
{
string out;
assert (d->Started);
map<string, vector<string> >::const_iterator it;
if(!inEnglish)
if(!inEnglish)
{
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]]);
out[0] = toupper(out[0]);
}
if(name.words[5] >=0)
if(name.words[5] >=0)
{
string word;
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(" ");
out.append(word);
}
if(name.words[6] >=0)
if(name.words[6] >=0)
{
string word;
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(" ");
out.append(word);
}
}
}
else
{
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]]);
out[0] = toupper(out[0]);
}
if(name.words[5] >=0)
if(name.words[5] >=0)
{
if(out.length() > 0)
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)
out.append(" of");

@ -25,7 +25,7 @@ distribution.
#include "Internal.h"
#include "ContextShared.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFVector.h"
#include "dfhack/DFTypes.h"
@ -40,7 +40,7 @@ struct Vegetation::Private
uint32_t tree_desc_offset;
// translation
DfVector <uint32_t> * p_veg;
DFContextShared *d;
Process * owner;
bool Inited;
@ -53,7 +53,7 @@ Vegetation::Vegetation(DFContextShared * d_)
d->owner = d_->p;
d->d = d_;
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->tree_desc_offset = mem->getOffset ("tree_desc_offset");
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 "dfhack/modules/World.h"
#include "dfhack/DFProcess.h"
#include "dfhack/DFMemInfo.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h"
using namespace DFHack;
@ -55,12 +55,12 @@ struct World::Private
World::World(DFContextShared * _d)
{
d = new Private;
d->d = _d;
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->tick_offset = mem->getAddress( "current_tick" );
d->Inited = d->Started = true;
@ -95,7 +95,7 @@ uint32_t World::ReadCurrentTick()
return 0;
}
// FIX'D according to this:
// FIX'D according to this:
/*
World::ReadCurrentMonth and World::ReadCurrentDay
« Sent to: peterix on: June 04, 2010, 04:44:30 »

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

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

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

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

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

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

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

@ -56,7 +56,7 @@ int main (void)
{
cout << "Testing ProcessEnumerator" << endl;
ProcessEnumerator Penum("Memory.xml");
memory_info * mem;
VersionInfo * mem;
do
{
// make the ProcessEnumerator update its list of Processes
@ -90,7 +90,7 @@ int main (void)
{
cout << "Testing ContextManager" << endl;
ContextManager Cman("Memory.xml");
memory_info * mem;
VersionInfo * mem;
do
{
// 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::memory_info* mem = DF->getMemoryInfo();
DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Position * pos = DF->getPosition();
DFHack::Vegetation * v = DF->getVegetation();
DFHack::Materials * mat = DF->getMaterials();

@ -21,7 +21,7 @@ using namespace DFHack;
int main ( int argc, char** argv )
{
DFHack::memory_info *mem;
DFHack::VersionInfo *mem;
DFHack::Process *proc;
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
// 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());
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());
end = min(4, (int)ranges.size());
@ -793,8 +793,8 @@ int main (void)
vector <DFHack::t_memrange> selected_ranges;
getRanges(p,selected_ranges);
DFHack::memory_info *minfo = DF->getMemoryInfo();
DFHack::memory_info::OSType os = minfo->getOS();
DFHack::VersionInfo *minfo = DF->getMemoryInfo();
DFHack::VersionInfo::OSType os = minfo->getOS();
string prompt =
"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>
DFHack::Materials * Materials;
DFHack::memory_info *mem;
DFHack::VersionInfo *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;

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

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

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