From 1645df7088bbcea12173459cd5356418fa81e7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 6 Jun 2010 00:56:09 +0200 Subject: [PATCH] Some offsets for 0.31.04, bugfixes --- library/DFProcess-linux-SHM.cpp | 4 +- library/DFProcess-linux-wine.cpp | 9 +- library/DFProcess-linux.cpp | 2 +- library/DFProcess-windows-SHM.cpp | 4 +- library/include/DFHack.h | 8 +- library/include/dfhack/DFMiscUtils.h | 6 +- library/modules/Translation.cpp | 2 +- library/modules/World.cpp | 14 +- output/Memory.xml | 268 +++++++++++++------------ tools/examples/processenum.cpp | 9 +- tools/playground/incrementalsearch.cpp | 202 ++++++++++++++++++- 11 files changed, 372 insertions(+), 156 deletions(-) diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index d4f90db93..9c8d9aab1 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -714,7 +714,7 @@ float SHMProcess::readFloat (const uint32_t offset) D_SHMHDR->address = offset; gcc_barrier d->SetAndWait(CORE_READ_DWORD); - return D_SHMHDR->value; + return reinterpret_cast (D_SHMHDR->value); } void SHMProcess::readFloat (const uint32_t offset, float &val) { @@ -723,7 +723,7 @@ void SHMProcess::readFloat (const uint32_t offset, float &val) D_SHMHDR->address = offset; gcc_barrier d->SetAndWait(CORE_READ_DWORD); - val = D_SHMHDR->value; + val = reinterpret_cast (D_SHMHDR->value); } /* diff --git a/library/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp index b9ef2339b..6f288a078 100644 --- a/library/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -367,9 +367,11 @@ void WineProcess::read (const uint32_t offset, const uint32_t size, uint8_t *tar if(size == 0) return; ssize_t result; - result = pread(d->memFileHandle, target,size,offset); - if(result != size) + ssize_t total = 0; + ssize_t remaining = size; + while (total != size) { + result = pread(d->memFileHandle, target + total ,remaining,offset + total); if(result == -1) { cerr << "pread failed: can't read " << size << " bytes at addres " << offset << endl; @@ -379,7 +381,8 @@ void WineProcess::read (const uint32_t offset, const uint32_t size, uint8_t *tar } else { - read(offset + result, size - result, target + result); + total += result; + remaining -= result; } } } diff --git a/library/DFProcess-linux.cpp b/library/DFProcess-linux.cpp index 343985a3d..2402609e1 100644 --- a/library/DFProcess-linux.cpp +++ b/library/DFProcess-linux.cpp @@ -86,7 +86,7 @@ NormalProcess::NormalProcess(uint32_t pid, vector< memory_info* >& known_version target_name[target_result] = 0; // is this the regular linux DF? - if (strstr(target_name, "dwarfort.exe") != NULL) + if (strstr(target_name, "dwarfort.exe") != 0 || strstr(target_name,"Dwarf_Fortress") != 0) { // create linux process, add it to the vector d->identified = d->validate(target_name,pid,mem_name,known_versions ); diff --git a/library/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp index 9a8bd8d4f..f9a7cad26 100644 --- a/library/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -756,7 +756,7 @@ float SHMProcess::readFloat (const uint32_t offset) D_SHMHDR->address = offset; full_barrier d->SetAndWait(CORE_READ_DWORD); - return (float) D_SHMHDR->value; + return reinterpret_cast (D_SHMHDR->value); } void SHMProcess::readFloat (const uint32_t offset, float &val) { @@ -765,7 +765,7 @@ void SHMProcess::readFloat (const uint32_t offset, float &val) D_SHMHDR->address = offset; full_barrier d->SetAndWait(CORE_READ_DWORD); - val = (float) D_SHMHDR->value; + val = reinterpret_cast (D_SHMHDR->value); } uint64_t SHMProcess::readQuad (const uint32_t offset) { diff --git a/library/include/DFHack.h b/library/include/DFHack.h index 865b12716..a5f40e896 100644 --- a/library/include/DFHack.h +++ b/library/include/DFHack.h @@ -23,10 +23,16 @@ #include "dfhack/modules/Vegetation.h" #include "dfhack/modules/Maps.h" +/* + * This is a header full of ugly, volatile things. + * Only for use of official DFHack tools! + */ #ifdef DFHACK_WANT_MISCUTILS #include "dfhack/DFMiscUtils.h" #endif + +// define this to get the static tiletype->properties mapping #ifdef DFHACK_WANT_TILETYPES #include "dfhack/DFTileTypes.h" #endif -#endif \ No newline at end of file +#endif diff --git a/library/include/dfhack/DFMiscUtils.h b/library/include/dfhack/DFMiscUtils.h index 14f192e6a..04676a769 100644 --- a/library/include/dfhack/DFMiscUtils.h +++ b/library/include/dfhack/DFMiscUtils.h @@ -8,17 +8,13 @@ #include #include #include + using namespace std; #include #include #include -/* - * This is a header full of ugly, volatile things. - * Only for use of official DFHack tools! - */ - void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr) { cout << "----==== " << name << " ====----" << endl; diff --git a/library/modules/Translation.cpp b/library/modules/Translation.cpp index 80412c690..ae0c8b7ed 100644 --- a/library/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -72,6 +72,7 @@ bool Translation::Start() if(!d->Inited) return false; Process * p = d->d->p; + Finish(); DfVector genericVec (p, d->genericAddress); DfVector transVec (p, d->transAddress); DFDict & translations = d->dicts.translations; @@ -92,7 +93,6 @@ bool Translation::Start() for (uint32_t i = 0; i < transVec.size();i++) { uint32_t transPtr = transVec.at(i); - DfVector trans_names_vec (p, transPtr + d->word_table_offset); for (uint32_t j = 0;j < trans_names_vec.size();j++) { diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 47f4d200d..92c8606d4 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -95,12 +95,22 @@ uint32_t World::ReadCurrentTick() return 0; } +// FIX'D according to this: +/* +World::ReadCurrentMonth and World::ReadCurrentDay +« Sent to: peterix on: June 04, 2010, 04:44:30 » +« You have forwarded or responded to this message. » +ReplyQuoteRemove +Shouldn't these be /28 and %28 instead of 24? There're 28 days in a DF month. +Using 28 and doing the calculation on the value stored at the memory location +specified by memory.xml gets me the current month/date. +*/ uint32_t World::ReadCurrentMonth() { - return this->ReadCurrentTick() / 1200 / 24; + return this->ReadCurrentTick() / 1200 / 28; } uint32_t World::ReadCurrentDay() { - return ((this->ReadCurrentTick() / 1200) % 24) + 1; + return ((this->ReadCurrentTick() / 1200) % 28) + 1; } diff --git a/output/Memory.xml b/output/Memory.xml index d5eae8cda..dbeb589b0 100755 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1621,115 +1621,52 @@ map_data_1b60_offset 0x1B9c - - 1d759a11af258263ef5c139d6d9a3e15 + Basic things ============ - 0xC - 0x0 - 0x4 - - - -
0x92D00C0
0x0165B188 + 0xC VERIFIED + 0x0 VERIFIED + 0x4 VERIFIED - Position and window dimensions - ============================== -
0x8cd3b18
0xe32798 -
0x8cd3b1c
0xe60838 -
0x8cd3b20
0xe60814 -
0x8b17370
0xae82cc - -
0x9464d6c
0x17f5ab8 - GUI State - ========= -
0x92c971c
0x146e45f - - Map stuff - ========= -
0x9322d20
WORLD + 0x52C60 - 0x08 - 0x20 - 0x24 - 0x006A - 0x026C - 0x066c - 0x156c - 0x176c - 0x1D6C - 0x0D6c - - Map Features - ============ - WORLD + 0x5487C -
0x932493C
- 0x94 - 0x28 - 0x2C - WORLD + 0x548F4 -
0x93249B4
- 0x24 - 0x28 + MAP BLOCK OFFSETS + ================= + 0x08 VERIFIED + 0x20 VERIFIED + 0x24 VERIFIED + 0x006A VERIFIED + 0x026C VERIFIED + 0x066c VERIFIED + 0x156c VERIFIED + 0x176c VERIFIED + 0x1D6C VERIFIED + 0x0D6c VERIFIED + + MAP FEATURE OFFSETS + =================== + 0x94 VERIFIED + 0x28 VERIFIED + 0x2C VERIFIED + + 0x24 VERIFIED + 0x28 VERIFIED - * map size in blocks * -
0x9322d34
0x016ad738 -
0x9322d38
0x016ad73C -
0x9322d3C
0x016ad740 - - * map size in tiles * -
0x9322d40
0x016ad744 -
0x9322d44
0x016ad748 -
0x9322d48
0x016ad74C - - * region coords * - WORLD + 0x525C8 -
0x9322d4C
0x016ad750 - WORLD + 0x525CC -
0x9322d50
0x016ad754 - WORLD + 0x525D0 -
0x9322d54
0x016ad758 - - * World size * (WORDs) - WORLD + 0x542E0 -
0x93243A0
0x016AEDD4 - WORLD + 0x542E2 -
0x93243A2
0x016AEDD6 - WORLD + 0x54894 -
0x9324954
FIX 0x16AF52C - WORLD + 0x548B8 -
0x9324978
FIX 0x16AF574 - values for the region structure =============================== - 0x58 0x64 FIX - 0x54 0x60 FIX + 0x58 VERIFIED + 0x54 VERIFIED geoblock offsets ================ - 0x4 vector - 0x4 vector + 0x4 VERIFIED + 0x4 VERIFIED Name struct =========== - 0x0 - 0x4 - 0x8 - - Creatures - ========= -
0x092E3AA0
-
0x092CB608
-
0x092CB5FC
+ 0x0 VERIFIED + 0x4 VERIFIED + 0x8 VERIFIED + + Creature offsets + ================ 0x0 0x6c 0x3c * @@ -1794,6 +1731,102 @@ map_data_1b60_offset 0x1B9c 0x4 subtype ? 0x8 index of material (for example, 2 is for silver) 0x18 set only for shell / bone mood requirements ? + + Creature type offsets + ===================== + 0x138 + 0x1A14 + 0xE0 + 0xF6 + + + Color descriptors + ================= + 0x0 VERIFIED + 0x1C VERIFIED + 0x24 VERIFIED + 0x28 VERIFIED + 0x2C VERIFIED + + Language tables + =============== + 0x1C + + Constructions + ============= + 0x14 +
+ + + 1d759a11af258263ef5c139d6d9a3e15 + +
0x92D00C0
+ + Position and window dimensions + ============================== +
0x8cd3b18
+
0x8cd3b1c
+
0x8cd3b20
+
0x8b17370
+
0x9464d6c
+ + GUI State + ========= +
0x92c971c
+ + Map data + ========= +
0x9322d20
WORLD + 0x52C60 + + Map Features + ============ + WORLD + 0x5487C +
0x932493C
+ WORLD + 0x548F4 +
0x93249B4
+ + * map size in blocks * +
0x9322d34
+
0x9322d38
+
0x9322d3C
+ + * map size in tiles * +
0x9322d40
+
0x9322d44
+
0x9322d48
+ + * region coords * + WORLD + 0x525C8 +
0x9322d4C
+ WORLD + 0x525CC +
0x9322d50
+ WORLD + 0x525D0 +
0x9322d54
+ + * World size * (WORDs) + WORLD + 0x542E0 +
0x93243A0
+ WORLD + 0x542E2 +
0x93243A2
+ WORLD + 0x54894 +
0x9324954
+ WORLD + 0x548B8 +
0x9324978
+ + Creatures + ========= +
0x092E3AA0
+
0x092CB608
+
0x092CB5FC
Materials ========= @@ -1812,42 +1845,30 @@ map_data_1b60_offset 0x1B9c creature types actually used for creatures,
0x09324F14
- 0x138 - 0x1A14 - 0xE0 - 0xF6 + Color descriptors + ================= +
0x9329378
VERIFIED +
0x9329390
VERIFIED Translations ============ WORLD + 0x54E50
0x9324fd4
WORLD + 0x54E80
0x9324fec
- 0x1C Constructions ============= WORLD + 0x84
0x92D0144
0x165b290 - 0x14 + + Time + ==== +
0x92C9680
+
0x92C9688
- Time - ==== -
0x92C9688
-
0x92C9680
+
+ + fea3801a26538b1741f3cc9294139fca diff --git a/tools/examples/processenum.cpp b/tools/examples/processenum.cpp index 1910ca733..50b0df0a1 100644 --- a/tools/examples/processenum.cpp +++ b/tools/examples/processenum.cpp @@ -88,15 +88,16 @@ int main (void) } // next test ContextManager and BadContexts { - cout << "Testing ProcessEnumerator" << endl; + cout << "Testing ContextManager" << endl; ContextManager Cman("Memory.xml"); memory_info * mem; do { - // make the ProcessEnumerator update its list of Processes + // make the ContextManager update its list of Contexts // by passing the pointer to 'inval', we make it export expired - // processes instead of destroying them outright - // (processes expire when the OS kills them for whatever reason) + // contexts instead of destroying them outright + // (contexts expire when the OS kills their process for whatever + // reason) BadContexts inval; Cman.Refresh(&inval); int nCont = Cman.size(); diff --git a/tools/playground/incrementalsearch.cpp b/tools/playground/incrementalsearch.cpp index 1207464e9..764c1d956 100644 --- a/tools/playground/incrementalsearch.cpp +++ b/tools/playground/incrementalsearch.cpp @@ -26,6 +26,31 @@ inline void printRange(DFHack::t_memrange * tpr) std::cout << std::hex << tpr->start << " - " << tpr->end << "|" << (tpr->read ? "r" : "-") << (tpr->write ? "w" : "-") << (tpr->execute ? "x" : "-") << "|" << tpr->name << std::endl; } +string rdWinString( char * offset, SegmentedFinder & sf ) +{ + char * start_offset = offset + 4; + uint32_t length = *(uint32_t *)(offset + 20); + uint32_t capacity = *(uint32_t *)(offset + 24); + char * temp = new char[capacity+1]; + + // read data from inside the string structure + if(capacity < 16) + { + memcpy(temp, start_offset,capacity); + //read(start_offset, capacity, (uint8_t *)temp); + } + else // read data from what the offset + 4 dword points to + { + start_offset = sf.Translate(*(uint32_t*)start_offset); + memcpy(temp, start_offset,capacity); + } + + temp[length] = 0; + string ret = temp; + delete temp; + return ret; +} + bool getRanges(DFHack::Process * p, vector & selected_ranges) { vector ranges; @@ -79,10 +104,17 @@ bool getRanges(DFHack::Process * p, vector & selected_ranges } end++; cout << "selected ranges:" <::iterator it; + it = ranges.begin() + start; + while (it != ranges.begin() + end) { - printRange(&(selected_ranges[i])); + // check if readable + if((*it).read) + { + selected_ranges.push_back(*it); + printRange(&*it); + } + it++; } } @@ -357,31 +389,109 @@ void FindStrings(DFHack::ContextManager & DFMgr, vector & ra } } +void printFound(vector &found, const char * what) +{ + cout << what << ":" << endl; + for(int i = 0; i < found.size();i++) + { + cout << hex << "0x" << found[i] << endl; + } +} + +void printFoundStrVec(vector &found, const char * what, SegmentedFinder & s) +{ + cout << what << ":" << endl; + for(int i = 0; i < found.size();i++) + { + cout << hex << "0x" << found[i] << endl; + cout << "--------------------------" << endl; + vecTriplet * vt = s.Translate(found[i]); + if(vt) + { + int j = 0; + for(uint32_t idx = vt->start; idx < vt->finish; idx += sizeof(uint32_t)) + { + uint32_t object_ptr; + // deref ptr idx, get ptr to object + if(!s.Read(idx,object_ptr)) + { + cout << "BAD!" << endl; + break; + } + // deref ptr to first object, get ptr to string + uint32_t string_ptr; + if(!s.Read(object_ptr,string_ptr)) + { + cout << "BAD!" << endl; + break; + } + // get string location in our local cache + char * str = s.Translate(string_ptr); + if(!str) + { + cout << "BAD!" << endl; + break; + } + cout << dec << j << ": " << str << endl; + j++; + } + } + else + { + cout << "BAD!" << endl; + break; + } + cout << "--------------------------" << endl; + } +} + + void automatedLangtables(DFHack::Context * DF, vector & ranges) { vector allVectors; + vector filtVectors; vector to_filter; + + cout << "stealing memory..." << endl; + SegmentedFinder sf(ranges, DF); + cout << "looking for vectors..." << endl; + sf.Find(0,4,allVectors, vectorAll); + + // trim vectors. anything with > 10000 entries is not interesting + for(uint64_t i = 0; i < allVectors.size();i++) + { + vecTriplet* vtrip = sf.Translate(allVectors[i]); + if(vtrip) + { + uint64_t length = (vtrip->finish - vtrip->start) / 4; + if(length < 10000 ) + { + filtVectors.push_back(allVectors[i]); + } + } + } + + cout << "-------------------" << endl; + cout << "!!LANGUAGE TABLES!!" << endl; + cout << "-------------------" << endl; + uint64_t kulet_vector; uint64_t word_table_offset; uint64_t DWARF_vector; uint64_t DWARF_object; - SegmentedFinder sf(ranges, DF); - - // enumerate all vectors - sf.Find(0,4,allVectors, vectorAll); // find lang vector (neutral word table) - to_filter = allVectors; + to_filter = filtVectors; sf.Find("ABBEY",4,to_filter, vectorStringFirst); uint64_t lang_addr = to_filter[0]; // find dwarven language word table - to_filter = allVectors; + to_filter = filtVectors; sf.Find("kulet",4,to_filter, vectorStringFirst); kulet_vector = to_filter[0]; // find vector of languages - to_filter = allVectors; + to_filter = filtVectors; sf.Find("DWARF",4,to_filter, vectorStringFirst); // verify @@ -400,6 +510,76 @@ void automatedLangtables(DFHack::Context * DF, vector & rang cout << "translation vector: " << hex << "0x" << DWARF_vector << endl; cout << "lang vector: " << hex << "0x" << lang_addr << endl; cout << "word table offset: " << hex << "0x" << word_table_offset << endl; + + cout << "-------------" << endl; + cout << "!!MATERIALS!!" << endl; + cout << "-------------" << endl; + // inorganics vector + to_filter = filtVectors; + //sf.Find(257 * 4,4,to_filter,vectorLength); + sf.Find("IRON",4,to_filter, vectorStringFirst); + sf.Find("RAW_ADAMANTINE",4,to_filter, vectorString); + sf.Find("BLOODSTONE",4,to_filter, vectorString); + printFound(to_filter,"inorganics"); + + // organics vector + to_filter = filtVectors; + sf.Find(52 * 4,4,to_filter,vectorLength); + sf.Find("MUSHROOM_HELMET_PLUMP",4,to_filter, vectorStringFirst); + printFound(to_filter,"organics"); + + // tree vector + to_filter = filtVectors; + sf.Find(31 * 4,4,to_filter,vectorLength); + sf.Find("MANGROVE",4,to_filter, vectorStringFirst); + printFound(to_filter,"trees"); + + // plant vector + to_filter = filtVectors; + sf.Find(21 * 4,4,to_filter,vectorLength); + sf.Find("MUSHROOM_HELMET_PLUMP",4,to_filter, vectorStringFirst); + printFound(to_filter,"plants"); + + // color descriptors + //AMBER, 112 + to_filter = filtVectors; + sf.Find(112 * 4,4,to_filter,vectorLength); + sf.Find("AMBER",4,to_filter, vectorStringFirst); + printFound(to_filter,"color descriptors"); + if(!to_filter.empty()) + { + uint64_t vec = to_filter[0]; + vecTriplet *vtColors = sf.Translate(vec); + uint32_t colorObj = sf.Read(vtColors->start); + cout << "Amber color:" << hex << "0x" << colorObj << endl; + // TODO: find string 'amber', the floats + } + + // all descriptors + //AMBER, 338 + to_filter = filtVectors; + sf.Find(338 * 4,4,to_filter,vectorLength); + sf.Find("AMBER",4,to_filter, vectorStringFirst); + printFound(to_filter,"all descriptors"); + + // creature type + //ELEPHANT, ?? (demons abound) + to_filter = filtVectors; + //sf.Find(338 * 4,4,to_filter,vectorLength); + sf.Find("ELEPHANT",4,to_filter, vectorString); + sf.Find("CAT",4,to_filter, vectorString); + sf.Find("DWARF",4,to_filter, vectorString); + sf.Find("WAMBLER_FLUFFY",4,to_filter, vectorString); + sf.Find("TOAD",4,to_filter, vectorString); + sf.Find("DEMON_1",4,to_filter, vectorString); + + vector toad_first = to_filter; + vector elephant_first = to_filter; + sf.Find("TOAD",4,toad_first, vectorStringFirst); + sf.Find("ELEPHANT",4,elephant_first, vectorStringFirst); + printFound(toad_first,"toad-first creature types"); + printFound(elephant_first,"elephant-first creature types"); + printFound(to_filter,"all creature types"); } int main (void) @@ -425,7 +605,7 @@ int main (void) string prompt = "Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n" - " 4=string, 5=automated lang tables, 6=vector by address in its array,\n" + " 4=string, 5=automated offset search, 6=vector by address in its array,\n" " 7=pointer vector by address of an object, 8=vector>first object>string\n"; int mode; do