Skip to content
Browse files

0.3.1.2 tag, fixes for attach on Windows

  • Loading branch information...
1 parent 81cf60c commit 4bcd653732c772bbed49d7828c19f328a6cd3a79 @peterix peterix committed Apr 13, 2010
Showing with 15 additions and 6 deletions.
  1. +15 −5 dfhack/DFProcess-windows.cpp
  2. +0 −1 examples/suspendtest.cpp
View
20 dfhack/DFProcess-windows.cpp
@@ -82,11 +82,21 @@ NormalProcess::NormalProcess(uint32_t pid, vector <memory_info *> & 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 *)&sections );
- 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 *)&sections );
+ 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<memory_info*>::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();
}
View
1 examples/suspendtest.cpp
@@ -27,7 +27,6 @@ int main (void)
#endif
return 1;
}
-
cout << "Attached, DF should be suspended now" << endl;
getline(cin, blah);

0 comments on commit 4bcd653

Please sign in to comment.
Something went wrong with that request. Please try again.