sync, rearranging things in khazad

develop
Petr Mrázek 2009-09-15 20:46:45 +00:00
parent f14bd91545
commit 28fb6f5703
1 changed files with 60 additions and 41 deletions

@ -141,7 +141,7 @@ bool ProcessManager::findProcessess()
} }
// FIXME: this fails when the wine process isn't started from the 'current working directory'. strip path data from cmdline // FIXME: this fails when the wine process isn't started from the 'current working directory'. strip path data from cmdline
// DF in wine? // is this windows version of Df running in wine?
if(strstr(target_name, "wine-preloader")!= NULL) if(strstr(target_name, "wine-preloader")!= NULL)
{ {
// get working directory // get working directory
@ -232,51 +232,61 @@ bool ProcessManager::findProcessess()
for ( int i = 0; i < numProccesses; i++ ) for ( int i = 0; i < numProccesses; i++ )
{ {
found = false; found = false;
// open process // open process
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcArray[i] ); hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcArray[i] );
if (NULL == hProcess) if (NULL == hProcess)
continue; continue;
// we've got some process, look at its first module
if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk)) // try getting the first module of the process
if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0)
{ {
// TODO: check module filename to verify that it's DF! CloseHandle(hProcess);
// got base ;) continue;
uint32_t base = (uint32_t)hmod; }
// read from this process
g_ProcessHandle = hProcess; // got base ;)
uint32_t pe_offset = MreadDWord(base+0x3C); uint32_t base = (uint32_t)hmod;
Mread(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header);
Mread(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)&sections ); // read from this process
// see if there's a version entry that matches this process g_ProcessHandle = hProcess;
vector<memory_info>::iterator it; uint32_t pe_offset = MreadDWord(base+0x3C);
for ( it=meminfo.begin() ; it < meminfo.end(); it++ ) Mread(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header);
{ Mread(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)&sections );
// filter by OS
if(memory_info::OS_WINDOWS == (*it).getOS()) // see if there's a version entry that matches this process
{ vector<memory_info>::iterator it;
uint32_t pe_timestamp = (*it).getHexValue("pe_timestamp"); for ( it=meminfo.begin() ; it < meminfo.end(); it++ )
if (pe_timestamp == pe_header.FileHeader.TimeDateStamp) {
{ // filter by OS
printf("Match found! Using version %s.\n", (*it).getVersion().c_str()); if(memory_info::OS_WINDOWS != (*it).getOS())
// give the process a data model and memory layout fixed for the base of first module continue;
memory_info *m = new memory_info(*it);
m->RebaseAll(base); // filter by timestamp
// keep track of created memory_info objects so we can destroy them later uint32_t pe_timestamp = (*it).getHexValue("pe_timestamp");
destroy_meminfo.push_back(m); if (pe_timestamp != pe_header.FileHeader.TimeDateStamp)
// process is responsible for destroying its data model continue;
Process *ret= new Process(new DMWindows40d(),m,hProcess, ProcArray[i]);
processes.push_back(ret); // all went well
found = true;
break; // break the iterator loop
}
}
}
// close handle of processes that aren't DF
if(!found)
{ {
CloseHandle(hProcess); printf("Match found! Using version %s.\n", (*it).getVersion().c_str());
// give the process a data model and memory layout fixed for the base of first module
memory_info *m = new memory_info(*it);
m->RebaseAll(base);
// keep track of created memory_info objects so we can destroy them later
destroy_meminfo.push_back(m);
// process is responsible for destroying its data model
Process *ret= new Process(new DMWindows40d(),m,hProcess, ProcArray[i]);
processes.push_back(ret);
found = true;
break; // break the iterator loop
} }
} }
// close handle of processes that aren't DF
if(!found)
{
CloseHandle(hProcess);
}
} }
if(processes.size()) if(processes.size())
return true; return true;
@ -289,32 +299,39 @@ void ProcessManager::ParseVTable(TiXmlElement* vtable, memory_info& mem)
{ {
TiXmlElement* pClassEntry; TiXmlElement* pClassEntry;
TiXmlElement* pClassSubEntry; TiXmlElement* pClassSubEntry;
// check for rebase, do rebase if check positive
const char * rebase = vtable->Attribute("rebase"); const char * rebase = vtable->Attribute("rebase");
if(rebase) if(rebase)
{ {
int32_t rebase_offset = strtol(rebase, NULL, 16); int32_t rebase_offset = strtol(rebase, NULL, 16);
mem.RebaseVTable(rebase_offset); mem.RebaseVTable(rebase_offset);
} }
// parse vtable entries
pClassEntry = vtable->FirstChildElement(); pClassEntry = vtable->FirstChildElement();
for(;pClassEntry;pClassEntry=pClassEntry->NextSiblingElement()) for(;pClassEntry;pClassEntry=pClassEntry->NextSiblingElement())
{ {
string type = pClassEntry->Value(); string type = pClassEntry->Value();
const char *cstr_name = pClassEntry->Attribute("name"); const char *cstr_name = pClassEntry->Attribute("name");
const char *cstr_vtable = pClassEntry->Attribute("vtable"); const char *cstr_vtable = pClassEntry->Attribute("vtable");
// it's a simple class
if(type== "class") if(type== "class")
{ {
mem.setClass(cstr_name, cstr_vtable); mem.setClass(cstr_name, cstr_vtable);
} }
// it's a multi-type class
else if (type == "multiclass") else if (type == "multiclass")
{ {
// get offset of the type variable
const char *cstr_typeoffset = pClassEntry->Attribute("typeoffset"); const char *cstr_typeoffset = pClassEntry->Attribute("typeoffset");
int mclass = mem.setMultiClass(cstr_name, cstr_vtable, cstr_typeoffset); int mclass = mem.setMultiClass(cstr_name, cstr_vtable, cstr_typeoffset);
// parse class sub-entries
pClassSubEntry = pClassEntry->FirstChildElement(); pClassSubEntry = pClassEntry->FirstChildElement();
for(;pClassSubEntry;pClassSubEntry=pClassSubEntry->NextSiblingElement()) for(;pClassSubEntry;pClassSubEntry=pClassSubEntry->NextSiblingElement())
{ {
type = pClassSubEntry->Value(); type = pClassSubEntry->Value();
if(type== "class") if(type== "class")
{ {
// type is a value loaded from type offset
cstr_name = pClassSubEntry->Attribute("name"); cstr_name = pClassSubEntry->Attribute("name");
const char *cstr_value = pClassSubEntry->Attribute("type"); const char *cstr_value = pClassSubEntry->Attribute("type");
mem.setMultiClassChild(mclass,cstr_name,cstr_value); mem.setMultiClassChild(mclass,cstr_name,cstr_value);
@ -338,6 +355,7 @@ void ProcessManager::ParseEntry (TiXmlElement* entry, memory_info& mem, map <str
string base = cstr_base; string base = cstr_base;
ParseEntry(knownEntries[base], mem, knownEntries); ParseEntry(knownEntries[base], mem, knownEntries);
} }
// mandatory attributes missing? // mandatory attributes missing?
if(!(cstr_version && cstr_os)) if(!(cstr_version && cstr_os))
{ {
@ -374,6 +392,7 @@ void ProcessManager::ParseEntry (TiXmlElement* entry, memory_info& mem, map <str
cerr << "unknown operating system " << os << endl; cerr << "unknown operating system " << os << endl;
return; return;
} }
// process additional entries // process additional entries
//cout << "Entry " << cstr_version << " " << cstr_os << endl; //cout << "Entry " << cstr_version << " " << cstr_os << endl;
pMemEntry = entry->FirstChildElement()->ToElement(); pMemEntry = entry->FirstChildElement()->ToElement();
@ -427,9 +446,9 @@ bool ProcessManager::loadDescriptors(string path_to_xml)
{ {
TiXmlDocument doc( path_to_xml.c_str() ); TiXmlDocument doc( path_to_xml.c_str() );
bool loadOkay = doc.LoadFile(); bool loadOkay = doc.LoadFile();
TiXmlHandle hDoc(&doc); TiXmlHandle hDoc(&doc);
TiXmlElement* pElem; TiXmlElement* pElem;
TiXmlHandle hRoot(0); TiXmlHandle hRoot(0);
memory_info mem; memory_info mem;
if ( loadOkay ) if ( loadOkay )