Offset stuff

develop
Petr Mrázek 2010-09-18 04:36:14 +02:00
parent 38f50f4a46
commit dfdd1467ff
5 changed files with 125 additions and 68 deletions

@ -674,6 +674,22 @@
</Group> </Group>
<Group name="string" description="An STL string."> <Group name="string" description="An STL string.">
<HexValue name="sizeof" description="The total size in bytes." /> <HexValue name="sizeof" description="The total size in bytes." />
<Group name="MSVC">
<!--
MSVC++ 9 string
void * allocator
union
{
char[16] start;
char * start_ptr
}
Uint32 length
Uint32 capacity
-->
<Offset name="buffer" description="Where the buffer/pointer starts." />
<Offset name="size" description="Where the number of leters is stored (string length without 0-terminator)." />
<Offset name="capacity" description="Capacity of the buffer in letters (default=15)." />
</Group>
</Group> </Group>
<Group name="name" description="A structure used for names all over the place."> <Group name="name" description="A structure used for names all over the place.">
<Offset name="first" description="Lowercase stl string with the first name. For ex. 'urist'" /> <Offset name="first" description="Lowercase stl string with the first name. For ex. 'urist'" />
@ -938,6 +954,11 @@
</Group> </Group>
<Group name="string"> <Group name="string">
<HexValue name="sizeof" value="0x1C" /> <HexValue name="sizeof" value="0x1C" />
<Group name="MSVC">
<Offset name="buffer" value="0x4" />
<Offset name="size" value="0x14" />
<Offset name="capacity" value="0x18" />
</Group>
</Group> </Group>
<Group name="name"> <Group name="name">
<Offset name="first" value="0x0" /> <Offset name="first" value="0x0" />
@ -1217,7 +1238,6 @@
</Group> </Group>
<Group name="Materials"> <Group name="Materials">
<Address name="inorganics" value="0x16B0D4C" /><!--inorganics vector = WORLD + 0x54B7C = 0x16B0D4C--> <Address name="inorganics" value="0x16B0D4C" /><!--inorganics vector = WORLD + 0x54B7C = 0x16B0D4C-->
<!--<Address name="other" value="0x16BA114" /> --> <!-- stuff like glass, coke, ... -->
<Address name="organics_all" value="0x16B0D64" /><!--WORLD + 0x54B94--> <Address name="organics_all" value="0x16B0D64" /><!--WORLD + 0x54B94-->
<Address name="organics_plants" value="0x16B0D7C" /><!--plant matter, WORLD + 0x54BAC--> <Address name="organics_plants" value="0x16B0D7C" /><!--plant matter, WORLD + 0x54BAC-->
<Address name="organics_trees" value="0x16B0DAC" /><!--just wood, WORLD + 0x54BDC--> <Address name="organics_trees" value="0x16B0DAC" /><!--just wood, WORLD + 0x54BDC-->
@ -1472,6 +1492,14 @@
NOT FINAL, needs research NOT FINAL, needs research
--> -->
</Group> </Group>
<Group name="string">
<HexValue name="sizeof" value="0x1C" />
<Group name="MSVC">
<Offset name="buffer" value="0x0" />
<Offset name="size" value="0x10" />
<Offset name="capacity" value="0x14" />
</Group>
</Group>
0x01482874 - current race 0x01482874 - current race
<Group name="Position"> <Group name="Position">
<Address name="cursor_xyz" value="0xac77f0" /> <Address name="cursor_xyz" value="0xac77f0" />
@ -1552,14 +1580,46 @@
--> -->
</Group> </Group>
</Group> </Group>
<Group name="Materials"> <Group name="Materials">
<Address name="inorganics" value="0x1699f18 0x16BD0B0" /> <Address name="inorganics" value="0x1699f14 0x16BD0B0" />
<Address name="organics_all" value="0x16BD0C8" /> <Address name="organics_all" value="0x1699f24 0x16BD0C8" />
<Address name="organics_plants" value="0x16bd0e0" /> <Address name="organics_trees" value="0x1699f54 0x16bd110" />
<Address name="organics_trees" value="0x16bd110" /> <Address name="organics_plants" value="0x1699f34 0x16bd0e0" />
<Address name="creature_type_vector" value="0x16BD204" /> <Address name="creature_type_vector" value="0x1699ff8 0x16BD204" />
<Address name="other" value="0x16C6478"/> <Address name="other" value="0x16C6478" invalid="true"/>
<Group name="creature">
<Offset name="caste_vector" value="0x138" />
<Offset name="extract_vector" value="0x1A14" />
<Offset name="tile" value="0xE0" />
<Offset name="tile_color" value="0xF6" />
<Group name="caste">
<Offset name="bodypart_vector" value="0x51C" />
<Offset name="attributes" value="0x654" />
<Offset name="color_modifiers" value="0xACC" />
</Group>
<Group name="caste_color_mods">
<Offset name="part" value="0x70" />
<Offset name="startdate" value="0x64" />
<Offset name="enddate" value="0x68" />
</Group>
<Group name="caste_bodyparts">
<Offset name="id" value="0x0" />
<Offset name="category" value="0x1C" />
<Offset name="layers_vector" value="0x44" />
<Offset name="singular_vector" value="0x78" />
<Offset name="plural_vector" value="0x90" />
</Group>
</Group>
<Group name="descriptors">
<Address name="vectors_start" value="0x16B9780" />
<Offset name="rawname" value="0x0" />
<Offset name="name" value="0x4C" />
<Address name="colors_vector" value="0x16B9768" />
<Offset name="color_r" value="0x6C" />
<Offset name="color_v" value="0x70" />
<Offset name="color_b" value="0x74" />
<Address name="all_colors_vector" value="0x16B9798" />
</Group>
<Group name="descriptors"> <Group name="descriptors">
<Address name="colors_vector" value="0x16C5ACC" /> <Address name="colors_vector" value="0x16C5ACC" />
<Address name="vectors_start" value="0x16C5AE4" /> <Address name="vectors_start" value="0x16C5AE4" />

@ -53,6 +53,9 @@ class WineProcess::Private
bool attached; bool attached;
bool suspended; bool suspended;
bool identified; 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 <VersionInfo *> & known_versions); bool validate(char * exe_file, uint32_t pid, char * mem_file, vector <VersionInfo *> & 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 // tell WineProcess about the /proc/PID/mem file
memFile = mem_file; memFile = mem_file;
identified = true; 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; 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) size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{ {
/* uint32_t start_offset = offset + d->STLSTR_buf_off;
MSVC++ string size_t length = readDWord(offset + d->STLSTR_size_off);
ptr allocator size_t capacity = readDWord(offset + d->STLSTR_cap_off);
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);
size_t read_real = min(length, bufcapacity-1);// keep space for null termination size_t read_real = min(length, bufcapacity-1);// keep space for null termination
// read data from inside the string structure // 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) const string WineProcess::readSTLString (uint32_t offset)
{ {
/* uint32_t start_offset = offset + d->STLSTR_buf_off;
MSVC++ string size_t length = readDWord(offset + d->STLSTR_size_off);
ptr allocator size_t capacity = readDWord(offset + d->STLSTR_cap_off);
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);
char * temp = new char[capacity+1]; char * temp = new char[capacity+1];
// read data from inside the string structure // read data from inside the string structure

@ -48,6 +48,9 @@ class NormalProcess::Private
bool attached; bool attached;
bool suspended; bool suspended;
bool identified; bool identified;
uint32_t STLSTR_buf_off;
uint32_t STLSTR_size_off;
uint32_t STLSTR_cap_off;
}; };
NormalProcess::NormalProcess(uint32_t pid, vector <VersionInfo *> & known_versions) NormalProcess::NormalProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
@ -134,7 +137,10 @@ NormalProcess::NormalProcess(uint32_t pid, vector <VersionInfo *> & known_versio
vector<uint32_t> threads; vector<uint32_t> threads;
getThreadIDs( threads ); getThreadIDs( threads );
d->my_main_thread = OpenThread(THREAD_ALL_ACCESS, FALSE, (DWORD) threads[0]); 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; found = true;
break; // break the iterator loop 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) size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
{ {
/* uint32_t start_offset = offset + d->STLSTR_buf_off;
MSVC++ string size_t length = readDWord(offset + d->STLSTR_size_off);
ptr allocator size_t capacity = readDWord(offset + d->STLSTR_cap_off);
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);
size_t read_real = min(length, bufcapacity-1);// keep space for null termination size_t read_real = min(length, bufcapacity-1);// keep space for null termination
// read data from inside the string structure // read data from inside the string structure
@ -464,20 +458,9 @@ Uint32 capacity
const string NormalProcess::readSTLString (uint32_t offset) const string NormalProcess::readSTLString (uint32_t offset)
{ {
/* uint32_t start_offset = offset + d->STLSTR_buf_off;
MSVC++ string size_t length = readDWord(offset + d->STLSTR_size_off);
ptr allocator size_t capacity = readDWord(offset + d->STLSTR_cap_off);
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);
char * temp = new char[capacity+1]; char * temp = new char[capacity+1];
// read data from inside the string structure // read data from inside the string structure

@ -311,4 +311,11 @@ bool findString (SegmentedFinder* s, uint32_t *addr, const char * compare )
return false; 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 #endif // SEGMENTED_FINDER_H

@ -482,6 +482,22 @@ void FindPtrVectorsByObjectAddress(DFHack::ContextManager & DFMgr, vector <DFHac
} }
} }
void FindStrBufs(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
vector <uint64_t> 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 <DFHack::t_memrange>& ranges) void FindStrings(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{ {
@ -799,12 +815,13 @@ int main (void)
string prompt = string prompt =
"Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n" "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" " 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; int mode;
do do
{ {
getNumber(prompt,mode, 1, false); getNumber(prompt,mode, 1, false);
} while (mode < 1 || mode > 8 ); } while (mode < 1 || mode > 9 );
switch (mode) switch (mode)
{ {
case 1: case 1:
@ -838,6 +855,10 @@ int main (void)
DF->Detach(); DF->Detach();
FindVectorByFirstObjectRawname(DFMgr, selected_ranges); FindVectorByFirstObjectRawname(DFMgr, selected_ranges);
break; break;
case 9:
DF->Detach();
FindStrBufs(DFMgr, selected_ranges);
break;
default: default:
cout << "not implemented :(" << endl; cout << "not implemented :(" << endl;
} }