From 4bcd653732c772bbed49d7828c19f328a6cd3a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 13 Apr 2010 14:18:09 +0200 Subject: [PATCH] 0.3.1.2 tag, fixes for attach on Windows --- dfhack/DFProcess-windows.cpp | 20 +++++++++++++++----- examples/suspendtest.cpp | 1 - 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dfhack/DFProcess-windows.cpp b/dfhack/DFProcess-windows.cpp index 00a3b56d2..7ac82aca9 100644 --- a/dfhack/DFProcess-windows.cpp +++ b/dfhack/DFProcess-windows.cpp @@ -82,11 +82,21 @@ NormalProcess::NormalProcess(uint32_t pid, vector & known_versio // temporarily assign this to allow some checks d->my_handle = hProcess; + d->my_main_thread = 0; // 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 ); - d->my_handle = 0; + try + { + 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 ); + d->my_handle = 0; + } + catch (exception &) + { + CloseHandle(hProcess); + d->my_handle = 0; + return; + } // see if there's a version entry that matches this process vector::iterator it; @@ -356,7 +366,7 @@ void NormalProcess::readDWord (const uint32_t offset, uint32_t &result) void NormalProcess::read (const uint32_t offset, uint32_t size, uint8_t *target) { - if(ReadProcessMemory(d->my_handle, (int*) offset, target, size, NULL)) + if(!ReadProcessMemory(d->my_handle, (int*) offset, target, size, NULL)) throw Error::MemoryAccessDenied(); } diff --git a/examples/suspendtest.cpp b/examples/suspendtest.cpp index 9e89a2e93..70cbe1816 100644 --- a/examples/suspendtest.cpp +++ b/examples/suspendtest.cpp @@ -27,7 +27,6 @@ int main (void) #endif return 1; } - cout << "Attached, DF should be suspended now" << endl; getline(cin, blah);