Process::readClassName implemented

develop
Petr Mrázek 2010-02-19 02:48:03 +01:00
parent da19d92f16
commit f71fef9ef5
7 changed files with 94 additions and 10 deletions

@ -16,6 +16,7 @@ using namespace DFHack;
#include <signal.h> #include <signal.h>
string error; string error;
API * pDF = 0;
static void finish(int sig); static void finish(int sig);
@ -185,9 +186,21 @@ int pickColor(int tiletype)
string getGCCClassName (Process * p, uint32_t vptr) string getGCCClassName (Process * p, uint32_t vptr)
{ {
int typeinfo = p->readDWord(vptr - 4); int typeinfo = p->readDWord(vptr - 0x4);
int typestring = p->readDWord(typeinfo + 4); int typestring = p->readDWord(typeinfo + 0x4);
return p->readCString(typestring); string raw = p->readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length();
return raw.substr(start,end-start - 2); // trim the 'st' from the end
}
string getMSVCClassName (Process * p, uint32_t vptr)
{
int rtti = p->readDWord(vptr - 0x4);
int typeinfo = p->readDWord(rtti + 0xC);
string raw = p->readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 4);// trim st@@ from end
return raw;
} }
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -241,17 +254,23 @@ main(int argc, char *argv[])
// init the API // init the API
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
pDF = &DF;
// attach // attach
if(!DF.Attach()) if(!DF.Attach())
{ {
error = "Can't find DF."; error = "Can't find DF.";
pDF = 0;
finish(0); finish(0);
} }
Process* p = DF.getProcess(); Process* p = DF.getProcess();
// init the map // init the map
DF.InitMap(); if(!DF.InitMap())
{
error = "Can't find a map to look at.";
pDF = 0;
finish(0);
}
DF.getSize(x_max_a,y_max_a,z_max_a); DF.getSize(x_max_a,y_max_a,z_max_a);
x_max = x_max_a; x_max = x_max_a;
@ -262,6 +281,7 @@ main(int argc, char *argv[])
if(!DF.ReadStoneMatgloss(stonetypes)) if(!DF.ReadStoneMatgloss(stonetypes))
{ {
error = "Can't read stone types."; error = "Can't read stone types.";
pDF = 0;
finish(0); finish(0);
} }
@ -269,6 +289,7 @@ main(int argc, char *argv[])
if(!DF.ReadGeology( layerassign )) if(!DF.ReadGeology( layerassign ))
{ {
error = "Can't read local geology."; error = "Can't read local geology.";
pDF = 0;
finish(0); finish(0);
} }
@ -283,6 +304,7 @@ main(int argc, char *argv[])
// walk the map! // walk the map!
for (;;) for (;;)
{ {
DF.Resume();
int c = getch(); /* refresh, accept single keystroke of input */ int c = getch(); /* refresh, accept single keystroke of input */
clrscr(); clrscr();
/* process the command keystroke */ /* process the command keystroke */
@ -371,8 +393,10 @@ main(int argc, char *argv[])
{ {
if(vein != -1 && vein < veinVector.size()) if(vein != -1 && vein < veinVector.size())
{ {
string str = getGCCClassName(p, veinVector[vein].vtable); //string str = getGCCClassName(p, veinVector[vein].vtable);
if(str == "34block_square_event_frozen_liquidst") string className = p->readClassName(veinVector[vein].vtable);
//string str = "34block_square_event_frozen_liquidst";
if(className == "block_square_event_frozen_liquid")
{ {
t_frozenliquidvein frozen; t_frozenliquidvein frozen;
uint32_t size = sizeof(t_frozenliquidvein); uint32_t size = sizeof(t_frozenliquidvein);
@ -391,7 +415,7 @@ main(int argc, char *argv[])
} }
} }
} }
else if (str == "28block_square_event_mineralst") else if (className == "block_square_event_mineral")
{ {
//iterate through vein rows //iterate through vein rows
for(uint32_t j = 0;j<16;j++) for(uint32_t j = 0;j<16;j++)
@ -411,17 +435,22 @@ main(int argc, char *argv[])
cprintf("%s",stonetypes[veinVector[vein].type].name); cprintf("%s",stonetypes[veinVector[vein].type].name);
} }
gotoxy(0,51); gotoxy(0,51);
cprintf("%s, address 0x%x",str.c_str(),veinVector[vein].address_of); cprintf("%s, address 0x%x",className.c_str(),veinVector[vein].address_of);
} }
} }
DF.Resume();
wrefresh(stdscr); wrefresh(stdscr);
} }
pDF = 0;
finish(0); finish(0);
} }
static void finish(int sig) static void finish(int sig)
{ {
// ugly
if(pDF)
{
pDF->Detach();
}
endwin(); endwin();
if(!error.empty()) if(!error.empty())
{ {

@ -636,4 +636,14 @@ void SHMProcess::writeSTLString(const uint32_t address, const std::string writeS
full_barrier full_barrier
((shm_write_small *)d->my_shm)->pingpong = DFPP_WRITE_STL_STRING; ((shm_write_small *)d->my_shm)->pingpong = DFPP_WRITE_STL_STRING;
d->waitWhile(DFPP_WRITE_STL_STRING); d->waitWhile(DFPP_WRITE_STL_STRING);
}
string SHMProcess::readClassName (uint32_t vptr)
{
int typeinfo = readDWord(vptr - 0x4);
int typestring = readDWord(typeinfo + 0x4);
string raw = readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length();
return raw.substr(start,end-start - 2); // trim the 'st' from the end
} }

@ -581,4 +581,13 @@ const string WineProcess::readSTLString (uint32_t offset)
string ret = temp; string ret = temp;
delete temp; delete temp;
return ret; return ret;
}
string WineProcess::readClassName (uint32_t vptr)
{
int rtti = readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 4);// trim st@@ from end
return raw;
} }

@ -526,4 +526,14 @@ const string NormalProcess::readSTLString (uint32_t offset)
string ret(temp); string ret(temp);
delete temp; delete temp;
return ret; return ret;
}
string NormalProcess::readClassName (uint32_t vptr)
{
int typeinfo = readDWord(vptr - 0x4);
int typestring = readDWord(typeinfo + 0x4);
string raw = readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length();
return raw.substr(start,end-start - 2); // trim the 'st' from the end
} }

@ -723,4 +723,13 @@ void SHMProcess::writeSTLString(const uint32_t address, const std::string writeS
full_barrier full_barrier
((shm_write_small *)d->my_shm)->pingpong = DFPP_WRITE_STL_STRING; ((shm_write_small *)d->my_shm)->pingpong = DFPP_WRITE_STL_STRING;
d->waitWhile(DFPP_WRITE_STL_STRING); d->waitWhile(DFPP_WRITE_STL_STRING);
}
string SHMProcess::readClassName (uint32_t vptr)
{
int rtti = readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 4);// trim st@@ from end
return raw;
} }

@ -463,4 +463,13 @@ const string NormalProcess::readSTLString (uint32_t offset)
string ret = temp; string ret = temp;
delete temp; delete temp;
return ret; return ret;
}
string NormalProcess::readClassName (uint32_t vptr)
{
int rtti = readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 4);// trim st@@ from end
return raw;
} }

@ -96,6 +96,8 @@ namespace DFHack
virtual void writeSTLString(const uint32_t address, const std::string writeString) = 0; virtual void writeSTLString(const uint32_t address, const std::string writeString) = 0;
// read a vector from memory // read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0; virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0;
// get class name of an object with rtti/type info
virtual string readClassName(uint32_t vptr) = 0;
virtual const std::string readCString (uint32_t offset) = 0; virtual const std::string readCString (uint32_t offset) = 0;
@ -152,6 +154,8 @@ namespace DFHack
void writeSTLString(const uint32_t address, const std::string writeString){}; void writeSTLString(const uint32_t address, const std::string writeString){};
// read a vector from memory // read a vector from memory
DfVector readVector (uint32_t offset, uint32_t item_size); DfVector readVector (uint32_t offset, uint32_t item_size);
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
const std::string readCString (uint32_t offset); const std::string readCString (uint32_t offset);
@ -203,6 +207,8 @@ namespace DFHack
void writeSTLString(const uint32_t address, const std::string writeString); void writeSTLString(const uint32_t address, const std::string writeString);
// read a vector from memory // read a vector from memory
DfVector readVector (uint32_t offset, uint32_t item_size); DfVector readVector (uint32_t offset, uint32_t item_size);
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
const std::string readCString (uint32_t offset); const std::string readCString (uint32_t offset);
@ -254,6 +260,8 @@ namespace DFHack
void writeSTLString(const uint32_t address, const std::string writeString){}; void writeSTLString(const uint32_t address, const std::string writeString){};
// read a vector from memory // read a vector from memory
DfVector readVector (uint32_t offset, uint32_t item_size); DfVector readVector (uint32_t offset, uint32_t item_size);
// get class name of an object with rtti/type info
string readClassName(uint32_t vptr);
const std::string readCString (uint32_t offset); const std::string readCString (uint32_t offset);