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] 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; }