From de32b65c114430e5de8d257266c881ae13ef7ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 12 Feb 2010 23:25:41 +0000 Subject: [PATCH] engraving offsets for linux d16, attempt to fix MSVC bugs --- library/DFProcess-windows-SHM.cpp | 203 +++++++++++++++--------------- output/Memory.xml | 5 + shmserver/shms-proto.cpp | 17 ++- tools/dfitemdump.cpp | 1 - 4 files changed, 124 insertions(+), 102 deletions(-) diff --git a/library/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp index dbe9ad552..fe58802ea 100644 --- a/library/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -153,109 +153,42 @@ SHMProcess::SHMProcess(vector & known_versions) char exe_link_name [256]; char target_name[1024]; int target_result; - // get server and client mutex - d->DFSVMutex = OpenMutex(SYNCHRONIZE,false, "DFSVMutex"); - if(d->DFSVMutex == 0) - { - return; - } - d->DFCLMutex = OpenMutex(SYNCHRONIZE,false, "DFCLMutex"); - if(d->DFCLMutex == 0) - { - return; - } - if(!attach()) - { - return; - } - - // All seems to be OK so far. Attached and connected to something that looks like DF - - // Test bridge version, will also detect when we connect to something that doesn't respond - bool bridgeOK; - if(!d->DF_TestBridgeVersion(bridgeOK)) - { - fprintf(stderr,"DF terminated during reading\n"); - UnmapViewOfFile(d->my_shm); - ReleaseMutex(d->DFCLMutex); - CloseHandle(d->DFSVMutex); - d->DFSVMutex = 0; - CloseHandle(d->DFCLMutex); - d->DFCLMutex = 0; - return; - } - if(!bridgeOK) + do { - fprintf(stderr,"SHM bridge version mismatch\n"); - ((shm_cmd *)d->my_shm)->pingpong = DFPP_RUNNING; - UnmapViewOfFile(d->my_shm); - ReleaseMutex(d->DFCLMutex); - CloseHandle(d->DFSVMutex); - d->DFSVMutex = 0; - CloseHandle(d->DFCLMutex); - d->DFCLMutex = 0; - return; - } - /* - * get the PID from DF - */ - if(d->DF_GetPID(d->my_pid)) - { - // try to identify the DF version - do // glorified goto - { - IMAGE_NT_HEADERS32 pe_header; - IMAGE_SECTION_HEADER sections[16]; - HMODULE hmod = NULL; - DWORD junk; - HANDLE hProcess; - bool found = false; - d->identified = false; - // open process, we only need the process open - hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, d->my_pid ); - if (NULL == hProcess) - break; - - // try getting the first module of the process - if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0) - { - CloseHandle(hProcess); - cout << "EnumProcessModules fail'd" << endl; - break; - } - // got base ;) - uint32_t base = (uint32_t)hmod; - - // read from this process - uint32_t pe_offset = readDWord(base+0x3C); - read(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header); - read(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)§ions ); - - // iterate over the list of memory locations - vector::iterator it; - for ( it=known_versions.begin() ; it < known_versions.end(); it++ ) - { - uint32_t pe_timestamp = (*it).getHexValue("pe_timestamp"); - if (pe_timestamp == pe_header.FileHeader.TimeDateStamp) - { - memory_info *m = new memory_info(*it); - m->RebaseAll(base); - d->my_datamodel = new DMWindows40d(); - d->my_descriptor = m; - d->identified = true; - cerr << "identified " << m->getVersion() << endl; - break; - } - } - CloseHandle(hProcess); - } while (0); // glorified goto end + // get server and client mutex + d->DFSVMutex = OpenMutex(SYNCHRONIZE,false, "DFSVMutex"); + if(d->DFSVMutex == 0) + { + break; + } + d->DFCLMutex = OpenMutex(SYNCHRONIZE,false, "DFCLMutex"); + if(d->DFCLMutex == 0) + { + break; + } + if(!attach()) + { + break; + } - if(d->identified) + // All seems to be OK so far. Attached and connected to something that looks like DF + + // Test bridge version, will also detect when we connect to something that doesn't respond + bool bridgeOK; + if(!d->DF_TestBridgeVersion(bridgeOK)) { - d->my_window = new DFWindow(this); + fprintf(stderr,"DF terminated during reading\n"); + UnmapViewOfFile(d->my_shm); + ReleaseMutex(d->DFCLMutex); + CloseHandle(d->DFSVMutex); + d->DFSVMutex = 0; + CloseHandle(d->DFCLMutex); + d->DFCLMutex = 0; + break; } - else + if(!bridgeOK) { + fprintf(stderr,"SHM bridge version mismatch\n"); ((shm_cmd *)d->my_shm)->pingpong = DFPP_RUNNING; UnmapViewOfFile(d->my_shm); ReleaseMutex(d->DFCLMutex); @@ -263,9 +196,79 @@ SHMProcess::SHMProcess(vector & known_versions) d->DFSVMutex = 0; CloseHandle(d->DFCLMutex); d->DFCLMutex = 0; - return; + break; } - } + /* + * get the PID from DF + */ + if(d->DF_GetPID(d->my_pid)) + { + // try to identify the DF version + do // glorified goto + { + IMAGE_NT_HEADERS32 pe_header; + IMAGE_SECTION_HEADER sections[16]; + HMODULE hmod = NULL; + DWORD junk; + HANDLE hProcess; + bool found = false; + d->identified = false; + // open process, we only need the process open + hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, d->my_pid ); + if (NULL == hProcess) + break; + + // try getting the first module of the process + if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0) + { + CloseHandle(hProcess); + cout << "EnumProcessModules fail'd" << endl; + break; + } + // got base ;) + uint32_t base = (uint32_t)hmod; + + // read from this process + uint32_t pe_offset = readDWord(base+0x3C); + read(base + pe_offset , sizeof(pe_header), (uint8_t *)&pe_header); + read(base + pe_offset+ sizeof(pe_header), sizeof(sections) , (uint8_t *)§ions ); + + // iterate over the list of memory locations + vector::iterator it; + for ( it=known_versions.begin() ; it < known_versions.end(); it++ ) + { + uint32_t pe_timestamp = (*it).getHexValue("pe_timestamp"); + if (pe_timestamp == pe_header.FileHeader.TimeDateStamp) + { + memory_info *m = new memory_info(*it); + m->RebaseAll(base); + d->my_datamodel = new DMWindows40d(); + d->my_descriptor = m; + d->identified = true; + cerr << "identified " << m->getVersion() << endl; + break; + } + } + CloseHandle(hProcess); + } while (0); // glorified goto end + + if(d->identified) + { + d->my_window = new DFWindow(this); + } + else + { + ((shm_cmd *)d->my_shm)->pingpong = DFPP_RUNNING; + UnmapViewOfFile(d->my_shm); + ReleaseMutex(d->DFCLMutex); + CloseHandle(d->DFSVMutex); + d->DFSVMutex = 0; + CloseHandle(d->DFCLMutex); + d->DFCLMutex = 0; + break; + } + } + } while (0); full_barrier // at this point, DF is attached and suspended, make it run detach(); diff --git a/output/Memory.xml b/output/Memory.xml index 8359d8cfb..f9bfd9c11 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1678,6 +1678,11 @@
0x8F35800
0x878493c
0x8f467e0
+ +
0x8f468c0
+ 0x0C + 0x20 + diff --git a/shmserver/shms-proto.cpp b/shmserver/shms-proto.cpp index 4e00275ae..8ea698524 100644 --- a/shmserver/shms-proto.cpp +++ b/shmserver/shms-proto.cpp @@ -158,7 +158,22 @@ void SHM_Act (void) fprintf(stderr, "no. of waits: %d\n", numwaits); //MessageBox(0,"Broke out of loop properly","FUN", MB_OK); break; - + + // client requests contents of STL string at address + /*case DFPP_READ_STL_STRING: + char * real = *(char **)((shm_read_small *)shm)->address; + strncpy(shm + SHM_HEADER,real,1024*1024-1); + full_barrier + ((shm_retval *)shm)->pingpong = DFPP_RET_STRING; + goto check_again; +*/ + // client requests contents of a C string at address, max length (0 means zero terminated) +/* case DFPP_READ_C_STRING: + break; + // sv -> cl length + string contents + // client wants to set STL string at address to something + case DFPP_WRITE_STL_STRING: + break;*/ default: ((shm_retval *)shm)->value = DFEE_INVALID_COMMAND; full_barrier diff --git a/tools/dfitemdump.cpp b/tools/dfitemdump.cpp index 6c44a79f5..15ced0c5f 100644 --- a/tools/dfitemdump.cpp +++ b/tools/dfitemdump.cpp @@ -92,7 +92,6 @@ int main () DF.ReadStoneMatgloss(mat.stoneMat); DF.ReadMetalMatgloss(mat.metalMat); DF.ReadCreatureMatgloss(mat.creatureMat); - DF.ForceResume(); vector objecttypes; DF.getClassIDMapping(objecttypes);