Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Once again, I have problem.

I created an DLL that sets few hooks into target application. But I have problem with one function. Let's call it ParseData.
I hooked this function and any data coming through are displayed in ListCtrl.
I have 3 classes that actually calls this function.
The first master class passes address of the ParseData to 2 remaining classes.
Like:

...
*(DWORD*)&ParseData = m_pParseDataAddress; // Set the function call for MasterClass 
m_SomeDlg->SetParseDataFunction(m_pParseDataAddress); // Pass the addr to class 2
m_Para.SetParseDataFunction(m_pParseDataAddress); // Pass the addr to class 3
...


When m_SomeDlg calls ParseData, it goes though hook and data are displayed in ListCtrl.

m_Para however creates new thread at some point via command:
...
// IN COMMAND HANDLER
	if( strcmp(chCommand, "Load") == 0)
	{
		Init();
		m_bActivated = true;
		_beginthread((void (__cdecl *)(void *))&ProcThreadAddr, 0, (void*)this);
	}
...


void __cdecl CPara::ProcThreadAddr(CPara * ParaPtr)
{
	ParaPtr->MainThread();
	_endthread();
}


In MainThread there is a while loop which checks if m_bActivated = true.
However any calls to ParseData from this thread aren't displayed in hook (Data is parsed however)

When I call ParseData from any place, data is displayed in hook, but when I call it from MainThread it doesn't display anything.

That's actually pretty strange for me.

Thank you for your help.
Posted

1 solution

Agghhh, I guess I know the problem now. All the precious time I lost... Damn it.

Anyways - Let me explain the solution/problem for any other coders that might have same issue:

I'm not using regular breakpoints or detour/jmp. I'm using Hardware breakpoints. However those breakpoints are set into thread context. And because the new thread is created after setting up hooks, it doesn't contain hardware breakpoints.

How I found what's wrong? I simply passed address of hook to m_Para class.
m_Para.SetParseDataFunction(&ParseDataHook);
 
Share this answer
 
Comments
mbue 29-Dec-10 20:58pm    
you should wait in command until the running thread has finnished. start the thread by calling CreateThread to get a waitable object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900