From 38f50f4a46d2373aae6c123306c2a65267b0eb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 17 Sep 2010 13:49:49 +0200 Subject: [PATCH 1/7] More 31.13 offsets - bits of the Maps module, many offsets are bad. --- data/Memory-ng.xml | 93 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index d34825c3e..04149ede2 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1459,6 +1459,19 @@
+ + + + + 0x01482874 - current race
@@ -1472,10 +1485,86 @@
-
+
-
+
+ + +
+
+
+
+
+
+
+
+ +
+ +
+ +
+
+ + + +
+ + + +
+ + + + +
+
+ + + + + +
+
+
+
+
+
+ +
+
+
+ From dfdd1467ffad6adccf2aef40e66b00e5b3bef71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 18 Sep 2010 04:36:14 +0200 Subject: [PATCH 2/7] Offset stuff --- data/Memory-ng.xml | 76 +++++++++++++++++++++++--- library/DFProcess-linux-wine.cpp | 42 +++++--------- library/DFProcess-windows.cpp | 43 +++++---------- tools/playground/SegmentedFinder.h | 7 +++ tools/playground/incrementalsearch.cpp | 25 ++++++++- 5 files changed, 125 insertions(+), 68 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 04149ede2..ade3190fc 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -674,6 +674,22 @@ + + + + + + @@ -938,6 +954,11 @@ + + + + + @@ -1217,7 +1238,6 @@
-
@@ -1472,6 +1492,14 @@ NOT FINAL, needs research --> + + + + + + + + 0x01482874 - current race
@@ -1552,14 +1580,46 @@ --> - -
-
-
-
-
-
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +
+
diff --git a/library/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp index 8e8e3c1f5..891a4f820 100644 --- a/library/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -53,6 +53,9 @@ class WineProcess::Private bool attached; bool suspended; bool identified; + uint32_t STLSTR_buf_off; + uint32_t STLSTR_size_off; + uint32_t STLSTR_cap_off; bool validate(char * exe_file, uint32_t pid, char * mem_file, vector & known_versions); }; @@ -155,6 +158,10 @@ bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file // tell WineProcess about the /proc/PID/mem file memFile = mem_file; identified = true; + OffsetGroup * strGrp = m->getGroup("string")->getGroup("MSVC"); + STLSTR_buf_off = strGrp->getOffset("buffer"); + STLSTR_size_off = strGrp->getOffset("size"); + STLSTR_cap_off = strGrp->getOffset("capacity"); return true; } } @@ -563,21 +570,10 @@ const std::string WineProcess::readCString (uint32_t offset) size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr - } - Uint32 length - Uint32 capacity - */ - uint32_t start_offset = offset + 4; - size_t length = readDWord(offset + 20); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); - 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 @@ -597,20 +593,10 @@ size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcap const string WineProcess::readSTLString (uint32_t offset) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr - } - Uint32 length - Uint32 capacity - */ - uint32_t start_offset = offset + 4; - uint32_t length = readDWord(offset + 20); - uint32_t capacity = readDWord(offset + 24); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); + char * temp = new char[capacity+1]; // read data from inside the string structure diff --git a/library/DFProcess-windows.cpp b/library/DFProcess-windows.cpp index a658b49a7..0b3d7959d 100644 --- a/library/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -48,6 +48,9 @@ class NormalProcess::Private bool attached; bool suspended; bool identified; + uint32_t STLSTR_buf_off; + uint32_t STLSTR_size_off; + uint32_t STLSTR_cap_off; }; NormalProcess::NormalProcess(uint32_t pid, vector & known_versions) @@ -134,7 +137,10 @@ NormalProcess::NormalProcess(uint32_t pid, vector & known_versio vector threads; getThreadIDs( threads ); d->my_main_thread = OpenThread(THREAD_ALL_ACCESS, FALSE, (DWORD) threads[0]); - + OffsetGroup * strGrp = m->getGroup("string")->getGroup("MSVC"); + d->STLSTR_buf_off = strGrp->getOffset("buffer"); + d->STLSTR_size_off = strGrp->getOffset("size"); + d->STLSTR_cap_off = strGrp->getOffset("capacity"); found = true; break; // break the iterator loop } @@ -430,21 +436,9 @@ const string NormalProcess::readCString (const uint32_t offset) size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr -} -Uint32 length -Uint32 capacity -*/ - uint32_t start_offset = offset + 4; - size_t length = readDWord(offset + 20); - - size_t capacity = readDWord(offset + 24); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); size_t read_real = min(length, bufcapacity-1);// keep space for null termination // read data from inside the string structure @@ -464,20 +458,9 @@ Uint32 capacity const string NormalProcess::readSTLString (uint32_t offset) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr - } - Uint32 length - Uint32 capacity - */ - uint32_t start_offset = offset + 4; - uint32_t length = readDWord(offset + 20); - uint32_t capacity = readDWord(offset + 24); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); char * temp = new char[capacity+1]; // read data from inside the string structure diff --git a/tools/playground/SegmentedFinder.h b/tools/playground/SegmentedFinder.h index c50cc4c6f..98de87711 100644 --- a/tools/playground/SegmentedFinder.h +++ b/tools/playground/SegmentedFinder.h @@ -311,4 +311,11 @@ bool findString (SegmentedFinder* s, uint32_t *addr, const char * compare ) return false; } +bool findStrBuffer (SegmentedFinder* s, uint32_t *addr, const char * compare ) +{ + if(strcmp((const char *)addr, compare) == 0) + return true; + return false; +} + #endif // SEGMENTED_FINDER_H \ No newline at end of file diff --git a/tools/playground/incrementalsearch.cpp b/tools/playground/incrementalsearch.cpp index 68ce20014..918577944 100644 --- a/tools/playground/incrementalsearch.cpp +++ b/tools/playground/incrementalsearch.cpp @@ -482,6 +482,22 @@ void FindPtrVectorsByObjectAddress(DFHack::ContextManager & DFMgr, vector & ranges) +{ + vector found; + string select; + while (Incremental(found,"buffer",select,"buffer","buffers")) + { + DFMgr.Refresh(); + DFHack::Context * DF = DFMgr.getSingleContext(); + DF->Attach(); + SegmentedFinder sf(ranges,DF); + sf.Find< const char * ,uint32_t>(select.c_str(),1,found, findStrBuffer); + DF->Detach(); + } +} + + void FindStrings(DFHack::ContextManager & DFMgr, vector & ranges) { @@ -799,12 +815,13 @@ int main (void) string prompt = "Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\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"; + " 7=pointer vector by address of an object, 8=vector>first object>string\n" + " 9=string buffers\n"; int mode; do { getNumber(prompt,mode, 1, false); - } while (mode < 1 || mode > 8 ); + } while (mode < 1 || mode > 9 ); switch (mode) { case 1: @@ -838,6 +855,10 @@ int main (void) DF->Detach(); FindVectorByFirstObjectRawname(DFMgr, selected_ranges); break; + case 9: + DF->Detach(); + FindStrBufs(DFMgr, selected_ranges); + break; default: cout << "not implemented :(" << endl; } From d9955a3b43fc6dc87c905e6b5bb2c20c48a16038 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Sat, 18 Sep 2010 10:48:06 +0100 Subject: [PATCH 3/7] Added memory layout for creatures in Linux DF v0.31.09 onwards (although only tested with DF v0.31.12 and v0.31.13. --- data/Memory-ng.xml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index ade3190fc..f2fd178f5 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1867,6 +1867,24 @@ + + + + + + + + + + + + + + CHMOD + + + + @@ -1905,6 +1923,9 @@
+ +
+
From c4403561d514afd4e0b234d0093ff1d6b962e32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 18 Sep 2010 14:04:13 +0200 Subject: [PATCH 4/7] Offsets, Materials, 31.13, windows --- data/Memory-ng.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index ade3190fc..872842ccf 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1588,12 +1588,12 @@
- - + + - + From 88934f0add6bd571380a2fb4f4fe9e7bf14f4a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 19 Sep 2010 06:17:48 +0200 Subject: [PATCH 5/7] Materials done --- data/Memory-ng.xml | 73 ++++++++++++++++------------------- library/modules/Materials.cpp | 4 ++ 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index fdb84d2b1..0b4293d55 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1481,13 +1481,13 @@
- + @@ -1516,7 +1516,7 @@
-
+
@@ -1551,7 +1551,7 @@ --> -
+
-
+
this is crap it seems - -
- - - -
- - -
-
-
+ +
+ + + +
diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 2ad78361e..608e7b663 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -402,19 +402,23 @@ bool Materials::ReadCreatureTypesEx (void) p->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular)); p->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural)); p->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective)); + cout << "Caste " << caste.rawname << " " << caste.singular << ": 0x" << hex << caste_start << endl; if(have_advanced) { /* color mod reading */ + // Caste + offset > color mod vector DfVector p_colormod(p, caste_start + caste_colormod_offset); sizecolormod = p_colormod.size(); caste.ColorModifier.resize(sizecolormod); for(uint32_t k = 0; k < sizecolormod;k++) { + // color mod [0] -> color list DfVector p_colorlist(p, p_colormod[k]); sizecolorlist = p_colorlist.size(); caste.ColorModifier[k].colorlist.resize(sizecolorlist); for(uint32_t l = 0; l < sizecolorlist; l++) caste.ColorModifier[k].colorlist[l] = p_colorlist[l]; + // color mod [color_modifier_part_offset] = string part p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part)); caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset ); caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset ); From 8eb67af2d63c9b212fb36f5ea6571cfb9ff3157f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 20 Sep 2010 05:47:15 +0200 Subject: [PATCH 6/7] Maps without geology and features --- data/Memory-ng.xml | 47 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 0b4293d55..1825fc0a9 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1519,36 +1519,33 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
+
-
-
-
@@ -1580,7 +1577,7 @@ --> - + YES
From 310b1629b671866c126ab1cf82876436a014b5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 20 Sep 2010 05:56:33 +0200 Subject: [PATCH 7/7] Fix tiletype offset --- data/Memory-ng.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 1825fc0a9..9925c8924 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1538,7 +1538,7 @@ - +