Automated lang tables finder in the search tool

develop
Petr Mrázek 2010-05-31 02:37:28 +02:00
parent 08fd20c65f
commit ca0f7a27d1
2 changed files with 65 additions and 28 deletions

@ -1820,10 +1820,10 @@ map_data_1b60_offset 0x1B9c
Translations Translations
============ ============
WORLD + 0x54E50 WORLD + 0x54E50
<Address name="language_vector">23</Address> <Address name="language_vector">0x9324fd4</Address>
WORLD + 0x54E80 WORLD + 0x54E80
<Address name="translation_vector">24</Address> <Address name="translation_vector">0x9324fec</Address>
<Offset name="word_table">0x4C</Offset> <Offset name="word_table">0x1C</Offset>
Constructions Constructions
============= =============

@ -1,5 +1,5 @@
// this will be an incremental search tool in the future. now it is just a memory region dump thing // this is an incremental search tool. It only works on Linux.
// here be dragons... and ugly code :P
#include <iostream> #include <iostream>
#include <climits> #include <climits>
#include <vector> #include <vector>
@ -98,9 +98,9 @@ class SegmentedFinder
return 0; return 0;
} }
template <class needleType, class hayType, typename comparator > template <class needleType, class hayType, typename comparator >
bool Find (const needleType needle, const uint8_t increment, vector <uint64_t> &found, vector <uint64_t> &newfound, comparator oper) bool Find (const needleType needle, const uint8_t increment, vector <uint64_t> &found, comparator oper)
{ {
newfound.clear(); vector <uint64_t> newfound;
for(int i = 0; i < segments.size(); i++) for(int i = 0; i < segments.size(); i++)
{ {
segments[i]->Find<needleType,hayType,comparator>(needle, increment, found, newfound, oper); segments[i]->Find<needleType,hayType,comparator>(needle, increment, found, newfound, oper);
@ -208,9 +208,7 @@ void searchLoop(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ran
{ {
uint32_t test1; uint32_t test1;
vector <uint64_t> found; vector <uint64_t> found;
vector <uint64_t> newfound;
found.reserve(100); found.reserve(100);
newfound.reserve(100);
//bool initial = 1; //bool initial = 1;
cout << "search ready - insert integers, 'p' for results" << endl; cout << "search ready - insert integers, 'p' for results" << endl;
string select; string select;
@ -236,13 +234,13 @@ void searchLoop(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ran
switch(size) switch(size)
{ {
case 1: case 1:
sf.Find<uint8_t,uint8_t>(test1,alignment,found,newfound, equalityP<uint8_t>); sf.Find<uint8_t,uint8_t>(test1,alignment,found, equalityP<uint8_t>);
break; break;
case 2: case 2:
sf.Find<uint16_t,uint16_t>(test1,alignment,found,newfound, equalityP<uint16_t>); sf.Find<uint16_t,uint16_t>(test1,alignment,found, equalityP<uint16_t>);
break; break;
case 4: case 4:
sf.Find<uint32_t,uint32_t>(test1,alignment,found,newfound, equalityP<uint32_t>); sf.Find<uint32_t,uint32_t>(test1,alignment,found, equalityP<uint32_t>);
break; break;
} }
if( found.size() == 1) if( found.size() == 1)
@ -263,9 +261,7 @@ void searchLoopVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange
vecTriplet load; vecTriplet load;
uint32_t length; uint32_t length;
vector <uint64_t> found; vector <uint64_t> found;
vector <uint64_t> newfound; found.reserve(100);
found.reserve(100000);
newfound.reserve(100000);
//bool initial = 1; //bool initial = 1;
cout << "search ready - insert vector length" << endl; cout << "search ready - insert vector length" << endl;
string select; string select;
@ -291,8 +287,8 @@ void searchLoopVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange
// clear the list of found addresses // clear the list of found addresses
found.clear(); found.clear();
SegmentedFinder sf(ranges,DF); SegmentedFinder sf(ranges,DF);
sf.Find<int ,vecTriplet>(0,4,found,newfound, vectorAll); sf.Find<int ,vecTriplet>(0,4,found,vectorAll);
sf.Find<uint32_t,vecTriplet>(length*element_size,4,found,newfound, vectorLength<uint32_t>); sf.Find<uint32_t,vecTriplet>(length*element_size,4,found,vectorLength<uint32_t>);
if( found.size() == 1) if( found.size() == 1)
{ {
cout << "Found an address!" << endl; cout << "Found an address!" << endl;
@ -313,9 +309,6 @@ void searchLoopVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange
void searchLoopStrObjVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges) void searchLoopStrObjVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{ {
vector <uint64_t> found; vector <uint64_t> found;
vector <uint64_t> newfound;
found.reserve(100000);
newfound.reserve(100000);
cout << "search ready - insert string" << endl; cout << "search ready - insert string" << endl;
string select; string select;
while (1) while (1)
@ -340,8 +333,8 @@ void searchLoopStrObjVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_me
// clear the list of found addresses // clear the list of found addresses
found.clear(); found.clear();
SegmentedFinder sf(ranges,DF); SegmentedFinder sf(ranges,DF);
sf.Find<int ,vecTriplet>(0,4,found,newfound, vectorAll); sf.Find<int ,vecTriplet>(0,4,found, vectorAll);
sf.Find<const char * ,vecTriplet>(select.c_str(),4,found,newfound, vectorString); sf.Find<const char * ,vecTriplet>(select.c_str(),4,found, vectorString);
if( found.size() == 1) if( found.size() == 1)
{ {
cout << "Found an address!" << endl; cout << "Found an address!" << endl;
@ -362,9 +355,6 @@ void searchLoopStrObjVector(DFHack::ContextManager & DFMgr, vector <DFHack::t_me
void searchLoopStr(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges) void searchLoopStr(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{ {
vector <uint64_t> found; vector <uint64_t> found;
vector <uint64_t> newfound;
found.reserve(1000);
newfound.reserve(1000);
cout << "search ready - insert string" << endl; cout << "search ready - insert string" << endl;
string select; string select;
while (1) while (1)
@ -389,7 +379,7 @@ void searchLoopStr(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>&
// clear the list of found addresses // clear the list of found addresses
found.clear(); found.clear();
SegmentedFinder sf(ranges,DF); SegmentedFinder sf(ranges,DF);
sf.Find< const char * ,uint32_t>(select.c_str(),1,found,newfound, findString); sf.Find< const char * ,uint32_t>(select.c_str(),1,found, findString);
if( found.size() == 1) if( found.size() == 1)
{ {
cout << "Found a string!" << endl; cout << "Found a string!" << endl;
@ -482,7 +472,7 @@ int main (void)
printRange(&(selected_ranges[i])); printRange(&(selected_ranges[i]));
} }
try_again_type: try_again_type:
cout << "Select search type: 1=number(default), 2=vector, 3=vector>object>string, 4=string" << endl; cout << "Select search type: 1=number(default), 2=vector, 3=vector>object>string, 4=string, 5=automated lang tables" << endl;
cout << ">>"; cout << ">>";
std::getline(cin, select); std::getline(cin, select);
int mode; int mode;
@ -492,7 +482,7 @@ int main (void)
} }
else if( sscanf(select.c_str(), "%d", &mode) == 1 ) else if( sscanf(select.c_str(), "%d", &mode) == 1 )
{ {
if(mode != 1 && mode != 2 && mode != 3 && mode != 4) if(mode != 1 && mode != 2 && mode != 3 && mode != 4 && mode != 5)
{ {
goto try_again_type; goto try_again_type;
} }
@ -501,6 +491,7 @@ int main (void)
{ {
goto try_again_type; goto try_again_type;
} }
if(mode == 1) if(mode == 1)
{ {
// input / validation of variable size // input / validation of variable size
@ -585,6 +576,52 @@ int main (void)
{ {
searchLoopStr(DFMgr, selected_ranges); searchLoopStr(DFMgr, selected_ranges);
} }
else if(mode == 5) // find lang tables and stuff
{
vector <uint64_t> allVectors;
vector <uint64_t> to_filter;
uint64_t kulet_vector;
uint64_t word_table_offset;
uint64_t DWARF_vector;
uint64_t DWARF_object;
cout << "Creating finder..." << endl;
SegmentedFinder sf(selected_ranges, DF);
// enumerate all vectors
cout << "enumerating vectors..." << endl;
sf.Find<int ,vecTriplet>(0,4,allVectors, vectorAll);
cout << "done." << endl;
// find lang vector (neutral word table)
to_filter = allVectors;
cout << "searching for lang vector" << endl;
sf.Find<const char * ,vecTriplet>("ABBEY",4,to_filter, vectorString);
uint64_t lang_addr = to_filter[0];
cout << "lang vector: " << hex << "0x" << lang_addr << endl;
// find dwarven language word table
to_filter = allVectors;
sf.Find<const char * ,vecTriplet>("kulet",4,to_filter, vectorString);
kulet_vector = to_filter[0];
to_filter = allVectors;
// find vector of languages
sf.Find<const char * ,vecTriplet>("DWARF",4,to_filter, vectorString);
// verify
for(int i = 0; i < to_filter.size(); i++)
{
vecTriplet * vec = (vecTriplet *) sf.translate(to_filter[i]);
if(((vec->finish - vec->start) / 4) == 4)
{
// verified, print the vector address
DWARF_vector = to_filter[i];
cout << "translation vector: " << hex << "0x" << DWARF_vector << endl;
DWARF_object = *(uint32_t *) sf.translate(vec->start);
// compute word table offset from dwarf word table and dwarf language object addresses
word_table_offset = kulet_vector - DWARF_object;
cout << "word table offset: " << hex << "0x" << word_table_offset << endl;
break;
}
}
}
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();