Click here to Skip to main content
15,914,016 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: c++ win32 CreateThread, Wait, final testing Pin
jkirkerx1-May-12 6:59
professionaljkirkerx1-May-12 6:59 
AnswerRe: c++ win32 CreateThread, Wait, final testing Pin
Albert Holguin2-May-12 5:35
professionalAlbert Holguin2-May-12 5:35 
AnswerI've traced it down to this Pin
jkirkerx1-May-12 13:55
professionaljkirkerx1-May-12 13:55 
GeneralSolved Now Pin
jkirkerx1-May-12 17:35
professionaljkirkerx1-May-12 17:35 
AnswerRe: Solved Now Pin
Albert Holguin1-May-12 18:22
professionalAlbert Holguin1-May-12 18:22 
GeneralRe: Solved Now Pin
jkirkerx1-May-12 18:33
professionaljkirkerx1-May-12 18:33 
GeneralRe: Solved Now Pin
Albert Holguin2-May-12 5:36
professionalAlbert Holguin2-May-12 5:36 
Question[Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
_Kel_30-Apr-12 12:24
_Kel_30-Apr-12 12:24 
First time on this forum. Hello Smile | :)

I wish my first post was shorter.
And forgive the obscure title. It's hard to nail it short - I don't even know what the actual problem is.

Here's a quick description of what happens:

1) My_exe launches a 3rd_party_exe via CreateProcess(). The main process thread is in a suspended state.

2) I WriteProcessMemory() in the 3rd_party_exe process, and copy in it an absolute path, pointing to a dll I wrote.

3) I CreateRemoteThread() to have the dll loaded. It's the trite and dull LoadLibraryA() method everybody knows.
This secondary thread is created not suspended.

4) I do stuff... My_exe opens a named and synchronous pipe. My dll inside 3rd_party_exe will connect to it. My_exe writes down the pipe a path pointing to a text file. My dll inside 3rd_party_exe retrieves such path, then closes the pipe. Control is back to My_exe, which disconnects the pipe and closes the handle. No errors. Never an error.

5) My_exe now WaitForSingleObject() that the (remote) thread from point 3 gracefully comes to an end. And it always does. When that thread is done, my DllMain() has returned. I do not unload my dll from the 3rd_party_exe process. I need it to stay loaded.

6) Time to cleanup. With the remote thread closed, the memory I wrote in the process is no longer needed. So I call VirtualfreeEx() to deallocate it.

7) Only now I let the main process thread run (remember? it was kept 'suspended' since CreateProcess()).

8) I do not need to wait for 3rd_party_exe to terminate. My_exe can close. I CloseHandle() the main thread handle and the process handle (from CreateProcess()), in that order.

9) End.


What I described works -- *almost* always.
I check for errors after every API call.
When there's a problem it's VirtualFreeEx() (from point 6) reporting Access Violation (0xc0000005).

The puzzling thing is that WriteProcessMemory() is always successful. You see, I wouldn't advance all the way to VirtualFreeEx() otherwise Confused | :confused:

Any idea what might be causing this?

I can repeat this procedure on a number of 3rd_party_exe programs. None crashes, except the one that does (lol, sorry).
I thought that perhaps this crashy program is doing something special as it starts... something that prevents me from accessing my own memory (the one from WriteProcessMemory())... but then I thought that it can't be, as the error occurs _before_ I even resume the main process thread.
How would it be interfering??

Help.
AnswerRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
Richard Andrew x6430-Apr-12 12:54
professionalRichard Andrew x6430-Apr-12 12:54 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
_Kel_30-Apr-12 13:18
_Kel_30-Apr-12 13:18 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
Richard Andrew x6430-Apr-12 13:22
professionalRichard Andrew x6430-Apr-12 13:22 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
_Kel_30-Apr-12 14:30
_Kel_30-Apr-12 14:30 
GeneralRe: [Win32 C++] VirtualFreeEx() error after WriteProcessMemory() success. But not always. Pin
Richard Andrew x6430-Apr-12 14:43
professionalRichard Andrew x6430-Apr-12 14:43 
QuestionOnInitDialog? Pin
Le Quang Long30-Apr-12 4:38
Le Quang Long30-Apr-12 4:38 
AnswerRe: OnInitDialog? Pin
Maximilien30-Apr-12 5:03
Maximilien30-Apr-12 5:03 
GeneralRe: OnInitDialog? Pin
Le Quang Long30-Apr-12 6:20
Le Quang Long30-Apr-12 6:20 
QuestionRe: OnInitDialog? Pin
David Crow30-Apr-12 6:07
David Crow30-Apr-12 6:07 
AnswerRe: OnInitDialog? Pin
Le Quang Long30-Apr-12 14:11
Le Quang Long30-Apr-12 14:11 
QuestionRestrict Copy and Paste Pin
john563229-Apr-12 18:35
john563229-Apr-12 18:35 
AnswerRe: Restrict Copy and Paste Pin
_AnsHUMAN_ 29-Apr-12 22:29
_AnsHUMAN_ 29-Apr-12 22:29 
AnswerRe: Restrict Copy and Paste Pin
JohnCz2-May-12 11:09
JohnCz2-May-12 11:09 
QuestionHow to setup the project settings when create an x64 project in cs2008? Pin
SAMZCN29-Apr-12 17:27
SAMZCN29-Apr-12 17:27 
AnswerRe: How to setup the project settings when create an x64 project in cs2008? Pin
Lakamraju Raghuram29-Apr-12 17:56
Lakamraju Raghuram29-Apr-12 17:56 
GeneralRe: How to setup the project settings when create an x64 project in cs2008? Pin
SAMZCN30-Apr-12 1:06
SAMZCN30-Apr-12 1:06 
GeneralRe: How to setup the project settings when create an x64 project in cs2008? Pin
Randor 30-Apr-12 2:42
professional Randor 30-Apr-12 2:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.